Register deferredLoadlibrary as backend impact

Closes #32998

Change-Id: If2a0a948f1209652925be360f7f145ebfdb3d60d
Reviewed-on: https://dart-review.googlesource.com/53008
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Johnni Winther 2018-05-01 11:05:31 +00:00 committed by commit-bot@chromium.org
parent 9371ca061c
commit d85c175a22
9 changed files with 90 additions and 114 deletions

View file

@ -151,6 +151,9 @@ class JavaScriptImpactTransformer extends ImpactTransformer {
case Feature.TYPE_VARIABLE_BOUNDS_CHECK:
registerImpact(_impacts.typeVariableBoundCheck);
break;
case Feature.LOAD_LIBRARY:
registerImpact(_impacts.loadLibrary);
break;
}
}

View file

@ -751,6 +751,7 @@ class KernelImpactBuilder extends ir.Visitor {
void visitLoadLibrary(ir.LoadLibrary node) {
impactBuilder.registerStaticUse(new StaticUse.staticInvoke(
commonElements.loadDeferredLibrary, CallStructure.ONE_ARG));
impactBuilder.registerFeature(Feature.LOAD_LIBRARY);
}
// TODO(johnniwinther): Make this throw and visit child nodes explicitly

View file

@ -46,11 +46,14 @@ enum Feature {
/// A generic instantiation (application of type parameters).
GENERIC_INSTANTIATION,
/// A field whose initialization is not a constant.
LAZY_FIELD,
/// A local variable without an initializer.
LOCAL_WITHOUT_INITIALIZER,
/// A field whose initialization is not a constant.
LAZY_FIELD,
/// Access to `loadLibrary` on a deferred import.
LOAD_LIBRARY,
/// A catch clause with a variable for the stack trace.
STACK_TRACE_IN_CATCH,

View file

@ -226,7 +226,7 @@ Future<CompiledData> computeData(
}
Expect.isNotNull(
member,
"Global member '$member' not found in the global "
"Global member '$memberName' not found in the global "
"libraries: ${globalLibraries.map((l) => l.canonicalUri).join(', ')}");
return member;
}

View file

@ -0,0 +1,80 @@
// Copyright (c) 2018, 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.
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/common_elements.dart';
import 'package:compiler/src/common/names.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/elements/entities.dart';
import 'package:compiler/src/js_model/js_strategy.dart';
import 'package:compiler/src/kernel/element_map.dart';
import 'package:compiler/src/types/types.dart';
import 'package:compiler/src/world.dart';
import 'package:expect/expect.dart';
import 'package:kernel/ast.dart' as ir;
import '../memory_compiler.dart';
const String source = '''
import 'package:expect/expect.dart' deferred as expect;
main() {
callLoadLibrary();
}
callLoadLibrary() => expect.loadLibrary();
''';
main() async {
asyncTest(() async {
print('--test Dart 1 --use-old-frontend ---------------------------------');
await runTest([Flags.useOldFrontend], trust: false, useOldFrontend: true);
print('--test Dart 1 ----------------------------------------------------');
await runTest([], trust: false);
print('--test Dart 1 --trust-type-annotations ---------------------------');
await runTest([Flags.trustTypeAnnotations]);
print('--test Dart 2 ----------------------------------------------------');
await runTest([Flags.strongMode], trust: false);
print('--test Dart 2 --omit-implicit-checks -----------------------------');
await runTest([Flags.strongMode, Flags.omitImplicitChecks]);
});
}
runTest(List<String> options,
{bool trust: true, bool useOldFrontend: false}) async {
CompilationResult result = await runCompiler(
memorySourceFiles: {'main.dart': source}, options: options);
Expect.isTrue(result.isSuccess);
Compiler compiler = result.compiler;
ClosedWorld closedWorld = compiler.backendClosedWorldForTesting;
ElementEnvironment elementEnvironment = closedWorld.elementEnvironment;
LibraryEntity helperLibrary =
elementEnvironment.lookupLibrary(Uris.dart__js_helper);
FunctionEntity loadDeferredLibrary = elementEnvironment.lookupLibraryMember(
helperLibrary, 'loadDeferredLibrary');
TypeMask typeMask;
if (useOldFrontend) {
MethodElement method = loadDeferredLibrary;
typeMask = compiler.globalInference.results
.resultOfParameter(method.parameters.first)
.type;
} else {
JsBackendStrategy backendStrategy = compiler.backendStrategy;
KernelToLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting
.getLocalsMap(loadDeferredLibrary);
MemberDefinition definition =
backendStrategy.elementMap.getMemberDefinition(loadDeferredLibrary);
ir.Procedure procedure = definition.node;
typeMask = compiler.globalInference.results
.resultOfParameter(localsMap
.getLocalVariable(procedure.function.positionalParameters.first))
.type;
}
if (trust) {
Expect.equals(closedWorld.commonMasks.stringType.nullable(), typeMask);
} else {
Expect.equals(closedWorld.commonMasks.dynamicType, typeMask);
}
}

View file

@ -9,8 +9,6 @@
import '32997a_lib.dart' deferred as b;
main() async {
// TODO(johnniwinther): Remove this when Issue #32998 has been fixed.
new Set<String>().add('foo');
await b.loadLibrary();
print(b.m(3));
}

View file

@ -9,8 +9,6 @@
import '32997b_lib.dart' deferred as b; //# 01: compile-time error
main() async {
// TODO(johnniwinther): Remove this when Issue #32998 has been fixed.
new Set<String>().add('foo');
await b.loadLibrary(); //# 01: continued
print(b.m<int>(3)); //# 01: continued
}

View file

@ -63,26 +63,10 @@ variable_type_test/03: Fail, OK
32997b_test/01: SkipByDesign # --omit-implicit-checks shouldn't be used together
[ $compiler == dart2js && $checked && $fasta ]
deferred/default_arg_is_tearoff_test: RuntimeError
deferred/deferred_class_test: RuntimeError
deferred/deferred_constant2_test: RuntimeError
deferred/deferred_constant3_test: RuntimeError
deferred/deferred_constant4_test: RuntimeError
deferred/deferred_function_test: RuntimeError
deferred/deferred_metadata_test: RuntimeError
deferred/deferred_mirrors1_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/deferred_mirrors2_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/deferred_overlapping_test: RuntimeError
deferred/interface_type_variable_test: RuntimeError
deferred/load_in_correct_order_test: RuntimeError
deferred/multiple_default_arg_test: RuntimeError
deferred/reflect_multiple_annotations_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/reflect_multiple_default_arg_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/shared_constant_test: RuntimeError
deferred/uninstantiated_type_variable_test: RuntimeError
deferred_custom_loader_test: RuntimeError
deferred_inheritance_test: RuntimeError
deferred_split_test: RuntimeError
dummy_compiler_test: Crash
local_signature_test: Crash
minus_zero_test/01: MissingCompileTimeError

View file

@ -303,7 +303,6 @@ deferred_constraints_type_annotation_test/type_annotation_top_level: MissingComp
deferred_inheritance_constraints_test/extends: MissingCompileTimeError
deferred_inheritance_constraints_test/implements: MissingCompileTimeError
deferred_inheritance_constraints_test/mixin: MissingCompileTimeError
deferred_load_constants_test/none: RuntimeError
deferred_load_library_wrong_args_test/01: MissingRuntimeError
deferred_not_loaded_check_test: RuntimeError # Test out of date. Issue 31933
deferred_redirecting_factory_test: RuntimeError
@ -605,9 +604,6 @@ 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
cha_deopt1_test: RuntimeError
cha_deopt2_test: RuntimeError
cha_deopt3_test: RuntimeError
check_member_static_test/02: MissingCompileTimeError
class_cycle_test/02: MissingCompileTimeError
class_cycle_test/03: MissingCompileTimeError
@ -649,40 +645,15 @@ cyclic_type_test/03: RuntimeError
cyclic_type_test/04: RuntimeError
cyclic_typedef_test/10: Crash # Crash when compiling file:///usr/local/google/home/sra/Dart/sdk/out/ReleaseX64/generated_tests/language_2/cyclic_typedef_test_10.dart,
cyclic_typedef_test/11: Crash # Crash when compiling file:///usr/local/google/home/sra/Dart/sdk/out/ReleaseX64/generated_tests/language_2/cyclic_typedef_test_11.dart,
deferred_closurize_load_library_test: RuntimeError
deferred_constant_list_test: RuntimeError
deferred_constraints_constants_test/default_argument2: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred_constraints_constants_test/none: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred_constraints_constants_test/reference_after_load: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred_constraints_type_annotation_test/new: RuntimeError
deferred_constraints_type_annotation_test/new_generic1: RuntimeError
deferred_constraints_type_annotation_test/none: RuntimeError
deferred_constraints_type_annotation_test/static_method: RuntimeError
deferred_constraints_type_annotation_test/type_annotation_non_deferred: RuntimeError
deferred_function_type_test: RuntimeError
deferred_global_test: RuntimeError
deferred_inheritance_constraints_test/extends: MissingCompileTimeError
deferred_inheritance_constraints_test/implements: MissingCompileTimeError
deferred_inheritance_constraints_test/mixin: MissingCompileTimeError
deferred_inlined_test: RuntimeError
deferred_load_constants_test/none: RuntimeError
deferred_load_inval_code_test: RuntimeError
deferred_load_library_wrong_args_test/01: CompileTimeError
deferred_mixin_test: RuntimeError
deferred_no_such_method_test: RuntimeError
deferred_not_loaded_check_test: RuntimeError # Test out of date. Issue 31933
deferred_only_constant_test: RuntimeError
deferred_optimized_test: RuntimeError
deferred_redirecting_factory_test: RuntimeError
deferred_regression_22995_test: RuntimeError
deferred_regression_28678_test: RuntimeError
deferred_shadow_load_library_test: RuntimeError
deferred_shared_and_unshared_classes_test: RuntimeError
deferred_static_seperate_test: RuntimeError
deferred_type_dependency_test/as: RuntimeError
deferred_type_dependency_test/is: RuntimeError
deferred_type_dependency_test/none: RuntimeError
deferred_type_dependency_test/type_annotation: RuntimeError
double_int_to_string_test: RuntimeError, OK # non JS number semantics
duplicate_export_negative_test: Fail
duplicate_implements_test/01: MissingCompileTimeError
@ -904,13 +875,11 @@ parser_quirks_test: CompileTimeError
redirecting_factory_default_values_test/01: MissingCompileTimeError
redirecting_factory_default_values_test/02: MissingCompileTimeError
redirecting_factory_reflection_test: RuntimeError
regress_22443_test: RuntimeError
regress_23089_test: Crash # Crash when compiling file:///usr/local/google/home/sra/Dart/sdk/tests/language_2/regress_23089_test.dart,
regress_23408_test: CompileTimeError
regress_24283_test: RuntimeError # non JS number semantics
regress_27617_test/1: Crash # Assertion failure: Unexpected constructor j:constructor(Foo._) in ConstructorDataImpl._getConstructorConstant
regress_28255_test: RuntimeError
regress_28278_test: RuntimeError
regress_29025_test: CompileTimeError
regress_29405_test: CompileTimeError
regress_29784_test/01: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in () for j:constructor(A.ok).
@ -1044,9 +1013,6 @@ 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
cha_deopt1_test: RuntimeError
cha_deopt2_test: RuntimeError
cha_deopt3_test: RuntimeError
check_member_static_test/01: MissingCompileTimeError
check_member_static_test/02: MissingCompileTimeError
class_cycle_test/02: MissingCompileTimeError
@ -1105,40 +1071,15 @@ cyclic_typedef_test/10: Crash # Stack Overflow
cyclic_typedef_test/11: Crash # Stack Overflow
default_factory2_test/01: MissingCompileTimeError
default_factory_test/01: MissingCompileTimeError
deferred_closurize_load_library_test: RuntimeError
deferred_constant_list_test: RuntimeError
deferred_constraints_constants_test/none: RuntimeError
deferred_constraints_constants_test/reference_after_load: RuntimeError
deferred_constraints_type_annotation_test/new: RuntimeError
deferred_constraints_type_annotation_test/new_generic1: RuntimeError
deferred_constraints_type_annotation_test/none: RuntimeError
deferred_constraints_type_annotation_test/static_method: RuntimeError
deferred_constraints_type_annotation_test/type_annotation_non_deferred: RuntimeError
deferred_function_type_test: RuntimeError
deferred_global_test: RuntimeError
deferred_inheritance_constraints_test/extends: MissingCompileTimeError
deferred_inheritance_constraints_test/implements: MissingCompileTimeError
deferred_inheritance_constraints_test/mixin: MissingCompileTimeError
deferred_inheritance_constraints_test/redirecting_constructor: MissingCompileTimeError
deferred_inlined_test: RuntimeError
deferred_load_constants_test/none: RuntimeError
deferred_load_inval_code_test: RuntimeError
deferred_load_library_wrong_args_test/01: CompileTimeError
deferred_mixin_test: RuntimeError
deferred_no_such_method_test: RuntimeError
deferred_not_loaded_check_test: RuntimeError # Test out of date. Issue 31933
deferred_only_constant_test: RuntimeError
deferred_optimized_test: RuntimeError
deferred_redirecting_factory_test: RuntimeError
deferred_regression_22995_test: RuntimeError
deferred_regression_28678_test: RuntimeError
deferred_shadow_load_library_test: RuntimeError
deferred_shared_and_unshared_classes_test: RuntimeError
deferred_static_seperate_test: RuntimeError
deferred_type_dependency_test/as: RuntimeError
deferred_type_dependency_test/is: RuntimeError
deferred_type_dependency_test/none: RuntimeError
deferred_type_dependency_test/type_annotation: RuntimeError
double_int_to_string_test: RuntimeError, OK # non JS number semantics
duplicate_export_negative_test: Fail
duplicate_implements_test/01: MissingCompileTimeError
@ -1447,13 +1388,11 @@ redirecting_factory_malbounded_test/01: MissingCompileTimeError
redirecting_factory_reflection_test: RuntimeError
regress_13462_1_test: RuntimeError
regress_18535_test: RuntimeError
regress_22443_test: RuntimeError
regress_23089_test: Crash # Stack Overflow
regress_23408_test: CompileTimeError
regress_24283_test: RuntimeError # non JS number semantics
regress_27617_test/1: Crash # Assertion failure: Unexpected constructor j:constructor(Foo._) in ConstructorDataImpl._getConstructorConstant
regress_28255_test: RuntimeError
regress_28278_test: RuntimeError
regress_29025_test: CompileTimeError
regress_29405_test: CompileTimeError
regress_29784_test/01: Crash # Assertion failure: Cannot find value Instance of 'ThisLocal' in () for j:constructor(A.ok).
@ -1662,9 +1601,6 @@ call_non_method_field_test/01: MissingCompileTimeError
call_non_method_field_test/02: MissingCompileTimeError
call_with_no_such_method_test: RuntimeError
canonical_const2_test: RuntimeError, OK # non JS number semantics
cha_deopt1_test: RuntimeError
cha_deopt2_test: RuntimeError
cha_deopt3_test: RuntimeError
check_member_static_test/01: MissingCompileTimeError
check_member_static_test/02: MissingCompileTimeError
class_cycle_test/02: MissingCompileTimeError
@ -1718,40 +1654,15 @@ cyclic_typedef_test/10: Crash # Stack Overflow
cyclic_typedef_test/11: Crash # Stack Overflow
default_factory2_test/01: MissingCompileTimeError
default_factory_test/01: MissingCompileTimeError
deferred_closurize_load_library_test: RuntimeError
deferred_constant_list_test: RuntimeError
deferred_constraints_constants_test/none: RuntimeError
deferred_constraints_constants_test/reference_after_load: RuntimeError
deferred_constraints_type_annotation_test/new: RuntimeError
deferred_constraints_type_annotation_test/new_generic1: RuntimeError
deferred_constraints_type_annotation_test/none: RuntimeError
deferred_constraints_type_annotation_test/static_method: RuntimeError
deferred_constraints_type_annotation_test/type_annotation_non_deferred: RuntimeError
deferred_function_type_test: RuntimeError
deferred_global_test: RuntimeError
deferred_inheritance_constraints_test/extends: MissingCompileTimeError
deferred_inheritance_constraints_test/implements: MissingCompileTimeError
deferred_inheritance_constraints_test/mixin: MissingCompileTimeError
deferred_inheritance_constraints_test/redirecting_constructor: MissingCompileTimeError
deferred_inlined_test: RuntimeError
deferred_load_constants_test/none: RuntimeError
deferred_load_inval_code_test: RuntimeError
deferred_load_library_wrong_args_test/01: CompileTimeError
deferred_mixin_test: RuntimeError
deferred_no_such_method_test: RuntimeError
deferred_not_loaded_check_test: RuntimeError # Test out of date. Issue 31933
deferred_only_constant_test: RuntimeError
deferred_optimized_test: RuntimeError
deferred_redirecting_factory_test: RuntimeError
deferred_regression_22995_test: RuntimeError
deferred_regression_28678_test: RuntimeError
deferred_shadow_load_library_test: RuntimeError
deferred_shared_and_unshared_classes_test: RuntimeError
deferred_static_seperate_test: RuntimeError
deferred_type_dependency_test/as: RuntimeError
deferred_type_dependency_test/is: RuntimeError
deferred_type_dependency_test/none: RuntimeError
deferred_type_dependency_test/type_annotation: RuntimeError
double_int_to_string_test: RuntimeError, OK # non JS number semantics
duplicate_export_negative_test: Fail
duplicate_implements_test/01: MissingCompileTimeError
@ -2059,13 +1970,11 @@ redirecting_factory_reflection_test: RuntimeError
regress_13462_1_test: RuntimeError
regress_18535_test: RuntimeError
regress_21795_test: RuntimeError # Issue 12605
regress_22443_test: RuntimeError
regress_23089_test: Crash # Stack Overflow
regress_23408_test: CompileTimeError
regress_24283_test: RuntimeError, OK # Requires 64 bit numbers.
regress_27617_test/1: Crash # Assertion failure: Unexpected constructor j:constructor(Foo._) in ConstructorDataImpl._getConstructorConstant
regress_28255_test: RuntimeError
regress_28278_test: RuntimeError
regress_29025_test: CompileTimeError
regress_29405_test: CompileTimeError
regress_29784_test/01: Crash # Issue 29784