Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8deb5aa

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
Reinstate reduction for closure call to known static method
This was accidentally removed during the migration to kernel. Change-Id: Ib4998074269b1bf5b1dd3feedebcb50dc1164c5d Reviewed-on: https://dart-review.googlesource.com/c/88229 Commit-Queue: Stephen Adams <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent ec86471 commit 8deb5aa

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

pkg/compiler/lib/src/ssa/builder_kernel.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,10 @@ class KernelSsaGraphBuilder extends ir.Visitor
42584258
} else if (selector.isSetter) {
42594259
push(new HInvokeDynamicSetter(selector, mask, null, inputs, isIntercepted,
42604260
type, sourceInformation));
4261+
} else if (selector.isClosureCall) {
4262+
assert(!isIntercepted);
4263+
push(new HInvokeClosure(selector, inputs, type, typeArguments)
4264+
..sourceInformation = sourceInformation);
42614265
} else {
42624266
push(new HInvokeDynamicMethod(
42634267
selector, mask, inputs, type, typeArguments, sourceInformation,

pkg/compiler/lib/src/ssa/optimize.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,8 @@ class SsaInstructionSimplifier extends HBaseVisitor
12831283
// TODO(sra): Handle adding optional arguments default values.
12841284
assert(!node.isInterceptedCall);
12851285
return new HInvokeStatic(target, node.inputs.skip(1).toList(),
1286-
node.instructionType, node.typeArguments);
1286+
node.instructionType, node.typeArguments)
1287+
..sourceInformation = node.sourceInformation;
12871288
}
12881289
}
12891290
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'package:async_helper/async_helper.dart';
7+
import '../helpers/compiler_helper.dart';
8+
9+
const String TEST1 = r"""
10+
aNonInstanceMethod(x) { print(x); }
11+
const f = aNonInstanceMethod;
12+
foo() {
13+
f(1);
14+
// Closure call is reduced to a direct static call.
15+
// present: '.aNonInstanceMethod(1)'
16+
// absent: '.call$1(1)'
17+
}
18+
""";
19+
20+
const String TEST2 = r"""
21+
aNonInstanceMethod([x]) { print(x); }
22+
final f = aNonInstanceMethod;
23+
foo() {
24+
f(1);
25+
// Closure call is reduced to a direct static call.
26+
// present: '.aNonInstanceMethod(1)'
27+
// absent: '.call$1(1)'
28+
}
29+
""";
30+
31+
const String TEST3 = r"""
32+
aNonInstanceMethod([x]) { print(x); }
33+
const f = aNonInstanceMethod;
34+
foo() {
35+
f();
36+
// Closure call is not reduced to a direct static call due to not wanting to
37+
// add default arguments. This may change.
38+
// absent: '.aNonInstanceMethod('
39+
// present: '.call$0()'
40+
}
41+
""";
42+
43+
// TODO(29147): Add tests like above where 'f' is local. The above tests fail if
44+
// 'f' is local due to static function references sometimes being represented by
45+
// HConstant (as above) and other times being referenced as HStatic.
46+
47+
main() {
48+
runTests() async {
49+
Future check(String test) {
50+
return compile(test, entry: 'foo', check: checkerForAbsentPresent(test));
51+
}
52+
53+
await check(TEST1);
54+
await check(TEST2);
55+
await check(TEST3);
56+
}
57+
58+
asyncTest(() async {
59+
print('--test from kernel------------------------------------------------');
60+
await runTests();
61+
});
62+
}

0 commit comments

Comments
 (0)