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

Side by Side Diff: pkg/compiler/lib/src/serialization/system.dart

Issue 2240823002: Deserialize ResolvedAsts and ResolutionImpacts only when needed for compilation. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.serialization_system; 5 library dart2js.serialization_system;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/resolution.dart'; 10 import '../common/resolution.dart';
11 import '../compiler.dart'; 11 import '../compiler.dart';
12 import '../elements/elements.dart'; 12 import '../elements/elements.dart';
13 import '../scanner/scanner.dart'; 13 import '../scanner/scanner.dart';
14 import '../script.dart'; 14 import '../script.dart';
15 import '../serialization/impact_serialization.dart'; 15 import '../serialization/impact_serialization.dart';
16 import '../tokens/token.dart'; 16 import '../tokens/token.dart';
17 import '../universe/call_structure.dart'; 17 import '../universe/call_structure.dart';
18 import '../universe/use.dart'; 18 import '../universe/use.dart';
19 import '../universe/world_impact.dart'; 19 import '../universe/world_impact.dart';
20 import 'modelz.dart'; 20 import 'modelz.dart';
21 import 'resolved_ast_serialization.dart'; 21 import 'resolved_ast_serialization.dart';
22 import 'serialization.dart'; 22 import 'serialization.dart';
23 import 'task.dart'; 23 import 'task.dart';
24 24
25 class DeserializerSystemImpl extends DeserializerSystem { 25 class ResolutionDeserializerSystem extends DeserializerSystem {
26 final Compiler _compiler; 26 final Compiler _compiler;
27 final Resolution resolution; 27 final Resolution resolution;
28 final DeserializationContext deserializationContext; 28 final DeserializationContext deserializationContext;
29 final List<LibraryElement> deserializedLibraries = <LibraryElement>[]; 29 final List<LibraryElement> deserializedLibraries = <LibraryElement>[];
30 final ResolutionImpactDeserializer _resolutionImpactDeserializer;
31 final ResolvedAstDeserializerPlugin _resolvedAstDeserializer;
32 30
33 factory DeserializerSystemImpl(Compiler compiler) { 31 factory ResolutionDeserializerSystem(Compiler compiler,
32 {bool deserializeCompilationDataForTesting: false}) {
34 DeserializationContext context = new DeserializationContext( 33 DeserializationContext context = new DeserializationContext(
35 compiler.reporter, compiler.resolution, compiler.libraryLoader); 34 compiler.reporter, compiler.resolution, compiler.libraryLoader);
36 DeserializerPlugin backendDeserializer = 35 DeserializerPlugin backendDeserializer =
37 compiler.backend.serialization.deserializer; 36 compiler.backend.serialization.deserializer;
38 context.plugins.add(backendDeserializer); 37 context.plugins.add(backendDeserializer);
39 ResolutionImpactDeserializer resolutionImpactDeserializer = 38 if (compiler.options.resolveOnly && !deserializeCompilationDataForTesting) {
40 new ResolutionImpactDeserializer(backendDeserializer); 39 return new ResolutionDeserializerSystem._(
41 context.plugins.add(resolutionImpactDeserializer); 40 compiler, compiler.resolution, context);
42 ResolvedAstDeserializerPlugin resolvedAstDeserializer = 41 } else {
43 new ResolvedAstDeserializerPlugin( 42 ResolutionImpactDeserializer resolutionImpactDeserializer =
44 compiler.parsingContext, backendDeserializer); 43 new ResolutionImpactDeserializer(backendDeserializer);
45 context.plugins.add(resolvedAstDeserializer); 44 context.plugins.add(resolutionImpactDeserializer);
46 return new DeserializerSystemImpl._(compiler, compiler.resolution, context, 45 ResolvedAstDeserializerPlugin resolvedAstDeserializer =
47 resolutionImpactDeserializer, resolvedAstDeserializer); 46 new ResolvedAstDeserializerPlugin(
47 compiler.parsingContext, backendDeserializer);
48 context.plugins.add(resolvedAstDeserializer);
49 return new CompilationDeserializerSystem._(compiler, compiler.resolution,
50 context, resolutionImpactDeserializer, resolvedAstDeserializer);
51 }
48 } 52 }
49 53
50 DeserializerSystemImpl._( 54 ResolutionDeserializerSystem._(
51 this._compiler, 55 this._compiler, this.resolution, this.deserializationContext);
52 this.resolution,
53 this.deserializationContext,
54 this._resolutionImpactDeserializer,
55 this._resolvedAstDeserializer);
56 56
57 @override 57 @override
58 Future<LibraryElement> readLibrary(Uri resolvedUri) { 58 Future<LibraryElement> readLibrary(Uri resolvedUri) {
59 LibraryElement library = deserializationContext.lookupLibrary(resolvedUri); 59 LibraryElement library = deserializationContext.lookupLibrary(resolvedUri);
60 if (library != null) { 60 if (library != null) {
61 deserializedLibraries.add(library); 61 deserializedLibraries.add(library);
62 return Future.forEach(library.compilationUnits, 62 return onReadLibrary(library);
63 (CompilationUnitElement compilationUnit) {
64 ScriptZ script = compilationUnit.script;
65 return _compiler
66 .readScript(script.readableUri)
67 .then((Script newScript) {
68 script.file = newScript.file;
69 script.isSynthesized = newScript.isSynthesized;
70 _resolvedAstDeserializer.scripts[script.resourceUri] = script;
71 });
72 }).then((_) => library);
73 } 63 }
74 return new Future<LibraryElement>.value(library); 64 return new Future<LibraryElement>.value(library);
75 } 65 }
76 66
67 Future<LibraryElement> onReadLibrary(LibraryElement library) {
68 return new Future<LibraryElement>.value(library);
69 }
70
77 // TODO(johnniwinther): Remove the need for this method. 71 // TODO(johnniwinther): Remove the need for this method.
78 @override 72 @override
79 bool hasResolvedAst(ExecutableElement element) { 73 bool hasResolvedAst(ExecutableElement element) {
80 return getResolvedAst(element) != null; 74 return getResolvedAst(element) != null;
81 } 75 }
82 76
83 @override 77 @override
78 ResolvedAst getResolvedAst(ExecutableElement element) => null;
79
80 @override
81 bool hasResolutionImpact(Element element) => true;
82
83 @override
84 ResolutionImpact getResolutionImpact(Element element) {
85 return const ResolutionImpact();
86 }
87
88 @override
89 WorldImpact computeWorldImpact(Element element) {
90 ResolutionImpact resolutionImpact = getResolutionImpact(element);
91 assert(invariant(element, resolutionImpact != null,
92 message: 'No impact found for $element (${element.library})'));
93 if (element is ExecutableElement) {
94 getResolvedAst(element);
95 }
96 if (element.isField && !element.isConst) {
97 FieldElement field = element;
98 if (field.isTopLevel || field.isStatic) {
99 if (field.constant == null) {
100 // TODO(johnniwinther): Find a cleaner way to do this. Maybe
101 // `Feature.LAZY_FIELD` of the resolution impact should be used
102 // instead.
103 _compiler.backend.constants.registerLazyStatic(element);
104 }
105 }
106 }
107 return resolution.transformResolutionImpact(element, resolutionImpact);
108 }
109
110 @override
111 bool isDeserialized(Element element) {
112 return deserializedLibraries.contains(element.library);
113 }
114 }
115
116 class CompilationDeserializerSystem extends ResolutionDeserializerSystem {
117 final ResolutionImpactDeserializer _resolutionImpactDeserializer;
118 final ResolvedAstDeserializerPlugin _resolvedAstDeserializer;
119
120 CompilationDeserializerSystem._(
121 Compiler compiler,
122 Resolution resolution,
123 DeserializationContext deserializationContext,
124 this._resolutionImpactDeserializer,
125 this._resolvedAstDeserializer)
126 : super._(compiler, resolution, deserializationContext);
127
128 @override
129 Future<LibraryElement> onReadLibrary(LibraryElement library) {
130 return Future.forEach(library.compilationUnits,
131 (CompilationUnitElement compilationUnit) {
132 ScriptZ script = compilationUnit.script;
133 return _compiler.readScript(script.readableUri).then((Script newScript) {
134 script.file = newScript.file;
135 script.isSynthesized = newScript.isSynthesized;
136 _resolvedAstDeserializer.scripts[script.resourceUri] = script;
137 });
138 }).then((_) => library);
139 }
140
141 @override
84 ResolvedAst getResolvedAst(ExecutableElement element) { 142 ResolvedAst getResolvedAst(ExecutableElement element) {
85 return _resolvedAstDeserializer.getResolvedAst(element); 143 return _resolvedAstDeserializer.getResolvedAst(element);
86 } 144 }
87 145
88 @override 146 @override
89 bool hasResolutionImpact(Element element) { 147 bool hasResolutionImpact(Element element) {
90 if (element.isConstructor && 148 if (element.isConstructor &&
91 element.enclosingClass.isUnnamedMixinApplication) { 149 element.enclosingClass.isUnnamedMixinApplication) {
92 return true; 150 return true;
93 } 151 }
(...skipping 15 matching lines...) Expand all
109 return _resolutionImpactDeserializer.registerResolutionImpact(element, 167 return _resolutionImpactDeserializer.registerResolutionImpact(element,
110 () { 168 () {
111 return new DeserializedResolutionImpact(staticUses: <StaticUse>[ 169 return new DeserializedResolutionImpact(staticUses: <StaticUse>[
112 new StaticUse.superConstructorInvoke( 170 new StaticUse.superConstructorInvoke(
113 superclassConstructor, callStructure) 171 superclassConstructor, callStructure)
114 ]); 172 ]);
115 }); 173 });
116 } 174 }
117 return _resolutionImpactDeserializer.getResolutionImpact(element); 175 return _resolutionImpactDeserializer.getResolutionImpact(element);
118 } 176 }
119
120 @override
121 WorldImpact computeWorldImpact(Element element) {
122 ResolutionImpact resolutionImpact = getResolutionImpact(element);
123 assert(invariant(element, resolutionImpact != null,
124 message: 'No impact found for $element (${element.library})'));
125 if (element is ExecutableElement) {
126 getResolvedAst(element);
127 }
128 if (element.isField && !element.isConst) {
129 FieldElement field = element;
130 if (field.isTopLevel || field.isStatic) {
131 if (field.constant == null) {
132 // TODO(johnniwinther): Find a cleaner way to do this. Maybe
133 // `Feature.LAZY_FIELD` of the resolution impact should be used
134 // instead.
135 _compiler.backend.constants.registerLazyStatic(element);
136 }
137 }
138 }
139 return resolution.transformResolutionImpact(element, resolutionImpact);
140 }
141
142 @override
143 bool isDeserialized(Element element) {
144 return deserializedLibraries.contains(element.library);
145 }
146 } 177 }
147 178
148 const String WORLD_IMPACT_TAG = 'worldImpact'; 179 const String WORLD_IMPACT_TAG = 'worldImpact';
149 180
150 class ResolutionImpactSerializer extends SerializerPlugin { 181 class ResolutionImpactSerializer extends SerializerPlugin {
151 final Resolution resolution; 182 final Resolution resolution;
152 final SerializerPlugin nativeDataSerializer; 183 final SerializerPlugin nativeDataSerializer;
153 184
154 ResolutionImpactSerializer(this.resolution, this.nativeDataSerializer); 185 ResolutionImpactSerializer(this.resolution, this.nativeDataSerializer);
155 186
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 305 }
275 306
276 @override 307 @override
277 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { 308 void onElement(Element element, ObjectDecoder getDecoder(String tag)) {
278 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); 309 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG);
279 if (decoder != null) { 310 if (decoder != null) {
280 _decoderMap[element] = decoder; 311 _decoderMap[element] = decoder;
281 } 312 }
282 } 313 }
283 } 314 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compile_time_constants.dart ('k') | pkg/compiler/lib/src/serialization/task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698