test for fix when static ETS imports dynamic enum Created-by: anjiaqi257 Commit-by: gcw_HJ4zMsdn Merged-by: openharmony_ci Description: ### 关联的Issue https://gitcode.com/openharmony/arkcompiler_ets_frontend/issues/11954 ### 提交类型 - [ ] 需求 - [ ] bugfix ### 需求背景/Description <!-- 仅涉及需求时填写 --> ### 问题现象&&分析/Reason <!-- 仅涉及bugfix时填写 --> ArkCompiler converts .ets source to ARK bytecode (.abc). The es2panda frontend compiles static ETS files, and the assembler (assembly-emitter.cpp) emits the final bytecode. A static ETS file importing a declare namespace with an enum from a dynamic module (configured as language: "js" in arktsconfig.json) causes a crash during bytecode emission. ``` // test.ets: import hilog from "dynamic/@ohos.hilog" let a = hilog.LogLevel.DEBUG a === 3 //@ohos.hilog.ets: 'use static' declare namespace hilog { enum LogLevel { DEBUG = 3, ... } } export default hilog; //arktsconfig.json: "dynamic/@ohos.hilog": {"language": "js", "path": ".../@@ohos.hilog.ets", "ohmUrl": "..."} // Command: es2panda --arktsconfig arktsconfig.json test.ets //Result: ASSERTION FAILED: false at assembly-emitter.cpp:833 (UNREACHABLE() in AddBytecodeIndexDependencies). ``` #### Reason The crash has two contributing factors: 1. Auto-static logic misclassifies enum valueOf as static (assembly-emitter.cpp:1428-1436). The valueOf method of an enum has no explicit parameters (this is implicit), so func.params.empty() is true. The auto-static heuristic moves it from functionInstanceTable to functionStaticTable, causing it to be placed in staticMethodItems despite being an instance method. 2. The code generator emits CALL_VIRT_SHORT (instance call) for valueOf (ETSCompiler.cpp:587-598). The enum method's signature lacks the STATIC flag, so EmitCall goes to the CallVirtual path, emitting CALL_VIRT_SHORT with METHOD_ID flag. The instruction looks up the method ID in methodItems (instance methods), but the method is in staticMethodItems (due to auto-static). The lookup fails, hitting UNREACHABLE(). The PANDA_WITH_ECMASCRIPT fallback that would handle this mismatch is disabled in debug builds. Why it works for regular ETS enums: For enums in the local program (not foreign/dynamic), the auto-static move is correct because the parser at assembly-parser.cpp:643 already sets ACC_STATIC on the function before it enters the table. The foreign methods from dynamic modules bypass the parser and don't have ACC_STATIC, making the auto-static heuristic incorrect for them. ### 修改方案/Scheme Add a guard in the auto-static logic — skip auto-static when p0 equals std.core.Object (the erased this type). ### 测试结果(测试截图直接贴在对应测试项,主干已知问题需明确引入pr/责任人) #### 功能测试(除仅涉及文本外必测项)[wiki](https://gitee.com/openharmony/arkcompiler_ets_frontend/wikis/代码提交要求及测试验证流程) 1. es2abc测试用例(Debug模式) - [ ] 已通过 - [ ] 不涉及,无需验证 2. Verifier测试 - [ ] 已通过 - [ ] 不涉及,无需验证 3. 64位RK编译 - [ ] 已通过 - [ ] 不涉及,无需验证 4. 编译mac平台sdk - [ ] 已通过 - [ ] 不涉及,无需验证 #### 混淆测试(涉及arkguard改动时必测项)[wiki](https://gitee.com/openharmony/arkcompiler_ets_frontend/wikis/混淆测试验证流程?sort_id=11451209) 1. 单元测试 - [ ] 已通过 - [ ] 不涉及,无需验证 2. Compiler测试套 - [ ] 已通过 - [ ] 不涉及,无需验证 3. TSC extra测试套 - [ ] 已通过 - [ ] 不涉及,无需验证 4. Test262测试套 - [ ] 已通过 - [ ] 不涉及,无需验证 5. Benchmark测试 - [ ] 已通过 - [ ] 不涉及,无需验证 6. 应用自动化测试套 - [ ] 已通过 - [ ] 不涉及,无需验证 7. 是否创建全局变量,若创建全局变量,是否有清空操作 - [ ] 创建了全局变量,且已清空 - [ ] 创建了全局变量,未清空 - [ ] 未创建全局变量 #### 兼容性测试(指令生成、文件格式修改时) 1. 小版本兼容性测试 <!-- 修改导致新abc无法运行在老镜像上时,需新增版本号 --> - [ ] 已增加版本号 - [ ] 已通过 - [ ] 不涉及,无需验证 2. 大版本兼容性测试 <!-- 配置target-api-version时,生成的abc需要能在对应版本运行--> - [ ] 已通过 - [ ] 不涉及,无需验证 3. es2abc版本兼容性测试 <!-- 新版本es2abc编译的老版本API的abc文件,应能被老版本es2abc正常识别和处理--> **说明:如PR涉及版本控制用例的变更,需同步检查修改对其他分支的影响,并确认是否要同步受影响的分支** - [ ] 涉及,变更影响 API/字节码 版本, 需同步修改到其他分支 - [ ] 涉及,变更影响 API/字节码 版本, 无需同步到其他分支 - [ ] 不涉及,变更不涉及 API/字节码 版本 4. 是否涉及词法环境修改 **说明:如PR涉及词法环境修改,需验证对应热重载场景是否兼容** - [ ] 涉及,影响热重载场景,需排查影响 - [ ] 涉及,不影响热重载场景 - [ ] 不涉及 #### 性能测试 (新增语法检查等场景) - [ ] 已通过 - [ ] 不涉及,无需验证 #### 指令/abc格式修改自检,需联系下方邮箱,同步至相关领域 **重要:涉及runtime_core仓abc2program、libpandafile、isa目录下的修改,必须提供一个编译helloworld项目的hap包给对应领域,并联系下方邮箱** - [ ] 涉及,已同步 - [ ] 不涉及 **Email:** wutao185@huawei.com ### 是否已执行L0用例 - [ ] 已验证 - [ ] 不涉及。如不涉及,请写明理由 ### 是否已执行L0用例 - [ ] 已验证 - [ ] 不涉及。如不涉及,请写明理由 Change-Id: Ie71587586cedadf6d0ff45e15d92a81789c8b2c0 See merge request: openharmony/arkcompiler_ets_frontend!11193
ets_frontend
Introduction
ets_frontend is a front-end tool in the ARK Runtime Subsystem. Combined with the ace-ets2bundle component, it supports converting ETS files into ARK bytecode files.
For more information, see: ARK Runtime Subsystem.
ets_frontend architecture
Directory Structure
/arkcompiler/ets_frontend/
├── test262 # scripts for configuration and running Test262
├── testTs # system test cases
├── test_ecma_bcopt # bytecode_optimize test cases
├── test # sdk,xts test cases
├── es2panda
├── aot # logical entry
├── binder # info binding
├── compiler # compiling logic
├── ir # Bytecode generation
├── lexer # lexical analysis
├── parser # syntax parsing, AST generation
├── scripts # script directory
├── test # test directory
├── typescript # typescript support
└── util # tool directory
├── legacy_bin # API8 Compiler directory
├── merge_abc
├── protos # proto template directory
├── scripts # script directory
├── src # proto Serialization and deserialization directory
Build
ets_frontend uses the command line interaction mode and converts JS code into ARK bytecode files that can be run on an ARK runtime system. ets_frontend supports Windows, Linux, and macOS. Front-end tools, converting JS source code into ARK bytecode, can be built by specifying the --build-target with ets_frontend_build on Linux.
$ ./build.sh --product-name rk3568 --build-target ets_frontend_build
Usage Guidelines
Usage For Es2panda
Use the es2abc executable under the ets_frontend component to convert JavaScript files into Ark bytecode files
$ cd out/rk3568/clang_x64/arkcompiler/ets_frontend/
$ ./es2abc [options] file.js
If no parameter is specified for [options], an ARK binary file is generated by default.
For more information, please see: ARK-Runtime-Usage-Guide.
