From 66b54232ee3412fb82e2f94f12fb0cd8eed1b2cc Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Tue, 12 May 2026 06:03:38 -0700 Subject: [PATCH] [vm] Make vm/cc/Inliner_InlineForceOptimized test less fragile This test verifies how deoptIds and environments are set when inlining force-optimized functions. The problem is that it looks at the chain of inlined calls: foo() { call1 -> Pointer.fromAddress } Pointer.fromAddress() { call2 -> _fromAddress } // force-optimized _fromAddress() { ... } During inlining of force-optimized callee, its instructions should receive deoptId/env from inlined call site. In this case, the call site is 'call2'. However, the test has been matching deoptId/env with 'call1'. It was a mere coincidence that deoptIds of call1 and call2 were the same. Any attempt to make a change which would affect deoptIds within Pointer.fromAddress breaks this test. In order to fix this, a simpler setup is now used: foo() { call1 -> newHash() } // force-optimized newHash() { ... } Also, the check for deoptId of outermost environment is dropped as in this case there are no multiple environments. In addition, also remove the duplicate pragma from _fromAddress. TEST=vm/cc/Inliner_InlineForceOptimized Change-Id: I1f592a74dfb8b7c2f67f3b0a51e7f7b74bf358eb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502801 Reviewed-by: Slava Egorov Commit-Queue: Alexander Markov --- runtime/vm/compiler/backend/inliner_test.cc | 19 ++++++++++--------- runtime/vm/compiler/recognized_methods_list.h | 2 +- sdk/lib/_internal/vm/lib/ffi_patch.dart | 1 - 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/runtime/vm/compiler/backend/inliner_test.cc b/runtime/vm/compiler/backend/inliner_test.cc index c6299d69238..97e4c9c8ac3 100644 --- a/runtime/vm/compiler/backend/inliner_test.cc +++ b/runtime/vm/compiler/backend/inliner_test.cc @@ -375,17 +375,20 @@ ISOLATE_UNIT_TEST_CASE(Inliner_List_of_inlined) { // by deopt_id and environment from the call itself. ISOLATE_UNIT_TEST_CASE(Inliner_InlineForceOptimized) { const char* kScript = R"( - import 'dart:ffi'; + @pragma('vm:force-optimize') + @pragma('vm:idempotent') + @pragma('vm:prefer-inline') + int newHash() => identityHashCode(Object()); @pragma('vm:never-inline') - int foo(int x) { - dynamic ptr = Pointer.fromAddress(x); - return x + ptr.hashCode; + int foo() { + int x = newHash(); + return x + 1; } main() { int r = 0; for (int i = 0; i < 1000; i++) { - r += foo(r); + r += foo(); } return r; } @@ -414,8 +417,8 @@ ISOLATE_UNIT_TEST_CASE(Inliner_InlineForceOptimized) { {kMoveGlob}, {kMatchAndMoveStaticCall, &call_instr}, })); - EXPECT(strcmp(call_instr->function().UserVisibleNameCString(), - "Pointer.fromAddress") == 0); + EXPECT(strcmp(call_instr->function().UserVisibleNameCString(), "newHash") == + 0); } pipeline.RunAdditionalPasses({ @@ -438,8 +441,6 @@ ISOLATE_UNIT_TEST_CASE(Inliner_InlineForceOptimized) { auto allocate_object_instr_env = allocate_object_instr->env(); EXPECT(allocate_object_instr_env->LazyDeoptToBeforeDeoptId()); - EXPECT(allocate_object_instr_env->Outermost()->GetDeoptId() == - call_instr->deopt_id()); const auto call_instr_env = call_instr->env(); const intptr_t call_first_index = call_instr_env->Length() - call_instr->InputCount(); diff --git a/runtime/vm/compiler/recognized_methods_list.h b/runtime/vm/compiler/recognized_methods_list.h index 7e0e86116f3..bbcf6452795 100644 --- a/runtime/vm/compiler/recognized_methods_list.h +++ b/runtime/vm/compiler/recognized_methods_list.h @@ -164,7 +164,7 @@ namespace dart { V(FfiLibrary, ::, _storeDoubleUnaligned, FfiStoreDoubleUnaligned, \ 0x49ce5c4f) \ V(FfiLibrary, ::, _storePointer, FfiStorePointer, 0xa08098b2) \ - V(FfiLibrary, ::, _fromAddress, FfiFromAddress, 0x941575ee) \ + V(FfiLibrary, ::, _fromAddress, FfiFromAddress, 0x9415722d) \ V(FfiLibrary, Pointer, get:address, FfiGetAddress, 0x7cc16ffe) \ V(FfiLibrary, Native, _addressOf, FfiNativeAddressOf, 0x7f8597d3) \ V(FfiLibrary, ::, _asExternalTypedDataInt8, FfiAsExternalTypedDataInt8, \ diff --git a/sdk/lib/_internal/vm/lib/ffi_patch.dart b/sdk/lib/_internal/vm/lib/ffi_patch.dart index a46067ec83f..d6da8e45fd2 100644 --- a/sdk/lib/_internal/vm/lib/ffi_patch.dart +++ b/sdk/lib/_internal/vm/lib/ffi_patch.dart @@ -81,7 +81,6 @@ int sizeOf() { throw UnimplementedError("$T"); } -@pragma("vm:idempotent") @pragma("vm:recognized", "other") @pragma("vm:idempotent") external Pointer _fromAddress(int ptr);