Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: pkg/compiler/lib/src/kernel/world_builder.dart

Issue 2824423002: Compute NativeBasicData for KernelWorldBuilder (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/kernel/world_builder.dart
diff --git a/pkg/compiler/lib/src/kernel/world_builder.dart b/pkg/compiler/lib/src/kernel/world_builder.dart
index 5e9272a55585b5cb4b4b2fbf67c50c6c88cd31c0..8ec774547011cf1cd497018c4f8b0fe4fa158661 100644
--- a/pkg/compiler/lib/src/kernel/world_builder.dart
+++ b/pkg/compiler/lib/src/kernel/world_builder.dart
@@ -19,7 +19,7 @@ import '../elements/elements.dart';
import '../elements/entities.dart';
import '../elements/types.dart';
import '../js_backend/constant_system_javascript.dart';
-import '../js_backend/native_data.dart' show NativeData;
+import '../js_backend/native_data.dart';
import '../js_backend/no_such_method_registry.dart';
import '../native/native.dart' as native;
import '../native/resolver.dart';
@@ -28,6 +28,7 @@ import '../universe/call_structure.dart';
import 'element_adapter.dart';
import 'elements.dart';
+part 'native_basic_data.dart';
part 'native_class_resolver.dart';
part 'no_such_method_resolver.dart';
@@ -40,6 +41,7 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
final DiagnosticReporter reporter;
ElementEnvironment _elementEnvironment;
DartTypeConverter _typeConverter;
+ KernelConstantEnvironment _constantEnvironment;
/// Library environment. Used for fast lookup.
KEnv _env;
@@ -78,9 +80,9 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
: _env = new KEnv(program) {
_elementEnvironment = new KernelElementEnvironment(this);
_commonElements = new CommonElements(_elementEnvironment);
- ConstantEnvironment constants = new KernelConstantEnvironment(this);
+ _constantEnvironment = new KernelConstantEnvironment(this);
_nativeBehaviorBuilder =
- new KernelBehaviorBuilder(_commonElements, constants);
+ new KernelBehaviorBuilder(_commonElements, _constantEnvironment);
_typeConverter = new DartTypeConverter(this);
}
@@ -96,12 +98,24 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
: null;
}
+ Iterable<LibraryEntity> get _libraries {
+ if (_env.length != _libraryMap.length) {
+ // Create a [KLibrary] for each library.
+ _env.forEachLibrary((KLibraryEnv env) {
+ _getLibrary(env.library, env);
+ });
+ }
+ return _libraryMap.values;
+ }
+
@override
CommonElements get commonElements => _commonElements;
@override
ElementEnvironment get elementEnvironment => _elementEnvironment;
+ ConstantEnvironment get constantEnvironment => _constantEnvironment;
+
@override
native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder;
@@ -140,6 +154,13 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
return null;
}
+ void _forEachClass(KLibrary library, void f(ClassEntity cls)) {
+ KLibraryEnv libraryEnv = _libraryEnvs[library.libraryIndex];
+ libraryEnv.forEachClass((KClassEnv classEnv) {
+ f(_getClass(classEnv.cls, classEnv));
+ });
+ }
+
MemberEntity lookupClassMember(KClass cls, String name,
{bool setter: false}) {
KClassEnv classEnv = _classEnvs[cls.classIndex];
@@ -165,6 +186,10 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
});
}
+ Iterable<ConstantExpression> _getClassMetadata(KClass cls) {
+ return _classEnvs[cls.classIndex].getMetadata(this);
+ }
+
KTypeVariable _getTypeVariable(ir.TypeParameter node) {
return _typeVariableMap.putIfAbsent(node, () {
if (node.parent is ir.Class) {
@@ -530,16 +555,32 @@ class KEnv {
KEnv(this.program);
- /// Return the [KLibraryEnv] for the library with the canonical [uri].
- KLibraryEnv lookupLibrary(Uri uri) {
+ void _ensureLibraryMap() {
if (_libraryMap == null) {
_libraryMap = <Uri, KLibraryEnv>{};
for (ir.Library library in program.libraries) {
_libraryMap[library.importUri] = new KLibraryEnv(library);
}
}
+ }
+
+ /// Return the [KLibraryEnv] for the library with the canonical [uri].
+ KLibraryEnv lookupLibrary(Uri uri) {
+ _ensureLibraryMap();
return _libraryMap[uri];
}
+
+ /// Calls [f] for each library in this environment.
+ void forEachLibrary(void f(KLibraryEnv library)) {
+ _ensureLibraryMap();
+ _libraryMap.values.forEach(f);
+ }
+
+ /// Returns the number of libraries in this environment.
+ int get length {
+ _ensureLibraryMap();
+ return _libraryMap.length;
+ }
}
/// Environment for fast lookup of library classes and members.
@@ -552,17 +593,27 @@ class KLibraryEnv {
KLibraryEnv(this.library);
- /// Return the [KClassEnv] for the class [name] in [library].
- KClassEnv lookupClass(String name) {
+ void _ensureClassMap() {
if (_classMap == null) {
_classMap = <String, KClassEnv>{};
for (ir.Class cls in library.classes) {
_classMap[cls.name] = new KClassEnv(cls);
}
}
+ }
+
+ /// Return the [KClassEnv] for the class [name] in [library].
+ KClassEnv lookupClass(String name) {
+ _ensureClassMap();
return _classMap[name];
}
+ /// Calls [f] for each class in this library.
+ void forEachClass(void f(KClassEnv cls)) {
+ _ensureClassMap();
+ _classMap.values.forEach(f);
+ }
+
/// Return the [ir.Member] for the member [name] in [library].
ir.Member lookupMember(String name, {bool setter: false}) {
if (_memberMap == null) {
@@ -589,6 +640,8 @@ class KClassEnv {
Map<String, ir.Member> _constructorMap;
Map<String, ir.Member> _memberMap;
+ Iterable<ConstantExpression> _metadata;
+
KClassEnv(this.cls);
void _ensureMaps() {
@@ -620,6 +673,13 @@ class KClassEnv {
_ensureMaps();
return _constructorMap[name];
}
+
+ Iterable<ConstantExpression> getMetadata(KernelWorldBuilder worldBuilder) {
+ if (_metadata == null) {
+ _metadata = worldBuilder.getMetadata(cls.annotations);
+ }
+ return _metadata;
+ }
}
class KernelElementEnvironment implements ElementEnvironment {
@@ -637,7 +697,7 @@ class KernelElementEnvironment implements ElementEnvironment {
FunctionEntity get mainFunction => worldBuilder._mainFunction;
@override
- Iterable<LibraryEntity> get libraries => worldBuilder._libraryMap.values;
+ Iterable<LibraryEntity> get libraries => worldBuilder._libraries;
@override
InterfaceType getThisType(ClassEntity cls) {
@@ -750,6 +810,11 @@ class KernelElementEnvironment implements ElementEnvironment {
}
@override
+ void forEachClass(KLibrary library, void f(ClassEntity cls)) {
+ worldBuilder._forEachClass(library, f);
+ }
+
+ @override
LibraryEntity lookupLibrary(Uri uri, {bool required: false}) {
LibraryEntity library = worldBuilder.lookupLibrary(uri);
if (library == null && required) {

Powered by Google App Engine
This is Rietveld 408576698