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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen_listener.dart

Issue 2716713003: Move main and isolate handling to enqueuer listeners. (Closed)
Patch Set: Created 3 years, 10 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/js_backend/backend.dart ('k') | pkg/compiler/lib/src/js_backend/enqueuer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_backend/codegen_listener.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen_listener.dart b/pkg/compiler/lib/src/js_backend/codegen_listener.dart
index 3dc42319a4796fedfdf425878be45f02645d00a7..042e3de0da06d0201fe0f25892918a6adc3eada7 100644
--- a/pkg/compiler/lib/src/js_backend/codegen_listener.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen_listener.dart
@@ -60,6 +60,58 @@ class CodegenEnqueuerListener extends EnqueuerListener {
_lookupMapAnalysis.registerInstantiatedType(type);
}
+ /// Called to enable support for isolates. Any backend specific [WorldImpact]
+ /// of this is returned.
+ WorldImpact _enableIsolateSupport(MethodElement mainMethod) {
+ WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl();
+ // TODO(floitsch): We should also ensure that the class IsolateMessage is
+ // instantiated. Currently, just enabling isolate support works.
+ if (mainMethod != null) {
+ // The JavaScript backend implements [Isolate.spawn] by looking up
+ // top-level functions by name. So all top-level function tear-off
+ // closures have a private name field.
+ //
+ // The JavaScript backend of [Isolate.spawnUri] uses the same internal
+ // implementation as [Isolate.spawn], and fails if it cannot look main up
+ // by name.
+ impactBuilder.registerStaticUse(new StaticUse.staticTearOff(mainMethod));
+ }
+ _impacts.isolateSupport.registerImpact(impactBuilder, _elementEnvironment);
+ return impactBuilder;
+ }
+
+ /// Computes the [WorldImpact] of calling [mainMethod] as the entry point.
+ WorldImpact _computeMainImpact(MethodElement mainMethod) {
+ WorldImpactBuilderImpl mainImpact = new WorldImpactBuilderImpl();
+ if (mainMethod.parameters.isNotEmpty) {
+ _impacts.mainWithArguments
+ .registerImpact(mainImpact, _elementEnvironment);
+ mainImpact.registerStaticUse(
+ new StaticUse.staticInvoke(mainMethod, CallStructure.TWO_ARGS));
+ // If the main method takes arguments, this compilation could be the
+ // target of Isolate.spawnUri. Strictly speaking, that can happen also if
+ // main takes no arguments, but in this case the spawned isolate can't
+ // communicate with the spawning isolate.
+ mainImpact.addImpact(_enableIsolateSupport(mainMethod));
+ }
+ mainImpact.registerStaticUse(
+ new StaticUse.staticInvoke(mainMethod, CallStructure.NO_ARGS));
+ return mainImpact;
+ }
+
+ @override
+ void onQueueOpen(Enqueuer enqueuer, FunctionEntity mainMethod,
+ Iterable<LibraryEntity> libraries) {
+ enqueuer
+ .applyImpact(enqueuer.nativeEnqueuer.processNativeClasses(libraries));
+ if (mainMethod != null) {
+ enqueuer.applyImpact(_computeMainImpact(mainMethod));
+ }
+ if (_backendUsage.isIsolateInUse) {
+ enqueuer.applyImpact(_enableIsolateSupport(mainMethod));
+ }
+ }
+
@override
bool onQueueEmpty(Enqueuer enqueuer, Iterable<ClassEntity> recentClasses) {
// Add elements used synthetically, that is, through features rather than
@@ -79,9 +131,6 @@ class CodegenEnqueuerListener extends EnqueuerListener {
if (!enqueuer.queueIsEmpty) return false;
- // TODO(johnniwinther): Avoid the need for accessing [_backend].
- _backend._onQueueEmpty(enqueuer, recentClasses);
-
_mirrorsAnalysis.onQueueEmpty(enqueuer, recentClasses);
return true;
}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/js_backend/enqueuer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698