Get the basics of deferred libraries working.

References to loadLibrary on a library prefix are compiled to a
helper function that returns a Future that always completes
successfully.

The deferred libraries aren't actually deferred, but code that uses
loadLibrary() now doesn't barf.

BUG=#27343
R=vsm@google.com

Review URL: https://codereview.chromium.org/2477673006 .
This commit is contained in:
Bob Nystrom 2016-11-07 10:41:23 -08:00
parent f61a3eacc4
commit 8daf4cfb73
10 changed files with 70 additions and 97 deletions

View file

@ -15,6 +15,13 @@
* `dart:developer`:
* The service protocol http server can now be controlled from Dart code.
### Tool changes
* Dart Dev Compiler
* Support calls to `loadLibrary()` on deferred libraries. Deferred libraries
are still loaded eagerly. (#27343)
## 1.20.1 - 2016-10-13
Patch release, resolves one issue:

View file

@ -1938,6 +1938,9 @@ define([], function() {
}
return name;
};
dart.loadLibrary = function() {
return async.Future.value();
};
dart.defineProperty = function(obj, name, desc) {
return Object.defineProperty(obj, name, desc);
};

View file

@ -1938,6 +1938,9 @@
}
return name;
};
dart.loadLibrary = function() {
return async.Future.value();
};
dart.defineProperty = function(obj, name, desc) {
return Object.defineProperty(obj, name, desc);
};

View file

@ -1936,6 +1936,9 @@ dart._canonicalMember = function(obj, name) {
}
return name;
};
dart.loadLibrary = function() {
return async.Future.value();
};
dart.defineProperty = function(obj, name, desc) {
return Object.defineProperty(obj, name, desc);
};

View file

@ -1939,6 +1939,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
}
return name;
};
dart.loadLibrary = function() {
return async.Future.value();
};
dart.defineProperty = function(obj, name, desc) {
return Object.defineProperty(obj, name, desc);
};

Binary file not shown.

View file

@ -3274,6 +3274,11 @@ class CodeGenerator extends GeneralizingAstVisitor
@override
visitMethodInvocation(MethodInvocation node) {
if (_isDeferredLoadLibrary(node.target, node.methodName)) {
// We are calling loadLibrary() on a deferred library prefix.
return _callHelper('loadLibrary()');
}
if (node.operator?.lexeme == '?.') {
return _emitNullSafe(node);
}
@ -4541,6 +4546,11 @@ class CodeGenerator extends GeneralizingAstVisitor
@override
visitPrefixedIdentifier(PrefixedIdentifier node) {
if (_isDeferredLoadLibrary(node.prefix, node.identifier)) {
// We are tearing off "loadLibrary" on a library prefix.
return _callHelper('loadLibrary');
}
if (isLibraryPrefix(node.prefix)) {
return _visit(node.identifier);
} else {
@ -5578,3 +5588,23 @@ LibraryElement _getLibrary(AnalysisContext c, String uri) =>
bool _isDartRuntime(LibraryElement l) =>
l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
/// Returns `true` if [target] is a prefix for a deferred library and [name]
/// is "loadLibrary".
///
/// If so, the expression should be compiled to call the runtime's
/// "loadLibrary" helper function.
bool _isDeferredLoadLibrary(Expression target, SimpleIdentifier name) {
if (name.name != "loadLibrary") return false;
if (target is! SimpleIdentifier) return false;
var targetIdentifier = target as SimpleIdentifier;
if (targetIdentifier.staticElement is! PrefixElement) return false;
var prefix = targetIdentifier.staticElement as PrefixElement;
// The library the prefix is referring to must come from a deferred import.
var containingLibrary = (target.root as CompilationUnit).element.library;
var imports = containingLibrary.getImportsWithPrefix(prefix);
return imports.length == 1 && imports[0].isDeferred;
}

View file

@ -124,22 +124,15 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require'],
'cyclic_type_test_03_multi': skip_fail,
'cyclic_type_test_04_multi': skip_fail,
'cyclic_type_variable_test_none_multi': skip_fail,
// Deferred libraries are not actually deferred. These tests all test
// that synchronous access to the library fails.
'deferred_call_empty_before_load_test': skip_fail,
'deferred_closurize_load_library_test': skip_fail,
'deferred_constant_list_test': skip_fail,
'deferred_function_type_test': skip_fail,
'deferred_inlined_test': skip_fail,
'deferred_load_inval_code_test': skip_fail,
'deferred_mixin_test': skip_fail,
'deferred_no_such_method_test': skip_fail, // deferred libs not implemented
'deferred_not_loaded_check_test': skip_fail,
'deferred_only_constant_test': skip_fail,
'deferred_optimized_test': skip_fail,
'deferred_redirecting_factory_test': skip_fail,
'deferred_regression_22995_test': skip_fail,
'deferred_shadow_load_library_test': skip_fail,
'deferred_shared_and_unshared_classes_test': skip_fail,
'deferred_static_seperate_test': skip_fail,
'deferred_regression_22995_test': skip_fail, // Strong mode "is" rejects some type tests.
'double_int_to_string_test': skip_fail,
'double_to_string_test': skip_fail,
'dynamic_test': skip_fail,

View file

@ -847,3 +847,9 @@ _canonicalMember(obj, name) {
}
return name;
}
/// Emulates the implicit "loadLibrary" function provided by a deferred library.
///
/// Libraries are not actually deferred in DDC, so this just returns a future
/// that completes immediately.
Future loadLibrary() => new Future.value();

View file

@ -5,86 +5,14 @@
[error] Invalid override. The type of 'ChunkedConverter.startChunkedConversion' ('(dynamic) → dynamic') isn't a subtype of 'Converter<S, T>.startChunkedConversion' ('(Sink<T>) → Sink<S>'). (dart:convert/chunked_conversion.dart, line 15, col 3)
[error] Invalid override. The type of '_EventStreamSubscription.asFuture' ('([dynamic]) → Future<dynamic>') isn't a subtype of 'StreamSubscription<T>.asFuture' ('<E>([E]) → Future<E>'). (dart:html, line 40152, col 3)
[error] Invalid override. The type of 'JsArray.[]=' ('(Object, E) → void') isn't a subtype of 'JsObject.[]=' ('(Object, dynamic) → dynamic'). (dart:js, line 363, col 3)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:_debugger, line 39, col 45)
[warning] Unsound implicit cast from 'dynamic' to 'List<NameValuePair>'. (dart:_debugger, line 750, col 43)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:_isolate_helper, line 839, col 37)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:_isolate_helper, line 886, col 11)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 117, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 159, col 17)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 167, col 17)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 198, col 27)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 239, col 27)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 252, col 27)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 264, col 27)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 277, col 27)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 295, col 16)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 300, col 17)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 443, col 27)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 455, col 27)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_interceptors/js_array.dart, line 564, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'JSArray<String>'. (dart:_js_helper, line 79, col 37)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:_js_helper, line 882, col 16)
[warning] Unsound implicit cast from 'dynamic' to '() → List<Type>'. (dart:_js_mirrors, line 425, col 40)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:_interceptors/js_string.dart, line 92, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:_interceptors/js_string.dart, line 95, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:_js_helper/linked_hash_map.dart, line 119, col 40)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:_js_helper/linked_hash_map.dart, line 148, col 44)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:_js_helper/linked_hash_map.dart, line 183, col 9)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:_js_helper/linked_hash_map.dart, line 299, col 42)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:_js_helper/linked_hash_map.dart, line 308, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'List<LinkedHashMapCell<K, V>>'. (dart:_js_helper/linked_hash_map.dart, line 312, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:_js_helper/linked_hash_map.dart, line 346, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'List<LinkedHashMapCell<K, V>>'. (dart:_js_helper/linked_hash_map.dart, line 351, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:_js_helper/regexp_helper.dart, line 108, col 22)
[warning] Unsound implicit cast from 'List<dynamic>' to 'List<String>'. (dart:_js_helper/regexp_helper.dart, line 140, col 43)
[warning] Unsound implicit cast from 'List<dynamic>' to 'List<String>'. (dart:_js_helper/regexp_helper.dart, line 152, col 43)
[warning] Unsound implicit cast from 'dynamic' to 'V'. (dart:collection, line 105, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'V'. (dart:collection, line 108, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'V'. (dart:collection, line 119, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'V'. (dart:collection, line 186, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'K'. (dart:collection, line 200, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'V'. (dart:collection, line 268, col 17)
[warning] Unsound implicit cast from 'dynamic' to 'K'. (dart:collection, line 404, col 49)
[warning] Unsound implicit cast from 'dynamic' to 'K'. (dart:collection, line 411, col 19)
[warning] Unsound implicit cast from 'Object' to 'K'. (dart:collection, line 411, col 49)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 436, col 9)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 462, col 18)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:collection, line 495, col 42)
[warning] Unsound implicit cast from 'dynamic' to 'V'. (dart:collection, line 532, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'K'. (dart:collection, line 569, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'V'. (dart:collection, line 569, col 19)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 614, col 9)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 653, col 18)
[warning] Unsound implicit cast from 'dynamic' to 'K'. (dart:collection, line 689, col 49)
[warning] Unsound implicit cast from 'dynamic' to 'LinkedHashMapCell<K, V>'. (dart:collection, line 696, col 42)
[warning] Unsound implicit cast from 'dynamic' to 'K'. (dart:collection, line 697, col 40)
[warning] Unsound implicit cast from 'Object' to 'E'. (dart:collection, line 758, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'List<E>'. (dart:collection, line 951, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 1009, col 21)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 1009, col 51)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 1019, col 47)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 1058, col 18)
[warning] Unsound implicit cast from 'Object' to 'E'. (dart:collection, line 1135, col 14)
[warning] Unsound implicit cast from 'dynamic' to '_LinkedHashSetCell<E>'. (dart:collection, line 1222, col 38)
[warning] Unsound implicit cast from 'dynamic' to '_LinkedHashSetCell<E>'. (dart:collection, line 1337, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'List<_LinkedHashSetCell<E>>'. (dart:collection, line 1351, col 12)
[warning] Unsound implicit cast from 'dynamic' to '_LinkedHashSetCell<E>'. (dart:collection, line 1358, col 40)
[warning] Unsound implicit cast from 'dynamic' to '_LinkedHashSetCell<E>'. (dart:collection, line 1391, col 40)
[warning] Unsound implicit cast from 'dynamic' to '_LinkedHashSetCell<E>'. (dart:collection, line 1412, col 40)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 1413, col 36)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 1423, col 47)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:collection, line 1485, col 18)
[warning] Unsound implicit cast from 'dynamic' to 'Stream<S>'. (dart:convert/chunked_conversion.dart, line 14, col 45)
[warning] Unsound implicit cast from 'dynamic' to 'Sink<T>'. (dart:convert/chunked_conversion.dart, line 16, col 36)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:convert, line 311, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'T'. (dart:core/expando.dart, line 55, col 12)
[warning] Unsound implicit cast from 'dynamic' to 'E'. (dart:core/list.dart, line 126, col 16)
[warning] Unsafe implicit cast from 'List<dynamic>' to 'List<String>'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:_js_helper/regexp_helper.dart, line 140, col 43)
[warning] Unsafe implicit cast from 'List<dynamic>' to 'List<String>'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:_js_helper/regexp_helper.dart, line 152, col 43)
[warning] Unsafe implicit cast from 'Object' to 'K'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:collection, line 411, col 49)
[warning] Unsafe implicit cast from 'Object' to 'E'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:collection, line 758, col 14)
[warning] Unsafe implicit cast from 'Object' to 'E'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:collection, line 1135, col 14)
[warning] The final variable 'origin' must be initialized. (dart:html, line 177, col 3)
[warning] The final variable 'origin' must be initialized. (dart:html, line 813, col 3)
[warning] Unsound implicit cast from 'dynamic' to 'List<String>'. (dart:html, line 1145, col 33)
[warning] The final variables 'form', 'labels' and '3' more must be initialized. (dart:html, line 1691, col 3)
[warning] Unsound implicit cast from 'dynamic' to 'List<num>'. (dart:html, line 2723, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'List<num>'. (dart:html, line 2725, col 14)
[warning] The final variable 'options' must be initialized. (dart:html, line 8972, col 3)
[warning] The final variables '_attributes', '_childElementCount' and '16' more must be initialized. (dart:html, line 13009, col 3)
[warning] The final variables 'elements', 'form' and '4' more must be initialized. (dart:html, line 16625, col 3)
@ -114,14 +42,11 @@
[warning] The final variables 'form', 'labels' and '5' more must be initialized. (dart:html, line 32069, col 3)
[warning] The final variables 'readyState' and 'track' must be initialized. (dart:html, line 33056, col 3)
[warning] The final variables 'decodedFrameCount', 'droppedFrameCount' and '2' more must be initialized. (dart:html, line 33754, col 3)
[warning] Unsound implicit cast from 'dynamic' to 'Rectangle<num>'. (dart:html, line 37618, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'Rectangle<num>'. (dart:html, line 37626, col 14)
[warning] Unsound implicit cast from 'dynamic' to 'Rectangle<num>'. (dart:html, line 37634, col 14)
[warning] Unsound implicit cast from '(T) → void' to '(Event) → dynamic'. (dart:html, line 40090, col 67)
[warning] Unsound implicit cast from '(T) → void' to '(Event) → dynamic'. (dart:html, line 40112, col 45)
[warning] Unsound implicit cast from 'num' to 'T'. (dart:math/rectangle.dart, line 158, col 22)
[warning] Unsound implicit cast from 'num' to 'T'. (dart:math/rectangle.dart, line 159, col 23)
[warning] Unsound implicit cast from 'num' to 'T'. (dart:math/rectangle.dart, line 282, col 10)
[warning] Unsafe implicit cast from '(T) → void' to '(Event) → dynamic'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:html, line 40090, col 67)
[warning] Unsafe implicit cast from '(T) → void' to '(Event) → dynamic'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:html, line 40112, col 45)
[warning] Unsafe implicit cast from 'num' to 'T'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:math/rectangle.dart, line 158, col 22)
[warning] Unsafe implicit cast from 'num' to 'T'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:math/rectangle.dart, line 159, col 23)
[warning] Unsafe implicit cast from 'num' to 'T'. This usually indicates that type information was lost and resulted in 'dynamic' and/or a place that will have a failure at runtime. (dart:math/rectangle.dart, line 282, col 10)
[warning] The final variables 'href' and 'target' must be initialized. (dart:svg, line 60, col 3)
[warning] The final variables 'requiredExtensions', 'requiredFeatures' and '2' more must be initialized. (dart:svg, line 489, col 3)
[warning] The final variables 'cx', 'cy' and '1' more must be initialized. (dart:svg, line 562, col 3)