From 1da170f1bd65402d62ced82f758bccf9d74306c1 Mon Sep 17 00:00:00 2001 From: huoqingyi Date: Wed, 8 Jun 2022 01:02:53 +0800 Subject: [PATCH] Add Type Infer Test Case Description: 1.Add type infer test cases for bitwise_op, callfunctions, ldobjbyvalue and logic_op Issue: https://gitee.com/openharmony/ark_js_runtime/issues/I5B78L Signed-off-by: huoqingyi Change-Id: I486f6f91a32e1c7caa2446b12b8e6b33db8d47fe --- .../compiler/bytecode_circuit_builder.cpp | 4 +- ecmascript/compiler/type.cpp | 55 +++++++++++++++++++ ecmascript/compiler/type.h | 9 +++ .../compiler/type_inference/type_infer.cpp | 22 ++++---- .../compiler/type_inference/type_infer.h | 2 +- script/run_ark_executable.py | 2 +- test/typeinfer/BUILD.gn | 15 ++++- test/typeinfer/bitwise_op/BUILD.gn | 18 ++++++ test/typeinfer/bitwise_op/bitwise_op.ts | 39 +++++++++++++ test/typeinfer/bitwise_op/expect_output.txt | 19 +++++++ test/typeinfer/callarg0dyn/BUILD.gn | 18 ++++++ test/typeinfer/callarg0dyn/callarg0dyn.ts | 22 ++++++++ test/typeinfer/callarg0dyn/expect_output.txt | 14 +++++ test/typeinfer/callarg1dyn/BUILD.gn | 18 ++++++ test/typeinfer/callarg1dyn/callarg1dyn.ts | 22 ++++++++ test/typeinfer/callarg1dyn/expect_output.txt | 14 +++++ test/typeinfer/callargs2dyn/BUILD.gn | 18 ++++++ test/typeinfer/callargs2dyn/callargs2dyn.ts | 22 ++++++++ test/typeinfer/callargs2dyn/expect_output.txt | 14 +++++ test/typeinfer/callargs3dyn/BUILD.gn | 18 ++++++ test/typeinfer/callargs3dyn/callargs3dyn.ts | 23 ++++++++ test/typeinfer/callargs3dyn/expect_output.txt | 14 +++++ test/typeinfer/callirangedyn/BUILD.gn | 18 ++++++ test/typeinfer/callirangedyn/callirangedyn.ts | 35 ++++++++++++ .../typeinfer/callirangedyn/expect_output.txt | 14 +++++ test/typeinfer/callithisrange/BUILD.gn | 18 ++++++ .../callithisrange/callithisrange.ts | 40 ++++++++++++++ .../callithisrange/expect_output.txt | 17 ++++++ test/typeinfer/ldobjbyname/expect_output.txt | 3 +- test/typeinfer/ldobjbyvalue/BUILD.gn | 18 ++++++ test/typeinfer/ldobjbyvalue/expect_output.txt | 16 ++++++ test/typeinfer/ldobjbyvalue/ldobjbyvalue.ts | 24 ++++++++ test/typeinfer/logic_op/BUILD.gn | 18 ++++++ test/typeinfer/logic_op/expect_output.txt | 21 +++++++ test/typeinfer/logic_op/logic_op.ts | 27 +++++++++ 35 files changed, 653 insertions(+), 18 deletions(-) create mode 100644 test/typeinfer/bitwise_op/BUILD.gn create mode 100644 test/typeinfer/bitwise_op/bitwise_op.ts create mode 100644 test/typeinfer/bitwise_op/expect_output.txt create mode 100644 test/typeinfer/callarg0dyn/BUILD.gn create mode 100644 test/typeinfer/callarg0dyn/callarg0dyn.ts create mode 100644 test/typeinfer/callarg0dyn/expect_output.txt create mode 100644 test/typeinfer/callarg1dyn/BUILD.gn create mode 100644 test/typeinfer/callarg1dyn/callarg1dyn.ts create mode 100644 test/typeinfer/callarg1dyn/expect_output.txt create mode 100644 test/typeinfer/callargs2dyn/BUILD.gn create mode 100644 test/typeinfer/callargs2dyn/callargs2dyn.ts create mode 100644 test/typeinfer/callargs2dyn/expect_output.txt create mode 100644 test/typeinfer/callargs3dyn/BUILD.gn create mode 100644 test/typeinfer/callargs3dyn/callargs3dyn.ts create mode 100644 test/typeinfer/callargs3dyn/expect_output.txt create mode 100644 test/typeinfer/callirangedyn/BUILD.gn create mode 100644 test/typeinfer/callirangedyn/callirangedyn.ts create mode 100644 test/typeinfer/callirangedyn/expect_output.txt create mode 100644 test/typeinfer/callithisrange/BUILD.gn create mode 100644 test/typeinfer/callithisrange/callithisrange.ts create mode 100644 test/typeinfer/callithisrange/expect_output.txt create mode 100644 test/typeinfer/ldobjbyvalue/BUILD.gn create mode 100644 test/typeinfer/ldobjbyvalue/expect_output.txt create mode 100644 test/typeinfer/ldobjbyvalue/ldobjbyvalue.ts create mode 100644 test/typeinfer/logic_op/BUILD.gn create mode 100644 test/typeinfer/logic_op/expect_output.txt create mode 100644 test/typeinfer/logic_op/logic_op.ts diff --git a/ecmascript/compiler/bytecode_circuit_builder.cpp b/ecmascript/compiler/bytecode_circuit_builder.cpp index c8b6c2c8..f96f59e1 100644 --- a/ecmascript/compiler/bytecode_circuit_builder.cpp +++ b/ecmascript/compiler/bytecode_circuit_builder.cpp @@ -2202,7 +2202,7 @@ void BytecodeCircuitBuilder::NewReturn(BytecodeRegion &bb, const uint8_t *pc, Ga auto gate = circuit_.NewGate(OpCode(OpCode::RETURN), 0, { state, depend, Circuit::NullGate(), Circuit::GetCircuitRoot(OpCode(OpCode::RETURN_LIST)) }, - GateType::Empty()); + GateType::AnyType()); jsgateToBytecode_[gate] = {bb.id, pc}; } else if (static_cast(bytecodeInfo.opcode) == EcmaOpcode::RETURNUNDEFINED_PREF) { // handle returnundefined bytecode @@ -2213,7 +2213,7 @@ void BytecodeCircuitBuilder::NewReturn(BytecodeRegion &bb, const uint8_t *pc, Ga auto gate = circuit_.NewGate(OpCode(OpCode::RETURN), 0, { state, depend, constant, Circuit::GetCircuitRoot(OpCode(OpCode::RETURN_LIST)) }, - GateType::Empty()); + GateType::AnyType()); jsgateToBytecode_[gate] = {bb.id, pc}; } } diff --git a/ecmascript/compiler/type.cpp b/ecmascript/compiler/type.cpp index e3b0ba3c..ece2b2ab 100644 --- a/ecmascript/compiler/type.cpp +++ b/ecmascript/compiler/type.cpp @@ -24,4 +24,59 @@ bool Type::IsBitset() const } Type::~Type() {} + +std::string GateType::GetTypeStr() const +{ + GlobalTSTypeRef gt = GlobalTSTypeRef(GetType()); + ASSERT(gt.GetFlag() == 0); + if (IsPrimitiveTypeKind()) { + auto primitive = static_cast(gt.GetLocalId()); + switch (primitive) { + case TSPrimitiveType::ANY: + return "any"; + case TSPrimitiveType::NUMBER: + return "number"; + case TSPrimitiveType::BOOLEAN: + return "boolean"; + case TSPrimitiveType::VOID_TYPE: + return "void"; + case TSPrimitiveType::STRING: + return "string"; + case TSPrimitiveType::SYMBOL: + return "symbol"; + case TSPrimitiveType::NULL_TYPE: + return "null"; + case TSPrimitiveType::UNDEFINED: + return "undefined"; + case TSPrimitiveType::INT: + return "int"; + case TSPrimitiveType::BIG_INT: + return "big_int"; + default: + break; + } + } + auto typeKind = static_cast(gt.GetKind()); + switch (typeKind) { + case TSTypeKind::CLASS: + return "class"; + case TSTypeKind::CLASS_INSTANCE: + return "class_instance"; + case TSTypeKind::FUNCTION: + return "function"; + case TSTypeKind::UNION: + return "union"; + case TSTypeKind::ARRAY: + return "array"; + case TSTypeKind::OBJECT: + return "object"; + case TSTypeKind::IMPORT: + return "import"; + case TSTypeKind::INTERFACE_KIND: + return "interface"; + default: + break; + } + return "gatetype:" + std::to_string(gt.GetType()); +} }; // namespace panda::ecmascript::kungfu \ No newline at end of file diff --git a/ecmascript/compiler/type.h b/ecmascript/compiler/type.h index b553f81b..5dec85bb 100644 --- a/ecmascript/compiler/type.h +++ b/ecmascript/compiler/type.h @@ -124,6 +124,13 @@ public: return GateType(TSPrimitiveType::BIG_INT); } + bool inline IsTSType() const + { + GlobalTSTypeRef gt = GlobalTSTypeRef(GetType()); + // 0: TS type + return gt.GetFlag() == 0; + } + bool inline IsAnyType() const { return type_ == static_cast(TSPrimitiveType::ANY); @@ -267,6 +274,8 @@ public: return type_ >= other.type_; } + std::string GetTypeStr() const; + private: uint32_t type_ {0}; }; diff --git a/ecmascript/compiler/type_inference/type_infer.cpp b/ecmascript/compiler/type_inference/type_infer.cpp index 7eee7b38..a7c22266 100644 --- a/ecmascript/compiler/type_inference/type_infer.cpp +++ b/ecmascript/compiler/type_inference/type_infer.cpp @@ -65,13 +65,15 @@ void TypeInfer::TypeInferPrint() const const auto &gateList = circuit_->GetAllGates(); std::string log("TestInfer:"); for (const auto &gate : gateList) { - auto op = gateAccessor_.GetOpCode(gate); - if (op == OpCode::JS_BYTECODE) { - log += "&" + builder_->GetBytecodeStr(gate) + ":"; - auto gateType = gateAccessor_.GetGateType(gate); - auto type = gateType.GetType() > GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT ? "INF" - : std::to_string(gateType.GetType()); - log += type; + auto type = gateAccessor_.GetGateType(gate); + if (ShouldInfer(gate) && type.IsTSType() && !type.IsAnyType()) { + auto op = gateAccessor_.GetOpCode(gate); + if (op == OpCode::VALUE_SELECTOR) { + log += "&" + op.Str() + ":"; + } else { + log += "&" + builder_->GetBytecodeStr(gate) + ":"; + } + log += type.GetTypeStr(); } } COMPILER_LOG(INFO) << std::dec << log; @@ -93,7 +95,7 @@ bool TypeInfer::UpdateType(GateRef gate, const GlobalTSTypeRef &typeRef) return UpdateType(gate, type); } -bool TypeInfer::ShouldInfer(const GateRef gate) +bool TypeInfer::ShouldInfer(const GateRef gate) const { auto op = gateAccessor_.GetOpCode(gate); // handle phi gates @@ -104,9 +106,9 @@ bool TypeInfer::ShouldInfer(const GateRef gate) op == OpCode::CONSTANT || op == OpCode::RETURN) { auto gateToBytecode = builder_->GetGateToBytecode(); - // handle gates generated by ecma.* bytecodes + // handle gates generated by ecma.* bytecodes (not including Jump) if (gateToBytecode.find(gate) != gateToBytecode.end()) { - return true; + return !builder_->GetByteCodeInfo(gate).IsJump(); } } return false; diff --git a/ecmascript/compiler/type_inference/type_infer.h b/ecmascript/compiler/type_inference/type_infer.h index c435b837..d998ce37 100644 --- a/ecmascript/compiler/type_inference/type_infer.h +++ b/ecmascript/compiler/type_inference/type_infer.h @@ -40,7 +40,7 @@ public: private: bool UpdateType(GateRef gate, const GateType type); bool UpdateType(GateRef gate, const GlobalTSTypeRef &typeRef); - bool ShouldInfer(const GateRef gate); + bool ShouldInfer(const GateRef gate) const; bool Infer(GateRef gate); bool InferPhiGate(GateRef gate); bool SetNumberType(GateRef gate); diff --git a/script/run_ark_executable.py b/script/run_ark_executable.py index 12e518a8..eeae2556 100755 --- a/script/run_ark_executable.py +++ b/script/run_ark_executable.py @@ -113,7 +113,7 @@ def judge_output(args): if "TestInfer:" in item: err_list.append(item.split("&")[1:]) expect_output = expect_output.replace('\n', '') - expect_list = [elements.split(",") for elements in expect_output.split("[")] + expect_list = [elements.split(",") for elements in expect_output.split("----")] for obj1, obj2 in zip(err_list, expect_list): if not isSubSequence(obj1, obj2): print(">>>>> Expect :", end = " ") diff --git a/test/typeinfer/BUILD.gn b/test/typeinfer/BUILD.gn index 2cc162fc..47955ab7 100644 --- a/test/typeinfer/BUILD.gn +++ b/test/typeinfer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -13,5 +13,16 @@ group("ark_typeinfer_test") { testonly = true - deps = [ "ldobjbyname:ldobjbynameAotTypeInferAction" ] + deps = [ + "bitwise_op:bitwise_opAotTypeInferAction", + "callarg0dyn:callarg0dynAotTypeInferAction", + "callarg1dyn:callarg1dynAotTypeInferAction", + "callargs2dyn:callargs2dynAotTypeInferAction", + "callargs3dyn:callargs3dynAotTypeInferAction", + "callirangedyn:callirangedynAotTypeInferAction", + "callithisrange:callithisrangeAotTypeInferAction", + "ldobjbyname:ldobjbynameAotTypeInferAction", + "ldobjbyvalue:ldobjbyvalueAotTypeInferAction", + "logic_op:logic_opAotTypeInferAction", + ] } diff --git a/test/typeinfer/bitwise_op/BUILD.gn b/test/typeinfer/bitwise_op/BUILD.gn new file mode 100644 index 00000000..eb25390f --- /dev/null +++ b/test/typeinfer/bitwise_op/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("bitwise_op") { + deps = [] +} diff --git a/test/typeinfer/bitwise_op/bitwise_op.ts b/test/typeinfer/bitwise_op/bitwise_op.ts new file mode 100644 index 00000000..2d954458 --- /dev/null +++ b/test/typeinfer/bitwise_op/bitwise_op.ts @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 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. + */ + +{ + let x:number = 123; + let y:number = 2; + let andRes = x & y; + typeof(andRes); + + let orRes = x | y; + typeof(orRes); + + let xorRes = x ^ y; + typeof(xorRes); + + let shlRes = x << y; + typeof(shlRes); + + let ashrRes = x >> y; + typeof(ashrRes); + + let shrRes = x >>> y; + typeof(shrRes); + + let notRes = ~x; + typeof(notRes); +} diff --git a/test/typeinfer/bitwise_op/expect_output.txt b/test/typeinfer/bitwise_op/expect_output.txt new file mode 100644 index 00000000..7bd6fe28 --- /dev/null +++ b/test/typeinfer/bitwise_op/expect_output.txt @@ -0,0 +1,19 @@ +# Copyright (c) 2022 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. + +AND2DYN:number, +OR2DYN:number, +XOR2DYN:number, +SHL2DYN:number, +ASHR2DYN:number, +SHR2DYN:number diff --git a/test/typeinfer/callarg0dyn/BUILD.gn b/test/typeinfer/callarg0dyn/BUILD.gn new file mode 100644 index 00000000..6c1e2d46 --- /dev/null +++ b/test/typeinfer/callarg0dyn/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("callarg0dyn") { + deps = [] +} diff --git a/test/typeinfer/callarg0dyn/callarg0dyn.ts b/test/typeinfer/callarg0dyn/callarg0dyn.ts new file mode 100644 index 00000000..bd989bbe --- /dev/null +++ b/test/typeinfer/callarg0dyn/callarg0dyn.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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. + */ + +{ + function foo():string + { + return "pass"; + } + typeof(foo()); +} diff --git a/test/typeinfer/callarg0dyn/expect_output.txt b/test/typeinfer/callarg0dyn/expect_output.txt new file mode 100644 index 00000000..1cb5f5a2 --- /dev/null +++ b/test/typeinfer/callarg0dyn/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +CALLARG0DYN:string diff --git a/test/typeinfer/callarg1dyn/BUILD.gn b/test/typeinfer/callarg1dyn/BUILD.gn new file mode 100644 index 00000000..6a2d19a7 --- /dev/null +++ b/test/typeinfer/callarg1dyn/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("callarg1dyn") { + deps = [] +} diff --git a/test/typeinfer/callarg1dyn/callarg1dyn.ts b/test/typeinfer/callarg1dyn/callarg1dyn.ts new file mode 100644 index 00000000..d5911d18 --- /dev/null +++ b/test/typeinfer/callarg1dyn/callarg1dyn.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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. + */ + +{ + function foo(v:number):number + { + return v + 1; + } + typeof(foo(0)); +} diff --git a/test/typeinfer/callarg1dyn/expect_output.txt b/test/typeinfer/callarg1dyn/expect_output.txt new file mode 100644 index 00000000..28d10e1c --- /dev/null +++ b/test/typeinfer/callarg1dyn/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +CALLARG1DYN:number diff --git a/test/typeinfer/callargs2dyn/BUILD.gn b/test/typeinfer/callargs2dyn/BUILD.gn new file mode 100644 index 00000000..ad2526d1 --- /dev/null +++ b/test/typeinfer/callargs2dyn/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("callargs2dyn") { + deps = [] +} diff --git a/test/typeinfer/callargs2dyn/callargs2dyn.ts b/test/typeinfer/callargs2dyn/callargs2dyn.ts new file mode 100644 index 00000000..1f7e9865 --- /dev/null +++ b/test/typeinfer/callargs2dyn/callargs2dyn.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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. + */ + +{ + function foo(flag1:boolean, flag2:boolean):boolean + { + return flag1 && flag2; + } + typeof(foo(true, false)); +} diff --git a/test/typeinfer/callargs2dyn/expect_output.txt b/test/typeinfer/callargs2dyn/expect_output.txt new file mode 100644 index 00000000..826b2f34 --- /dev/null +++ b/test/typeinfer/callargs2dyn/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +CALLARGS2DYN:boolean diff --git a/test/typeinfer/callargs3dyn/BUILD.gn b/test/typeinfer/callargs3dyn/BUILD.gn new file mode 100644 index 00000000..f8e2e4aa --- /dev/null +++ b/test/typeinfer/callargs3dyn/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("callargs3dyn") { + deps = [] +} diff --git a/test/typeinfer/callargs3dyn/callargs3dyn.ts b/test/typeinfer/callargs3dyn/callargs3dyn.ts new file mode 100644 index 00000000..49363814 --- /dev/null +++ b/test/typeinfer/callargs3dyn/callargs3dyn.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 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. + */ + +{ + function foo(v1:number, v2:number, v3:number):number[] + { + let arr:number[] = [v1, v2, v3]; + return arr; + } + typeof(foo(0, 1, 2)); +} diff --git a/test/typeinfer/callargs3dyn/expect_output.txt b/test/typeinfer/callargs3dyn/expect_output.txt new file mode 100644 index 00000000..4e8c2479 --- /dev/null +++ b/test/typeinfer/callargs3dyn/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +CALLARGS3DYN:array diff --git a/test/typeinfer/callirangedyn/BUILD.gn b/test/typeinfer/callirangedyn/BUILD.gn new file mode 100644 index 00000000..47e6aa6b --- /dev/null +++ b/test/typeinfer/callirangedyn/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("callirangedyn") { + deps = [] +} diff --git a/test/typeinfer/callirangedyn/callirangedyn.ts b/test/typeinfer/callirangedyn/callirangedyn.ts new file mode 100644 index 00000000..99b2585d --- /dev/null +++ b/test/typeinfer/callirangedyn/callirangedyn.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 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 { + v1:number; + v2:string; + v3:boolean; + v4:number; + constructor(v1:number, v2:string, v3:boolean, v4:number) { + this.v1 = v1; + this.v2 = v2; + this.v3 = v3; + this.v4 = v4; + } + } + function foo(v1:number, v2:string, v3:boolean, v4:number):A + { + let a = new A(v1, v2, v3, v4); + return a; + } + typeof(foo(0, "1", true, 3)); +} diff --git a/test/typeinfer/callirangedyn/expect_output.txt b/test/typeinfer/callirangedyn/expect_output.txt new file mode 100644 index 00000000..a362c2d8 --- /dev/null +++ b/test/typeinfer/callirangedyn/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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. + +CALLIRANGEDYN:class_instance diff --git a/test/typeinfer/callithisrange/BUILD.gn b/test/typeinfer/callithisrange/BUILD.gn new file mode 100644 index 00000000..8775e72b --- /dev/null +++ b/test/typeinfer/callithisrange/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("callithisrange") { + deps = [] +} diff --git a/test/typeinfer/callithisrange/callithisrange.ts b/test/typeinfer/callithisrange/callithisrange.ts new file mode 100644 index 00000000..8b1bc5b7 --- /dev/null +++ b/test/typeinfer/callithisrange/callithisrange.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 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 { + v:number; + constructor(v:number) { + this.v = v; + } + fun(value:number):number { + return this.v + value; + } + fun1():void { + this.v += 1; + } + fun2():string { + return "hello"; + } + fun3():boolean { + return true; + } + } + let a = new A(1); + typeof(a.fun(2)); + typeof(a.fun1()); + typeof(a.fun2()); + typeof(a.fun3()); +} diff --git a/test/typeinfer/callithisrange/expect_output.txt b/test/typeinfer/callithisrange/expect_output.txt new file mode 100644 index 00000000..b1b07671 --- /dev/null +++ b/test/typeinfer/callithisrange/expect_output.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2022 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. + +CALLITHISRANGEDYN:number, +CALLITHISRANGEDYN:void, +CALLITHISRANGEDYN:string, +CALLITHISRANGEDYN:boolean diff --git a/test/typeinfer/ldobjbyname/expect_output.txt b/test/typeinfer/ldobjbyname/expect_output.txt index a8fcaa00..edeaab4a 100644 --- a/test/typeinfer/ldobjbyname/expect_output.txt +++ b/test/typeinfer/ldobjbyname/expect_output.txt @@ -11,5 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -LDLEXENVDYN:0,LDA_STR:4,DEFINECLASSWITHBUFFER:INF,LDA_STR:4,LDOBJBYNAME:4,TYPEOFDYN:4 -[LDLEXENVDYN:0 \ No newline at end of file +LDOBJBYNAME:string diff --git a/test/typeinfer/ldobjbyvalue/BUILD.gn b/test/typeinfer/ldobjbyvalue/BUILD.gn new file mode 100644 index 00000000..c5c1fd2f --- /dev/null +++ b/test/typeinfer/ldobjbyvalue/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("ldobjbyvalue") { + deps = [] +} diff --git a/test/typeinfer/ldobjbyvalue/expect_output.txt b/test/typeinfer/ldobjbyvalue/expect_output.txt new file mode 100644 index 00000000..320155b1 --- /dev/null +++ b/test/typeinfer/ldobjbyvalue/expect_output.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2022 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. + +LDOBJBYVALUE:string, +LDOBJBYVALUE:number, +LDOBJBYVALUE:boolean diff --git a/test/typeinfer/ldobjbyvalue/ldobjbyvalue.ts b/test/typeinfer/ldobjbyvalue/ldobjbyvalue.ts new file mode 100644 index 00000000..9c8d6302 --- /dev/null +++ b/test/typeinfer/ldobjbyvalue/ldobjbyvalue.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 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. + */ + +{ + let arr1:string[] = ["a", "b", "c"]; + let arr2:number[] = [1, 2, 3, 4]; + let arr3:boolean[] = [true, false, false]; + let t = 1; + typeof(arr1[t]); + typeof(arr2[t]); + typeof(arr3[t]); +} diff --git a/test/typeinfer/logic_op/BUILD.gn b/test/typeinfer/logic_op/BUILD.gn new file mode 100644 index 00000000..e0cc1416 --- /dev/null +++ b/test/typeinfer/logic_op/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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. + +import("//ark/js_runtime/test/test_helper.gni") + +host_typeinfer_test_action("logic_op") { + deps = [] +} diff --git a/test/typeinfer/logic_op/expect_output.txt b/test/typeinfer/logic_op/expect_output.txt new file mode 100644 index 00000000..9e351f7c --- /dev/null +++ b/test/typeinfer/logic_op/expect_output.txt @@ -0,0 +1,21 @@ +# Copyright (c) 2022 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. + +GREATEREQDYN:boolean, +GREATERDYN:boolean, +LESSDYN:boolean, +LESSEQDYN:boolean, +EQDYN:boolean, +NOTEQDYN:boolean, +STRICTEQDYN:boolean, +STRICTNOTEQDYN:boolean diff --git a/test/typeinfer/logic_op/logic_op.ts b/test/typeinfer/logic_op/logic_op.ts new file mode 100644 index 00000000..48998756 --- /dev/null +++ b/test/typeinfer/logic_op/logic_op.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 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. + */ + +{ + let num1:number = 1; + let num2:number = 2; + typeof(num1 >= num2); + typeof(num1 > num2); + typeof(num1 < num2); + typeof(num1 <= num2); + typeof(num1 == num2); + typeof(num1 != num2); + typeof(num1 === num2); + typeof(num1 !== num2); +}