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

Unified Diff: pkg/compiler/lib/src/serialization/modelz.dart

Issue 2150533002: Serialize data for LibraryElement.getImportsFor (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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/serialization/modelz.dart
diff --git a/pkg/compiler/lib/src/serialization/modelz.dart b/pkg/compiler/lib/src/serialization/modelz.dart
index a067b9e6ebf65dc3c3440a5b576370bc6ed731ba..33563f8832f4002fe05300061b12545bc7950ea9 100644
--- a/pkg/compiler/lib/src/serialization/modelz.dart
+++ b/pkg/compiler/lib/src/serialization/modelz.dart
@@ -196,7 +196,7 @@ class MappedContainer {
String setterName = '$name,=';
bool hasSetterId = members.containsKey(setterName);
Element element;
- Element setterElement;
+ SetterElement setterElement;
if (!hasId && !hasSetterId) {
_lookupCache[name] = null;
return null;
@@ -334,7 +334,18 @@ class AbstractFieldElementZ extends ElementZ
final GetterElementZ getter;
final SetterElementZ setter;
- AbstractFieldElementZ(this.name, this.getter, this.setter) {
+ factory AbstractFieldElementZ(
+ String name, GetterElement getter, SetterElement setter) {
+ if (getter != null && getter.abstractField != null) {
Harry Terkelsen 2016/07/13 18:06:46 if (getter?.abstractField != null)
Johnni Winther 2016/07/15 08:15:20 Done.
+ return getter.abstractField;
+ } else if (setter != null && setter.abstractField != null) {
+ return setter.abstractField;
+ } else {
+ return new AbstractFieldElementZ._(name, getter, setter);
+ }
+ }
+
+ AbstractFieldElementZ._(this.name, this.getter, this.setter) {
if (getter != null) {
getter.abstractField = this;
getter.setter = setter;
@@ -398,6 +409,7 @@ class LibraryElementZ extends DeserializedElementZ
List<ExportElement> _exports;
ListedContainer _exportsMap;
ListedContainer _importsMap;
+ Map<Element, List<ImportElement>> _importsFor;
LibraryElementZ(ObjectDecoder decoder) : super(decoder);
@@ -497,7 +509,28 @@ class LibraryElementZ extends DeserializedElementZ
void _ensureImports() {
if (_importsMap == null) {
- _importsMap = new ListedContainer(_decoder.getElements(Key.IMPORT_SCOPE));
+ _importsMap = new ListedContainer(
+ _decoder.getElements(Key.IMPORT_SCOPE, isOptional: true));
+ _importsFor = <Element, List<ImportElement>>{};
+
+ ListDecoder importsDecoder = _decoder.getList(Key.IMPORTS_FOR);
+ for (int index = 0; index < importsDecoder.length; index++) {
+ ObjectDecoder objectDecoder = importsDecoder.getObject(index);
Harry Terkelsen 2016/07/13 18:06:46 maybe ListDecoder can implement Iterable<Decoder>?
Johnni Winther 2016/07/15 08:15:20 The elements are either ObjectDecoder or MapDecode
+ Element key = objectDecoder.getElement(Key.ELEMENT);
+ List<ImportElement> imports =
+ objectDecoder.getElements(Key.IMPORTS, isOptional: true);
+
+ // Imports are mapped to [AbstractFieldElement] which are not serialized
+ // so we use getter (or setter if there is no getter) as the key.
+ Element importedElement = key;
+ if (key.isDeferredLoaderGetter) {
+ // Use as [importedElement].
+ } else if (key.isAccessor) {
+ AccessorElement accessor = key;
+ importedElement = accessor.abstractField;
+ }
+ _importsFor[importedElement] = imports;
+ }
}
}
@@ -509,9 +542,8 @@ class LibraryElementZ extends DeserializedElementZ
@override
Iterable<ImportElement> getImportsFor(Element element) {
- // TODO(johnniwinther): Serialize this to support deferred access to
- // serialized entities.
- return <ImportElement>[];
+ _ensureImports();
+ return _importsFor[element] ?? const <ImportElement>[];
}
String toString() {
« no previous file with comments | « pkg/compiler/lib/src/serialization/keys.dart ('k') | tests/compiler/dart2js/serialization/equivalence_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698