Skip to content

Commit 3d77741

Browse files
sstricklcommit-bot@chromium.org
authored andcommitted
[vm/compiler] Unify name checking in dynamic closure call dispatchers.
Instead of possibly looping over the closure function parameter names array multiple times, just do it once. Check each entry against the provided argument names. If none match, check the required bit (if in null-safe mode). Also keep a count of matched names to check that all provided names matched after the iteration. Now that optional name checking is part of the fragment built by BuildClosureCallArgumentsValidCheck, that method builds checks for exactly the same things as its namesake in Function. Also refactor the variables used by the checker into read/write ones that need to be allocated in the parsed function and read-only ones that can just be temporaries since no Phi nodes are needed. Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try Bug: #40813 Change-Id: I3cb421dd538629d7f5499f3bbf0653d34b850dce Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160725 Commit-Queue: Tess Strickland <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Daco Harkes <[email protected]>
1 parent b0acaea commit 3d77741

File tree

10 files changed

+386
-367
lines changed

10 files changed

+386
-367
lines changed

runtime/vm/compiler/frontend/base_flow_graph_builder.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,15 @@ Fragment BaseFlowGraphBuilder::StoreLocalRaw(TokenPosition position,
682682
return instructions;
683683
}
684684

685-
LocalVariable* BaseFlowGraphBuilder::MakeTemporary() {
686-
char name[64];
685+
LocalVariable* BaseFlowGraphBuilder::MakeTemporary(const char* suffix) {
686+
static constexpr intptr_t kTemporaryNameLength = 64;
687+
char name[kTemporaryNameLength];
687688
intptr_t index = stack_->definition()->temp_index();
688-
Utils::SNPrint(name, 64, ":t%" Pd, index);
689+
if (suffix != nullptr) {
690+
Utils::SNPrint(name, kTemporaryNameLength, ":t_%s", suffix);
691+
} else {
692+
Utils::SNPrint(name, kTemporaryNameLength, ":t%" Pd, index);
693+
}
689694
const String& symbol_name =
690695
String::ZoneHandle(Z, Symbols::New(thread_, name));
691696
LocalVariable* variable =
@@ -707,6 +712,16 @@ LocalVariable* BaseFlowGraphBuilder::MakeTemporary() {
707712
return variable;
708713
}
709714

715+
Fragment BaseFlowGraphBuilder::DropTemporary(LocalVariable** temp) {
716+
ASSERT(temp != nullptr && *temp != nullptr && (*temp)->HasIndex());
717+
// Check that the temporary matches the current stack definition.
718+
ASSERT_EQUAL(
719+
stack_->definition()->temp_index(),
720+
-(*temp)->index().value() - parsed_function_->num_stack_locals());
721+
*temp = nullptr; // Clear to avoid inadvertent usage after dropping.
722+
return Drop();
723+
}
724+
710725
void BaseFlowGraphBuilder::SetTempIndex(Definition* definition) {
711726
definition->set_temp_index(
712727
stack_ == NULL ? 0 : stack_->definition()->temp_index() + 1);

runtime/vm/compiler/frontend/base_flow_graph_builder.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ class BaseFlowGraphBuilder {
183183
void SetTempIndex(Definition* definition);
184184

185185
Fragment LoadLocal(LocalVariable* variable);
186+
Fragment StoreLocal(LocalVariable* variable) {
187+
return StoreLocal(TokenPosition::kNoSource, variable);
188+
}
186189
Fragment StoreLocal(TokenPosition position, LocalVariable* variable);
187190
Fragment StoreLocalRaw(TokenPosition position, LocalVariable* variable);
188191
Fragment LoadContextAt(int depth);
@@ -242,8 +245,8 @@ class BaseFlowGraphBuilder {
242245
// goto B3
243246
// B3:
244247
// LoadLocal(t)
245-
//
246-
LocalVariable* MakeTemporary();
248+
LocalVariable* MakeTemporary(const char* suffix = nullptr);
249+
Fragment DropTemporary(LocalVariable** temp);
247250

248251
InputsArray* GetArguments(int count);
249252

0 commit comments

Comments
 (0)