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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/serialization/system.dart
diff --git a/pkg/compiler/lib/src/serialization/system.dart b/pkg/compiler/lib/src/serialization/system.dart
index 9be7d6dcc62b539f5656267ced59c3b36c51975c..8d241ceea9350d61b118df5677d0717f05423a1c 100644
--- a/pkg/compiler/lib/src/serialization/system.dart
+++ b/pkg/compiler/lib/src/serialization/system.dart
@@ -22,58 +22,52 @@ import 'resolved_ast_serialization.dart';
import 'serialization.dart';
import 'task.dart';
-class DeserializerSystemImpl extends DeserializerSystem {
+class ResolutionDeserializerSystem extends DeserializerSystem {
final Compiler _compiler;
final Resolution resolution;
final DeserializationContext deserializationContext;
final List<LibraryElement> deserializedLibraries = <LibraryElement>[];
- final ResolutionImpactDeserializer _resolutionImpactDeserializer;
- final ResolvedAstDeserializerPlugin _resolvedAstDeserializer;
- factory DeserializerSystemImpl(Compiler compiler) {
+ factory ResolutionDeserializerSystem(Compiler compiler,
+ {bool deserializeCompilationDataForTesting: false}) {
DeserializationContext context = new DeserializationContext(
compiler.reporter, compiler.resolution, compiler.libraryLoader);
DeserializerPlugin backendDeserializer =
compiler.backend.serialization.deserializer;
context.plugins.add(backendDeserializer);
- ResolutionImpactDeserializer resolutionImpactDeserializer =
- new ResolutionImpactDeserializer(backendDeserializer);
- context.plugins.add(resolutionImpactDeserializer);
- ResolvedAstDeserializerPlugin resolvedAstDeserializer =
- new ResolvedAstDeserializerPlugin(
- compiler.parsingContext, backendDeserializer);
- context.plugins.add(resolvedAstDeserializer);
- return new DeserializerSystemImpl._(compiler, compiler.resolution, context,
- resolutionImpactDeserializer, resolvedAstDeserializer);
+ if (compiler.options.resolveOnly && !deserializeCompilationDataForTesting) {
+ return new ResolutionDeserializerSystem._(
+ compiler, compiler.resolution, context);
+ } else {
+ ResolutionImpactDeserializer resolutionImpactDeserializer =
+ new ResolutionImpactDeserializer(backendDeserializer);
+ context.plugins.add(resolutionImpactDeserializer);
+ ResolvedAstDeserializerPlugin resolvedAstDeserializer =
+ new ResolvedAstDeserializerPlugin(
+ compiler.parsingContext, backendDeserializer);
+ context.plugins.add(resolvedAstDeserializer);
+ return new CompilationDeserializerSystem._(compiler, compiler.resolution,
+ context, resolutionImpactDeserializer, resolvedAstDeserializer);
+ }
}
- DeserializerSystemImpl._(
- this._compiler,
- this.resolution,
- this.deserializationContext,
- this._resolutionImpactDeserializer,
- this._resolvedAstDeserializer);
+ ResolutionDeserializerSystem._(
+ this._compiler, this.resolution, this.deserializationContext);
@override
Future<LibraryElement> readLibrary(Uri resolvedUri) {
LibraryElement library = deserializationContext.lookupLibrary(resolvedUri);
if (library != null) {
deserializedLibraries.add(library);
- return Future.forEach(library.compilationUnits,
- (CompilationUnitElement compilationUnit) {
- ScriptZ script = compilationUnit.script;
- return _compiler
- .readScript(script.readableUri)
- .then((Script newScript) {
- script.file = newScript.file;
- script.isSynthesized = newScript.isSynthesized;
- _resolvedAstDeserializer.scripts[script.resourceUri] = script;
- });
- }).then((_) => library);
+ return onReadLibrary(library);
}
return new Future<LibraryElement>.value(library);
}
+ Future<LibraryElement> onReadLibrary(LibraryElement library) {
+ return new Future<LibraryElement>.value(library);
+ }
+
// TODO(johnniwinther): Remove the need for this method.
@override
bool hasResolvedAst(ExecutableElement element) {
@@ -81,6 +75,70 @@ class DeserializerSystemImpl extends DeserializerSystem {
}
@override
+ ResolvedAst getResolvedAst(ExecutableElement element) => null;
+
+ @override
+ bool hasResolutionImpact(Element element) => true;
+
+ @override
+ ResolutionImpact getResolutionImpact(Element element) {
+ return const ResolutionImpact();
+ }
+
+ @override
+ WorldImpact computeWorldImpact(Element element) {
+ ResolutionImpact resolutionImpact = getResolutionImpact(element);
+ assert(invariant(element, resolutionImpact != null,
+ message: 'No impact found for $element (${element.library})'));
+ if (element is ExecutableElement) {
+ getResolvedAst(element);
+ }
+ if (element.isField && !element.isConst) {
+ FieldElement field = element;
+ if (field.isTopLevel || field.isStatic) {
+ if (field.constant == null) {
+ // TODO(johnniwinther): Find a cleaner way to do this. Maybe
+ // `Feature.LAZY_FIELD` of the resolution impact should be used
+ // instead.
+ _compiler.backend.constants.registerLazyStatic(element);
+ }
+ }
+ }
+ return resolution.transformResolutionImpact(element, resolutionImpact);
+ }
+
+ @override
+ bool isDeserialized(Element element) {
+ return deserializedLibraries.contains(element.library);
+ }
+}
+
+class CompilationDeserializerSystem extends ResolutionDeserializerSystem {
+ final ResolutionImpactDeserializer _resolutionImpactDeserializer;
+ final ResolvedAstDeserializerPlugin _resolvedAstDeserializer;
+
+ CompilationDeserializerSystem._(
+ Compiler compiler,
+ Resolution resolution,
+ DeserializationContext deserializationContext,
+ this._resolutionImpactDeserializer,
+ this._resolvedAstDeserializer)
+ : super._(compiler, resolution, deserializationContext);
+
+ @override
+ Future<LibraryElement> onReadLibrary(LibraryElement library) {
+ return Future.forEach(library.compilationUnits,
+ (CompilationUnitElement compilationUnit) {
+ ScriptZ script = compilationUnit.script;
+ return _compiler.readScript(script.readableUri).then((Script newScript) {
+ script.file = newScript.file;
+ script.isSynthesized = newScript.isSynthesized;
+ _resolvedAstDeserializer.scripts[script.resourceUri] = script;
+ });
+ }).then((_) => library);
+ }
+
+ @override
ResolvedAst getResolvedAst(ExecutableElement element) {
return _resolvedAstDeserializer.getResolvedAst(element);
}
@@ -116,33 +174,6 @@ class DeserializerSystemImpl extends DeserializerSystem {
}
return _resolutionImpactDeserializer.getResolutionImpact(element);
}
-
- @override
- WorldImpact computeWorldImpact(Element element) {
- ResolutionImpact resolutionImpact = getResolutionImpact(element);
- assert(invariant(element, resolutionImpact != null,
- message: 'No impact found for $element (${element.library})'));
- if (element is ExecutableElement) {
- getResolvedAst(element);
- }
- if (element.isField && !element.isConst) {
- FieldElement field = element;
- if (field.isTopLevel || field.isStatic) {
- if (field.constant == null) {
- // TODO(johnniwinther): Find a cleaner way to do this. Maybe
- // `Feature.LAZY_FIELD` of the resolution impact should be used
- // instead.
- _compiler.backend.constants.registerLazyStatic(element);
- }
- }
- }
- return resolution.transformResolutionImpact(element, resolutionImpact);
- }
-
- @override
- bool isDeserialized(Element element) {
- return deserializedLibraries.contains(element.library);
- }
}
const String WORLD_IMPACT_TAG = 'worldImpact';
« 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