[vm] Add receiver argument to `WriteError` runtime entry
Note this changes the error in AOT to tell what is the typed data that
is not writable.
This CL eases the follow up CL which starts reusing the
`CheckWritableInstr` and accompanying slow path and runtime entry for
other messages.
TEST=tests/lib/typed_data/polymorphic_unmodifiable_typed_data_test.dart
Bug: https://github.com/dart-lang/sdk/issues/55067
Change-Id: Icf26d119501059e2ea4e885897539ebcb1063da0
Cq-Include-Trybots: dart-internal/g3.dart-internal.try:g3-cbuild-try
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-simriscv64-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-linux-release-simarm-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359063
Reviewed-by: Ilya Yanok <yanok@google.com>
diff --git a/runtime/vm/compiler/backend/flow_graph_compiler.cc b/runtime/vm/compiler/backend/flow_graph_compiler.cc
index f10e53f..ef10523 100644
--- a/runtime/vm/compiler/backend/flow_graph_compiler.cc
+++ b/runtime/vm/compiler/backend/flow_graph_compiler.cc
@@ -3192,6 +3192,12 @@
#endif
}
+void WriteErrorSlowPath::PushArgumentsForRuntimeCall(
+ FlowGraphCompiler* compiler) {
+ LocationSummary* locs = instruction()->locs();
+ __ PushRegister(locs->in(CheckWritableInstr::kReceiver).reg());
+}
+
void WriteErrorSlowPath::EmitSharedStubCall(FlowGraphCompiler* compiler,
bool save_fpu_registers) {
#if defined(TARGET_ARCH_IA32)
diff --git a/runtime/vm/compiler/backend/flow_graph_compiler.h b/runtime/vm/compiler/backend/flow_graph_compiler.h
index 1648a3e..1a7ba91 100644
--- a/runtime/vm/compiler/backend/flow_graph_compiler.h
+++ b/runtime/vm/compiler/backend/flow_graph_compiler.h
@@ -301,6 +301,12 @@
virtual void EmitSharedStubCall(FlowGraphCompiler* compiler,
bool save_fpu_registers);
+
+ virtual void PushArgumentsForRuntimeCall(FlowGraphCompiler* compiler);
+
+ virtual intptr_t GetNumberOfArgumentsForRuntimeCall() {
+ return 1; // receiver
+ }
};
class LateInitializationErrorSlowPath : public ThrowErrorSlowPathCode {
diff --git a/runtime/vm/compiler/backend/il.h b/runtime/vm/compiler/backend/il.h
index 3c1b683..8214ee8 100644
--- a/runtime/vm/compiler/backend/il.h
+++ b/runtime/vm/compiler/backend/il.h
@@ -10877,14 +10877,14 @@
intptr_t deopt_id,
const InstructionSource& source)
: TemplateDefinition(source, deopt_id) {
- SetInputAt(0, array);
+ SetInputAt(kReceiver, array);
}
virtual bool AttributesEqual(const Instruction& other) const { return true; }
DECLARE_INSTRUCTION(CheckWritable)
- Value* value() const { return inputs_[0]; }
+ Value* value() const { return inputs_[kReceiver]; }
virtual Definition* Canonicalize(FlowGraph* flow_graph);
@@ -10892,6 +10892,11 @@
virtual bool ComputeCanDeoptimize() const { return false; }
+ // Give a name to the location/input indices.
+ enum {
+ kReceiver = 0,
+ };
+
DECLARE_EMPTY_SERIALIZATION(CheckWritableInstr, TemplateDefinition)
private:
diff --git a/runtime/vm/compiler/backend/il_arm.cc b/runtime/vm/compiler/backend/il_arm.cc
index e6f91f2..87abc1f 100644
--- a/runtime/vm/compiler/backend/il_arm.cc
+++ b/runtime/vm/compiler/backend/il_arm.cc
@@ -6410,7 +6410,7 @@
zone, kNumInputs, kNumTemps,
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
: LocationSummary::kCallOnSlowPath);
- locs->set_in(0, Location::RequiresRegister());
+ locs->set_in(kReceiver, Location::RequiresRegister());
return locs;
}
diff --git a/runtime/vm/compiler/backend/il_arm64.cc b/runtime/vm/compiler/backend/il_arm64.cc
index a0d837a..fb5d21a 100644
--- a/runtime/vm/compiler/backend/il_arm64.cc
+++ b/runtime/vm/compiler/backend/il_arm64.cc
@@ -5348,7 +5348,7 @@
zone, kNumInputs, kNumTemps,
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
: LocationSummary::kCallOnSlowPath);
- locs->set_in(0, Location::RequiresRegister());
+ locs->set_in(kReceiver, Location::RequiresRegister());
return locs;
}
diff --git a/runtime/vm/compiler/backend/il_ia32.cc b/runtime/vm/compiler/backend/il_ia32.cc
index becc638..14e4947 100644
--- a/runtime/vm/compiler/backend/il_ia32.cc
+++ b/runtime/vm/compiler/backend/il_ia32.cc
@@ -5541,7 +5541,7 @@
zone, kNumInputs, kNumTemps,
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
: LocationSummary::kCallOnSlowPath);
- locs->set_in(0, Location::RequiresRegister());
+ locs->set_in(kReceiver, Location::RequiresRegister());
return locs;
}
diff --git a/runtime/vm/compiler/backend/il_riscv.cc b/runtime/vm/compiler/backend/il_riscv.cc
index a62ba62..ea25ede 100644
--- a/runtime/vm/compiler/backend/il_riscv.cc
+++ b/runtime/vm/compiler/backend/il_riscv.cc
@@ -5518,7 +5518,7 @@
zone, kNumInputs, kNumTemps,
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
: LocationSummary::kCallOnSlowPath);
- locs->set_in(0, Location::RequiresRegister());
+ locs->set_in(kReceiver, Location::RequiresRegister());
return locs;
}
diff --git a/runtime/vm/compiler/backend/il_x64.cc b/runtime/vm/compiler/backend/il_x64.cc
index c6cc09a..e303595 100644
--- a/runtime/vm/compiler/backend/il_x64.cc
+++ b/runtime/vm/compiler/backend/il_x64.cc
@@ -5665,7 +5665,7 @@
zone, kNumInputs, kNumTemps,
UseSharedSlowPathStub(opt) ? LocationSummary::kCallOnSharedSlowPath
: LocationSummary::kCallOnSlowPath);
- locs->set_in(0, Location::RequiresRegister());
+ locs->set_in(kReceiver, Location::RequiresRegister());
return locs;
}
diff --git a/runtime/vm/compiler/stub_code_compiler_arm.cc b/runtime/vm/compiler/stub_code_compiler_arm.cc
index 6e11b4a..19f89c9 100644
--- a/runtime/vm/compiler/stub_code_compiler_arm.cc
+++ b/runtime/vm/compiler/stub_code_compiler_arm.cc
@@ -503,7 +503,7 @@
void StubCodeCompiler::GenerateWriteError(bool with_fpu_regs) {
auto perform_runtime_call = [&]() {
- __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
+ __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/1);
__ Breakpoint();
};
diff --git a/runtime/vm/compiler/stub_code_compiler_arm64.cc b/runtime/vm/compiler/stub_code_compiler_arm64.cc
index 7ce5e1a..dd58880 100644
--- a/runtime/vm/compiler/stub_code_compiler_arm64.cc
+++ b/runtime/vm/compiler/stub_code_compiler_arm64.cc
@@ -724,7 +724,7 @@
void StubCodeCompiler::GenerateWriteError(bool with_fpu_regs) {
auto perform_runtime_call = [&]() {
- __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
+ __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/1);
__ Breakpoint();
};
diff --git a/runtime/vm/compiler/stub_code_compiler_riscv.cc b/runtime/vm/compiler/stub_code_compiler_riscv.cc
index 56ee020..720d203 100644
--- a/runtime/vm/compiler/stub_code_compiler_riscv.cc
+++ b/runtime/vm/compiler/stub_code_compiler_riscv.cc
@@ -591,7 +591,7 @@
void StubCodeCompiler::GenerateWriteError(bool with_fpu_regs) {
auto perform_runtime_call = [&]() {
- __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
+ __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/1);
__ Breakpoint();
};
diff --git a/runtime/vm/compiler/stub_code_compiler_x64.cc b/runtime/vm/compiler/stub_code_compiler_x64.cc
index f14c94f..517e6595 100644
--- a/runtime/vm/compiler/stub_code_compiler_x64.cc
+++ b/runtime/vm/compiler/stub_code_compiler_x64.cc
@@ -684,7 +684,7 @@
void StubCodeCompiler::GenerateWriteError(bool with_fpu_regs) {
auto perform_runtime_call = [&]() {
- __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/0);
+ __ CallRuntime(kWriteErrorRuntimeEntry, /*argument_count=*/1);
__ Breakpoint();
};
diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc
index c6bc675..9fef6d9 100644
--- a/runtime/vm/runtime_entry.cc
+++ b/runtime/vm/runtime_entry.cc
@@ -163,8 +163,13 @@
Exceptions::ThrowByType(Exceptions::kRange, args);
}
-DEFINE_RUNTIME_ENTRY(WriteError, 0) {
- Exceptions::ThrowUnsupportedError("Cannot modify an unmodifiable list");
+DEFINE_RUNTIME_ENTRY(WriteError, 1) {
+ const Instance& receiver = Instance::CheckedHandle(zone, arguments.ArgAt(0));
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(
+ 0, String::Handle(String::NewFormatted(
+ "Cannot modify an unmodifiable list: %s", receiver.ToCString())));
+ Exceptions::ThrowByType(Exceptions::kUnsupported, args);
}
static void NullErrorHelper(Zone* zone,