From 67058778e498e7f690eef86af2c0eb028cd2d629 Mon Sep 17 00:00:00 2001 From: songqi Date: Sat, 8 Apr 2023 14:22:51 +0800 Subject: [PATCH] Fix aot failure caused by redundant bytecode and wrong lexenv instruction Issue: I6TUAZ Tests: test262/tsc/parser/compiler Signed-off-by: songqi Change-Id: I4d7cf9aa3716c06d6f29b75a4a82019b01ca8116 --- es2panda/binder/binder.cpp | 6 ++-- es2panda/compiler/core/pandagen.cpp | 2 +- .../async/test-ts-async-1-expected.txt | 2 ++ .../conformance/async/test-ts-async-1.ts | 26 +++++++++++++++ .../test-ts-concurrent-1-expected.txt | 2 ++ .../functions/test-ts-concurrent-1.ts | 24 ++++++++++++++ .../test-ts-declare-function-1-expected.txt | 1 + .../functions/test-ts-declare-function-1.ts | 32 +++++++++++++++++++ 8 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1.ts create mode 100644 es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1.ts create mode 100644 es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1.ts diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 930a6afc35..e203801cb3 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -293,8 +293,10 @@ void Binder::LookupIdentReference(ir::Identifier *ident) if (res.level != 0) { ASSERT(res.variable); - util::Concurrent::VerifyImportVarForConcurrentFunction(Program()->GetLineIndex(), ident, res); - res.variable->SetLexical(res.scope, program_->HotfixHelper()); + if (!res.variable->Declaration()->IsDeclare()) { + util::Concurrent::VerifyImportVarForConcurrentFunction(Program()->GetLineIndex(), ident, res); + res.variable->SetLexical(res.scope, program_->HotfixHelper()); + } } if (res.variable == nullptr) { diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 567ddb418b..a0f674fa4f 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -840,7 +840,7 @@ void PandaGen::Condition(const ir::AstNode *node, lexer::TokenType op, VReg lhs, } } - BranchIfFalse(node, ifFalse); + ra_.Emit(node, ifFalse); } void PandaGen::Unary(const ir::AstNode *node, lexer::TokenType op, VReg operand) diff --git a/es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1-expected.txt new file mode 100644 index 0000000000..94954abda4 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1-expected.txt @@ -0,0 +1,2 @@ +hello +world diff --git a/es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1.ts b/es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1.ts new file mode 100644 index 0000000000..5cb1e50ee2 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/async/test-ts-async-1.ts @@ -0,0 +1,26 @@ +/* + * 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. + */ + + +class A { + async getA() { + print("hello"); + await 1; + print("world"); + } +} + +let c = new A(); +c.getA(); diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1-expected.txt new file mode 100644 index 0000000000..3be1a1c634 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1-expected.txt @@ -0,0 +1,2 @@ +concurrent +end diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1.ts b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1.ts new file mode 100644 index 0000000000..b27c13cfdc --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-concurrent-1.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + + +declare function print(str:string):string; + +function func() { + "use concurrent"; + print("concurrent"); +} +func(); +print("end"); \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1-expected.txt b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1-expected.txt new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1-expected.txt @@ -0,0 +1 @@ +2 diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1.ts b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1.ts new file mode 100644 index 0000000000..0cb3633e5b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-declare-function-1.ts @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +declare function print(str:any):string; +declare var ArkTools:any; + +class C { + method1() { + print("hello"); + } +} + +let c = new C(); +let env = ArkTools.getLexicalEnv(c.method1); +if (env !== undefined) { + print(1); +} else { + print(2); +} -- Gitee