From 478bc0a357383dbffbd63708a030f5517b7aca5b Mon Sep 17 00:00:00 2001 From: Igor Loginov Date: Tue, 29 Jul 2025 10:36:59 +0300 Subject: [PATCH 1/2] Attempt to remove annotate --- incremental/runtime/package.json | 2 +- incremental/runtime/src/memo/bind.ts | 20 +- incremental/runtime/src/memo/testing.ts | 14 +- incremental/runtime/ui2abcconfig.json | 4 +- .../libarkts/native/src/generated/bridges.cc | 2 +- .../libarkts/src/generated/Es2pandaEnums.ts | 181 +++++++++--------- ui2abc/memo-plugin/demo/demo/demo.ets | 2 +- ui2abc/memo-plugin/demo/ui2abcconfig.json | 4 +- ui2abc/memo-plugin/src/FunctionTransformer.ts | 9 +- ui2abc/memo-plugin/src/MemoTransformer.ts | 3 +- ui2abc/memo-plugin/src/ParserTransformer.ts | 97 +++++++++- ui2abc/memo-plugin/src/utils.ts | 117 +++++++---- 12 files changed, 292 insertions(+), 163 deletions(-) diff --git a/incremental/runtime/package.json b/incremental/runtime/package.json index ba267ab6dc..f3f6617ba5 100644 --- a/incremental/runtime/package.json +++ b/incremental/runtime/package.json @@ -18,7 +18,7 @@ "test:coverage": "nyc mocha", "annotate": "npm run compile --prefix ../../ui2abc/annotate && node ../../ui2abc/annotate", "annotate:tests": "npm run compile --prefix ../../ui2abc/annotate && node ../../ui2abc/annotate annotate-tests.json", - "build": "npm run annotate && node ../../ui2abc/fast-arktsc --config ./ui2abcconfig.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --simultaneous && PANDA_SDK_PATH=${PANDA_SDK_PATH:=../tools/panda/node_modules/@panda/sdk} ninja ${NINJA_OPTIONS} -f build/recheck/build.ninja", + "build": "node ../../ui2abc/fast-arktsc --config ./ui2abcconfig.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime.abc --simultaneous && PANDA_SDK_PATH=${PANDA_SDK_PATH:=../tools/panda/node_modules/@panda/sdk} ninja ${NINJA_OPTIONS} -f build/recheck/build.ninja", "build:tests": "node ../../ui2abc/fast-arktsc --config ./ui2abcconfig-tests.json --compiler ../tools/panda/arkts/ui2abc --link-name ./build/runtime-tests.abc --simultaneous && PANDA_SDK_PATH=${PANDA_SDK_PATH:=../tools/panda/node_modules/@panda/sdk} ninja ${NINJA_OPTIONS} -f build/build.ninja", "arkts:test:run": "bash ../tools/panda/arkts/ark build/runtime-tests.abc --ark-boot-files ../compat/build/compat.abc:../common/build/common.abc:../harness/build/harness.abc --ark-entry-point @koalaui.runtime-tests.ets-test.tests.ETSGLOBAL::main", "arkts:test": "npm run build --prefix ../compat && npm run build --prefix ../common && npm run build --prefix ../harness && npm run annotate && npm run annotate:tests && npm run build:tests && npm run arkts:test:run" diff --git a/incremental/runtime/src/memo/bind.ts b/incremental/runtime/src/memo/bind.ts index 2a1eb6880e..f095de86e9 100644 --- a/incremental/runtime/src/memo/bind.ts +++ b/incremental/runtime/src/memo/bind.ts @@ -21,10 +21,7 @@ export function memoBind( /** @memo */ () => void { - return ( - /** @memo */ - (): void => { item(value) } - ) + throw new Error("no impl") } /** @internal */ @@ -35,10 +32,7 @@ export function memoBind2( /** @memo */ () => void { - return ( - /** @memo */ - (): void => { item(value1, value2) } - ) + throw new Error("no impl") } /** @internal */ @@ -50,10 +44,7 @@ export function memoPartialBind2_1( /** @memo */ (arg2: T2) => void { - return ( - /** @memo */ - (arg2: T2): void => { item(value1, arg2) } - ) + throw new Error("no impl") } /** @internal */ @@ -65,8 +56,5 @@ export function memoPartialBind3_2( /** @memo */ (arg2: T2, arg3: T3) => void { - return ( - /** @memo */ - (arg2: T2, arg3: T3): void => { item(value1, arg2, arg3) } - ) + throw new Error("no impl") } diff --git a/incremental/runtime/src/memo/testing.ts b/incremental/runtime/src/memo/testing.ts index 0daed99362..dc11c8b1ef 100644 --- a/incremental/runtime/src/memo/testing.ts +++ b/incremental/runtime/src/memo/testing.ts @@ -40,13 +40,13 @@ export class TestNode extends IncrementalNode { return memoRoot(new TestNode(), content) } - /** @memo:intrinsic */ - static attach( - /** @memo */ - content: (node: TestNode) => void - ): void { - NodeAttach(():TestNode => new TestNode(), content) - } + // /** @memo:intrinsic */ + // static attach( + // /** @memo */ + // content: (node: TestNode) => void + // ): void { + // NodeAttach(():TestNode => new TestNode(), content) + // } } diff --git a/incremental/runtime/ui2abcconfig.json b/incremental/runtime/ui2abcconfig.json index db3f7a8280..1f5b216199 100644 --- a/incremental/runtime/ui2abcconfig.json +++ b/incremental/runtime/ui2abcconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "package": "@koalaui/runtime", "outDir": "build/recheck", - "baseUrl": "./ets", + "baseUrl": "./src", "paths": { "@koalaui/common": ["../../common/src"], "@koalaui/compat": ["../../compat/src/arkts"], @@ -22,5 +22,5 @@ } ] }, - "include": ["ets/**/*.ts"] + "include": ["src/**/*.ts"] } diff --git a/ui2abc/libarkts/native/src/generated/bridges.cc b/ui2abc/libarkts/native/src/generated/bridges.cc index 37f14a92e4..adf27ac393 100644 --- a/ui2abc/libarkts/native/src/generated/bridges.cc +++ b/ui2abc/libarkts/native/src/generated/bridges.cc @@ -17,7 +17,7 @@ /* * THIS FILE IS AUTOGENERATED BY arktscgen v2.1.9-arktscgen-8. DO NOT EDIT MANUALLY! - * es2panda 78c262f8932b0c00eb1085a94c931b9b420d3540(2025-07-25) sdk v1.5.0-dev.38942 + * es2panda c2e49f679ddaf2ddd5970f5d5294b73fe9164283(2025-07-28) sdk v1.5.0-dev.39026 */ KNativePointer impl_CreateNumberLiteral(KNativePointer context, KInt value) diff --git a/ui2abc/libarkts/src/generated/Es2pandaEnums.ts b/ui2abc/libarkts/src/generated/Es2pandaEnums.ts index 114f409cac..8f024a015b 100644 --- a/ui2abc/libarkts/src/generated/Es2pandaEnums.ts +++ b/ui2abc/libarkts/src/generated/Es2pandaEnums.ts @@ -1024,96 +1024,97 @@ export enum Es2pandaGlobalTypeId { GLOBAL_TYPE_ID_ETS_BIG_INT_BUILTIN = 92, GLOBAL_TYPE_ID_ETS_BIG_INT = 93, GLOBAL_TYPE_ID_ETS_ARRAY = 94, - GLOBAL_TYPE_ID_ETS_FUNCTION0_CLASS = 95, - GLOBAL_TYPE_ID_ETS_FUNCTION1_CLASS = 96, - GLOBAL_TYPE_ID_ETS_FUNCTION2_CLASS = 97, - GLOBAL_TYPE_ID_ETS_FUNCTION3_CLASS = 98, - GLOBAL_TYPE_ID_ETS_FUNCTION4_CLASS = 99, - GLOBAL_TYPE_ID_ETS_FUNCTION5_CLASS = 100, - GLOBAL_TYPE_ID_ETS_FUNCTION6_CLASS = 101, - GLOBAL_TYPE_ID_ETS_FUNCTION7_CLASS = 102, - GLOBAL_TYPE_ID_ETS_FUNCTION8_CLASS = 103, - GLOBAL_TYPE_ID_ETS_FUNCTION9_CLASS = 104, - GLOBAL_TYPE_ID_ETS_FUNCTION10_CLASS = 105, - GLOBAL_TYPE_ID_ETS_FUNCTION11_CLASS = 106, - GLOBAL_TYPE_ID_ETS_FUNCTION12_CLASS = 107, - GLOBAL_TYPE_ID_ETS_FUNCTION13_CLASS = 108, - GLOBAL_TYPE_ID_ETS_FUNCTION14_CLASS = 109, - GLOBAL_TYPE_ID_ETS_FUNCTION15_CLASS = 110, - GLOBAL_TYPE_ID_ETS_FUNCTION16_CLASS = 111, - GLOBAL_TYPE_ID_ETS_FUNCTIONN_CLASS = 112, - GLOBAL_TYPE_ID_ETS_LAMBDA0_CLASS = 113, - GLOBAL_TYPE_ID_ETS_LAMBDA1_CLASS = 114, - GLOBAL_TYPE_ID_ETS_LAMBDA2_CLASS = 115, - GLOBAL_TYPE_ID_ETS_LAMBDA3_CLASS = 116, - GLOBAL_TYPE_ID_ETS_LAMBDA4_CLASS = 117, - GLOBAL_TYPE_ID_ETS_LAMBDA5_CLASS = 118, - GLOBAL_TYPE_ID_ETS_LAMBDA6_CLASS = 119, - GLOBAL_TYPE_ID_ETS_LAMBDA7_CLASS = 120, - GLOBAL_TYPE_ID_ETS_LAMBDA8_CLASS = 121, - GLOBAL_TYPE_ID_ETS_LAMBDA9_CLASS = 122, - GLOBAL_TYPE_ID_ETS_LAMBDA10_CLASS = 123, - GLOBAL_TYPE_ID_ETS_LAMBDA11_CLASS = 124, - GLOBAL_TYPE_ID_ETS_LAMBDA12_CLASS = 125, - GLOBAL_TYPE_ID_ETS_LAMBDA13_CLASS = 126, - GLOBAL_TYPE_ID_ETS_LAMBDA14_CLASS = 127, - GLOBAL_TYPE_ID_ETS_LAMBDA15_CLASS = 128, - GLOBAL_TYPE_ID_ETS_LAMBDA16_CLASS = 129, - GLOBAL_TYPE_ID_ETS_LAMBDAN_CLASS = 130, - GLOBAL_TYPE_ID_ETS_FUNCTIONR0_CLASS = 131, - GLOBAL_TYPE_ID_ETS_FUNCTIONR1_CLASS = 132, - GLOBAL_TYPE_ID_ETS_FUNCTIONR2_CLASS = 133, - GLOBAL_TYPE_ID_ETS_FUNCTIONR3_CLASS = 134, - GLOBAL_TYPE_ID_ETS_FUNCTIONR4_CLASS = 135, - GLOBAL_TYPE_ID_ETS_FUNCTIONR5_CLASS = 136, - GLOBAL_TYPE_ID_ETS_FUNCTIONR6_CLASS = 137, - GLOBAL_TYPE_ID_ETS_FUNCTIONR7_CLASS = 138, - GLOBAL_TYPE_ID_ETS_FUNCTIONR8_CLASS = 139, - GLOBAL_TYPE_ID_ETS_FUNCTIONR9_CLASS = 140, - GLOBAL_TYPE_ID_ETS_FUNCTIONR10_CLASS = 141, - GLOBAL_TYPE_ID_ETS_FUNCTIONR11_CLASS = 142, - GLOBAL_TYPE_ID_ETS_FUNCTIONR12_CLASS = 143, - GLOBAL_TYPE_ID_ETS_FUNCTIONR13_CLASS = 144, - GLOBAL_TYPE_ID_ETS_FUNCTIONR14_CLASS = 145, - GLOBAL_TYPE_ID_ETS_FUNCTIONR15_CLASS = 146, - GLOBAL_TYPE_ID_ETS_FUNCTIONR16_CLASS = 147, - GLOBAL_TYPE_ID_ETS_LAMBDAR0_CLASS = 148, - GLOBAL_TYPE_ID_ETS_LAMBDAR1_CLASS = 149, - GLOBAL_TYPE_ID_ETS_LAMBDAR2_CLASS = 150, - GLOBAL_TYPE_ID_ETS_LAMBDAR3_CLASS = 151, - GLOBAL_TYPE_ID_ETS_LAMBDAR4_CLASS = 152, - GLOBAL_TYPE_ID_ETS_LAMBDAR5_CLASS = 153, - GLOBAL_TYPE_ID_ETS_LAMBDAR6_CLASS = 154, - GLOBAL_TYPE_ID_ETS_LAMBDAR7_CLASS = 155, - GLOBAL_TYPE_ID_ETS_LAMBDAR8_CLASS = 156, - GLOBAL_TYPE_ID_ETS_LAMBDAR9_CLASS = 157, - GLOBAL_TYPE_ID_ETS_LAMBDAR10_CLASS = 158, - GLOBAL_TYPE_ID_ETS_LAMBDAR11_CLASS = 159, - GLOBAL_TYPE_ID_ETS_LAMBDAR12_CLASS = 160, - GLOBAL_TYPE_ID_ETS_LAMBDAR13_CLASS = 161, - GLOBAL_TYPE_ID_ETS_LAMBDAR14_CLASS = 162, - GLOBAL_TYPE_ID_ETS_LAMBDAR15_CLASS = 163, - GLOBAL_TYPE_ID_ETS_LAMBDAR16_CLASS = 164, - GLOBAL_TYPE_ID_ETS_TUPLE0_CLASS = 165, - GLOBAL_TYPE_ID_ETS_TUPLE1_CLASS = 166, - GLOBAL_TYPE_ID_ETS_TUPLE2_CLASS = 167, - GLOBAL_TYPE_ID_ETS_TUPLE3_CLASS = 168, - GLOBAL_TYPE_ID_ETS_TUPLE4_CLASS = 169, - GLOBAL_TYPE_ID_ETS_TUPLE5_CLASS = 170, - GLOBAL_TYPE_ID_ETS_TUPLE6_CLASS = 171, - GLOBAL_TYPE_ID_ETS_TUPLE7_CLASS = 172, - GLOBAL_TYPE_ID_ETS_TUPLE8_CLASS = 173, - GLOBAL_TYPE_ID_ETS_TUPLE9_CLASS = 174, - GLOBAL_TYPE_ID_ETS_TUPLE10_CLASS = 175, - GLOBAL_TYPE_ID_ETS_TUPLE11_CLASS = 176, - GLOBAL_TYPE_ID_ETS_TUPLE12_CLASS = 177, - GLOBAL_TYPE_ID_ETS_TUPLE13_CLASS = 178, - GLOBAL_TYPE_ID_ETS_TUPLE14_CLASS = 179, - GLOBAL_TYPE_ID_ETS_TUPLE15_CLASS = 180, - GLOBAL_TYPE_ID_ETS_TUPLE16_CLASS = 181, - GLOBAL_TYPE_ID_ETS_TUPLEN_CLASS = 182, - GLOBAL_TYPE_ID_TYPE_ERROR = 183, - GLOBAL_TYPE_ID_COUNT = 184 + GLOBAL_TYPE_ID_ETS_READONLY_ARRAY = 95, + GLOBAL_TYPE_ID_ETS_FUNCTION0_CLASS = 96, + GLOBAL_TYPE_ID_ETS_FUNCTION1_CLASS = 97, + GLOBAL_TYPE_ID_ETS_FUNCTION2_CLASS = 98, + GLOBAL_TYPE_ID_ETS_FUNCTION3_CLASS = 99, + GLOBAL_TYPE_ID_ETS_FUNCTION4_CLASS = 100, + GLOBAL_TYPE_ID_ETS_FUNCTION5_CLASS = 101, + GLOBAL_TYPE_ID_ETS_FUNCTION6_CLASS = 102, + GLOBAL_TYPE_ID_ETS_FUNCTION7_CLASS = 103, + GLOBAL_TYPE_ID_ETS_FUNCTION8_CLASS = 104, + GLOBAL_TYPE_ID_ETS_FUNCTION9_CLASS = 105, + GLOBAL_TYPE_ID_ETS_FUNCTION10_CLASS = 106, + GLOBAL_TYPE_ID_ETS_FUNCTION11_CLASS = 107, + GLOBAL_TYPE_ID_ETS_FUNCTION12_CLASS = 108, + GLOBAL_TYPE_ID_ETS_FUNCTION13_CLASS = 109, + GLOBAL_TYPE_ID_ETS_FUNCTION14_CLASS = 110, + GLOBAL_TYPE_ID_ETS_FUNCTION15_CLASS = 111, + GLOBAL_TYPE_ID_ETS_FUNCTION16_CLASS = 112, + GLOBAL_TYPE_ID_ETS_FUNCTIONN_CLASS = 113, + GLOBAL_TYPE_ID_ETS_LAMBDA0_CLASS = 114, + GLOBAL_TYPE_ID_ETS_LAMBDA1_CLASS = 115, + GLOBAL_TYPE_ID_ETS_LAMBDA2_CLASS = 116, + GLOBAL_TYPE_ID_ETS_LAMBDA3_CLASS = 117, + GLOBAL_TYPE_ID_ETS_LAMBDA4_CLASS = 118, + GLOBAL_TYPE_ID_ETS_LAMBDA5_CLASS = 119, + GLOBAL_TYPE_ID_ETS_LAMBDA6_CLASS = 120, + GLOBAL_TYPE_ID_ETS_LAMBDA7_CLASS = 121, + GLOBAL_TYPE_ID_ETS_LAMBDA8_CLASS = 122, + GLOBAL_TYPE_ID_ETS_LAMBDA9_CLASS = 123, + GLOBAL_TYPE_ID_ETS_LAMBDA10_CLASS = 124, + GLOBAL_TYPE_ID_ETS_LAMBDA11_CLASS = 125, + GLOBAL_TYPE_ID_ETS_LAMBDA12_CLASS = 126, + GLOBAL_TYPE_ID_ETS_LAMBDA13_CLASS = 127, + GLOBAL_TYPE_ID_ETS_LAMBDA14_CLASS = 128, + GLOBAL_TYPE_ID_ETS_LAMBDA15_CLASS = 129, + GLOBAL_TYPE_ID_ETS_LAMBDA16_CLASS = 130, + GLOBAL_TYPE_ID_ETS_LAMBDAN_CLASS = 131, + GLOBAL_TYPE_ID_ETS_FUNCTIONR0_CLASS = 132, + GLOBAL_TYPE_ID_ETS_FUNCTIONR1_CLASS = 133, + GLOBAL_TYPE_ID_ETS_FUNCTIONR2_CLASS = 134, + GLOBAL_TYPE_ID_ETS_FUNCTIONR3_CLASS = 135, + GLOBAL_TYPE_ID_ETS_FUNCTIONR4_CLASS = 136, + GLOBAL_TYPE_ID_ETS_FUNCTIONR5_CLASS = 137, + GLOBAL_TYPE_ID_ETS_FUNCTIONR6_CLASS = 138, + GLOBAL_TYPE_ID_ETS_FUNCTIONR7_CLASS = 139, + GLOBAL_TYPE_ID_ETS_FUNCTIONR8_CLASS = 140, + GLOBAL_TYPE_ID_ETS_FUNCTIONR9_CLASS = 141, + GLOBAL_TYPE_ID_ETS_FUNCTIONR10_CLASS = 142, + GLOBAL_TYPE_ID_ETS_FUNCTIONR11_CLASS = 143, + GLOBAL_TYPE_ID_ETS_FUNCTIONR12_CLASS = 144, + GLOBAL_TYPE_ID_ETS_FUNCTIONR13_CLASS = 145, + GLOBAL_TYPE_ID_ETS_FUNCTIONR14_CLASS = 146, + GLOBAL_TYPE_ID_ETS_FUNCTIONR15_CLASS = 147, + GLOBAL_TYPE_ID_ETS_FUNCTIONR16_CLASS = 148, + GLOBAL_TYPE_ID_ETS_LAMBDAR0_CLASS = 149, + GLOBAL_TYPE_ID_ETS_LAMBDAR1_CLASS = 150, + GLOBAL_TYPE_ID_ETS_LAMBDAR2_CLASS = 151, + GLOBAL_TYPE_ID_ETS_LAMBDAR3_CLASS = 152, + GLOBAL_TYPE_ID_ETS_LAMBDAR4_CLASS = 153, + GLOBAL_TYPE_ID_ETS_LAMBDAR5_CLASS = 154, + GLOBAL_TYPE_ID_ETS_LAMBDAR6_CLASS = 155, + GLOBAL_TYPE_ID_ETS_LAMBDAR7_CLASS = 156, + GLOBAL_TYPE_ID_ETS_LAMBDAR8_CLASS = 157, + GLOBAL_TYPE_ID_ETS_LAMBDAR9_CLASS = 158, + GLOBAL_TYPE_ID_ETS_LAMBDAR10_CLASS = 159, + GLOBAL_TYPE_ID_ETS_LAMBDAR11_CLASS = 160, + GLOBAL_TYPE_ID_ETS_LAMBDAR12_CLASS = 161, + GLOBAL_TYPE_ID_ETS_LAMBDAR13_CLASS = 162, + GLOBAL_TYPE_ID_ETS_LAMBDAR14_CLASS = 163, + GLOBAL_TYPE_ID_ETS_LAMBDAR15_CLASS = 164, + GLOBAL_TYPE_ID_ETS_LAMBDAR16_CLASS = 165, + GLOBAL_TYPE_ID_ETS_TUPLE0_CLASS = 166, + GLOBAL_TYPE_ID_ETS_TUPLE1_CLASS = 167, + GLOBAL_TYPE_ID_ETS_TUPLE2_CLASS = 168, + GLOBAL_TYPE_ID_ETS_TUPLE3_CLASS = 169, + GLOBAL_TYPE_ID_ETS_TUPLE4_CLASS = 170, + GLOBAL_TYPE_ID_ETS_TUPLE5_CLASS = 171, + GLOBAL_TYPE_ID_ETS_TUPLE6_CLASS = 172, + GLOBAL_TYPE_ID_ETS_TUPLE7_CLASS = 173, + GLOBAL_TYPE_ID_ETS_TUPLE8_CLASS = 174, + GLOBAL_TYPE_ID_ETS_TUPLE9_CLASS = 175, + GLOBAL_TYPE_ID_ETS_TUPLE10_CLASS = 176, + GLOBAL_TYPE_ID_ETS_TUPLE11_CLASS = 177, + GLOBAL_TYPE_ID_ETS_TUPLE12_CLASS = 178, + GLOBAL_TYPE_ID_ETS_TUPLE13_CLASS = 179, + GLOBAL_TYPE_ID_ETS_TUPLE14_CLASS = 180, + GLOBAL_TYPE_ID_ETS_TUPLE15_CLASS = 181, + GLOBAL_TYPE_ID_ETS_TUPLE16_CLASS = 182, + GLOBAL_TYPE_ID_ETS_TUPLEN_CLASS = 183, + GLOBAL_TYPE_ID_TYPE_ERROR = 184, + GLOBAL_TYPE_ID_COUNT = 185 } export enum Es2pandaMethodDefinitionKind { METHOD_DEFINITION_KIND_NONE = 0, diff --git a/ui2abc/memo-plugin/demo/demo/demo.ets b/ui2abc/memo-plugin/demo/demo/demo.ets index f25204e34d..3c29c97d69 100644 --- a/ui2abc/memo-plugin/demo/demo/demo.ets +++ b/ui2abc/memo-plugin/demo/demo/demo.ets @@ -44,7 +44,7 @@ function Stringer( const state = mutableState(17) -@memo +/** @memo */ function demo(node: StringerNode): void { Stringer("First", () => { console.log("Content of the first") diff --git a/ui2abc/memo-plugin/demo/ui2abcconfig.json b/ui2abc/memo-plugin/demo/ui2abcconfig.json index 8c774696ac..829f1964a1 100644 --- a/ui2abc/memo-plugin/demo/ui2abcconfig.json +++ b/ui2abc/memo-plugin/demo/ui2abcconfig.json @@ -7,18 +7,20 @@ "@koalaui/compat": [ "../../../../incremental/compat/src/arkts" ], "#platform": [ "../../../../incremental/compat/src/arkts" ], "@koalaui/common": [ "../../../../incremental/common/src" ], - "@koalaui/runtime": [ "../../../../incremental/runtime/ets" ], + "@koalaui/runtime": [ "../../../../incremental/runtime/src" ], "@koalaui/runtime/annotations": [ "../../../../incremental/runtime/annotations" ] }, "plugins": [ { "transform": "@koalaui/memo-plugin", "state": "parsed", + "jsDocAnnotations": true, "name": "memo" }, { "transform": "@koalaui/memo-plugin", "state": "checked", + "jsDocAnnotations": true, "name": "memo" } ] diff --git a/ui2abc/memo-plugin/src/FunctionTransformer.ts b/ui2abc/memo-plugin/src/FunctionTransformer.ts index 1636080cfe..5de23473d5 100644 --- a/ui2abc/memo-plugin/src/FunctionTransformer.ts +++ b/ui2abc/memo-plugin/src/FunctionTransformer.ts @@ -20,8 +20,7 @@ import { PositionalIdTracker, RuntimeNames, getDeclResolveGensym, - hasMemoStableAnnotation, - hasWrapAnnotation, + AnnotationGetter, isTrackableParam, moveToFront, shouldWrap, @@ -161,7 +160,7 @@ export class FunctionTransformer extends arkts.AbstractVisitor { enter(node: arkts.AstNode) { if (arkts.isClassDefinition(node)) { - if (hasMemoStableAnnotation(node)) { + if (AnnotationGetter.hasMemoStableAnnotation(node)) { this.stable++ } } @@ -170,7 +169,7 @@ export class FunctionTransformer extends arkts.AbstractVisitor { exit(node: arkts.AstNode) { if (arkts.isClassDefinition(node)) { - if (hasMemoStableAnnotation(node)) { + if (AnnotationGetter.hasMemoStableAnnotation(node)) { this.stable-- } } @@ -178,7 +177,7 @@ export class FunctionTransformer extends arkts.AbstractVisitor { } fixObjectArg(arg: arkts.Expression, param: arkts.ETSParameterExpression) { - if (param.typeAnnotation && (arkts.isObjectExpression(arg) || hasWrapAnnotation(param))) { + if (param.typeAnnotation && (arkts.isObjectExpression(arg) || AnnotationGetter.hasWrapAnnotation(param))) { return arkts.factory.createTSAsExpression( arg, param.typeAnnotation.clone(), diff --git a/ui2abc/memo-plugin/src/MemoTransformer.ts b/ui2abc/memo-plugin/src/MemoTransformer.ts index e8e065422e..6e605dd958 100644 --- a/ui2abc/memo-plugin/src/MemoTransformer.ts +++ b/ui2abc/memo-plugin/src/MemoTransformer.ts @@ -16,7 +16,7 @@ import * as arkts from "@koalaui/libarkts" import { AnalysisVisitor } from "./AnalysisVisitor" import { FunctionTransformer } from "./FunctionTransformer" -import { dumpAstToFile, MemoFunctionKind, PositionalIdTracker } from "./utils" +import { AnnotationGetter, dumpAstToFile, MemoFunctionKind, PositionalIdTracker } from "./utils" import { InternalsTransformer } from "./InternalsTransformer" import { ParameterTransformer } from "./ParameterTransformer" import { ReturnTransformer } from "./ReturnTranformer" @@ -30,6 +30,7 @@ export interface TransformerOptions { keepTransformed?: string, addLogging?: boolean, trackContentParam?: boolean, + jsDocAnnotations?: boolean, } export default function memoTransformer( diff --git a/ui2abc/memo-plugin/src/ParserTransformer.ts b/ui2abc/memo-plugin/src/ParserTransformer.ts index d450609c18..f0891ff488 100644 --- a/ui2abc/memo-plugin/src/ParserTransformer.ts +++ b/ui2abc/memo-plugin/src/ParserTransformer.ts @@ -15,6 +15,7 @@ import * as arkts from "@koalaui/libarkts" import { factory } from "./MemoFactory" +import { Annotations } from "./utils" const ignore = [ "@koalaui/compat", @@ -34,7 +35,59 @@ const ignore = [ export interface TransformerOptions { contextImport?: string, - stableForTests?: boolean + stableForTests?: boolean, + jsDocAnnotations?: boolean, +} + +/** + * Currently, some jsdoc annotations are lost on proceeding to checked, + * so we obtain them on parsed state and convert to ets annotations. + */ +class AnnotationTransformer extends arkts.AbstractVisitor { + needImport = false + + annotation(name: string) { + const annotation = arkts.factory.createAnnotationUsage( + arkts.factory.createIdentifier(name).setAnnotationUsage(), + [], + ) + annotation.modifierFlags = arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_ANNOTATION_USAGE + this.needImport = true + return annotation + } + + visitor(node: arkts.BlockStatement): arkts.BlockStatement + visitor(beforeChildren: arkts.AstNode): arkts.AstNode { + const node = this.visitEachChild(beforeChildren) + if (arkts.isScriptFunction(node) && arkts.isFunctionDeclaration(node.parent)) { + const jsDoc = arkts.getJsDoc(node) + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION)) { + node.parent.setAnnotations([this.annotation(Annotations.ANNOTATION), ...node.parent.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_ENTRY)) { + node.parent.setAnnotations([this.annotation(Annotations.ANNOTATION_ENTRY), ...node.parent.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_INTRINSIC)) { + node.parent.setAnnotations([this.annotation(Annotations.ANNOTATION_INTRINSIC), ...node.parent.annotations]) + } + } + if (arkts.isETSParameterExpression(node)) { + const jsDoc = arkts.getJsDoc(node) + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION)) { + node.setAnnotations([this.annotation(Annotations.ANNOTATION), ...node.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_ENTRY)) { + node.setAnnotations([this.annotation(Annotations.ANNOTATION_ENTRY), ...node.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_INTRINSIC)) { + node.setAnnotations([this.annotation(Annotations.ANNOTATION_INTRINSIC), ...node.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_SKIP)) { + node.setAnnotations([this.annotation(Annotations.ANNOTATION_SKIP), ...node.annotations]) + } + } + return node + } } export default function memoParserTransformer( @@ -46,6 +99,48 @@ export default function memoParserTransformer( return } + if (program.moduleName.startsWith("@koalaui/runtime") || userPluginOptions?.jsDocAnnotations) { + const annotationTransformer = new AnnotationTransformer() + annotationTransformer.visitor(program.ast) + if (annotationTransformer.needImport) { + const module = program.ast as arkts.ETSModule + console.log(program.ast.dumpSrc()) + program.setAst( + arkts.factory.updateETSModule( + module, + [ + arkts.factory.createETSImportDeclaration( + arkts.factory.createStringLiteral("@koalaui/runtime/annotations"), + [ + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier(Annotations.ANNOTATION), + arkts.factory.createIdentifier(Annotations.ANNOTATION), + ), + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier(Annotations.ANNOTATION_ENTRY), + arkts.factory.createIdentifier(Annotations.ANNOTATION_ENTRY), + ), + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier(Annotations.ANNOTATION_INTRINSIC), + arkts.factory.createIdentifier(Annotations.ANNOTATION_INTRINSIC), + ), + arkts.factory.createImportSpecifier( + arkts.factory.createIdentifier(Annotations.ANNOTATION_SKIP), + arkts.factory.createIdentifier(Annotations.ANNOTATION_SKIP), + ), + ], + arkts.Es2pandaImportKinds.IMPORT_KINDS_ALL + ), + ...module.statements, + ], + module.ident, + module.getNamespaceFlag(), + module.program, + ) + ) + } + } + const module = program.ast as arkts.ETSModule program.setAst( arkts.factory.updateETSModule( diff --git a/ui2abc/memo-plugin/src/utils.ts b/ui2abc/memo-plugin/src/utils.ts index 43ba7052f6..76f4938f6a 100644 --- a/ui2abc/memo-plugin/src/utils.ts +++ b/ui2abc/memo-plugin/src/utils.ts @@ -31,12 +31,6 @@ export enum RuntimeNames { __CONTEXT = "__context", __ID = "__id", __KEY = "__key", - ANNOTATION = "memo", - ANNOTATION_ENTRY = "memo_entry", - ANNOTATION_INTRINSIC = "memo_intrinsic", - ANNOTATION_SKIP = "memo_skip", - ANNOTATION_STABLE = "memo_stable", - ANNOTATION_WRAP = "memo_wrap", COMPUTE = "compute", CONTENT = "content", CONTEXT = "__memo_context", @@ -117,44 +111,93 @@ export enum MemoFunctionKind { ENTRY = 4, } -function hasMemoAnnotation(node: MemoAnnotatable) { - return node.annotations.some((it) => - it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === RuntimeNames.ANNOTATION - ) +export enum Annotations { + ANNOTATION = "memo", + ANNOTATION_ENTRY = "memo_entry", + ANNOTATION_INTRINSIC = "memo_intrinsic", + ANNOTATION_SKIP = "memo_skip", + ANNOTATION_STABLE = "memo_stable", + ANNOTATION_WRAP = "memo_wrap", + JSDOC_ANNOTATION = "/** @memo */", + JSDOC_ANNOTATION_ENTRY = "/** @memo:entry */", + JSDOC_ANNOTATION_INTRINSIC = "/** @memo:intrinsic */", + JSDOC_ANNOTATION_SKIP = "/** @skip:memo */", + JSDOC_ANNOTATION_STABLE = "/** @memo:stable */", + JSDOC_ANNOTATION_WRAP = "/** @memo:wrap */", } -function hasMemoEntryAnnotation(node: MemoAnnotatable) { - return node.annotations.some((it) => - it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === RuntimeNames.ANNOTATION_ENTRY - ) -} +export class AnnotationGetter { + static checkJsDoc = false -function hasMemoIntrinsicAnnotation(node: MemoAnnotatable) { - return node.annotations.some((it) => - it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === RuntimeNames.ANNOTATION_INTRINSIC - ) -} + static hasMemoAnnotation(node: MemoAnnotatable) { + if (this.checkJsDoc) { + if (arkts.getJsDoc(node) == Annotations.JSDOC_ANNOTATION) { + return true + } + } + return node.annotations.some((it) => + it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === Annotations.ANNOTATION + ) + } -function hasMemoSkipAnnotation(node: MemoSkipAnnotatable) { - return node.annotations.some((it) => - it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === RuntimeNames.ANNOTATION_SKIP - ) -} + static hasMemoEntryAnnotation(node: MemoAnnotatable) { + if (this.checkJsDoc) { + if (arkts.getJsDoc(node) == Annotations.JSDOC_ANNOTATION_ENTRY) { + return true + } + } + return node.annotations.some((it) => + it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === Annotations.ANNOTATION_ENTRY + ) + } -export function hasMemoStableAnnotation(node: MemoStableAnnotatable) { - return node.annotations.some((it) => - it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === RuntimeNames.ANNOTATION_STABLE - ) -} + static hasMemoIntrinsicAnnotation(node: MemoAnnotatable) { + if (this.checkJsDoc) { + if (arkts.getJsDoc(node) == Annotations.JSDOC_ANNOTATION_INTRINSIC) { + return true + } + } + return node.annotations.some((it) => + it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === Annotations.ANNOTATION_INTRINSIC + ) + } + + static hasMemoSkipAnnotation(node: MemoSkipAnnotatable) { + if (this.checkJsDoc) { + if (arkts.getJsDoc(node) == Annotations.JSDOC_ANNOTATION_SKIP) { + return true + } + } + return node.annotations.some((it) => + it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === Annotations.ANNOTATION_SKIP + ) + } -export function hasWrapAnnotation(node: arkts.ETSParameterExpression) { - return node.annotations.some((it) => - it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === RuntimeNames.ANNOTATION_WRAP - ) + static hasMemoStableAnnotation(node: MemoStableAnnotatable) { + if (this.checkJsDoc) { + if (arkts.getJsDoc(node) == Annotations.JSDOC_ANNOTATION_STABLE) { + return true + } + } + return node.annotations.some((it) => + it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === Annotations.ANNOTATION_STABLE + ) + } + + static hasWrapAnnotation(node: arkts.ETSParameterExpression) { + if (this.checkJsDoc) { + if (arkts.getJsDoc(node) == Annotations.JSDOC_ANNOTATION_WRAP) { + return true + } + } + return node.annotations.some((it) => + it.expr !== undefined && arkts.isIdentifier(it.expr) && it.expr.name === Annotations.ANNOTATION_WRAP + ) + } } export function getMemoFunctionKind(node: MemoAnnotatable): MemoFunctionKind { - const mask = (+hasMemoEntryAnnotation(node) << 2) + (+hasMemoIntrinsicAnnotation(node) << 1) + (+hasMemoAnnotation(node)) + const mask = (+AnnotationGetter.hasMemoEntryAnnotation(node) << 2) + (+AnnotationGetter.hasMemoIntrinsicAnnotation(node) << 1) + (+AnnotationGetter.hasMemoAnnotation(node)) switch (mask) { case 0: return MemoFunctionKind.NONE @@ -175,11 +218,11 @@ export function isWrappable(type: arkts.TypeNode | undefined, arg: arkts.Express } export function isTrackableParam(node: arkts.ETSParameterExpression, isLast: boolean, trackContentParam: boolean) { - return !hasMemoSkipAnnotation(node) && !(!trackContentParam && isLast && node.ident?.name == RuntimeNames.CONTENT) + return !AnnotationGetter.hasMemoSkipAnnotation(node) && !(!trackContentParam && isLast && node.ident?.name == RuntimeNames.CONTENT) } export function shouldWrap(param: arkts.ETSParameterExpression, isLastParam: boolean, trackContentParam: boolean, arg: arkts.Expression) { - return (isWrappable(param.typeAnnotation, arg) && isTrackableParam(param, isLastParam, trackContentParam)) || hasWrapAnnotation(param) + return (isWrappable(param.typeAnnotation, arg) && isTrackableParam(param, isLastParam, trackContentParam)) || AnnotationGetter.hasWrapAnnotation(param) } function filterGensym(value: string): string { -- Gitee From f1b6acb6dc453e609f6c446ecbac7bede85dc569 Mon Sep 17 00:00:00 2001 From: Igor Loginov Date: Tue, 29 Jul 2025 11:22:10 +0300 Subject: [PATCH 2/2] more --- incremental/runtime/src/memo/bind.ts | 20 ++++++++--- incremental/runtime/src/memo/testing.ts | 14 ++++---- ui2abc/memo-plugin/src/ParserTransformer.ts | 40 ++++++++++++++++++++- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/incremental/runtime/src/memo/bind.ts b/incremental/runtime/src/memo/bind.ts index f095de86e9..2a1eb6880e 100644 --- a/incremental/runtime/src/memo/bind.ts +++ b/incremental/runtime/src/memo/bind.ts @@ -21,7 +21,10 @@ export function memoBind( /** @memo */ () => void { - throw new Error("no impl") + return ( + /** @memo */ + (): void => { item(value) } + ) } /** @internal */ @@ -32,7 +35,10 @@ export function memoBind2( /** @memo */ () => void { - throw new Error("no impl") + return ( + /** @memo */ + (): void => { item(value1, value2) } + ) } /** @internal */ @@ -44,7 +50,10 @@ export function memoPartialBind2_1( /** @memo */ (arg2: T2) => void { - throw new Error("no impl") + return ( + /** @memo */ + (arg2: T2): void => { item(value1, arg2) } + ) } /** @internal */ @@ -56,5 +65,8 @@ export function memoPartialBind3_2( /** @memo */ (arg2: T2, arg3: T3) => void { - throw new Error("no impl") + return ( + /** @memo */ + (arg2: T2, arg3: T3): void => { item(value1, arg2, arg3) } + ) } diff --git a/incremental/runtime/src/memo/testing.ts b/incremental/runtime/src/memo/testing.ts index dc11c8b1ef..0daed99362 100644 --- a/incremental/runtime/src/memo/testing.ts +++ b/incremental/runtime/src/memo/testing.ts @@ -40,13 +40,13 @@ export class TestNode extends IncrementalNode { return memoRoot(new TestNode(), content) } - // /** @memo:intrinsic */ - // static attach( - // /** @memo */ - // content: (node: TestNode) => void - // ): void { - // NodeAttach(():TestNode => new TestNode(), content) - // } + /** @memo:intrinsic */ + static attach( + /** @memo */ + content: (node: TestNode) => void + ): void { + NodeAttach(():TestNode => new TestNode(), content) + } } diff --git a/ui2abc/memo-plugin/src/ParserTransformer.ts b/ui2abc/memo-plugin/src/ParserTransformer.ts index f0891ff488..5dbccefc1d 100644 --- a/ui2abc/memo-plugin/src/ParserTransformer.ts +++ b/ui2abc/memo-plugin/src/ParserTransformer.ts @@ -71,6 +71,43 @@ class AnnotationTransformer extends arkts.AbstractVisitor { node.parent.setAnnotations([this.annotation(Annotations.ANNOTATION_INTRINSIC), ...node.parent.annotations]) } } + if (arkts.isMethodDefinition(node) && arkts.isScriptFunction(node.function)) { + const jsDoc = arkts.getJsDoc(node) + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION)) { + node.function.setAnnotations([this.annotation(Annotations.ANNOTATION), ...node.function.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_ENTRY)) { + node.function.setAnnotations([this.annotation(Annotations.ANNOTATION_ENTRY), ...node.function.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_INTRINSIC)) { + node.function.setAnnotations([this.annotation(Annotations.ANNOTATION_INTRINSIC), ...node.function.annotations]) + } + } + if (arkts.isArrowFunctionExpression(node) && arkts.isScriptFunction(node.function)) { + const jsDoc = arkts.getJsDoc(node.function) + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION)) { + node.function.setAnnotations([this.annotation(Annotations.ANNOTATION), ...node.function.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_ENTRY)) { + node.function.setAnnotations([this.annotation(Annotations.ANNOTATION_ENTRY), ...node.function.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_INTRINSIC)) { + node.function.setAnnotations([this.annotation(Annotations.ANNOTATION_INTRINSIC), ...node.function.annotations]) + } + } + if (arkts.isETSFunctionType(node)) { + const jsDoc = arkts.getJsDoc(node) + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION)) { + node.setAnnotations([...node.annotations, this.annotation(Annotations.ANNOTATION)]) + // ??? + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_ENTRY)) { + node.setAnnotations([this.annotation(Annotations.ANNOTATION_ENTRY), ...node.annotations]) + } + if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION_INTRINSIC)) { + node.setAnnotations([this.annotation(Annotations.ANNOTATION_INTRINSIC), ...node.annotations]) + } + } if (arkts.isETSParameterExpression(node)) { const jsDoc = arkts.getJsDoc(node) if (jsDoc?.includes(Annotations.JSDOC_ANNOTATION)) { @@ -104,7 +141,8 @@ export default function memoParserTransformer( annotationTransformer.visitor(program.ast) if (annotationTransformer.needImport) { const module = program.ast as arkts.ETSModule - console.log(program.ast.dumpSrc()) + if (program.moduleName.includes("bind")) + console.log(program.ast.dumpSrc()) program.setAst( arkts.factory.updateETSModule( module, -- Gitee