From 13a40ddc59ad23b280abb0e6d1a28cfe40ab4df3 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Tue, 10 Jun 2025 09:43:08 +0300 Subject: [PATCH 1/9] Cache saga cont'd --- ets-tests/package.json | 2 +- ui2abc/libarkts/src-host/es2panda.ts | 55 ++++++++++++------- .../libarkts/src/arkts-api/peers/Context.ts | 50 ++++++++++++++++- .../src/arkts-api/utilities/private.ts | 7 +-- ui2abc/libarkts/src/plugin-utils.ts | 29 +++++++++- 5 files changed, 113 insertions(+), 30 deletions(-) diff --git a/ets-tests/package.json b/ets-tests/package.json index 94034c3b9..f9528e9c9 100644 --- a/ets-tests/package.json +++ b/ets-tests/package.json @@ -12,7 +12,7 @@ "clean:all": "npm run clean && npm run clean:all --prefix ../arkoala-arkts", "copy:deps:m3": "npm run copy:arkoala:m3 -C ../arkoala-arkts && mkdir -p ../arkoala-arkts/build/bootPandaFiles && cp ../incremental/harness/build/harness.abc ../arkoala-arkts/build/bootPandaFiles/", "build:deps:m3": "npm run compile:native:node-host -C ../arkoala-arkts && npm run build:arkoala:m3 -C ../arkoala-arkts && npm run build:harness:inc:ui2abc -C ../incremental/harness && npm run build:loader:node -C ../arkoala-arkts && npm run copy:deps:m3", - "compile:m3": "node ../ui2abc/fast-arktsc --group-by 5 --config ./ui2abcconfig-m3.json --compiler ../incremental/tools/panda/arkts/ui2abc --link-name ./build/tests-m3.abc && ninja ${NINJA_OPTIONS} -f build/ets-m3/abc/build.ninja", + "compile:m3": "node ../ui2abc/fast-arktsc --group-by 2 --config ./ui2abcconfig-m3.json --compiler ../incremental/tools/panda/arkts/ui2abc --link-name ./build/tests-m3.abc && ninja ${NINJA_OPTIONS} -f build/ets-m3/abc/build.ninja", "run:m3": "npm run compile:m3 && mkdir -p ../arkoala-arkts/build/userPandaFiles && cp ./build/tests-m3.abc ../arkoala-arkts/build/userPandaFiles/ && cd ../arkoala-arkts && ACE_LIBRARY_PATH=build PANDA_HOME=../incremental/tools/panda/node_modules/@panda/sdk node build/index.js panda:tests=StateIncrement", "all:m3": "npm run build:deps:m3 && npm run run:m3", "check": "npm run compile --prefix ../ui2abc/ui-plugins && npm run run:m3" diff --git a/ui2abc/libarkts/src-host/es2panda.ts b/ui2abc/libarkts/src-host/es2panda.ts index 454729f48..20822b667 100644 --- a/ui2abc/libarkts/src-host/es2panda.ts +++ b/ui2abc/libarkts/src-host/es2panda.ts @@ -15,7 +15,7 @@ import * as fs from "node:fs" import * as path from "node:path" -import { checkSDK, arktsGlobal as global, metaDatabase, runTransformer, CompilationOptions } from "@koalaui/libarkts" +import { checkSDK, arktsGlobal as global, metaDatabase, runTransformer, CompilationOptions, GlobalContext } from "@koalaui/libarkts" import { CheckedBackFilter, PluginContextImpl } from "@koalaui/libarkts" import { Command } from "commander" import { filterSource, isNumber, throwError, withWarning } from "@koalaui/libarkts" @@ -141,7 +141,32 @@ function restartCompiler(source: string, configPath: string, filePath: string, s } const defaultPandaSdk = "../../../incremental/tools/panda/node_modules/@panda/sdk" + +function stdlib(): string { + const sdk = process.env.PANDA_SDK_PATH ?? withWarning( + defaultPandaSdk, + `PANDA_SDK_PATH not set, assuming ${defaultPandaSdk}` + ) + return `${sdk}/ets/stdlib` +} + +function createConfig(configPath: string, filePath: string, outputPath: string): Config { + return Config.create([ + '_', + '--arktsconfig', + configPath, + filePath, + '--extension', + 'ets', + '--stdlib', + stdlib(), + '--output', + outputPath + ]) +} + function invokeWithPlugins( + globalContext: GlobalContext, configPath: string, filePath: string, outputPath: string, @@ -152,31 +177,20 @@ function invokeWithPlugins( pluginNames: string[], pluginContext: PluginContextImpl ): void { - const sdk = process.env.PANDA_SDK_PATH ?? withWarning( - defaultPandaSdk, - `PANDA_SDK_PATH not set, assuming ${defaultPandaSdk}` - ) - const stdlib = `${sdk}/ets/stdlib` - global.filePath = filePath const compilerConfig = Config.create([ '_', '--arktsconfig', configPath, filePath, - '--extension', - 'ets', - '--stdlib', - stdlib, - '--output', outputPath - ]) + ) global.config = compilerConfig.peer if (!global.configIsInitialized()) throw new Error(`Wrong config: path=${configPath} file=${filePath} stdlib=${stdlib} output=${outputPath}`) console.log(outputPath) fs.mkdirSync(path.dirname(outputPath), {recursive: true}) - const compilerContext = Context.createFromFile(filePath, configPath, stdlib, outputPath)! + const compilerContext = Context.createCacheFromFile(filePath, configPath, stdlib(), globalContext, true)! global.compilerContext = compilerContext pluginNames.push(`_proceed_to_binary`) @@ -199,7 +213,7 @@ function invokeWithPlugins( } pluginsApplied++ const before = Date.now() - restartCompiler(fs.readFileSync(filePath, 'utf-8'), newConfigPath, newFilePath, stdlib, outputPath) + restartCompiler(fs.readFileSync(filePath, 'utf-8'), newConfigPath, newFilePath, stdlib(), outputPath) const after = Date.now() configPath = newConfigPath filePath = newFilePath @@ -216,7 +230,7 @@ function invokeWithPlugins( const options = Options.createOptions(new Config(global.config)) global.arktsconfig = options.getArkTsConfig() - + console.log("COMPILATION STARTED") dumpArkTsConfigInfo(global.arktsconfig) dumpProgramInfo(compilerContext.program) @@ -228,7 +242,7 @@ function invokeWithPlugins( restartProcedure(Es2pandaContextState.ES2PANDA_STATE_PARSED) } }) - + if (!terminate) { proceedToState(Es2pandaContextState.ES2PANDA_STATE_BOUND) global.profiler.curContextState = Es2pandaContextState.ES2PANDA_STATE_BOUND @@ -327,14 +341,17 @@ export function main() { const pluginNames = plugins.map((it: any) => `${it.name}-${it.stage}`) const pluginContext = new PluginContextImpl() const pluginsByState = readAndSortPlugins(configDir, plugins) - + const globalConfig = createConfig(configPath, files[0], outDir) + const globalContext = GlobalContext.create(globalConfig, files) for (var i = 0; i < files.length; i++) { global.profiler.compilationStarted(files[i]) - invokeWithPlugins(configPath, files[i], outputs[i], pluginsByState, dumpAst, restartStages, stage, pluginNames, pluginContext) + invokeWithPlugins(globalContext, configPath, files[i], outputs[i], pluginsByState, dumpAst, restartStages, stage, pluginNames, pluginContext) global.profiler.compilationEnded() global.profiler.report() global.profiler.reportToFile(true) } + globalContext.destroy() + globalConfig.destroy() } function reportErrorAndExit(message: string): never { diff --git a/ui2abc/libarkts/src/arkts-api/peers/Context.ts b/ui2abc/libarkts/src/arkts-api/peers/Context.ts index f4b72224a..2f93c7217 100644 --- a/ui2abc/libarkts/src/arkts-api/peers/Context.ts +++ b/ui2abc/libarkts/src/arkts-api/peers/Context.ts @@ -16,10 +16,35 @@ import { ArktsObject } from "./ArktsObject" import { Program } from "../../generated" import { global } from "../static/global" -import { passString } from "../utilities/private" +import { passString, passStringArray } from "../utilities/private" import { KNativePointer, nullptr } from "@koalaui/interop" import { Config } from "./Config" -import * as fs from "fs" + +export class GlobalContext extends ArktsObject { + static create( + config: Config, externalFileList: string[] + ): GlobalContext { + return new GlobalContext( + global.es2panda._CreateGlobalContext( + config.peer, + passStringArray(externalFileList), + externalFileList.length, + false + ) + ) + } + + constructor(peer: KNativePointer) { + super(peer) + } + + destroy() { + if (this.peer != nullptr) { + global.es2panda._DestroyGlobalContext(this.peer) + this.peer = nullptr + } + } +} export class Context extends ArktsObject { constructor(peer: KNativePointer) { @@ -62,6 +87,27 @@ export class Context extends ArktsObject { ) } + static createCacheFromFile(filePath: string, configPath: string, stdlibPath: string, globalContext: GlobalContext, isExternal: boolean) { + const config = Config.create([ + "", + "--arktsconfig", + configPath, + '--extension', + 'ets', + '--stdlib', + stdlibPath, + filePath + ]) + return new Context( + global.es2panda._CreateCacheContextFromFile( + config.peer, + passString(filePath), + globalContext.peer, + isExternal + ) + ) + } + destroy() { if (this.peer != nullptr) { global.es2panda._DestroyContext(this.peer) diff --git a/ui2abc/libarkts/src/arkts-api/utilities/private.ts b/ui2abc/libarkts/src/arkts-api/utilities/private.ts index d8a52263c..be5bb4775 100644 --- a/ui2abc/libarkts/src/arkts-api/utilities/private.ts +++ b/ui2abc/libarkts/src/arkts-api/utilities/private.ts @@ -119,15 +119,10 @@ export function unpackString(peer: KNativePointer): string { return global.interop._RawUtf8ToString(peer) } -// TODO: use direct string arguments instead. export function passString(str: string | undefined): string { - if (str === undefined) { - return "" - } - return withString(str, (it: string) => it) + return str ?? "" } - // TODO: use direct string arguments instead. export function passStringArray(strings: readonly string[]): string[] { return withStringArray(strings, (it: string[]) => it) diff --git a/ui2abc/libarkts/src/plugin-utils.ts b/ui2abc/libarkts/src/plugin-utils.ts index 355671af9..4c7485cf0 100644 --- a/ui2abc/libarkts/src/plugin-utils.ts +++ b/ui2abc/libarkts/src/plugin-utils.ts @@ -33,6 +33,17 @@ export interface RunTransformerHooks { onProgramTransformEnd?(options: CompilationOptions): void } +class ASTCache { + processedPrograms = new Set() + constructor() {} + find(program: Program): boolean { + return this.processedPrograms.has(program.absoluteName) + } + update(program: Program) { + this.processedPrograms.add(program.absoluteName) + } +} + export function runTransformer(prog: Program, state: Es2pandaContextState, restart: boolean, transform: ProgramTransformer | undefined, pluginContext: PluginContext, hooks: RunTransformerHooks = {}, onlyModifyMain: boolean = false) { // Program provider used to provide programs to transformer dynamically relative to inserted imports const provider = new ProgramProvider(prog) @@ -41,6 +52,13 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta let currentProgram = provider.next() let isMainProgram = true + let cache = pluginContext.parameter("ASTCache") + if (!cache) { + cache = new ASTCache() + pluginContext.setParameter("ASTCache", cache) + } + + while (currentProgram) { // Options passed to plugin and hooks const options: CompilationOptions = { @@ -54,7 +72,7 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta // AST to be transformed const ast = currentProgram.ast - + // Save currently existing imports in the program const importStorage = new ImportStorage(currentProgram, state == Es2pandaContextState.ES2PANDA_STATE_PARSED) @@ -63,7 +81,14 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta // Run the plugin itself if (options.isMainProgram || !onlyModifyMain) { - transform?.(currentProgram, options, pluginContext) + if (!cache.find(currentProgram)) { + //console.log(`APPLY TRANSFORMATION FOR ${currentProgram.absoluteName}`) + transform?.(currentProgram, options, pluginContext) + cache.update(currentProgram) + } else { + console.log(`SKIP TRANSFORMATION FOR ${currentProgram.absoluteName}`) + } + //transform?.(currentProgram, options, pluginContext) } // Run some common plugins that should be run after plugin usage and depends on the current stage -- Gitee From 58749ba229bebad1bf1571d7f04025af110b672b Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Tue, 10 Jun 2025 13:11:14 +0300 Subject: [PATCH 2/9] X Signed-off-by: Nikolay Igotti --- ui2abc/libarkts/src/plugin-utils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui2abc/libarkts/src/plugin-utils.ts b/ui2abc/libarkts/src/plugin-utils.ts index 4c7485cf0..ea4b05b11 100644 --- a/ui2abc/libarkts/src/plugin-utils.ts +++ b/ui2abc/libarkts/src/plugin-utils.ts @@ -58,7 +58,6 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta pluginContext.setParameter("ASTCache", cache) } - while (currentProgram) { // Options passed to plugin and hooks const options: CompilationOptions = { @@ -80,7 +79,7 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta stageSpecificPreFilters(ast, state) // Run the plugin itself - if (options.isMainProgram || !onlyModifyMain) { + if (isMainProgram || !onlyModifyMain) { if (!cache.find(currentProgram)) { //console.log(`APPLY TRANSFORMATION FOR ${currentProgram.absoluteName}`) transform?.(currentProgram, options, pluginContext) -- Gitee From 96ab499b7cec76a5016dd8d27b5b3855ce2f58ec Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Tue, 10 Jun 2025 13:48:44 +0300 Subject: [PATCH 3/9] Rebase Signed-off-by: Nikolay Igotti --- ui2abc/libarkts/src-host/es2panda.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ui2abc/libarkts/src-host/es2panda.ts b/ui2abc/libarkts/src-host/es2panda.ts index 20822b667..ef550e2a4 100644 --- a/ui2abc/libarkts/src-host/es2panda.ts +++ b/ui2abc/libarkts/src-host/es2panda.ts @@ -150,18 +150,17 @@ function stdlib(): string { return `${sdk}/ets/stdlib` } -function createConfig(configPath: string, filePath: string, outputPath: string): Config { +function createConfig(configPath: string, filePath: string, outPath: string): Config { return Config.create([ '_', '--arktsconfig', configPath, - filePath, '--extension', 'ets', '--stdlib', stdlib(), - '--output', - outputPath + filePath, + outPath ]) } @@ -184,7 +183,7 @@ function invokeWithPlugins( configPath, filePath, outputPath - ) + ]) global.config = compilerConfig.peer if (!global.configIsInitialized()) throw new Error(`Wrong config: path=${configPath} file=${filePath} stdlib=${stdlib} output=${outputPath}`) @@ -341,7 +340,7 @@ export function main() { const pluginNames = plugins.map((it: any) => `${it.name}-${it.stage}`) const pluginContext = new PluginContextImpl() const pluginsByState = readAndSortPlugins(configDir, plugins) - const globalConfig = createConfig(configPath, files[0], outDir) + const globalConfig = createConfig(configPath, files[0], outputs[0]) const globalContext = GlobalContext.create(globalConfig, files) for (var i = 0; i < files.length; i++) { global.profiler.compilationStarted(files[i]) -- Gitee From c9097c7a1363cabe4cca56ba7393802b7e24e0a1 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Tue, 10 Jun 2025 13:58:51 +0300 Subject: [PATCH 4/9] Update Signed-off-by: Nikolay Igotti --- ui2abc/libarkts/src/plugin-utils.ts | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/ui2abc/libarkts/src/plugin-utils.ts b/ui2abc/libarkts/src/plugin-utils.ts index ea4b05b11..0bc81458b 100644 --- a/ui2abc/libarkts/src/plugin-utils.ts +++ b/ui2abc/libarkts/src/plugin-utils.ts @@ -24,7 +24,9 @@ import { Program, inferVoidReturnType, ProgramProvider, - CompilationOptions + CompilationOptions, + GlobalContext, + Context } from "./arkts-api" import { AstNode } from "./reexport-for-generated" @@ -35,7 +37,7 @@ export interface RunTransformerHooks { class ASTCache { processedPrograms = new Set() - constructor() {} + constructor() { } find(program: Program): boolean { return this.processedPrograms.has(program.absoluteName) } @@ -51,6 +53,7 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta // The first program provided by program provider is the main program let currentProgram = provider.next() let isMainProgram = true + const cached = false let cache = pluginContext.parameter("ASTCache") if (!cache) { @@ -58,6 +61,8 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta pluginContext.setParameter("ASTCache", cache) } + let compilerContext = arktsGlobal.compilerContext as Context + while (currentProgram) { // Options passed to plugin and hooks const options: CompilationOptions = { @@ -66,6 +71,11 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta restart, } + if (!isMainProgram && cached) { + //const compilerContext = Context.createCacheFromFile(currentProgram.absoluteName, configPath, stdlib(), globalContext, true)! + // asktsGlobal.compilerContext = compilerContext + } + // Perform some additional actions before the transformation start hooks.onProgramTransformStart?.(options) @@ -79,15 +89,18 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta stageSpecificPreFilters(ast, state) // Run the plugin itself - if (isMainProgram || !onlyModifyMain) { - if (!cache.find(currentProgram)) { - //console.log(`APPLY TRANSFORMATION FOR ${currentProgram.absoluteName}`) - transform?.(currentProgram, options, pluginContext) - cache.update(currentProgram) + if (isMainProgram || !onlyModifyMain) { + if (cached) { + if (!cache.find(currentProgram)) { + //console.log(`APPLY TRANSFORMATION FOR ${currentProgram.absoluteName}`) + transform?.(currentProgram, options, pluginContext) + cache.update(currentProgram) + } else { + console.log(`SKIP TRANSFORMATION FOR ${currentProgram.absoluteName}`) + } } else { - console.log(`SKIP TRANSFORMATION FOR ${currentProgram.absoluteName}`) + transform?.(currentProgram, options, pluginContext) } - //transform?.(currentProgram, options, pluginContext) } // Run some common plugins that should be run after plugin usage and depends on the current stage @@ -109,6 +122,8 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta if (restart) break isMainProgram = false + if (cached) compilerContext.destroy() + // Proceed to the next program currentProgram = provider.next() } -- Gitee From da8d6a1e909fba24c0c276b7d8e6ea422d34e2b7 Mon Sep 17 00:00:00 2001 From: Sokolova Irina Date: Tue, 10 Jun 2025 11:00:30 +0000 Subject: [PATCH 5/9] !1080 CI-Cleanup * CI-Cleanup --- arkoala-arkts/.gitlab-ci.yml | 120 ----------------------------------- 1 file changed, 120 deletions(-) diff --git a/arkoala-arkts/.gitlab-ci.yml b/arkoala-arkts/.gitlab-ci.yml index c08a74907..d06343fb0 100644 --- a/arkoala-arkts/.gitlab-ci.yml +++ b/arkoala-arkts/.gitlab-ci.yml @@ -63,99 +63,6 @@ install node modules (arkoala-arkts): - arkoala-arkts/framework/build/libc++.so expire_in: 1 day - build arkui-common.abc: - stage: build - interruptible: true - extends: - - .linux-vm-shell-task - needs: - - install node modules (ui2abc) - - install node modules (arkoala) - - install node modules (arkoala-arkts) - - install node modules (incremental) - - install node modules (interop) - - install node modules (tools) - - build fast-arktsc - before_script: - - !reference [.setup, script] - - npm run panda:sdk:install --prefix arkoala-arkts - script: - - npm run build:arkui-common:inc --prefix arkoala-arkts - artifacts: - paths: - - arkoala-arkts/arkui-common/build/arkui-common.abc - expire_in: 1 day - - build arkui-no-common.abc: - stage: build - interruptible: true - extends: - - .linux-vm-shell-task - needs: - - install node modules (ui2abc) - - install node modules (arkoala) - - install node modules (arkoala-arkts) - - install node modules (incremental) - - install node modules (interop) - - install node modules (tools) - - build fast-arktsc - before_script: - - !reference [.setup, script] - - npm run panda:sdk:install --prefix arkoala-arkts - script: - - npm run build:arkui-no-common --prefix arkoala-arkts - artifacts: - paths: - - arkoala-arkts/arkui/build/arkui-no-common.abc - expire_in: 1 day - - build arkui-no-common.abc (w/restart): - stage: build - allow_failure: true - interruptible: true - extends: - - .linux-vm-shell-task - needs: - - install node modules (ui2abc) - - install node modules (arkoala) - - install node modules (arkoala-arkts) - - install node modules (incremental) - - install node modules (interop) - - install node modules (tools) - - annotate all - before_script: - - !reference [.setup, script] - - !reference [.setup, regenerate-plugin-api] - script: - - npm run build:arkui-no-common:inc:ui2abc:restart --prefix arkoala-arkts/arkui - - build arkui-no-common.abc (w/plugins): - stage: build - allow_failure: true - when: manual - interruptible: true - extends: - - .linux-vm-shell-task - needs: - - install node modules (ui2abc) - - install node modules (arkoala) - - install node modules (arkoala-arkts) - - install node modules (incremental) - - install node modules (interop) - - install node modules (tools) - - annotate all - before_script: - - !reference [.setup, script] - - !reference [.setup, regenerate-plugin-api] - script: - - npm run compile --prefix ui2abc/memo-plugin - - npm run build:compat:inc:ui2abc --prefix incremental/compat - - npm run build:common:inc:ui2abc --prefix incremental/common - - npm run build:runtime:inc:ui2abc --prefix incremental/runtime - - npm run build:interop:inc:ui2abc --prefix interop - - npm run build:arkui-common:inc:ui2abc --prefix arkoala/arkui-common - - npm run build:arkui-no-common --prefix arkoala-arkts/arkui - build incremental.abc: stage: build interruptible: true @@ -285,8 +192,6 @@ install node modules (arkoala-arkts): - install node modules (incremental) - install node modules (interop) - install node modules (tools) - - build arkui-common.abc - - build arkui-no-common.abc - build incremental.abc - build interop.abc before_script: @@ -299,28 +204,6 @@ install node modules (arkoala-arkts): - arkoala-arkts/build/arkoala.abc expire_in: 1 day - build user.abc: - stage: build - interruptible: true - extends: - - .linux-vm-shell-task - needs: - - install node modules (ui2abc) - - install node modules (arkoala) - - install node modules (arkoala-arkts) - - install node modules (incremental) - - install node modules (interop) - - install node modules (tools) - before_script: - - !reference [.setup, script] - - npm run panda:sdk:install --prefix arkoala-arkts - script: - - npm run build:user --prefix arkoala-arkts - artifacts: - paths: - - arkoala-arkts/trivial/user/build/user.abc - expire_in: 1 day - build shopping.abc (recheck): stage: build interruptible: true @@ -374,7 +257,6 @@ install node modules (arkoala-arkts): - install node modules (incremental) - install node modules (interop) - link arkoala.abc - - build user.abc - build ArkoalaNative (linux, linux, node+panda) before_script: - !reference [.setup, script] @@ -420,7 +302,6 @@ install node modules (arkoala-arkts): - install node modules (incremental) - install node modules (interop) - install node modules (tools) - - build user.abc before_script: - !reference [.setup, script] - npm run panda:sdk:install --prefix arkoala-arkts @@ -532,7 +413,6 @@ notification: ${ARKTS_STATUS} "${ARKTS_JOB_NAME}" "${ARKTS_RESULT}" \ ${ARKOALA_STATUS} "${ARKOALA_JOB_NAME}" "${ARKOALA_RESULT}" - ets-harness-m3 (linux, node): stage: test interruptible: true -- Gitee From af73ed5767e8042f70243ee0eeb930ae5a35959c Mon Sep 17 00:00:00 2001 From: Peter Z Date: Tue, 10 Jun 2025 11:32:48 +0000 Subject: [PATCH 6/9] !1066 Corrected imports in test files * Corrected import in subset/arkoala-arkts * Corrected import in test_performance.ts --- .../arkoala-arkts/arkui/src/generated/main.ts | 19 ++++++++++++------- subset/arkoala/arkui/src/test_performance.ts | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/subset/arkoala-arkts/arkui/src/generated/main.ts b/subset/arkoala-arkts/arkui/src/generated/main.ts index 2f50f4fbb..7e0dfabd8 100644 --- a/subset/arkoala-arkts/arkui/src/generated/main.ts +++ b/subset/arkoala-arkts/arkui/src/generated/main.ts @@ -16,13 +16,18 @@ import { ArkUINativeModule, TestNativeModule } from "#components" import { wrapCallback, disposeCallback, callCallback, wrapSystemCallback, registerNativeModuleLibraryName, KSerializerBuffer, KBuffer } from "@koalaui/interop" import { deserializeAndCallCallback } from './peers/CallbackDeserializeCall.ts' import { assertEquals, assertThrows } from "./test_utils" -import { ArkButtonPeer } from "@arkoala/arkui/button" -import { ArkColumnPeer } from "@arkoala/arkui/column" -import { ButtonType, ButtonLabelStyle } from '@arkoala/arkui/button' -import { BlurOptions, SheetTitleOptions } from "@arkoala/arkui/common" -import { ResourceColor, ResourceStr, Font } from "@arkoala/arkui/units" -import { Alignment, TextOverflow, TextHeightAdaptivePolicy } from "@arkoala/arkui/enums" - +import { ArkButtonPeer, + ArkColumnPeer, + ButtonType, + ButtonLabelStyle, + BlurOptions, + SheetTitleOptions, + ResourceColor, + ResourceStr, + Font, + TextOverflow, + TextHeightAdaptivePolicy +} from "@arkoala/arkui" import { Deserializer } from "@arkoala/arkui/peers/Deserializer" import { Serializer } from "@arkoala/arkui/peers/Serializer" import { CallbackKind } from "@arkoala/arkui/peers/CallbackKind" diff --git a/subset/arkoala/arkui/src/test_performance.ts b/subset/arkoala/arkui/src/test_performance.ts index 746dfc5bb..837f8d29b 100644 --- a/subset/arkoala/arkui/src/test_performance.ts +++ b/subset/arkoala/arkui/src/test_performance.ts @@ -23,7 +23,7 @@ import { testLength_number100, testNumber100 } from "@arkoala/arkui/test_data" import { withStringResult } from "@koalaui/interop" -import { ArkCommonMethodComponent, ArkCommonMethodPeer } from "./generated/common" +import { ArkCommonMethodPeer } from "@arkoala/arkui/generated" enum DumpOptions { TOTAL = 0, -- Gitee From 4d342dbd5ad9b55bf994c461e9fda6602b8afe8f Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Tue, 10 Jun 2025 11:38:52 +0000 Subject: [PATCH 7/9] !1085 Fix trivial build and run --- arkoala-arkts/arkui/src/ets/ArkStateProperties.ets | 7 ++++--- arkoala-arkts/trivial/user/package.json | 2 +- arkoala-arkts/trivial/user/src/ets/page1.ets | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arkoala-arkts/arkui/src/ets/ArkStateProperties.ets b/arkoala-arkts/arkui/src/ets/ArkStateProperties.ets index 6fd3e4e37..4218a9aad 100644 --- a/arkoala-arkts/arkui/src/ets/ArkStateProperties.ets +++ b/arkoala-arkts/arkui/src/ets/ArkStateProperties.ets @@ -70,10 +70,11 @@ export class LinkDecoratorProperty implements SubscribedAbstractProperty< this.watch = watch } - linkTo(property: SubscribedAbstractProperty | Value | undefined): void { - if (!(property instanceof SubscribedAbstractProperty)) throw new Error('Property must be passed') + linkTo(maybeProperty: SubscribedAbstractProperty | Value | undefined): void { + if (!maybeProperty) throw new Error(`${this.name} must be linked with another property`) + const property = maybeProperty! // TODO: this is to workaround Any considered non-nulish + if (!(property instanceof SubscribedAbstractProperty)) throw new Error('Property must be passed, got') if (this.property) throw new Error(`${this.name} is already linked with some property`) - if (!property) throw new Error(`${this.name} must be linked with another property`) this.property = property if (this.watch) property.subscribe(this.watch!) } diff --git a/arkoala-arkts/trivial/user/package.json b/arkoala-arkts/trivial/user/package.json index a46a8752a..6d743a862 100644 --- a/arkoala-arkts/trivial/user/package.json +++ b/arkoala-arkts/trivial/user/package.json @@ -13,7 +13,7 @@ "build:restart": "npm run compile -C ../../../ui2abc/ui-plugins && node ../../../ui2abc/fast-arktsc --config ./ui2abcconfig-m3.json --compiler ../../../incremental/tools/panda/arkts/ui2abc --link-name ./build/user.abc --restart-stages && ninja ${NINJA_OPTIONS} -f build/ets-m3/abc/build.ninja", "build:recheck": "npm run compile -C ../../../ui2abc/ui-plugins && node ../../../ui2abc/fast-arktsc --config ./ui2abcconfig-m3-recheck.json --compiler ../../../incremental/tools/panda/arkts/ui2abc --link-name ./build/user.abc && ninja ${NINJA_OPTIONS} -f build/ets-m3/abc/build.ninja", "build": "npm run build:recheck", - "run": "npm run build && mkdir -p ../../build/userPandaFiles && cp ./build/hello-m3.abc ../../build/userPandaFiles/hello-m3.abc && npm run build:loader:node -C ../.. && ACE_LIBRARY_PATH=../../build PANDA_HOME=../../../incremental/tools/panda/node_modules/@panda/sdk node ../../build/index.js panda-ani:class=@ohos.example.src.ets.entry.Entry 10", + "run": "npm run build && mkdir -p ../../build/userPandaFiles && cp ./build/user.abc ../../build/userPandaFiles/hello-m3.abc && npm run build:loader:node -C ../.. && ACE_LIBRARY_PATH=../../build PANDA_HOME=../../../incremental/tools/panda/node_modules/@panda/sdk node ../../build/index.js panda-ani:class=@ohos.example.src.ets.entry.Entry 10", "copy": "mkdir -p ../build && cp -r build/user.abc ../build/", "pack": "npm run clt:download && cd app && DEVECO_SDK_HOME=../$npm_package_config_sdk_path ../$npm_package_config_hvigorw_path --no-daemon --mode module -p product=default -p module=user@default assembleHar", "har-arm32": "npm run build && node $npm_package_config_sdk_cli_path download && node scripts/build-har.mjs --name user --arch arm32 && npm run pack", diff --git a/arkoala-arkts/trivial/user/src/ets/page1.ets b/arkoala-arkts/trivial/user/src/ets/page1.ets index 7de6c28f4..51e674567 100644 --- a/arkoala-arkts/trivial/user/src/ets/page1.ets +++ b/arkoala-arkts/trivial/user/src/ets/page1.ets @@ -57,7 +57,7 @@ struct TestProvide { .width(200).height(100) .backgroundColor('#b420a0') .onClick((e?: ClickEvent) => { this.inc() }) - TestConsume(/*{ linkState: this.aState }*/) + TestConsume({ linkState: this.aState }) } } -- Gitee From 645cca87f66102b2b1947856fcc79992b8890902 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Tue, 10 Jun 2025 15:15:34 +0300 Subject: [PATCH 8/9] Provide --output flags Signed-off-by: Alexander Gorshenev --- ui2abc/libarkts/src-host/es2panda.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui2abc/libarkts/src-host/es2panda.ts b/ui2abc/libarkts/src-host/es2panda.ts index ef550e2a4..464f22c40 100644 --- a/ui2abc/libarkts/src-host/es2panda.ts +++ b/ui2abc/libarkts/src-host/es2panda.ts @@ -160,6 +160,7 @@ function createConfig(configPath: string, filePath: string, outPath: string): Co '--stdlib', stdlib(), filePath, + '--output', outPath ]) } @@ -182,6 +183,7 @@ function invokeWithPlugins( '--arktsconfig', configPath, filePath, + '--output', outputPath ]) global.config = compilerConfig.peer -- Gitee From 45934924b8ccc2f8b569f1e8a823111832b8b1de Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Tue, 10 Jun 2025 17:26:26 +0300 Subject: [PATCH 9/9] Tweaks Signed-off-by: Nikolay Igotti --- ui2abc/libarkts/src-host/es2panda.ts | 12 ++++++++---- ui2abc/libarkts/src/plugin-utils.ts | 13 ++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ui2abc/libarkts/src-host/es2panda.ts b/ui2abc/libarkts/src-host/es2panda.ts index 464f22c40..a59dae896 100644 --- a/ui2abc/libarkts/src-host/es2panda.ts +++ b/ui2abc/libarkts/src-host/es2panda.ts @@ -67,6 +67,7 @@ function insertPlugin( dumpAst: boolean, restart: boolean, pluginContext: PluginContextImpl, + contextFactory: (sourcePath: string) => Context, updateWith?: (node: AstNode) => void ): AstNode { const script = createETSModuleFromContext() @@ -83,7 +84,8 @@ function insertPlugin( global.profiler.curPlugin = pluginName global.profiler.transformStarted() - runTransformer(global.compilerContext.program, state, restart, transform, pluginContext, { + runTransformer(global.compilerContext.program, state, restart, transform, pluginContext, contextFactory, + { onProgramTransformStart(options: CompilationOptions) { if (!options.isMainProgram) global.profiler.transformDepStarted() }, @@ -236,10 +238,12 @@ function invokeWithPlugins( dumpArkTsConfigInfo(global.arktsconfig) dumpProgramInfo(compilerContext.program) + const contextFactory = (sourcePath: string) => Context.createCacheFromFile(sourcePath, configPath, stdlib(), globalContext, true)! + global.profiler.curContextState = Es2pandaContextState.ES2PANDA_STATE_PARSED pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_PARSED)?.forEach(plugin => { if (!terminate) { - insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_PARSED, pluginNames[pluginsApplied], dumpAst, restart, pluginContext) + insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_PARSED, pluginNames[pluginsApplied], dumpAst, restart, pluginContext, contextFactory) restartProcedure(Es2pandaContextState.ES2PANDA_STATE_PARSED) } }) @@ -251,7 +255,7 @@ function invokeWithPlugins( pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_BOUND)?.forEach(plugin => { if (!terminate) { - insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_BOUND, pluginNames[pluginsApplied], dumpAst, restart, pluginContext, rebindSubtree) + insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_BOUND, pluginNames[pluginsApplied], dumpAst, restart, pluginContext, contextFactory, rebindSubtree) restartProcedure(Es2pandaContextState.ES2PANDA_STATE_BOUND) } }) @@ -263,7 +267,7 @@ function invokeWithPlugins( pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_CHECKED)?.forEach(plugin => { if (!terminate) { - insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_CHECKED, pluginNames[pluginsApplied], dumpAst, restart, pluginContext, recheckSubtree) + insertPlugin(plugin, Es2pandaContextState.ES2PANDA_STATE_CHECKED, pluginNames[pluginsApplied], dumpAst, restart, pluginContext, contextFactory, recheckSubtree) restartProcedure(Es2pandaContextState.ES2PANDA_STATE_CHECKED) } }) diff --git a/ui2abc/libarkts/src/plugin-utils.ts b/ui2abc/libarkts/src/plugin-utils.ts index 0bc81458b..60ef29f1e 100644 --- a/ui2abc/libarkts/src/plugin-utils.ts +++ b/ui2abc/libarkts/src/plugin-utils.ts @@ -25,7 +25,6 @@ import { inferVoidReturnType, ProgramProvider, CompilationOptions, - GlobalContext, Context } from "./arkts-api" import { AstNode } from "./reexport-for-generated" @@ -46,7 +45,7 @@ class ASTCache { } } -export function runTransformer(prog: Program, state: Es2pandaContextState, restart: boolean, transform: ProgramTransformer | undefined, pluginContext: PluginContext, hooks: RunTransformerHooks = {}, onlyModifyMain: boolean = false) { +export function runTransformer(prog: Program, state: Es2pandaContextState, restart: boolean, transform: ProgramTransformer | undefined, pluginContext: PluginContext, contextFactory: ((path: string) => Context) | undefined = undefined, hooks: RunTransformerHooks = {}, onlyModifyMain: boolean = false) { // Program provider used to provide programs to transformer dynamically relative to inserted imports const provider = new ProgramProvider(prog) @@ -62,6 +61,7 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta } let compilerContext = arktsGlobal.compilerContext as Context + const oldCompilerContext = compilerContext while (currentProgram) { // Options passed to plugin and hooks @@ -71,9 +71,9 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta restart, } - if (!isMainProgram && cached) { - //const compilerContext = Context.createCacheFromFile(currentProgram.absoluteName, configPath, stdlib(), globalContext, true)! - // asktsGlobal.compilerContext = compilerContext + if (!isMainProgram && cached && contextFactory) { + const compilerContext = contextFactory(currentProgram.absoluteName) + arktsGlobal.compilerContext = compilerContext } // Perform some additional actions before the transformation start @@ -126,7 +126,10 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta // Proceed to the next program currentProgram = provider.next() + if (contextFactory) compilerContext.destroy() } + + arktsGlobal.compilerContext = oldCompilerContext } function setAllParents(ast: AstNode) { -- Gitee