From 2ff03ab8cb29a1449e2b315151892b0545755e8d Mon Sep 17 00:00:00 2001 From: huangyu Date: Fri, 9 Jun 2023 15:41:46 +0800 Subject: [PATCH] fixed 3ea5301 from https://gitee.com/huangyu76/arkcompiler_ets_frontend/pulls/1064 Fix es2abc inconsistent type info literal order in repeat compilation Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I7C9Z5 Signed-off-by: huangyu Change-Id: I24f4026b86e2cb9823dd003eebc883f446391913 --- es2panda/compiler/core/emitter/emitter.h | 4 ++ .../core/emitter/typeExtractorEmitter.cpp | 19 ++++--- .../core/emitter/typeExtractorEmitter.h | 15 ++++-- ...st-builtin-generic-class-type-expected.txt | 2 +- .../testcases/test-class-1-expected.txt | 52 +++++++++---------- .../testcases/test-class-expected.txt | 4 +- .../test-class-generic-type-expected.txt | 14 ++--- ...st-class-with-abstract-method-expected.txt | 16 +++--- ...st-class-with-overload-method-expected.txt | 50 +++++++++--------- .../test-class-with-static-field-expected.txt | 4 +- .../test-function-with-this-expected.txt | 38 +++++++------- .../test-index-signature-expected.txt | 10 ++-- .../testcases/test-interface-expected.txt | 2 +- ...ace-enum-transformed-function-expected.txt | 18 +++---- 14 files changed, 128 insertions(+), 120 deletions(-) diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index 7964889a27..676d7b4a0b 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -118,6 +118,10 @@ public: void GenJsonContentRecord(const CompilerContext *context); void GenRecordNameInfo() const; void GenTypeInfoRecord() const; + std::mutex &GetEmitterLock() + { + return m_; + }; private: void SetCommonjsField(bool isCommonjs); diff --git a/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp b/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp index c07c148f95..9b7c288618 100644 --- a/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp +++ b/es2panda/compiler/core/emitter/typeExtractorEmitter.cpp @@ -22,7 +22,6 @@ namespace panda::es2panda::compiler { -using AnnotationData = panda::pandasm::AnnotationData; using AnnotationElement = panda::pandasm::AnnotationElement; using ArrayValue = panda::pandasm::ArrayValue; using Field = panda::pandasm::Field; @@ -31,8 +30,6 @@ using ScalarValue = panda::pandasm::ScalarValue; using Type = panda::pandasm::Type; using ValueType = panda::pandasm::Value::Type; -int32_t TypeExtractorEmitter::literalId_ = -1; - TypeExtractorEmitter::TypeExtractorEmitter(const PandaGen *pg, panda::pandasm::Function *func) : pg_(pg), func_(func) { auto prog = pg_->Context()->GetEmitter()->GetProgram(); @@ -90,7 +87,7 @@ static void GenInsnTypeInfo(const extractor::TypeRecorder *recorder, uint32_t or GenTypeInfo(recorder, typeIndex, typedInsns); } -void TypeExtractorEmitter::GenFunctionTypeInfo(panda::pandasm::Program *prog) const +void TypeExtractorEmitter::GenFunctionTypeInfo(panda::pandasm::Program *prog) { auto recorder = pg_->Context()->TypeRecorder(); std::vector typedInsns; @@ -132,8 +129,9 @@ void TypeExtractorEmitter::GenFunctionTypeInfo(panda::pandasm::Program *prog) co return; } + std::lock_guard lock(pg_->Context()->GetEmitter()->GetEmitterLock()); std::string literalId = std::string(recorder->GetRecordName()) + "_" + - std::to_string(literalId_--); + func_->name + "_" + std::to_string(literalId_--); auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(typedInsns)); prog->literalarray_table.emplace(literalId, std::move(literalArrayInstance)); @@ -145,8 +143,8 @@ void TypeExtractorEmitter::GenFunctionTypeInfo(panda::pandasm::Program *prog) co } template -static void GenImportOrDeclareTypeInfo(panda::pandasm::Program *prog, const extractor::TypeRecorder *recorder, - const M &map, AnnotationData &funcTypeAnnotation) +void TypeExtractorEmitter::GenImportOrDeclareTypeInfo(panda::pandasm::Program *prog, + const extractor::TypeRecorder *recorder, const M &map, AnnotationData &funcTypeAnnotation) { std::string symbolTypeStr; if constexpr (isExport) { @@ -170,8 +168,9 @@ static void GenImportOrDeclareTypeInfo(panda::pandasm::Program *prog, const extr GenTypeInfo(recorder, t.second, typedSymbols); } + std::lock_guard lock(pg_->Context()->GetEmitter()->GetEmitterLock()); std::string literalId = std::string(recorder->GetRecordName()) + "_" + - std::to_string(TypeExtractorEmitter::literalId_--); + func_->name + "_" + std::to_string(literalId_--); auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(typedSymbols)); prog->literalarray_table.emplace(literalId, std::move(literalArrayInstance)); @@ -180,7 +179,7 @@ static void GenImportOrDeclareTypeInfo(panda::pandasm::Program *prog, const extr funcTypeAnnotation.AddElement(std::move(funcSymbolTypeElement)); } -void TypeExtractorEmitter::GenExportTypeInfo(panda::pandasm::Program *prog) const +void TypeExtractorEmitter::GenExportTypeInfo(panda::pandasm::Program *prog) { AnnotationData funcTypeAnnotation(TypeExtractorEmitter::TYPE_ANNOTATION); GenImportOrDeclareTypeInfo(prog, pg_->Context()->TypeRecorder(), @@ -188,7 +187,7 @@ void TypeExtractorEmitter::GenExportTypeInfo(panda::pandasm::Program *prog) cons func_->metadata->AddAnnotations({ funcTypeAnnotation }); } -void TypeExtractorEmitter::GenDeclareTypeInfo(panda::pandasm::Program *prog) const +void TypeExtractorEmitter::GenDeclareTypeInfo(panda::pandasm::Program *prog) { AnnotationData funcTypeAnnotation(TypeExtractorEmitter::TYPE_ANNOTATION); GenImportOrDeclareTypeInfo(prog, pg_->Context()->TypeRecorder(), diff --git a/es2panda/compiler/core/emitter/typeExtractorEmitter.h b/es2panda/compiler/core/emitter/typeExtractorEmitter.h index 0c85293aff..ff3c142092 100644 --- a/es2panda/compiler/core/emitter/typeExtractorEmitter.h +++ b/es2panda/compiler/core/emitter/typeExtractorEmitter.h @@ -26,6 +26,8 @@ namespace panda::es2panda::compiler { +using AnnotationData = panda::pandasm::AnnotationData; + class TypeExtractorEmitter { public: explicit TypeExtractorEmitter(const PandaGen *pg, panda::pandasm::Function *func); @@ -39,8 +41,6 @@ public: const std::string &recordName); static void GenTypeLiteralBuffers(panda::pandasm::Program *prog, const extractor::TypeRecorder *recorder); - static int32_t literalId_; - static constexpr const char *TYPE_INFO_RECORD = "_ESTypeInfoRecord"; static constexpr const char *TYPE_ANNOTATION = "_ESTypeAnnotation"; static constexpr const char *TYPE_INSTRUCTION = "_TypeOfInstruction"; @@ -51,13 +51,18 @@ public: static constexpr const char *DECLARED_SYMBOL_TYPES = "declaredSymbolTypes"; private: + int32_t literalId_ = -1; const PandaGen *pg_; panda::pandasm::Function *func_; bool IsFuncMain0(const std::string &funcName, bool isMergeAbc) const; - void GenFunctionTypeInfo(panda::pandasm::Program *prog) const; - void GenExportTypeInfo(panda::pandasm::Program *prog) const; - void GenDeclareTypeInfo(panda::pandasm::Program *prog) const; + void GenFunctionTypeInfo(panda::pandasm::Program *prog); + void GenExportTypeInfo(panda::pandasm::Program *prog); + void GenDeclareTypeInfo(panda::pandasm::Program *prog); + + template + void GenImportOrDeclareTypeInfo(panda::pandasm::Program *prog, const extractor::TypeRecorder *recorder, + const M &map, AnnotationData &funcTypeAnnotation); }; } // namespace panda::es2panda::compiler diff --git a/es2panda/test/type_extractor/testcases/test-builtin-generic-class-type-expected.txt b/es2panda/test/type_extractor/testcases/test-builtin-generic-class-type-expected.txt index 7a463133aa..ed3db23c9d 100644 --- a/es2panda/test/type_extractor/testcases/test-builtin-generic-class-type-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-builtin-generic-class-type-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-class-1-expected.txt b/es2panda/test/type_extractor/testcases/test-class-1-expected.txt index b43b179cf1..dc19515ed3 100644 --- a/es2panda/test/type_extractor/testcases/test-class-1-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-1-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.Student_-1 { index: 0 tag: 0 @@ -9,7 +9,7 @@ slot _-1 { index: 1 tag: 2 - val: -1 + val: -2 }, { index: 2 @@ -18,31 +18,11 @@ slot _-1 }, { index: 3 - tag: 24 - val: _4 -}, -{ - index: 4 - tag: 0 - val: 2 -}, -{ - index: 5 - tag: 2 - val: -2 -}, -{ - index: 6 - tag: 0 - val: 24 -}, -{ - index: 7 tag: 24 val: _3 }, ------------------------------------ -slot _-2 +slot _.cur_-1 { index: 0 tag: 0 @@ -84,7 +64,7 @@ slot _-2 val: _3 }, ------------------------------------ -slot _-3 +slot _.dump_-1 { index: 0 tag: 0 @@ -93,7 +73,7 @@ slot _-3 { index: 1 tag: 2 - val: -2 + val: -1 }, { index: 2 @@ -102,11 +82,31 @@ slot _-3 }, { index: 3 + tag: 24 + val: _4 +}, +{ + index: 4 + tag: 0 + val: 2 +}, +{ + index: 5 + tag: 2 + val: -2 +}, +{ + index: 6 + tag: 0 + val: 24 +}, +{ + index: 7 tag: 24 val: _3 }, ------------------------------------ -slot _-4 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-class-expected.txt b/es2panda/test/type_extractor/testcases/test-class-expected.txt index 421c3b950d..448a3c0340 100644 --- a/es2panda/test/type_extractor/testcases/test-class-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.Student_-1 { index: 0 tag: 0 @@ -22,7 +22,7 @@ slot _-1 val: _2 }, ------------------------------------ -slot _-2 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt b/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt index e529d463d9..d82e2115d1 100644 --- a/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.C_-1 { index: 0 tag: 0 @@ -19,7 +19,7 @@ slot _-1 { index: 3 tag: 24 - val: _3 + val: _2 }, { index: 4 @@ -39,10 +39,10 @@ slot _-1 { index: 7 tag: 24 - val: _1 + val: _4 }, ------------------------------------ -slot _-2 +slot _.foo_-1 { index: 0 tag: 0 @@ -61,7 +61,7 @@ slot _-2 { index: 3 tag: 24 - val: _2 + val: _3 }, { index: 4 @@ -81,10 +81,10 @@ slot _-2 { index: 7 tag: 24 - val: _4 + val: _1 }, ------------------------------------ -slot _-3 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-class-with-abstract-method-expected.txt b/es2panda/test/type_extractor/testcases/test-class-with-abstract-method-expected.txt index ba8c3081b7..c3d38adf0c 100644 --- a/es2panda/test/type_extractor/testcases/test-class-with-abstract-method-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-with-abstract-method-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.func_main_0_-1 { index: 0 tag: 0 @@ -9,7 +9,7 @@ slot _-1 { index: 1 tag: 2 - val: -1 + val: 2 }, { index: 2 @@ -19,10 +19,10 @@ slot _-1 { index: 3 tag: 24 - val: _5 + val: _1 }, ------------------------------------ -slot _-2 +slot _.w_-1 { index: 0 tag: 0 @@ -41,10 +41,10 @@ slot _-2 { index: 3 tag: 24 - val: _3 + val: _5 }, ------------------------------------ -slot _-3 +slot _.y_-1 { index: 0 tag: 0 @@ -53,7 +53,7 @@ slot _-3 { index: 1 tag: 2 - val: 2 + val: -1 }, { index: 2 @@ -63,7 +63,7 @@ slot _-3 { index: 3 tag: 24 - val: _1 + val: _3 }, ------------------------------------ slot _0 diff --git a/es2panda/test/type_extractor/testcases/test-class-with-overload-method-expected.txt b/es2panda/test/type_extractor/testcases/test-class-with-overload-method-expected.txt index 941c35f6d7..ea90750b41 100644 --- a/es2panda/test/type_extractor/testcases/test-class-with-overload-method-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-with-overload-method-expected.txt @@ -1,6 +1,28 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.Student_-1 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: -2 +}, +{ + index: 2 + tag: 0 + val: 24 +}, +{ + index: 3 + tag: 24 + val: _7 +}, +------------------------------------ +slot _.bar_-1 { index: 0 tag: 0 @@ -42,7 +64,7 @@ slot _-1 val: _7 }, ------------------------------------ -slot _-2 +slot _.foo_-1 { index: 0 tag: 0 @@ -84,29 +106,7 @@ slot _-2 val: _7 }, ------------------------------------ -slot _-3 -{ - index: 0 - tag: 0 - val: 2 -}, -{ - index: 1 - tag: 2 - val: -2 -}, -{ - index: 2 - tag: 0 - val: 24 -}, -{ - index: 3 - tag: 24 - val: _7 -}, ------------------------------------- -slot _-4 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt b/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt index 5cfe6a866e..ea2ae51318 100644 --- a/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.Student_-1 { index: 0 tag: 0 @@ -22,7 +22,7 @@ slot _-1 val: _2 }, ------------------------------------ -slot _-2 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt b/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt index dbfe968418..904fc60c3c 100644 --- a/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.#10022928042193459397#dump_-1 { index: 0 tag: 0 @@ -22,7 +22,7 @@ slot _-1 val: _6 }, ------------------------------------ -slot _-2 +slot _.Base_-1 { index: 0 tag: 0 @@ -31,7 +31,7 @@ slot _-2 { index: 1 tag: 2 - val: -1 + val: -2 }, { index: 2 @@ -41,30 +41,32 @@ slot _-2 { index: 3 tag: 24 - val: _3 + val: _4 }, +------------------------------------ +slot _.Student_-1 { - index: 4 + index: 0 tag: 0 val: 2 }, { - index: 5 + index: 1 tag: 2 val: -2 }, { - index: 6 + index: 2 tag: 0 val: 24 }, { - index: 7 + index: 3 tag: 24 val: _5 }, ------------------------------------ -slot _-3 +slot _.dump_-1 { index: 0 tag: 0 @@ -73,7 +75,7 @@ slot _-3 { index: 1 tag: 2 - val: -2 + val: -1 }, { index: 2 @@ -83,32 +85,30 @@ slot _-3 { index: 3 tag: 24 - val: _5 + val: _3 }, ------------------------------------- -slot _-4 { - index: 0 + index: 4 tag: 0 val: 2 }, { - index: 1 + index: 5 tag: 2 val: -2 }, { - index: 2 + index: 6 tag: 0 val: 24 }, { - index: 3 + index: 7 tag: 24 - val: _4 + val: _5 }, ------------------------------------ -slot _-5 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-index-signature-expected.txt b/es2panda/test/type_extractor/testcases/test-index-signature-expected.txt index 9db60c6c5c..e57a141d68 100644 --- a/es2panda/test/type_extractor/testcases/test-index-signature-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-index-signature-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.Rectangle_-1 { index: 0 tag: 0 @@ -19,10 +19,10 @@ slot _-1 { index: 3 tag: 24 - val: _9 + val: _8 }, ------------------------------------ -slot _-2 +slot _.Square_-1 { index: 0 tag: 0 @@ -41,10 +41,10 @@ slot _-2 { index: 3 tag: 24 - val: _8 + val: _9 }, ------------------------------------ -slot _-3 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-interface-expected.txt b/es2panda/test/type_extractor/testcases/test-interface-expected.txt index e9e1fd923c..833d2fbcd2 100644 --- a/es2panda/test/type_extractor/testcases/test-interface-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-interface-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.func_main_0_-1 { index: 0 tag: 0 diff --git a/es2panda/test/type_extractor/testcases/test-namespace-enum-transformed-function-expected.txt b/es2panda/test/type_extractor/testcases/test-namespace-enum-transformed-function-expected.txt index 6f5b814143..624c19573f 100644 --- a/es2panda/test/type_extractor/testcases/test-namespace-enum-transformed-function-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-namespace-enum-transformed-function-expected.txt @@ -1,6 +1,6 @@ ======> literal array buffer <====== ------------------------------------ -slot _-1 +slot _.#6142509188972423790#_-1 { index: 0 tag: 0 @@ -19,10 +19,10 @@ slot _-1 { index: 3 tag: 25 - val: 254 + val: 255 }, ------------------------------------ -slot _-2 +slot _.#6142509188972423790_1#_-1 { index: 0 tag: 0 @@ -44,7 +44,7 @@ slot _-2 val: 255 }, ------------------------------------ -slot _-3 +slot _.#6142509188972423790_2#_-1 { index: 0 tag: 0 @@ -66,7 +66,7 @@ slot _-3 val: 254 }, ------------------------------------ -slot _-4 +slot _.#6142509188972423790_3#_-1 { index: 0 tag: 0 @@ -88,7 +88,7 @@ slot _-4 val: 255 }, ------------------------------------ -slot _-5 +slot _.#6142509188972423790_4#_-1 { index: 0 tag: 0 @@ -110,7 +110,7 @@ slot _-5 val: 254 }, ------------------------------------ -slot _-6 +slot _.#6142509188972423790_5#_-1 { index: 0 tag: 0 @@ -132,7 +132,7 @@ slot _-6 val: 255 }, ------------------------------------ -slot _-7 +slot _.#6142509188972423790_6#_-1 { index: 0 tag: 0 @@ -151,7 +151,7 @@ slot _-7 { index: 3 tag: 25 - val: 255 + val: 254 }, ------------------------------------ slot _0 -- Gitee