From 05312bfcf784776e947dc17b7ad9966537741697 Mon Sep 17 00:00:00 2001 From: aleksisch Date: Thu, 26 Oct 2023 14:37:06 +0300 Subject: [PATCH] fix undeterministic output in es2panda Change-Id: I7a196f75a234817203dac73ddd23d3bc2be4aa02 Signed-off-by: aleksisch --- ets2panda/compiler/core/emitter.cpp | 7 ++++--- ets2panda/parser/parserImpl.h | 2 +- ets2panda/varbinder/scope.cpp | 2 +- ets2panda/varbinder/scope.h | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index 42a9e15938..3e44eed810 100644 --- a/ets2panda/compiler/core/emitter.cpp +++ b/ets2panda/compiler/core/emitter.cpp @@ -312,8 +312,10 @@ void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const varbin GenLocalVariableInfo(variable_debug, param, start, vars_length, cg_->TotalRegsNum(), extension); } } - - for (const auto &[_, variable] : scope->Bindings()) { + const auto &unsorted_bindings = scope->Bindings(); + std::map bindings(unsorted_bindings.begin(), + unsorted_bindings.end()); + for (const auto &[_, variable] : bindings) { (void)_; if (!variable->IsLocalVariable() || variable->LexicalBound() || variable->Declaration()->IsParameterDecl() || variable->Declaration()->IsTypeAliasDecl()) { @@ -347,7 +349,6 @@ void FunctionEmitter::GenVariablesDebugInfo(pandasm::Function *func) Emitter::Emitter(const CompilerContext *context) : context_(context) { prog_ = new pandasm::Program(); - prog_->function_table.reserve(context->VarBinder()->Functions().size()); } Emitter::~Emitter() diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 21c674b2e6..f2c74eab8a 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -797,7 +797,7 @@ protected: return varbinder_; } - varbinder::Scope::VariableMap SavedBindings() const + const varbinder::Scope::VariableMap &SavedBindings() const { return saved_bindings_; } diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 8999d8cb9e..7d1e614da8 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -480,7 +480,7 @@ Scope::InsertResult GlobalScope::InsertImpl(const util::StringView &name, Variab if (const bool exported = node->IsClassDefinition() ? node->Parent()->IsExported() : node->IsExported(); !exported) { if (!node->IsDefaultExported()) { - return Scope::InsertResult {{}, false}; + return Scope::InsertResult {Bindings().end(), false}; } } } diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index 644e49e5c4..c1c11520e3 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -73,7 +73,7 @@ public: NO_MOVE_SEMANTIC(Scope); using VariableMap = ArenaUnorderedMap; - using InsertResult = std::pair; + using InsertResult = std::pair; virtual ScopeType Type() const = 0; -- Gitee