From 6fc2f3a590f4934047804ed45a0557e44385c311 Mon Sep 17 00:00:00 2001 From: Andrey Efremov Date: Thu, 4 Apr 2024 18:59:50 +0300 Subject: [PATCH] Inline Set/Map has builtin * Add tests Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9E585 Change-Id: I97a1d6da6172c459fe68f7fb58697a2ae5568ec5 Signed-off-by: Andrey Efremov --- .../builtins/builtins_call_signature.h | 8 ++++ .../builtins_collection_stub_builder.cpp | 2 +- .../linked_hashtable_stub_builder.cpp | 18 +-------- ecmascript/compiler/call_signature.cpp | 39 ++++++++++++------ ecmascript/compiler/call_signature.h | 9 +++++ ecmascript/compiler/circuit_builder.h | 3 +- ecmascript/compiler/common_stubs.cpp | 29 ++++++++++++-- ecmascript/compiler/common_stubs.h | 2 + ecmascript/compiler/mcr_opcodes.h | 2 + .../compiler/native_inline_lowering.cpp | 6 +++ .../compiler/number_speculative_retype.cpp | 7 +++- .../compiler/number_speculative_retype.h | 3 +- ecmascript/compiler/stub_builder-inl.h | 10 +++++ ecmascript/compiler/stub_builder.cpp | 21 ++-------- ecmascript/compiler/stub_builder.h | 2 + .../compiler/typed_native_inline_lowering.cpp | 6 +++ ecmascript/global_env_constants.h | 2 + ecmascript/linked_hash_table.cpp | 3 ++ .../builtin_inlining/map/Has/builtinMapHas.ts | 40 ++++++++++++++----- .../builtin_inlining/set/Has/builtinSetHas.ts | 40 ++++++++++++++----- test/moduletest/mapget/mapget.js | 28 +++++++++++++ 21 files changed, 203 insertions(+), 77 deletions(-) diff --git a/ecmascript/compiler/builtins/builtins_call_signature.h b/ecmascript/compiler/builtins/builtins_call_signature.h index b3f351c041..1843f9a18a 100644 --- a/ecmascript/compiler/builtins/builtins_call_signature.h +++ b/ecmascript/compiler/builtins/builtins_call_signature.h @@ -327,6 +327,8 @@ public: switch (builtinId) { case BuiltinsStubCSigns::ID::StringFromCharCode: case BuiltinsStubCSigns::ID::MapGet: + case BuiltinsStubCSigns::ID::MapHas: + case BuiltinsStubCSigns::ID::SetHas: return true; default: return false; @@ -445,6 +447,10 @@ public: return ConstantIndex::MATH_IMUL_INDEX; case BuiltinsStubCSigns::ID::MapGet: return ConstantIndex::MAP_GET_INDEX; + case BuiltinsStubCSigns::ID::MapHas: + return ConstantIndex::MAP_HAS_INDEX; + case BuiltinsStubCSigns::ID::SetHas: + return ConstantIndex::SET_HAS_INDEX; case BuiltinsStubCSigns::ID::StringLocaleCompare: return ConstantIndex::LOCALE_COMPARE_FUNCTION_INDEX; case BuiltinsStubCSigns::ID::ArraySort: @@ -559,6 +565,8 @@ public: {GlobalIsFinite, "isFinite"}, {GlobalIsNan, "isNan"}, {MapGet, "Map.get"}, + {MapHas, "Map.has"}, + {SetHas, "Set.has"}, }; if (builtinId2Str.count(id) > 0) { return builtinId2Str.at(id); diff --git a/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp index e60f4eaf27..3dacaefa7e 100644 --- a/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_collection_stub_builder.cpp @@ -245,7 +245,7 @@ void BuiltinsCollectionStubBuilder::Has(Variable *result, Label LinkedHashTableStubBuilder linkedHashTableStubBuilder(this, glue_); res = linkedHashTableStubBuilder.Has(linkedTable, key); } - *result = res; + *result = BooleanToTaggedBooleanPtr(res); Jump(exit); } diff --git a/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp b/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp index ceeeca5bef..9c1725b416 100644 --- a/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp +++ b/ecmascript/compiler/builtins/linked_hashtable_stub_builder.cpp @@ -579,26 +579,10 @@ GateRef LinkedHashTableStubBuilder:: auto env = GetEnvironment(); Label cfgEntry(env); env->SubCfgEntry(&cfgEntry); - Label exit(env); - Label nonEmpty(env); - DEFVARIABLE(res, VariableType::JS_ANY(), TaggedFalse()); - GateRef size = GetNumberOfElements(linkedTable); - BRANCH(Int32Equal(size, Int32(0)), &exit, &nonEmpty); - Bind(&nonEmpty); HashStubBuilder hashBuilder(this, glue_); GateRef hash = hashBuilder.GetHash(key); - GateRef entry = FindElement(linkedTable, key, hash); - Label findEntry(env); - BRANCH(Int32Equal(entry, Int32(-1)), &exit, &findEntry); - Bind(&findEntry); - { - res = TaggedTrue(); - Jump(&exit); - } - - Bind(&exit); - auto ret = *res; + GateRef ret = Int32NotEqual(entry, Int32(-1)); env->SubCfgExit(); return ret; } diff --git a/ecmascript/compiler/call_signature.cpp b/ecmascript/compiler/call_signature.cpp index 9dd224f78d..a6e536ab99 100644 --- a/ecmascript/compiler/call_signature.cpp +++ b/ecmascript/compiler/call_signature.cpp @@ -2383,18 +2383,32 @@ DEF_CALL_SIGNATURE(CreateJSMapIterator) DEF_CALL_SIGNATURE(JSMapGet) { - // 3 : 3 input parameters - CallSignature signature("JSMapGet", 0, 3, - ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); - *callSign = signature; - // 3 : 3 input parameters - std::array params = { - VariableType::NATIVE_POINTER(), // glue - VariableType::JS_ANY(), // obj - VariableType::JS_ANY(), // key - }; - callSign->SetParameters(params.data()); - callSign->SetCallConv(CallSignature::CallConv::CCallConv); + *callSign = CallSignature("JSMapGet", 0, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY(), + { + VariableType::NATIVE_POINTER(), // glue + VariableType::JS_ANY(), // obj + VariableType::JS_ANY(), // key + }); +} + +DEF_CALL_SIGNATURE(JSMapHas) +{ + *callSign = CallSignature("JSMapHas", 0, ArgumentsOrder::DEFAULT_ORDER, VariableType::BOOL(), + { + VariableType::NATIVE_POINTER(), // glue + VariableType::JS_ANY(), // obj + VariableType::JS_ANY(), // key + }); +} + +DEF_CALL_SIGNATURE(JSSetHas) +{ + *callSign = CallSignature("JSSetHas", 0, ArgumentsOrder::DEFAULT_ORDER, VariableType::BOOL(), + { + VariableType::NATIVE_POINTER(), // glue + VariableType::JS_ANY(), // obj + VariableType::JS_ANY(), // key + }); } DEF_CALL_SIGNATURE(FastStringEqual) @@ -2410,7 +2424,6 @@ DEF_CALL_SIGNATURE(FastStringEqual) VariableType::JS_ANY(), // ecmaString2 }; callSign->SetParameters(params.data()); - callSign->SetCallConv(CallSignature::CallConv::CCallConv); } DEF_CALL_SIGNATURE(FastStringAdd) diff --git a/ecmascript/compiler/call_signature.h b/ecmascript/compiler/call_signature.h index 44e5a88fc9..97a4b8e4f7 100644 --- a/ecmascript/compiler/call_signature.h +++ b/ecmascript/compiler/call_signature.h @@ -81,6 +81,13 @@ public: SetVariadicArgs(flags); } + CallSignature(std::string name, int flags, ArgumentsOrder order, VariableType returnType, + std::initializer_list params) + : CallSignature(std::move(name), flags, params.size(), order, returnType) + { + paramsType_ = std::make_unique>(params); + } + CallSignature() = default; ~CallSignature() = default; @@ -505,6 +512,8 @@ private: V(CreateJSSetIterator) \ V(CreateJSMapIterator) \ V(JSMapGet) \ + V(JSMapHas) \ + V(JSSetHas) \ V(JSHClassFindProtoTransitions) \ V(NumberHelperStringToDouble) \ V(GetStringToListCacheArray) \ diff --git a/ecmascript/compiler/circuit_builder.h b/ecmascript/compiler/circuit_builder.h index d828213b3c..ddef6ff1e5 100644 --- a/ecmascript/compiler/circuit_builder.h +++ b/ecmascript/compiler/circuit_builder.h @@ -174,7 +174,8 @@ class PostSchedule; V(Int64LessThanOrEqual, Icmp, static_cast(ICmpCondition::SLE)) \ V(Int64GreaterThan, Icmp, static_cast(ICmpCondition::SGT)) \ V(Int64GreaterThanOrEqual, Icmp, static_cast(ICmpCondition::SGE)) \ - V(Int64UnsignedLessThanOrEqual, Icmp, static_cast(ICmpCondition::ULE)) + V(Int64UnsignedLessThanOrEqual, Icmp, static_cast(ICmpCondition::ULE)) \ + V(Int64UnsignedGreaterThanOrEqual, Icmp, static_cast(ICmpCondition::UGE)) class CircuitBuilder { public: diff --git a/ecmascript/compiler/common_stubs.cpp b/ecmascript/compiler/common_stubs.cpp index e7853b3786..4c95cb30a6 100644 --- a/ecmascript/compiler/common_stubs.cpp +++ b/ecmascript/compiler/common_stubs.cpp @@ -1148,10 +1148,31 @@ void JSMapGetStubBuilder::GenerateCircuit() GateRef obj = TaggedArgument(1); GateRef key = TaggedArgument(2U); - LinkedHashTableStubBuilder linkedHashTableStubBuilder(this, glue); - GateRef linkedTable = linkedHashTableStubBuilder.GetLinked(obj); - GateRef result = linkedHashTableStubBuilder.Get(linkedTable, key); - Return(result); + LinkedHashTableStubBuilder builder(this, glue); + GateRef linkedTable = builder.GetLinked(obj); + Return(builder.Get(linkedTable, key)); +} + +void JSMapHasStubBuilder::GenerateCircuit() +{ + GateRef glue = PtrArgument(0); + GateRef obj = TaggedArgument(1); + GateRef key = TaggedArgument(2U); + + LinkedHashTableStubBuilder builder(this, glue); + GateRef linkedTable = builder.GetLinked(obj); + Return(builder.Has(linkedTable, key)); +} + +void JSSetHasStubBuilder::GenerateCircuit() +{ + GateRef glue = PtrArgument(0); + GateRef obj = TaggedArgument(1); + GateRef key = TaggedArgument(2U); + + LinkedHashTableStubBuilder builder(this, glue); + GateRef linkedTable = builder.GetLinked(obj); + Return(builder.Has(linkedTable, key)); } CallSignature CommonStubCSigns::callSigns_[CommonStubCSigns::NUM_OF_STUBS]; diff --git a/ecmascript/compiler/common_stubs.h b/ecmascript/compiler/common_stubs.h index 6a531b67b8..ba41bad544 100644 --- a/ecmascript/compiler/common_stubs.h +++ b/ecmascript/compiler/common_stubs.h @@ -92,6 +92,8 @@ namespace panda::ecmascript::kungfu { V(CreateJSSetIterator) \ V(CreateJSMapIterator) \ V(JSMapGet) \ + V(JSMapHas) \ + V(JSSetHas) \ V(GetSingleCharCodeByIndex) \ V(FastStringEqual) \ V(FastStringAdd) \ diff --git a/ecmascript/compiler/mcr_opcodes.h b/ecmascript/compiler/mcr_opcodes.h index aac486bd6a..757e0c91b7 100644 --- a/ecmascript/compiler/mcr_opcodes.h +++ b/ecmascript/compiler/mcr_opcodes.h @@ -118,6 +118,8 @@ namespace panda::ecmascript::kungfu { V(DataViewSet, DATA_VIEW_SET, GateFlags::NO_WRITE, 1, 1, 6) \ V(MapGet, MAP_GET, GateFlags::NO_WRITE, 1, 1, 2) \ V(DateGetTime, DATE_GET_TIME, GateFlags::NO_WRITE, 1, 1, 1) \ + V(MapHas, MAP_HAS, GateFlags::NO_WRITE, 1, 1, 2) \ + V(SetHas, SET_HAS, GateFlags::NO_WRITE, 1, 1, 2) \ MCR_BINARY_GATE_META_DATA_CACHE_LIST(V) #define MCR_GATE_META_DATA_LIST_WITH_PC_OFFSET(V) \ diff --git a/ecmascript/compiler/native_inline_lowering.cpp b/ecmascript/compiler/native_inline_lowering.cpp index 4417cdc2e0..44d8a10088 100644 --- a/ecmascript/compiler/native_inline_lowering.cpp +++ b/ecmascript/compiler/native_inline_lowering.cpp @@ -224,6 +224,12 @@ void NativeInlineLowering::RunNativeInlineLowering() case BuiltinsStubCSigns::ID::MapGet: InlineStubBuiltin(gate, 1U, argc, id, circuit_->MapGet(), skipThis); break; + case BuiltinsStubCSigns::ID::MapHas: + InlineStubBuiltin(gate, 1U, argc, id, circuit_->MapHas(), skipThis); + break; + case BuiltinsStubCSigns::ID::SetHas: + InlineStubBuiltin(gate, 1U, argc, id, circuit_->SetHas(), skipThis); + break; default: break; } diff --git a/ecmascript/compiler/number_speculative_retype.cpp b/ecmascript/compiler/number_speculative_retype.cpp index 861525b12a..931bf3c9dc 100644 --- a/ecmascript/compiler/number_speculative_retype.cpp +++ b/ecmascript/compiler/number_speculative_retype.cpp @@ -241,6 +241,9 @@ GateRef NumberSpeculativeRetype::VisitGate(GateRef gate) return VisitDataViewSet(gate); case OpCode::DATE_GET_TIME: return VisitDateGetTime(gate); + case OpCode::MAP_HAS: + case OpCode::SET_HAS: + return VisitOthers(gate, GateType::BooleanType()); case OpCode::JS_BYTECODE: case OpCode::RUNTIME_CALL: case OpCode::PRIMITIVE_TYPE_CHECK: @@ -795,10 +798,10 @@ GateRef NumberSpeculativeRetype::VisitFrameState(GateRef gate) return Circuit::NullGate(); } -GateRef NumberSpeculativeRetype::VisitOthers(GateRef gate) +GateRef NumberSpeculativeRetype::VisitOthers(GateRef gate, GateType outputType) { if (IsRetype()) { - return SetOutputType(gate, GateType::AnyType()); + return SetOutputType(gate, outputType); } if (IsConvert()) { size_t valueNum = acc_.GetNumValueIn(gate); diff --git a/ecmascript/compiler/number_speculative_retype.h b/ecmascript/compiler/number_speculative_retype.h index e616aaf952..47f2364310 100644 --- a/ecmascript/compiler/number_speculative_retype.h +++ b/ecmascript/compiler/number_speculative_retype.h @@ -109,10 +109,9 @@ private: GateRef VisitStoreProperty(GateRef gate); GateRef VisitLoadProperty(GateRef gate); GateRef VisitNumberRelated(GateRef gate, ParamType paramType); - GateRef VisitCallBuiltins(GateRef gate); GateRef VisitDataViewGet(GateRef gate); GateRef VisitDataViewSet(GateRef gate); - GateRef VisitOthers(GateRef gate); + GateRef VisitOthers(GateRef gate, GateType outputType = GateType::AnyType()); GateRef VisitTypeConvert(GateRef gate); GateRef VisitFrameState(GateRef gate); GateRef VisitIsTrueOrFalse(GateRef gate); diff --git a/ecmascript/compiler/stub_builder-inl.h b/ecmascript/compiler/stub_builder-inl.h index a7ebcdccf1..96e09e0f9f 100644 --- a/ecmascript/compiler/stub_builder-inl.h +++ b/ecmascript/compiler/stub_builder-inl.h @@ -829,6 +829,11 @@ inline GateRef StubBuilder::DoubleToTaggedDoublePtr(GateRef x) return env_->GetBuilder()->DoubleToTaggedDoublePtr(x); } +inline GateRef StubBuilder::BooleanToTaggedBooleanPtr(GateRef x) +{ + return env_->GetBuilder()->BooleanToTaggedBooleanPtr(x); +} + inline GateRef StubBuilder::TaggedPtrToTaggedDoublePtr(GateRef x) { return DoubleToTaggedDoublePtr(CastInt64ToFloat64(ChangeTaggedPointerToInt64(x))); @@ -995,6 +1000,11 @@ inline GateRef StubBuilder::Int64UnsignedLessThanOrEqual(GateRef x, GateRef y) return env_->GetBuilder()->Int64UnsignedLessThanOrEqual(x, y); } +inline GateRef StubBuilder::Int64UnsignedGreaterThanOrEqual(GateRef x, GateRef y) +{ + return env_->GetBuilder()->Int64UnsignedGreaterThanOrEqual(x, y); +} + inline GateRef StubBuilder::IntPtrGreaterThan(GateRef x, GateRef y) { return env_->GetBuilder()->IntPtrGreaterThan(x, y); diff --git a/ecmascript/compiler/stub_builder.cpp b/ecmascript/compiler/stub_builder.cpp index 2aa89422d8..c3dcd54b1d 100644 --- a/ecmascript/compiler/stub_builder.cpp +++ b/ecmascript/compiler/stub_builder.cpp @@ -6776,7 +6776,6 @@ void StubBuilder::CalcHashcodeForDouble(GateRef x, Variable *res, Label *exit) GateRef xInt64 = Int64Sub(ChangeTaggedPointerToInt64(x), Int64(JSTaggedValue::DOUBLE_ENCODE_OFFSET)); GateRef fractionBits = Int64And(xInt64, Int64(base::DOUBLE_SIGNIFICAND_MASK)); GateRef expBits = Int64And(xInt64, Int64(base::DOUBLE_EXPONENT_MASK)); - GateRef signBit = Int64And(xInt64, Int64(base::DOUBLE_SIGN_MASK)); GateRef isZero = BoolAnd( Int64Equal(expBits, Int64(0)), Int64Equal(fractionBits, Int64(0))); @@ -6796,22 +6795,8 @@ void StubBuilder::CalcHashcodeForDouble(GateRef x, Variable *res, Label *exit) BRANCH(CanDoubleRepresentInt(exp, expBits, fractionBits), &calcHash, &convertToInt); Bind(&convertToInt); { - GateRef shift = Int64Sub(Int64(base::DOUBLE_SIGNIFICAND_SIZE), exp); - GateRef intVal = Int64Add( - Int64LSL(Int64(1), exp), - Int64LSR(fractionBits, shift)); - DEFVARIABLE(intVariable, VariableType::INT64(), intVal); - Label negate(env); - Label pass(env); - BRANCH(Int64NotEqual(signBit, Int64(0)), &negate, &pass); - Bind(&negate); - { - intVariable = Int64Sub(Int64(0), intVal); - Jump(&pass); - } - Bind(&pass); - value = IntToTaggedPtr(TruncInt64ToInt32(*intVariable)); - Jump(&calcHash); + *res = ChangeFloat64ToInt32(CastInt64ToFloat64(xInt64)); + Jump(exit); } Bind(&calcHash); { @@ -6821,7 +6806,7 @@ void StubBuilder::CalcHashcodeForDouble(GateRef x, Variable *res, Label *exit) } Bind(&zero); - *res = env_->GetBuilder()->CalcHashcodeForInt(IntToTaggedPtr(Int32(0))); + *res = Int32(0); Jump(exit); } diff --git a/ecmascript/compiler/stub_builder.h b/ecmascript/compiler/stub_builder.h index 33b6277133..05389cdb9d 100644 --- a/ecmascript/compiler/stub_builder.h +++ b/ecmascript/compiler/stub_builder.h @@ -272,6 +272,7 @@ public: GateRef Int64ToTaggedInt(GateRef x); GateRef Int64ToTaggedIntPtr(GateRef x); GateRef DoubleToTaggedDoublePtr(GateRef x); + GateRef BooleanToTaggedBooleanPtr(GateRef x); GateRef TaggedPtrToTaggedDoublePtr(GateRef x); GateRef TaggedPtrToTaggedIntPtr(GateRef x); GateRef CastDoubleToInt64(GateRef x); @@ -306,6 +307,7 @@ public: GateRef Int64LessThanOrEqual(GateRef x, GateRef y); GateRef Int64GreaterThanOrEqual(GateRef x, GateRef y); GateRef Int64UnsignedLessThanOrEqual(GateRef x, GateRef y); + GateRef Int64UnsignedGreaterThanOrEqual(GateRef x, GateRef y); GateRef IntPtrGreaterThan(GateRef x, GateRef y); // cast operation GateRef ChangeInt64ToIntPtr(GateRef val); diff --git a/ecmascript/compiler/typed_native_inline_lowering.cpp b/ecmascript/compiler/typed_native_inline_lowering.cpp index 12c0755785..a423be5e55 100644 --- a/ecmascript/compiler/typed_native_inline_lowering.cpp +++ b/ecmascript/compiler/typed_native_inline_lowering.cpp @@ -198,6 +198,12 @@ GateRef TypedNativeInlineLowering::VisitGate(GateRef gate) case OpCode::DATE_GET_TIME: LowerDateGetTime(gate); break; + case OpCode::MAP_HAS: + LowerToCommonStub(gate, CommonStubCSigns::JSMapHas); + break; + case OpCode::SET_HAS: + LowerToCommonStub(gate, CommonStubCSigns::JSSetHas); + break; default: break; } diff --git a/ecmascript/global_env_constants.h b/ecmascript/global_env_constants.h index 77ba09d941..89ac2eddf0 100644 --- a/ecmascript/global_env_constants.h +++ b/ecmascript/global_env_constants.h @@ -195,6 +195,8 @@ class ObjectFactory; V(JSTaggedValue, GlobalIsFinite, GLOBAL_IS_FINITE_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, GlobalIsNan, GLOBAL_IS_NAN_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, MapGet, MAP_GET_INDEX, ecma_roots_builtins) \ + V(JSTaggedValue, MapHas, MAP_HAS_INDEX, ecma_roots_builtins) \ + V(JSTaggedValue, SetHas, SET_HAS_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, LocaleCompareFunction, LOCALE_COMPARE_FUNCTION_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, ArraySortFunction, ARRAY_SORT_FUNCTION_INDEX, ecma_roots_builtins) \ V(JSTaggedValue, JsonStringifyFunction, JSON_STRINGIFY_FUNCTION_INDEX, ecma_roots_builtins) \ diff --git a/ecmascript/linked_hash_table.cpp b/ecmascript/linked_hash_table.cpp index de668f9567..68f1e816bf 100644 --- a/ecmascript/linked_hash_table.cpp +++ b/ecmascript/linked_hash_table.cpp @@ -265,6 +265,9 @@ int LinkedHash::Hash(const JSThread *thread, JSTaggedValue key) // Int, Double, Special and HeapObject(except symbol and string) if (key.IsDouble()) { key = JSTaggedValue::TryCastDoubleToInt32(key.GetDouble()); + if (key.IsInt()) { + return key.GetInt(); + } } uint64_t keyValue = key.GetRawData(); return GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); diff --git a/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts b/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts index ba00c646d2..751e28581f 100644 --- a/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts +++ b/test/aottest/builtin_inlining/map/Has/builtinMapHas.ts @@ -36,31 +36,42 @@ function printHas(x: any) { let myMap = new Map([[0, 0], [0.0, 5], [-1, 1], [2.5, -2.5], [NaN, Infinity], [2000, -0.0], [56, "oops"], ["xyz", "12345"]]); // Check without params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has()); //: false // Check with adding element undefined myMap.set(undefined, 42); +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has()); //: true // Check with single param +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(0)); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(3)); //: false +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2.5)); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(NaN)); //: true // Check with 2 params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(0, 0)); //: true // Check with 3 params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(-21, 10.2, 15)); //: false // Check with 4 params +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2.5, -800, 0.56, 0)); //: true // Check after inserting elements myMap.set(2000, 1e-98); myMap.set(133.33, -1); +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2000)); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(133.33)); //: true // Replace standard builtin @@ -71,11 +82,16 @@ myMap.has = replace print(myMap.has(2.5)); //: 2.5 myMap.has = true_has +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas(-1); //: true // Call standard builtin with non-number param +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("abc"); //: false +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("-1"); //: false +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas(56); //: true +//aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("xyz"); //: true if (ArkTools.isAOTCompiled(printHas)) { @@ -83,46 +99,52 @@ if (ArkTools.isAOTCompiled(printHas)) { myMap.has = replace } printHas(2.5); //pgo: true +//aot: [trace] Check Type: NotCallTarget1 //aot: 2.5 printHas("abc"); //pgo: false +//aot: [trace] Check Type: NotCallTarget1 //aot: abc myMap.has = true_has // Check IR correctness inside try-block try { + //aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas(2000); //: true + //aot: [trace] aot inline builtin: Map.has, caller function name:doHas@builtinMapHas printHas("abc"); //: false } catch (e) { } let obj = {}; obj.valueOf = (() => { return 0; }) +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(obj)); //: false function Throwing() { - this.value = -1; -} -//aot: [trace] Check Type: InconsistentHClass6 -Throwing.prototype.valueOf = function() { - if (this.value > 0) { - throw new Error("already positive"); + this.value = 2.5; + this.valueOf = function() { + if (this.value > 0) { + throw new Error("already positive"); + } + return this.value; } - return this.value; } + let throwingObj = new Throwing(); try { - print(myMap.has(throwingObj)); //: false - throwingObj.value = 2.5; + //aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(throwingObj)); //: false } catch(e) { print(e); } finally { + //aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(obj)); //: false } // Check after clearing myMap.clear(); +//aot: [trace] aot inline builtin: Map.has, caller function name:func_main_0@builtinMapHas print(myMap.has(2000)); //: false diff --git a/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts b/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts index 239f5a8daf..762711ce0a 100644 --- a/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts +++ b/test/aottest/builtin_inlining/set/Has/builtinSetHas.ts @@ -36,31 +36,42 @@ function printHas(x: any) { let mySet = new Set([0, 0.0, -5, 2.5, 1e-78, NaN, "xyz", "12345"]); // Check without params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has()); //: false // Check with adding element undefined mySet.add(undefined); +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has()); //: true // Check with single param +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(0)); //: true +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(3)); //: false +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(2.5)); //: true +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(NaN)); //: true // Check with 2 params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(0, 0)); //: true // Check with 3 params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(-21, 10.2, 15)); //: false // Check with 4 params +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(2.5, -800, 0.56, 0)); //: true // Check after inserting elements mySet.add(-5); mySet.add(133.33); +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(-5)); //: true +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(133.33)); //: true // Replace standard builtin @@ -71,10 +82,14 @@ mySet.has = replace print(mySet.has(2.5)); //: 2.5 mySet.has = true_has +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas(-5); //: true // Call standard builtin with non-number param +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("abc"); //: false +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("-5"); //: false +//aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("xyz"); //: true if (ArkTools.isAOTCompiled(printHas)) { @@ -82,46 +97,51 @@ if (ArkTools.isAOTCompiled(printHas)) { mySet.has = replace } printHas(2.5); //pgo: true +//aot: [trace] Check Type: NotCallTarget1 //aot: 2.5 printHas("abc"); //pgo: false +//aot: [trace] Check Type: NotCallTarget1 //aot: abc mySet.has = true_has // Check IR correctness inside try-block try { + //aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas(NaN); //: true + //aot: [trace] aot inline builtin: Set.has, caller function name:doHas@builtinSetHas printHas("abc"); //: false } catch (e) { } let obj = {}; obj.valueOf = (() => { return 0; }) +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(obj)); //: false function Throwing() { - this.value = -1; -} -//aot: [trace] Check Type: InconsistentHClass6 -Throwing.prototype.valueOf = function() { - if (this.value > 0) { - throw new Error("already positive"); + this.value = 2.5; + this.valueOf = function() { + if (this.value > 0) { + throw new Error("already positive"); + } + return this.value; } - return this.value; } -let throwingObj = new Throwing(); +let throwingObj = new Throwing(); try { - print(mySet.has(throwingObj)); //: false - throwingObj.value = 2.5; + //aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(throwingObj)); //: false } catch(e) { print(e); } finally { + //aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(obj)); //: false } // Check after clearing mySet.clear(); +//aot: [trace] aot inline builtin: Set.has, caller function name:func_main_0@builtinSetHas print(mySet.has(0)); //: false diff --git a/test/moduletest/mapget/mapget.js b/test/moduletest/mapget/mapget.js index 60b827f814..12e21a0ea2 100644 --- a/test/moduletest/mapget/mapget.js +++ b/test/moduletest/mapget/mapget.js @@ -48,8 +48,18 @@ function check(key) { } } +function checkIntAsDouble(intKey) { + intKey /= 2; + intKey += 0.5; + intKey *= 2; + intKey -= 1; + check(intKey); +} + check(0); check(1); +check(1 << 30); +check((1 << 30) - 1); check(-1); check(1.5); check(-1.5); @@ -66,6 +76,24 @@ check(Number.POSITIVE_INFINITY); check(Number.NEGATIVE_INFINITY); check(Number.parseFloat("+0.0")); check(Number.parseFloat("-0.0")); +check(true); +check(false); +check(undefined); +check(null); +check(""); +check("ab"); +check({}); +check(12n); +checkIntAsDouble(0); +checkIntAsDouble(1); +checkIntAsDouble(-1); +checkIntAsDouble(-1234); +checkIntAsDouble(1234); +checkIntAsDouble(1 << 29); +checkIntAsDouble(-(1 << 29)); +checkIntAsDouble(1 << 30); +checkIntAsDouble(-(1 << 30)); +check(Symbol.iterator); // regression test check(Number.parseFloat("1392210229")); -- Gitee