From f1eb1942262064a797f38cf99158ceca230b2ac1 Mon Sep 17 00:00:00 2001 From: chenyiyuan Date: Fri, 1 Sep 2023 16:33:05 +0800 Subject: [PATCH] Shield error in hotreload && add nexlexenv Ins in patch's func_main_0 Change-Id: I8d10ab0cff2f7c17f4cd7724456720bb00105b6b Signed-off-by: chenyiyuan --- es2panda/binder/scope.h | 5 ++ es2panda/binder/variable.cpp | 2 + .../hotreload-noerror/add-lexenv-3/base.js | 8 +++ .../add-lexenv-3/base_mod.js | 8 +++ .../add-lexenv-3/expected.txt | 53 +++++++++++++++++++ .../modify-class-1/expected.txt | 2 +- es2panda/test/runner.py | 7 +-- es2panda/util/patchFix.cpp | 12 +++-- es2panda/util/patchFix.h | 1 + 9 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base_mod.js create mode 100644 es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/expected.txt diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index df26bb49997..9dc0cf11c13 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/test/hotreload/hotreload-noerror/add-lexenv-3/base.js b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base.js new file mode 100644 index 00000000000..adfba702550 --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base.js @@ -0,0 +1,8 @@ +let a = 1; +let b = 1; +let c = 1; +function A() { + a = 2; + b = 2; + c = 2; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base_mod.js b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base_mod.js new file mode 100644 index 00000000000..5761bc6f08c --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/base_mod.js @@ -0,0 +1,8 @@ +let a = 1; +let b = 2; +let c = 1; +function A() { + a = 4; + b = 2; + c = 3; +} diff --git a/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/expected.txt b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/expected.txt new file mode 100644 index 00000000000..f79be095e6f --- /dev/null +++ b/es2panda/test/hotreload/hotreload-noerror/add-lexenv-3/expected.txt @@ -0,0 +1,53 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +.language ECMAScript + +.function any .A(any a0, any a1, any a2) { +label_1: +label_0: + ldlexvar 0x0, 0x0 + throw.undefinedifholewithname a + ldai 0x4 + stlexvar 0x0, 0x0 + ldlexvar 0x0, 0x1 + throw.undefinedifholewithname b + ldai 0x2 + stlexvar 0x0, 0x1 + ldlexvar 0x0, 0x2 + throw.undefinedifholewithname c + ldai 0x3 + stlexvar 0x0, 0x2 + ldundefined + returnundefined +label_2: +} + +.function any .func_main_0(any a0, any a1, any a2) { +label_1: +label_0: + newlexenv 0x3 + definefunc 0x0, .A, 0x0 + ldai 0x1 + sta v0 + lda v0 + stlexvar 0x0, 0x0 + ldai 0x2 + stlexvar 0x0, 0x1 + lda v0 + stlexvar 0x0, 0x2 + ldundefined + returnundefined +label_2: +} + + diff --git a/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt b/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt index 2bb59871906..c2769ab6dc4 100644 --- a/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt +++ b/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -[Patch] Found class .Model changed, not supported! If .Model 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. +[Patch] Found class .Model changed, not supported! [Patch] Found unsupported change in file, will not generate patch! Error: [base_mod.js:0:0] the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 91b2bab2096..0ca2655cc5d 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1083,9 +1083,10 @@ class PatchTest(Test): patch_test_cmd.extend([os.path.join(self.path, modified_input_file)]) if 'record-name-with-dots' in os.path.basename(self.path): patch_test_cmd.extend(['--merge-abc', '--record-name=record.name.with.dots']) - if ('modify-anon-content-keep-origin-name' in os.path.basename(self.path) or - 'modify-class-memeber-function' in os.path.basename(self.path)): - patch_test_cmd.extend(['--dump-assembly']) + dump_assembly_testname = ['modify-anon-content-keep-origin-name', 'modify-class-memeber-function', 'add-lexenv-3'] + for name in dump_assembly_testname: + if name in os.path.basename(self.path): + patch_test_cmd.extend(['--dump-assembly']) self.log_cmd(patch_test_cmd) process_base = subprocess.Popen(gen_base_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/es2panda/util/patchFix.cpp b/es2panda/util/patchFix.cpp index e5a8a8ad55b..fff3fbf62a2 100644 --- a/es2panda/util/patchFix.cpp +++ b/es2panda/util/patchFix.cpp @@ -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)); @@ -497,11 +504,6 @@ bool PatchFix::CompareClassHash(std::vector> 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