From d81314c8fa9031760b5b602ef9d5e0eccad27a24 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Wed, 22 Mar 2023 17:40:35 +0800 Subject: [PATCH] Shield error in hotreload && add nexlexenv Ins in patch's func_main_0 Signed-off-by: gavin1012_hw Change-Id: Ic0cda7129c39c3099f8cbfbcee524eb110464a43 --- es2panda/binder/scope.h | 5 +++++ es2panda/binder/variable.cpp | 2 ++ es2panda/util/patchFix.cpp | 30 ++++++++++++++++-------------- es2panda/util/patchFix.h | 1 + 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index df26bb49997..ec2225db3d9 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -390,6 +390,11 @@ public: return (flags_ & flag) != 0; } + void RestoreFuncMain0LexEnv(uint32_t slotSize) + { + slotIndex_ = slotSize; + } + uint32_t NextSlot() { return slotIndex_++; diff --git a/es2panda/binder/variable.cpp b/es2panda/binder/variable.cpp index 2d5536c1120..77f909c3796 100644 --- a/es2panda/binder/variable.cpp +++ b/es2panda/binder/variable.cpp @@ -54,6 +54,8 @@ void LocalVariable::SetLexical(Scope *scope, util::PatchFix *patchFixHelper) slot = patchFixHelper->GetSlotIdFromSymbolTable(std::string(name)); if (patchFixHelper->IsPatchVar(slot)) { patchFixHelper->AllocSlotfromPatchEnv(std::string(name)); + } else { + varScope->RestoreFuncMain0LexEnv(patchFixHelper->GetEnvSizeOfFuncMain0()); } } else { slot = varScope->NextSlot(); diff --git a/es2panda/util/patchFix.cpp b/es2panda/util/patchFix.cpp index e5a8a8ad55b..54273d883e4 100644 --- a/es2panda/util/patchFix.cpp +++ b/es2panda/util/patchFix.cpp @@ -84,13 +84,13 @@ void PatchFix::ValidateModuleInfo(const std::string &recordName, std::vector &moduleBuffer) { auto it = originModuleInfo_->find(recordName); - if (it == originModuleInfo_->end()) { + if (!IsHotReload() && it == originModuleInfo_->end()) { std::cerr << "[Patch] Found new import/export expression in " << recordName << ", not supported!" << std::endl; patchError_ = true; return; } - if (Helpers::GetHashString(ConvertLiteralToString(moduleBuffer)) != it->second) { + if (!IsHotReload() && Helpers::GetHashString(ConvertLiteralToString(moduleBuffer)) != it->second) { std::cerr << "[Patch] Found import/export expression changed in " << recordName << ", not supported!" << std::endl; patchError_ = true; @@ -109,14 +109,14 @@ void PatchFix::DumpJsonContentRecInfo(const std::string &recordName, const std:: void PatchFix::ValidateJsonContentRecInfo(const std::string &recordName, const std::string &jsonFileContent) { auto it = originModuleInfo_->find(recordName); - if (it == originModuleInfo_->end()) { + if (!IsHotReload() && it == originModuleInfo_->end()) { std::cerr << "[Patch] Found new import/require json file expression in " << recordName << ", not supported!" << std::endl; patchError_ = true; return; } - if (Helpers::GetHashString(jsonFileContent) != it->second) { + if (!IsHotReload() && Helpers::GetHashString(jsonFileContent) != it->second) { std::cerr << "[Patch] Found imported/required json file content changed in " << recordName << ", not supported!" << std::endl; patchError_ = true; @@ -293,6 +293,13 @@ uint32_t PatchFix::GetSlotIdFromSymbolTable(const std::string &variableName) return UINT32_MAX; } +uint32_t PatchFix::GetEnvSizeOfFuncMain0() +{ + auto functionIter = originFunctionInfo_->find(funcMain0_); + ASSERT(functionIter != originFunctionInfo_->end()); + return functionIter->second.lexenv.size(); +} + uint32_t PatchFix::GetPatchLexicalIdx(const std::string &variableName) { ASSERT(topScopeLexEnvs_.count(variableName)); @@ -457,7 +464,7 @@ bool PatchFix::CompareLexenv(const std::string &funcName, const compiler::PandaG auto &lexicalVarNameAndTypes = pg->TopScope()->GetLexicalVarNameAndTypes(); auto &lexenv = bytecodeInfo.lexenv; if (funcName != funcMain0_) { - if (lexenv.size() != lexicalVarNameAndTypes.size()) { + if (!IsHotReload() && lexenv.size() != lexicalVarNameAndTypes.size()) { std::cerr << "[Patch] Found lexical variable added or removed in " << funcName << ", not supported!" << std::endl; patchError_ = true; @@ -466,7 +473,7 @@ bool PatchFix::CompareLexenv(const std::string &funcName, const compiler::PandaG for (auto &variable: lexicalVarNameAndTypes) { auto varSlot = variable.first; auto lexenvIter = lexenv.find(varSlot); - if (lexenvIter == lexenv.end()) { + if (!IsHotReload() && lexenvIter == lexenv.end()) { std::cerr << "[Patch] Found new lexical variable added in function " << funcName << ", not supported!" << std::endl; patchError_ = true; @@ -474,8 +481,8 @@ bool PatchFix::CompareLexenv(const std::string &funcName, const compiler::PandaG } auto &lexInfo = lexenvIter->second; - if (!IsColdFix() && (std::string(variable.second.first) != lexInfo.first || - variable.second.second != lexInfo.second)) { + if (IsHotFix() && (std::string(variable.second.first) != lexInfo.first || + variable.second.second != lexInfo.second)) { std::cerr << "[Patch] Found lexical variable changed in function " << funcName << ", not supported!" << std::endl; patchError_ = true; @@ -493,15 +500,10 @@ bool PatchFix::CompareClassHash(std::vector> for (size_t i = 0; i < hashList.size() - 1; ++i) { auto &className = hashList[i].first; auto classIter = classInfo.find(className); - if (classIter != classInfo.end() && classIter->second != hashList[i].second) { + if (!IsHotReload() && classIter != classInfo.end() && classIter->second != hashList[i].second) { if (IsColdFix()) { modifiedClassNames_.insert(className); continue; - } else if (IsHotReload()) { - std::cerr << "[Patch] Found class " << hashList[i].first << " changed, not supported! If " << - hashList[i].first << " is not changed and you are changing UI Component, please only " << - "change one Component at a time and make sure the Component is placed at the bottom " << - "of the file." << std::endl; } else { ASSERT(IsHotFix()); std::cerr << "[Patch] Found class " << hashList[i].first << " changed, not supported!" << std::endl; diff --git a/es2panda/util/patchFix.h b/es2panda/util/patchFix.h index 3b255b23289..794358cfa7d 100644 --- a/es2panda/util/patchFix.h +++ b/es2panda/util/patchFix.h @@ -66,6 +66,7 @@ public: void Finalize(panda::pandasm::Program **prog); bool IsScopeValidToPatchLexical(binder::VariableScope *scope) const; uint32_t GetSlotIdFromSymbolTable(const std::string &variableName); + uint32_t GetEnvSizeOfFuncMain0(); void AllocSlotfromPatchEnv(const std::string &variableName); uint32_t GetPatchLexicalIdx(const std::string &variableName); bool IsPatchVar(uint32_t slot); -- Gitee