diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index dd116614c31d5088a3492c0499a2481e5adf5c3c..411f34656fbf4e219fc4ba4c962f38a4d20de151 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -119,6 +119,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 c07c148f959ea41534904715be81f58c6d2d3fea..9b7c288618b0eb7e79e765fb4520958653256e3f 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 0c85293affdbdceda98b89c76ed26cd50ec88621..ff3c142092ebf084c5c98b4e613e33ad06de3c93 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 7a463133aaa52e51158553a2f9ea6234650f6a68..ed3db23c9dc1150cc72a99c635206faa05e60242 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 b43b179cf19d8cbbf9bc532b4f9890e0348a0177..dc19515ed39858f0304b218ff3bc53456ec55e3d 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 421c3b950d167f43da6f3639abe8d3e9453a1859..448a3c034028d5a66da9df213436c920ff74c570 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 e529d463d948985490f8b1329db8fb23d562cccd..d82e2115d153edd598305f1c0170de949d8fcfbc 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 ba8c3081b78b797344e8d4a8eaba2e0e459c5290..c3d38adf0c9af677f59a639594d197a25114ebc8 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 941c35f6d7e71a1af6bdbe4cf04bb8c54f8b964d..ea90750b41a6f61bca313ba27c201cee0b545106 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 5cfe6a866e7c48fb720aa0ab543e17ed70661e14..ea2ae51318566d3215f7652e378a814ee63a0bab 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 dbfe968418d15664bf3da689078b345a11c0da40..904fc60c3cdb235b960096ec44b304cea01865c2 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 9db60c6c5ca14f3a072c20c79abc391f2a3092ad..e57a141d68d045e31c2d9b8e15ec95e75ba17eff 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 e9e1fd923c7362f17c3f5ec7dd453068eed4b03c..833d2fbcd29c185502eb3e6519b0d1527f72eb7e 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 6f5b8141434b98d9a35e8ad6be6fb103fa002259..624c19573fec41a718d839342c5269ec5183e895 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