Skip to content

Commit b9edd17

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] Avoid checks on non-tear-off static methods
Change-Id: I279481775d35a17844d912f563b8696435a787cd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106422 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
1 parent b6ae6da commit b9edd17

5 files changed

Lines changed: 33 additions & 20 deletions

File tree

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import '../options.dart';
4545
import '../tracer.dart';
4646
import '../universe/call_structure.dart';
4747
import '../universe/feature.dart';
48+
import '../universe/member_usage.dart' show MemberAccess;
4849
import '../universe/selector.dart';
4950
import '../universe/side_effects.dart' show SideEffects;
5051
import '../universe/target_checks.dart' show TargetChecks;
@@ -1197,7 +1198,7 @@ class KernelSsaGraphBuilder extends ir.Visitor {
11971198
/// that no corresponding ir.Node actually exists for it. We just use the
11981199
/// targetElement.
11991200
void _buildMethodSignature(ir.FunctionNode originalClosureNode) {
1200-
_openFunction(targetElement);
1201+
_openFunction(targetElement, checks: TargetChecks.none);
12011202
List<HInstruction> typeArguments = <HInstruction>[];
12021203

12031204
// Add function type variables.
@@ -1243,13 +1244,10 @@ class KernelSsaGraphBuilder extends ir.Visitor {
12431244
return;
12441245
}
12451246

1246-
// TODO(sra): Static methods with no tear-off can be generated with no
1247-
// checks.
1248-
// TODO(sra): Instance methods can be generated with reduced checks if
1249-
// called only from non-dynamic call-sites.
12501247
_openFunction(function,
12511248
functionNode: functionNode,
1252-
parameterStructure: function.parameterStructure);
1249+
parameterStructure: function.parameterStructure,
1250+
checks: _checksForFunction(function));
12531251

12541252
// If [functionNode] is `operator==` we explicitly add a null check at the
12551253
// beginning of the method. This is to avoid having call sites do the null
@@ -1308,7 +1306,8 @@ class KernelSsaGraphBuilder extends ir.Visitor {
13081306
void _buildGenerator(FunctionEntity function, ir.FunctionNode functionNode) {
13091307
_openFunction(function,
13101308
functionNode: functionNode,
1311-
parameterStructure: function.parameterStructure);
1309+
parameterStructure: function.parameterStructure,
1310+
checks: _checksForFunction(function));
13121311

13131312
// Prepare to tail-call the body.
13141313

@@ -1474,7 +1473,8 @@ class KernelSsaGraphBuilder extends ir.Visitor {
14741473
assert(functionNode.body == null);
14751474
_openFunction(function,
14761475
functionNode: functionNode,
1477-
parameterStructure: function.parameterStructure);
1476+
parameterStructure: function.parameterStructure,
1477+
checks: _checksForFunction(function));
14781478

14791479
if (closedWorld.nativeData.isNativeMember(targetElement)) {
14801480
registry.registerNativeMethod(targetElement);
@@ -1572,12 +1572,24 @@ class KernelSsaGraphBuilder extends ir.Visitor {
15721572
}
15731573
}
15741574

1575+
TargetChecks _checksForFunction(FunctionEntity function) {
1576+
if (!function.isInstanceMember) {
1577+
// Static methods with no tear-off can be generated with no checks.
1578+
MemberAccess access = closedWorld.getMemberAccess(function);
1579+
if (access != null && access.reads.isEmpty) {
1580+
return TargetChecks.none;
1581+
}
1582+
}
1583+
// TODO(sra): Instance methods can be generated with reduced checks if
1584+
// called only from non-dynamic call-sites.
1585+
return TargetChecks.dynamicChecks;
1586+
}
1587+
15751588
void _openFunction(MemberEntity member,
15761589
{ir.FunctionNode functionNode,
15771590
ParameterStructure parameterStructure,
15781591
TargetChecks checks}) {
1579-
// TODO(sra): Pass from all sites.
1580-
checks ??= TargetChecks.dynamicChecks;
1592+
assert(checks != null);
15811593

15821594
Map<Local, AbstractValue> parameterMap = {};
15831595
List<ir.VariableDeclaration> elidedParameters = [];

tests/compiler/dart2js/rti/emission/fixed_type_argument_implements.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ main() {
2626
}
2727

2828
@pragma('dart2js:noInline')
29-
void test(C<A> c) {}
29+
void test(Object o) => test1(o);
30+
31+
@pragma('dart2js:noInline')
32+
void test1(C<A> c) {}

tests/compiler/dart2js/rti/emission/list.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/*strong.class: global#JSArray:checkedInstance,checks=[$isIterable,$isList],instance*/
5+
/*strong.class: global#JSArray:checkedInstance,checks=[$isIterable],instance*/
66
/*omit.class: global#JSArray:checkedInstance,checks=[$isIterable],instance*/
77

88
/*class: global#Iterable:checkedInstance*/
99

10-
/*strong.class: A:checkedInstance,checkedTypeArgument,checks=[],typeArgument*/
10+
/*strong.class: A:checkedTypeArgument,checks=[],typeArgument*/
1111
/*omit.class: A:checkedTypeArgument,checks=[],typeArgument*/
1212
class A {}
1313

14-
/*strong.class: B:checkedInstance,checks=[],typeArgument*/
14+
/*strong.class: B:checks=[],typeArgument*/
1515
/*omit.class: B:checks=[],typeArgument*/
1616
class B {}
1717

tests/compiler/dart2js/rti/emission/map_literal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/*strong.class: global#Map:checkedInstance,instance*/
5+
/*strong.class: global#Map:instance*/
66

77
/*class: global#LinkedHashMap:*/
88
/*class: global#JsLinkedHashMap:checks=[],instance*/

tests/compiler/dart2js/rti/emission/static_argument.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/*strong.class: I1:checkedInstance*/
5+
/*strong.class: I1:*/
66
/*omit.class: I1:*/
77
class I1 {}
88

99
/*strong.class: I2:checkedInstance,checkedTypeArgument,checks=[],typeArgument*/
1010
/*omit.class: I2:checkedTypeArgument,checks=[],typeArgument*/
1111
class I2 {}
1212

13-
// TODO(32954): Exclude $isI1 because foo is only called directly.
14-
/*strong.class: A:checks=[$isI1,$isI2],instance*/
13+
/*strong.class: A:checks=[$isI2],instance*/
1514
/*omit.class: A:checks=[$isI2],instance*/
1615
class A implements I1, I2 {}
1716

18-
// TODO(32954): Exclude $isI1 because foo is only called directly.
19-
/*strong.class: B:checks=[$isI1,$isI2],instance*/
17+
/*strong.class: B:checks=[$isI2],instance*/
2018
/*omit.class: B:checks=[$isI2],instance*/
2119
class B implements I1, I2 {}
2220

0 commit comments

Comments
 (0)