From 6d55ba30372f913329fbd9a6d6e5c7926715ffb7 Mon Sep 17 00:00:00 2001 From: Stephen Adams Date: Thu, 17 May 2018 00:03:24 +0000 Subject: [PATCH] [dart2js] Remove checks from inlined static call sites Change-Id: Ib309684efa6c518dd57bff76491484fe7288e628 Reviewed-on: https://dart-review.googlesource.com/55522 Commit-Queue: Stephen Adams Reviewed-by: Sigmund Cherem --- pkg/compiler/lib/src/ssa/builder_kernel.dart | 29 ++++++++++++++++++-- pkg/compiler/lib/src/ssa/type_builder.dart | 8 ++++++ tests/language_2/language_2_dart2js.status | 12 -------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart index b46ea02d146..26834cf7c9c 100644 --- a/pkg/compiler/lib/src/ssa/builder_kernel.dart +++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart @@ -5300,14 +5300,37 @@ class KernelSsaGraphBuilder extends ir.Visitor void _potentiallyCheckInlinedParameterTypes(FunctionEntity function) { if (!typeBuilder.checkOrTrustTypes) return; - checkTypeVariableBounds(function); + // TODO(sra): Incorporate properties of call site to help determine which + // type parameters and value parameters need to be checked. + bool trusted = false; + if (options.strongMode) { + if (function.isStatic || + function.isTopLevel || + function.isConstructor || + function is ConstructorBodyEntity) { + // We inline static methods, top-level methods, constructors and + // constructor bodies only from direct call sites. + trusted = true; + } + } + + if (!trusted) { + checkTypeVariableBounds(function); + } KernelToLocalsMap localsMap = _globalLocalsMap.getLocalsMap(function); forEachOrderedParameter(_globalLocalsMap, _elementMap, function, (Local parameter) { HInstruction argument = localsHandler.readLocal(parameter); - typeBuilder.potentiallyCheckOrTrustTypeOfParameter( - argument, localsMap.getLocalType(_elementMap, parameter)); + DartType type = localsMap.getLocalType(_elementMap, parameter); + HInstruction checkedOrTrusted; + if (trusted) { + checkedOrTrusted = typeBuilder.trustTypeOfParameter(argument, type); + } else { + checkedOrTrusted = + typeBuilder.potentiallyCheckOrTrustTypeOfParameter(argument, type); + } + localsHandler.updateLocal(parameter, checkedOrTrusted); }); } diff --git a/pkg/compiler/lib/src/ssa/type_builder.dart b/pkg/compiler/lib/src/ssa/type_builder.dart index eb06192ac44..a60c98e7fa9 100644 --- a/pkg/compiler/lib/src/ssa/type_builder.dart +++ b/pkg/compiler/lib/src/ssa/type_builder.dart @@ -75,6 +75,14 @@ abstract class TypeBuilder { return other; } + HInstruction trustTypeOfParameter(HInstruction original, DartType type) { + if (type == null) return original; + HInstruction trusted = _trustType(original, type); + if (trusted == original) return original; + builder.add(trusted); + return trusted; + } + HInstruction potentiallyCheckOrTrustTypeOfParameter( HInstruction original, DartType type) { if (type == null) return original; diff --git a/tests/language_2/language_2_dart2js.status b/tests/language_2/language_2_dart2js.status index ae902f9e31f..4579ab60d24 100644 --- a/tests/language_2/language_2_dart2js.status +++ b/tests/language_2/language_2_dart2js.status @@ -549,10 +549,6 @@ async_star_test/none: RuntimeError bad_override_test/03: MissingCompileTimeError bit_operations_test: RuntimeError branch_canonicalization_test: RuntimeError -call_method_implicit_tear_off_implements_function_test/02: RuntimeError -call_method_implicit_tear_off_implements_function_test/04: RuntimeError -call_method_implicit_tear_off_test/02: RuntimeError -call_method_implicit_tear_off_test/04: RuntimeError canonical_const2_test: RuntimeError, OK # non JS number semantics check_member_static_test/02: MissingCompileTimeError class_cycle_test/02: MissingCompileTimeError @@ -920,10 +916,6 @@ bad_override_test/02: MissingCompileTimeError bad_override_test/03: MissingCompileTimeError bit_operations_test: RuntimeError branch_canonicalization_test: RuntimeError -call_method_implicit_tear_off_implements_function_test/02: RuntimeError -call_method_implicit_tear_off_implements_function_test/04: RuntimeError -call_method_implicit_tear_off_test/02: RuntimeError -call_method_implicit_tear_off_test/04: RuntimeError call_non_method_field_test/01: MissingCompileTimeError call_non_method_field_test/02: MissingCompileTimeError canonical_const2_test: RuntimeError, OK # non JS number semantics @@ -1471,10 +1463,6 @@ bad_override_test/02: MissingCompileTimeError bad_override_test/03: MissingCompileTimeError bit_operations_test: RuntimeError branch_canonicalization_test: RuntimeError -call_method_implicit_tear_off_implements_function_test/02: RuntimeError -call_method_implicit_tear_off_implements_function_test/04: RuntimeError -call_method_implicit_tear_off_test/02: RuntimeError -call_method_implicit_tear_off_test/04: RuntimeError call_non_method_field_test/01: MissingCompileTimeError call_non_method_field_test/02: MissingCompileTimeError call_with_no_such_method_test: RuntimeError