Files
sdk/pkg/front_end/testcases/closure_context_lowering/foo45.dart
T
Chloe Stefantsova a3eb228d44 [cfe] Add strategy of context allocation based on loop depth
Part of https://github.com/dart-lang/sdk/issues/61572

Change-Id: If94282dd9e38bfc1807a46831b09ca3ef9d72a52
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475820
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-02-02 00:54:29 -08:00

45 lines
988 B
Dart

// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@pragma('vm:never-inline')
@pragma('wasm:never-inline')
@pragma('dart2js:noInline')
int opaqueVal() => int.parse('42');
@pragma('vm:never-inline')
@pragma('wasm:never-inline')
@pragma('dart2js:noInline')
void callClosure(void Function() func) {
if (opaqueVal() == 1) func();
}
// All of the local variables in [foo45] are expected to be captured: a, b, and
// c. When the loop-depth allocation strategy is enabled, all of the variables
// are expected to be put in the same context.
void foo45() {
int a = 10;
callClosure(() {
a += 11;
});
if (opaqueVal() == 1) {
int b = 20;
callClosure(() {
a += 12;
b += 22;
});
}
if (opaqueVal() == 1) {
int c = 30;
callClosure(() {
a += 13;
c += 33;
});
}
}