diff --git a/arkoala-arkts/arkui/package.json b/arkoala-arkts/arkui/package.json index 9cb5413c0436a14b987132753e33963b223bd2d0..afef9a31b3a967df427862a702cf3d7d46f65334 100644 --- a/arkoala-arkts/arkui/package.json +++ b/arkoala-arkts/arkui/package.json @@ -10,7 +10,7 @@ "build:arkui-no-common": "npm run build:m3:recheck", "copy:abc": "mkdir -p ../build/bootPandaFiles/ && cp ./build-m3-impl/arkui-m3.abc ../build/bootPandaFiles/arkui.abc", "build:m3:restart": "node ../../ui2abc/fast-arktsc --config ./ui2abcconfig-m3.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build-m3-impl/arkui-m3.abc --restart-stages && ninja ${NINJA_OPTIONS} -f build-m3-impl/build.ninja -k 1200 && npm run copy:abc", - "build:m3:recheck": "node ../../ui2abc/fast-arktsc --config ./ui2abcconfig-recheck.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build-m3-impl/arkui-m3.abc && ninja ${NINJA_OPTIONS} -f build-m3-recheck/build.ninja -k 1200 && npm run copy:abc", + "build:m3:recheck": "node ../../ui2abc/fast-arktsc --config ./ui2abcconfig-recheck.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build-m3-impl/arkui-m3.abc --group-by 4 && ninja ${NINJA_OPTIONS} -f build-m3-recheck/build.ninja -k 1200 -j 1 && npm run copy:abc", "build:m3": "npm run build:m3:restart", "build:sdk-m3": "npm run build:sdk-m3:restart", "build:sdk-m3:restart": "node ../../ui2abc/fast-arktsc --config ./ui2abcconfig-sdk-m3.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build-m3-sdk/arkui-sdk.abc --restart-stages && ninja ${NINJA_OPTIONS} -f build-m3-sdk/build.ninja -k 1200", diff --git a/incremental/common/src/math.ts b/incremental/common/src/math.ts index 8827d8d7b5e5b5268775bc36c557eb384f6db8f1..d3358f44af87feb4734f1f91282fc677131c7108 100644 --- a/incremental/common/src/math.ts +++ b/incremental/common/src/math.ts @@ -68,7 +68,7 @@ export function parseNumber(str: string, name: string = "number", verify: boolea const value = asFloat64(str) if (verify) { const reverseStr = asString(value) - if (reverseStr !== undefined && reverseStr?.length == str.length && reverseStr == str) { + if (reverseStr !== undefined && reverseStr!.length == str.length && reverseStr == str) { return value } } diff --git a/incremental/runtime/package.json b/incremental/runtime/package.json index 1a3f83f180e1bf45a15726256901e2ae11aeb98e..fb49e6f0df4c266322af063a58d0bce95dcccd7e 100644 --- a/incremental/runtime/package.json +++ b/incremental/runtime/package.json @@ -38,7 +38,7 @@ "annotate": "npm run compile --prefix ../../ui2abc/annotate && node ../../ui2abc/annotate", "fast-arktsc": "npm run compile --prefix ../../ui2abc/fast-arktsc", "build:runtime:inc:ui2abc": "npm run annotate && npm run fast-arktsc && node ../../ui2abc/fast-arktsc --config ./ui2abcconfig.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --restart-stages --group-by 5 && PANDA_SDK_PATH=${PANDA_SDK_PATH:=../tools/panda/node_modules/@panda/sdk} ninja ${NINJA_OPTIONS} -f build/build.ninja", - "build:runtime:inc:ui2abc:recheck": "npm run annotate && npm run fast-arktsc && node ../../ui2abc/fast-arktsc --config ./ui2abcconfig-recheck.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --group-by 5 && PANDA_SDK_PATH=${PANDA_SDK_PATH:=../tools/panda/node_modules/@panda/sdk} ninja ${NINJA_OPTIONS} -f build/recheck/build.ninja", + "build:runtime:inc:ui2abc:recheck": "npm run annotate && npm run fast-arktsc && node ../../ui2abc/fast-arktsc --config ./ui2abcconfig-recheck.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --group-by 100 && PANDA_SDK_PATH=${PANDA_SDK_PATH:=../tools/panda/node_modules/@panda/sdk} ninja ${NINJA_OPTIONS} -f build/recheck/build.ninja", "build:runtime:with:tests": "npm run unmemoize:with:tests && fast-arktsc --config ./arktsconfig-test-unmemoized.json --compiler ../tools/panda/arkts/arktsc --link-name ./build/runtime-tests.abc && ninja ${NINJA_OPTIONS} -f build/unmemoized/abc/build.ninja", "build:incremental:components": "npm run build:compat && npm run build:common && npm run build:runtime", "build:incremental:components:inc": "npm run build:compat:inc && npm run build:common:inc && npm run build:runtime:inc", diff --git a/ui2abc/libarkts/native/src/bridges.cc b/ui2abc/libarkts/native/src/bridges.cc index c57450bff3389b20a3cc08f5cb4ebe2912912aaf..a556ffa53205b4fc4f01570bc64ca90666334367 100644 --- a/ui2abc/libarkts/native/src/bridges.cc +++ b/ui2abc/libarkts/native/src/bridges.cc @@ -561,6 +561,6 @@ KInt impl_GenerateTsDeclarationsFromContext(KNativePointer contextPtr, KStringPt KBoolean exportAll, KBoolean isolated) { auto context = reinterpret_cast(contextPtr); - return GetImpl()->GenerateTsDeclarationsFromContext(context, outputDeclEts.data(), outputEts.data(), exportAll/*, isolated */); + return GetImpl()->GenerateTsDeclarationsFromContext(context, outputDeclEts.data(), outputEts.data(), exportAll, isolated); } KOALA_INTEROP_5(GenerateTsDeclarationsFromContext, KInt, KNativePointer, KStringPtr, KStringPtr, KBoolean, KBoolean) diff --git a/ui2abc/libarkts/native/src/generated/bridges.cc b/ui2abc/libarkts/native/src/generated/bridges.cc index d8d866576f0aab32c1d2e68332a43f90d3753534..681f980d0a895ff9ad68c0f77ca515f78cda3b6a 100644 --- a/ui2abc/libarkts/native/src/generated/bridges.cc +++ b/ui2abc/libarkts/native/src/generated/bridges.cc @@ -4254,25 +4254,6 @@ KUInt impl_ScriptFunctionFormalParamsLengthConst(KNativePointer context, KNative } KOALA_INTEROP_2(ScriptFunctionFormalParamsLengthConst, KUInt, KNativePointer, KNativePointer); -void impl_ScriptFunctionSetIsolatedDeclgenReturnType(KNativePointer context, KNativePointer receiver, KStringPtr& type) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - const auto _type = getStringCopy(type); - GetImpl()->ScriptFunctionSetIsolatedDeclgenReturnType(_context, _receiver, _type); - return ; -} -KOALA_INTEROP_V3(ScriptFunctionSetIsolatedDeclgenReturnType, KNativePointer, KNativePointer, KStringPtr); - -KNativePointer impl_ScriptFunctionGetIsolatedDeclgenReturnTypeConst(KNativePointer context, KNativePointer receiver) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - auto result = GetImpl()->ScriptFunctionGetIsolatedDeclgenReturnTypeConst(_context, _receiver); - return StageArena::strdup(result); -} -KOALA_INTEROP_2(ScriptFunctionGetIsolatedDeclgenReturnTypeConst, KNativePointer, KNativePointer, KNativePointer); - void impl_ScriptFunctionEmplaceReturnStatements(KNativePointer context, KNativePointer receiver, KNativePointer returnStatements) { const auto _context = reinterpret_cast(context); @@ -6718,15 +6699,6 @@ KNativePointer impl_AstNodeDumpDeclConst(KNativePointer context, KNativePointer } KOALA_INTEROP_2(AstNodeDumpDeclConst, KNativePointer, KNativePointer, KNativePointer); -KNativePointer impl_AstNodeIsolatedDumpDeclConst(KNativePointer context, KNativePointer receiver) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - auto result = GetImpl()->AstNodeIsolatedDumpDeclConst(_context, _receiver); - return StageArena::strdup(result); -} -KOALA_INTEROP_2(AstNodeIsolatedDumpDeclConst, KNativePointer, KNativePointer, KNativePointer); - void impl_AstNodeDumpConst(KNativePointer context, KNativePointer receiver, KNativePointer dumper) { const auto _context = reinterpret_cast(context); @@ -12058,16 +12030,15 @@ KNativePointer impl_CreateSrcDumper(KNativePointer context, KNativePointer node) } KOALA_INTEROP_2(CreateSrcDumper, KNativePointer, KNativePointer, KNativePointer); -KNativePointer impl_CreateSrcDumper1(KNativePointer context, KNativePointer node, KBoolean isDeclgen, KBoolean isIsolatedDeclgen) +KNativePointer impl_CreateSrcDumper1(KNativePointer context, KNativePointer node, KBoolean isDeclgen) { const auto _context = reinterpret_cast(context); const auto _node = reinterpret_cast(node); const auto _isDeclgen = static_cast(isDeclgen); - const auto _isIsolatedDeclgen = static_cast(isIsolatedDeclgen); - auto result = GetImpl()->CreateSrcDumper1(_context, _node, _isDeclgen, _isIsolatedDeclgen); + auto result = GetImpl()->CreateSrcDumper1(_context, _node, _isDeclgen); return result; } -KOALA_INTEROP_4(CreateSrcDumper1, KNativePointer, KNativePointer, KNativePointer, KBoolean, KBoolean); +KOALA_INTEROP_3(CreateSrcDumper1, KNativePointer, KNativePointer, KNativePointer, KBoolean); void impl_SrcDumperAdd(KNativePointer context, KNativePointer receiver, KStringPtr& str) { @@ -12185,15 +12156,6 @@ KBoolean impl_SrcDumperIsDeclgenConst(KNativePointer context, KNativePointer rec } KOALA_INTEROP_2(SrcDumperIsDeclgenConst, KBoolean, KNativePointer, KNativePointer); -KBoolean impl_SrcDumperIsIsolatedDeclgenConst(KNativePointer context, KNativePointer receiver) -{ - const auto _context = reinterpret_cast(context); - const auto _receiver = reinterpret_cast(receiver); - auto result = GetImpl()->SrcDumperIsIsolatedDeclgenConst(_context, _receiver); - return result; -} -KOALA_INTEROP_2(SrcDumperIsIsolatedDeclgenConst, KBoolean, KNativePointer, KNativePointer); - void impl_SrcDumperDumpNode(KNativePointer context, KNativePointer receiver, KStringPtr& key) { const auto _context = reinterpret_cast(context); diff --git a/ui2abc/libarkts/package.json b/ui2abc/libarkts/package.json index 207c451cc46631605dde23a75df2673c34076790..553d15f7c504c4f32c5727bb42a946e022611e37 100644 --- a/ui2abc/libarkts/package.json +++ b/ui2abc/libarkts/package.json @@ -59,6 +59,10 @@ "restart": "node ../fast-arktsc --config arktsconfig.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/abc/main.abc --restart-stages && ninja -f build/abc/build.ninja", "direct": "node ../fast-arktsc --config arktsconfig.json --compiler ../../incremental/tools/panda/arkts/ui2abc --link-name ./build/abc/main.abc && ninja -f build/abc/build.ninja", "run": "npm run compile && npm run compile:plugins && npm run direct", + "es2panda:check": " rm -rf build/abc && npx rollup -c rollup.es2panda.mjs && npm run direct", + "es2panda:check2": " rm -rf ../../incremental/common/build/abc && npx rollup -c rollup.es2panda.mjs && npm run build:common:inc:ui2abc --prefix ../../incremental/common", + "es2panda:check3": " rm -rf ../../incremental/runtime/build && npx rollup -c rollup.es2panda.mjs && npm run build:runtime:inc:ui2abc:recheck --prefix ../../incremental/runtime", + "es2panda:check4": " rm -rf ../../arkoala-arkts/arkui/build && npx rollup -c rollup.es2panda.mjs && npm run build:m3:recheck --prefix ../../arkoala-arkts/arkui", "run:memo": "npm run compile && npm run compile:plugins && npm run compile --prefix ../memo-plugin && npm run memo", "run:abc": "$npm_package_config_panda_sdk_path/linux_host_tools/bin/ark --load-runtimes=ets --boot-panda-files=$npm_package_config_panda_sdk_path/ets/etsstdlib.abc ./main.abc main.ETSGLOBAL::main", "mocha": "PANDA_SDK_PATH=${PANDA_SDK_PATH:=$npm_package_config_panda_sdk_path} TS_NODE_PROJECT=./test/tsconfig.json mocha -r tsconfig-paths/register --reporter-option maxDiffSize=0", diff --git a/ui2abc/libarkts/src-host/es2panda.ts b/ui2abc/libarkts/src-host/es2panda.ts index c51a1ba16a2086ddf6095fcafcc299b0294a076e..fc2b5920c49496410a0d8dad4690931639b97266 100644 --- a/ui2abc/libarkts/src-host/es2panda.ts +++ b/ui2abc/libarkts/src-host/es2panda.ts @@ -15,12 +15,16 @@ import * as fs from "node:fs" import * as path from "node:path" -import { checkSDK, arktsGlobal as global, metaDatabase, runTransformer, runTransformerOnProgram, CompilationOptions, findStdlib } from "@koalaui/libarkts" +import { checkSDK, arktsGlobal as global, metaDatabase, runTransformer, CompilationOptions, findStdlib, passStringArray, passString, recheckContext, defaultFilter } from "@koalaui/libarkts" import { CheckedBackFilter, PluginContextImpl } from "@koalaui/libarkts" import { Command } from "commander" import { filterSource, isNumber, throwError } from "@koalaui/libarkts" import { Es2pandaContextState } from "@koalaui/libarkts" -import { Options, AstNode, GlobalContext, Config, Context, createETSModuleFromContext, proceedToState, ProgramTransformer, rebindSubtree, recheckSubtree, dumpProgramInfo, dumpArkTsConfigInfo, collectDependencies } from "@koalaui/libarkts" +import { Options, AstNode, Config, Context, createETSModuleFromContext, proceedToState, ProgramTransformer, rebindSubtree, recheckSubtree, dumpProgramInfo, dumpArkTsConfigInfo } from "@koalaui/libarkts" +import { compileWithCache, listPrograms, Program } from "@koalaui/libarkts" + +// This is to switch between adding stdlib to cache or not (probably makes no effect) +let withStdlib = false function parseCommandLineArgs() { const commander = new Command() @@ -330,6 +334,11 @@ export function main() { const pluginContext = new PluginContextImpl() const pluginsByState = readAndSortPlugins(configDir, plugins) + if (!restartStages) { + withCache(configPath, files, outputs, pluginsByState) + return + } + for (var i = 0; i < files.length; i++) { invokeWithPlugins(configPath, files[i], outputs[i], pluginsByState, dumpAst, restartStages, stage, pluginNames, pluginContext) } @@ -341,3 +350,108 @@ function reportErrorAndExit(message: string): never { } main() + +interface ProgramInfo { + absoluteName: string, + isExternal: boolean, + depsCount: number, +} + +function withCache( + configPath: string, + inputs: string[], + outputs: string[], + pluginsByState: Map, +) { + const timeStarted = new Date().getTime() + + const allFiles = [...new Set(inputs.flatMap(it => getAllDeps(configPath, it, pluginsByState)))] + const order = allFiles.map(it => { + return { absoluteName: it, isExternal: !inputs.includes(it), depsCount: getAllDeps(configPath, it, pluginsByState).length } as ProgramInfo + }).sort((a: ProgramInfo, b: ProgramInfo) => { + if (a.absoluteName.includes("observable") && b.absoluteName.includes("observable")) + return 0 + if (a.absoluteName.includes("observable")) + return -99999 + if (b.absoluteName.includes("observable")) + return 99999 + if (a.isExternal == b.isExternal) + return a.depsCount - b.depsCount + if (a.isExternal && !b.isExternal) + return -1 + if (!a.isExternal && b.isExternal) + return 1 + throw new Error("never") + }) // Good dependency resolving order! + const timeDepsResolved = new Date().getTime() + + compileWithCache( + configPath, + order.map(it => { + const idx = inputs.findIndex(it2 => it2 == it.absoluteName) + return { + absoluteName: it.absoluteName, + output: idx != -1 ? outputs[idx] : undefined, + } + }), + pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_PARSED), + pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_CHECKED), + ) + + const timeFinished = new Date().getTime() + + console.log( + `All Time: ${timeFinished - timeStarted}\n`, + `\tDeps: ${timeDepsResolved - timeStarted}\n`, + `\tTransformation: ${timeFinished - timeDepsResolved}\n` + ) +} + +function getAllDeps( + configPath: string, + file: string, + pluginsByState: Map, +) { + const stdlibPath = path.normalize(findStdlib()) + if (file.includes(stdlibPath)) { + // No deps for stdlib, it should be processed before anything + return [] + } + const config = Config.create( + ['_', '--arktsconfig', configPath, '--extension', 'ets', '--stdlib', stdlibPath, file] + ) + const context = new Context( + global.es2panda._CreateContextFromFile( + config.peer, + file, + ) + ) + global.config = config.peer + global.compilerContext = context + proceedToState(Es2pandaContextState.ES2PANDA_STATE_PARSED) + // We need to run parsed stage plugins because they might modify dependency lists + pluginsByState.get(Es2pandaContextState.ES2PANDA_STATE_PARSED)?.forEach(plugin => { + const program = new Program(global.es2panda._ContextProgram(context.peer)) + runTransformer( + program, + Es2pandaContextState.ES2PANDA_STATE_PARSED, + false, + plugin, + new PluginContextImpl(), + ) + }) + if (withStdlib) { // We want to put stdlib files to global context as well + proceedToState(Es2pandaContextState.ES2PANDA_STATE_CHECKED) + } + // TODO: build deps graph more optimally + const programs = listPrograms( + new Program(global.es2panda._ContextProgram(context.peer)), + withStdlib ? (_: string) => true : defaultFilter, + context.peer, + ) + const result = programs.map(it => it.absoluteName) + context.destroy() + config.destroy() + withStdlib = false + return result +} \ No newline at end of file diff --git a/ui2abc/libarkts/src/arkts-api/CompileWithCache.ts b/ui2abc/libarkts/src/arkts-api/CompileWithCache.ts index f25e23bb4674fc7d6c9c0b63d1a5b6b615af9a15..56ce5997dca2914b31ee6952803fe541a20756f4 100644 --- a/ui2abc/libarkts/src/arkts-api/CompileWithCache.ts +++ b/ui2abc/libarkts/src/arkts-api/CompileWithCache.ts @@ -21,7 +21,8 @@ import { passString, passStringArray } from "./utilities/private" import { Context } from "./peers/Context" import { Es2pandaContextState } from "../generated/Es2pandaEnums" import { Program } from "../generated" -import { runTransformer, runTransformerOnProgram } from "../plugin-utils" +import { runTransformerOnProgram } from "../plugin-utils" +import { ProgramProvider } from "./ProgramProvider" export interface ProgramInfo { /** @@ -34,6 +35,23 @@ export interface ProgramInfo { output: string | undefined } +export function getProgramsForPluginApplication( + programs: ProgramInfo[], +) { + const programsForCodeGeneration = programs + .filter(it => it.output != undefined) + .map(it => it.absoluteName) + // Generally, it would be ok to return just the list above, + // but for experimental purpose let's filter programs that + // are mentioned as both codegeneration and caching + const programsForCaching = new Set( + programs + .filter(it => it.output == undefined) + .map(it => it.absoluteName) + ) + return programsForCodeGeneration.filter(it => !programsForCaching.has(it)) +} + export function compileWithCache( configPath: string, orderedPrograms: ProgramInfo[], @@ -57,6 +75,10 @@ export function compileWithCache( false ) + const programsForPluginApplication = getProgramsForPluginApplication( + orderedPrograms + ) + orderedPrograms.forEach((it) => { const args = ['_', '--arktsconfig', configPath, '--extension', 'ets', '--stdlib', findStdlib()] if (it.output) { @@ -65,12 +87,12 @@ export function compileWithCache( const config = Config.create( args ) - const isMainProgram = (it.output != undefined) + const isExternalProgram = (it.output == undefined) const context = global.es2panda._CreateCacheContextFromFile( config.peer, passString(it.absoluteName), globalContext, - !isMainProgram, + isExternalProgram, ) global.config = config.peer @@ -79,20 +101,26 @@ export function compileWithCache( function applyPlugins(plugins: ProgramTransformer[] | undefined, state: Es2pandaContextState) { plugins?.forEach(plugin => { const program = new Program(global.es2panda._ContextProgram(context)) - const options: CompilationOptions = { - isMainProgram: isMainProgram, - stage: state, - restart: false + const provider = new ProgramProvider(program) + let currentProgram = provider.next() + let isFirstProgram = true + while (currentProgram) { + if (programsForPluginApplication.includes(currentProgram.absoluteName) || currentProgram.absoluteName == it.absoluteName) { + const options: CompilationOptions = { + isMainProgram: isFirstProgram, + stage: state, + restart: false, + } + runTransformerOnProgram( + currentProgram, + options, + plugin, + new PluginContextImpl(), + ) + } + currentProgram = provider.next() + isFirstProgram = false } - runTransformerOnProgram( - program, - options, - plugin, - new PluginContextImpl(), - {}, - // For external programs only that program (it is one of external programs in that context) - // For main programs all main programs - ) if (state == Es2pandaContextState.ES2PANDA_STATE_CHECKED) { recheckContext(context) } @@ -117,16 +145,18 @@ export function compileWithCache( function proceedToFinalState() { if (it.output) { - proceedToState(Es2pandaContextState.ES2PANDA_STATE_BIN_GENERATED) + proceedToState(Es2pandaContextState.ES2PANDA_STATE_ASM_GENERATED) } else { proceedToState(Es2pandaContextState.ES2PANDA_STATE_LOWERED) } } function cleanup() { - global.es2panda._DestroyContext( - context - ) + if (!it.output) { + global.es2panda._DestroyContext( + context + ) + } global.es2panda._DestroyConfig( config.peer ) diff --git a/ui2abc/libarkts/src/arkts-api/SetAllParentsByPlugin.ts b/ui2abc/libarkts/src/arkts-api/SetAllParentsByPlugin.ts new file mode 100644 index 0000000000000000000000000000000000000000..6afde46dd4ea709d3f82cde2c2137504b4fcd9f7 --- /dev/null +++ b/ui2abc/libarkts/src/arkts-api/SetAllParentsByPlugin.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbstractVisitor } from "./AbstractVisitor" +import { AstNode } from "./peers/AstNode" + +interface SetAllParentsOptions { + node: AstNode +} + +// We should not visit BlockExpression and ChainExpression in SetAllParents, so use handwritten SetAllParents +// See also changes in visitor.ts +class SetAllParents extends AbstractVisitor { + visitor(node: AstNode, options?: SetAllParentsOptions): AstNode { + if (options) { + node.parent = options.node + } + return this.visitEachChild(node, { node }) + } +} + +export function setAllParentsByPlugin(node: AstNode) { + new SetAllParents().visitor(node) +} diff --git a/ui2abc/libarkts/src/arkts-api/index.ts b/ui2abc/libarkts/src/arkts-api/index.ts index e5497804db96f2ed2ee3c9534aaf47df53715a21..d2e22807f1f1c6ef6d4a116e8e157e6307803d9f 100644 --- a/ui2abc/libarkts/src/arkts-api/index.ts +++ b/ui2abc/libarkts/src/arkts-api/index.ts @@ -28,6 +28,8 @@ export * from "./plugins" export * from "./ImportStorage" export * from "./InferVoidReturnType" export * from "./ProgramProvider" +export * from "./CompileWithCache" +export * from "./SetAllParentsByPlugin" export * from "./peers/AstNode" export * from "./peers/Config" diff --git a/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts b/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts index 39d4542a1ba9af2b3c5d67551d6803b90e3eefde..90453029e70d320d6d53d5cf966caf92e416c2d2 100644 --- a/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts +++ b/ui2abc/libarkts/src/arkts-api/peers/AstNode.ts @@ -28,7 +28,6 @@ export abstract class AstNode extends ArktsObject { throwError(`attempted to create AstNode from nullptr`) } super(peer) - this.updateChildren() } public get originalPeer(): KNativePointer { diff --git a/ui2abc/libarkts/src/arkts-api/utilities/public.ts b/ui2abc/libarkts/src/arkts-api/utilities/public.ts index abd4c8a8191d09df2dd23db6a25eb68eef63c1e8..9b9d3b6dbfb539581ac6d830cdc4b88792ccffa1 100644 --- a/ui2abc/libarkts/src/arkts-api/utilities/public.ts +++ b/ui2abc/libarkts/src/arkts-api/utilities/public.ts @@ -19,6 +19,7 @@ import { KNativePointer, nullptr } from "@koalaui/interop" import { passNode, passNodeArray, unpackNodeArray, unpackNonNullableNode } from "./private" import { Es2pandaContextState, Es2pandaModifierFlags } from "../../generated/Es2pandaEnums" import type { AstNode } from "../peers/AstNode" +import { isSameNativeObject } from "../peers/ArktsObject" import { type AnnotationUsage, ClassDefinition, @@ -73,6 +74,9 @@ export function updateETSModuleByStatements( node: ETSModule, statements: readonly AstNode[], ): ETSModule { + if (isSameNativeObject(statements, node.statements)) { + return node + } global.generatedEs2panda._BlockStatementSetStatements(global.context, node.peer, passNodeArray(statements), statements.length) return node } diff --git a/ui2abc/libarkts/src/arkts-api/visitor.ts b/ui2abc/libarkts/src/arkts-api/visitor.ts index f1fb3340f7359b14201ecbee80fa94c4c9cef06b..ac64f41d257e0e3d90b06a4c37d54d7ba9068b40 100644 --- a/ui2abc/libarkts/src/arkts-api/visitor.ts +++ b/ui2abc/libarkts/src/arkts-api/visitor.ts @@ -144,6 +144,10 @@ export function visitEachChild( node: AstNode, visitor: Visitor ): AstNode { + // Unable to visit such nodes due to es2panda cache bug + if (isBlockExpression(node) || isChainExpression(node)) { + return node + } global.profiler.nodeVisited() if (isETSModule(node)) { return updateETSModuleByStatements( diff --git a/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts b/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts index 833446f05e46d1dc7c205f365dc93b2d1116070f..db1f2d58e2747a1f1fb0835ed6b6fc523487ac99 100644 --- a/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts +++ b/ui2abc/libarkts/src/generated/Es2pandaNativeModule.ts @@ -1336,12 +1336,6 @@ export class Es2pandaNativeModule { _ScriptFunctionFormalParamsLengthConst(context: KNativePointer, receiver: KNativePointer): KUInt { throw new Error("This methods was not overloaded by native module initialization") } - _ScriptFunctionSetIsolatedDeclgenReturnType(context: KNativePointer, receiver: KNativePointer, type: KStringPtr): void { - throw new Error("This methods was not overloaded by native module initialization") - } - _ScriptFunctionGetIsolatedDeclgenReturnTypeConst(context: KNativePointer, receiver: KNativePointer): KStringPtr { - throw new Error("This methods was not overloaded by native module initialization") - } _ScriptFunctionEmplaceReturnStatements(context: KNativePointer, receiver: KNativePointer, returnStatements: KNativePointer): void { throw new Error("This methods was not overloaded by native module initialization") } @@ -2098,9 +2092,6 @@ export class Es2pandaNativeModule { _AstNodeDumpDeclConst(context: KNativePointer, receiver: KNativePointer): KStringPtr { throw new Error("This methods was not overloaded by native module initialization") } - _AstNodeIsolatedDumpDeclConst(context: KNativePointer, receiver: KNativePointer): KStringPtr { - throw new Error("This methods was not overloaded by native module initialization") - } _AstNodeDumpConst(context: KNativePointer, receiver: KNativePointer, dumper: KNativePointer): void { throw new Error("This methods was not overloaded by native module initialization") } @@ -3742,7 +3733,7 @@ export class Es2pandaNativeModule { _CreateSrcDumper(context: KNativePointer, node: KNativePointer): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } - _CreateSrcDumper1(context: KNativePointer, node: KNativePointer, isDeclgen: KBoolean, isIsolatedDeclgen: KBoolean): KNativePointer { + _CreateSrcDumper1(context: KNativePointer, node: KNativePointer, isDeclgen: KBoolean): KNativePointer { throw new Error("This methods was not overloaded by native module initialization") } _SrcDumperAdd(context: KNativePointer, receiver: KNativePointer, str: KStringPtr): void { @@ -3781,9 +3772,6 @@ export class Es2pandaNativeModule { _SrcDumperIsDeclgenConst(context: KNativePointer, receiver: KNativePointer): KBoolean { throw new Error("This methods was not overloaded by native module initialization") } - _SrcDumperIsIsolatedDeclgenConst(context: KNativePointer, receiver: KNativePointer): KBoolean { - throw new Error("This methods was not overloaded by native module initialization") - } _SrcDumperDumpNode(context: KNativePointer, receiver: KNativePointer, key: KStringPtr): void { throw new Error("This methods was not overloaded by native module initialization") } diff --git a/ui2abc/libarkts/src/generated/index.ts b/ui2abc/libarkts/src/generated/index.ts index acb52f8f42a5cc7177e87eb758baa67a986ca588..8ee50a1a66c6568bffb8bca7426e213c86c0a1ab 100644 --- a/ui2abc/libarkts/src/generated/index.ts +++ b/ui2abc/libarkts/src/generated/index.ts @@ -208,7 +208,6 @@ export * from "./peers/NewExpression" export * from "./peers/TSParameterProperty" export * from "./peers/ETSWildcardType" export * from "./peers/TSThisType" -export * from "./peers/ETSDynamicFunctionType" export * from "./peers/InterfaceDecl" export * from "./peers/FunctionDecl" export * from "./peers/Program" diff --git a/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts b/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts index 4cd3a144371ac5244f8bb5417982e020a28253f0..6ca88b1836545636a90e9921611b130894a5ca8f 100644 --- a/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts +++ b/ui2abc/libarkts/src/generated/peers/ScriptFunction.ts @@ -190,14 +190,6 @@ export class ScriptFunction extends AstNode { return global.generatedEs2panda._ScriptFunctionFormalParamsLengthConst(global.context, this.peer) } /** @deprecated */ - setIsolatedDeclgenReturnType(type: string): this { - global.generatedEs2panda._ScriptFunctionSetIsolatedDeclgenReturnType(global.context, this.peer, type) - return this - } - get isolatedDeclgenReturnType(): string { - return unpackString(global.generatedEs2panda._ScriptFunctionGetIsolatedDeclgenReturnTypeConst(global.context, this.peer)) - } - /** @deprecated */ emplaceReturnStatements(returnStatements?: ReturnStatement): this { global.generatedEs2panda._ScriptFunctionEmplaceReturnStatements(global.context, this.peer, passNode(returnStatements)) return this diff --git a/ui2abc/libarkts/src/generated/peers/SrcDumper.ts b/ui2abc/libarkts/src/generated/peers/SrcDumper.ts index 8ec090e54218eb167355b717a2e242c210cd8f69..ff56dbb4973f719fda5bf5b89c097493d9711844 100644 --- a/ui2abc/libarkts/src/generated/peers/SrcDumper.ts +++ b/ui2abc/libarkts/src/generated/peers/SrcDumper.ts @@ -32,8 +32,8 @@ export class SrcDumper extends ArktsObject { constructor(pointer: KNativePointer) { super(pointer) } - static create1SrcDumper(node: AstNode | undefined, isDeclgen: boolean, isIsolatedDeclgen: boolean): SrcDumper { - return new SrcDumper(global.generatedEs2panda._CreateSrcDumper1(global.context, passNode(node), isDeclgen, isIsolatedDeclgen)) + static create1SrcDumper(node: AstNode | undefined, isDeclgen: boolean): SrcDumper { + return new SrcDumper(global.generatedEs2panda._CreateSrcDumper1(global.context, passNode(node), isDeclgen)) } /** @deprecated */ add(str: string): this { @@ -91,9 +91,6 @@ export class SrcDumper extends ArktsObject { get isDeclgen(): boolean { return global.generatedEs2panda._SrcDumperIsDeclgenConst(global.context, this.peer) } - get isIsolatedDeclgen(): boolean { - return global.generatedEs2panda._SrcDumperIsIsolatedDeclgenConst(global.context, this.peer) - } /** @deprecated */ dumpNode(key: string): this { global.generatedEs2panda._SrcDumperDumpNode(global.context, this.peer, key) diff --git a/ui2abc/libarkts/src/index.ts b/ui2abc/libarkts/src/index.ts index c1738ed5eae2c458c7e2a22d6c51b123ed110f40..64749e8c5bc54d78b156e5db9840568108d44a6c 100644 --- a/ui2abc/libarkts/src/index.ts +++ b/ui2abc/libarkts/src/index.ts @@ -33,6 +33,7 @@ export * from "./arkts-api/InferVoidReturnType" export * from "./arkts-api/ProgramProvider" export * from "./arkts-api/node-utilities/Program" export * from "./arkts-api/node-utilities/ArkTsConfig" +export * from "./arkts-api/CompileWithCache" export * from "./arkts-api/peers/AstNode" export * from "./arkts-api/peers/Config" diff --git a/ui2abc/libarkts/src/plugin-utils.ts b/ui2abc/libarkts/src/plugin-utils.ts index f8903a482535a30c567437da0e19cc7d0aa5779f..32187d1f0ef3604f43291f168580653a86cb9222 100644 --- a/ui2abc/libarkts/src/plugin-utils.ts +++ b/ui2abc/libarkts/src/plugin-utils.ts @@ -24,7 +24,8 @@ import { Program, inferVoidReturnType, ProgramProvider, - CompilationOptions + CompilationOptions, + setAllParentsByPlugin } from "./arkts-api" import { AstNode } from "./reexport-for-generated" @@ -70,7 +71,7 @@ export function runTransformerOnProgram(program: Program, options: CompilationOp importStorage.update() // Set parents of all nodes in AST - setAllParents(ast) + setAllParentsByPlugin(ast) // Perform some additional actions after the transformation end hooks.onProgramTransformEnd?.(options) @@ -95,7 +96,8 @@ export function runTransformer(prog: Program, state: Es2pandaContextState, resta runTransformerOnProgram(currentProgram, options, transform, pluginContext, hooks) // The first program is always the main program, so break here if should not proceed external sources - if (restart) break + if (restart) + break isMainProgram = false // Proceed to the next program