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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend.dart

Issue 1146813009: Introduce WorldImpact (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased Created 5 years, 6 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
« no previous file with comments | « pkg/compiler/lib/src/enqueue.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of js_backend; 5 part of js_backend;
6 6
7 const VERBOSE_OPTIMIZER_HINTS = false; 7 const VERBOSE_OPTIMIZER_HINTS = false;
8 8
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { 9 class JavaScriptItemCompilationContext extends ItemCompilationContext {
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>();
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 void registerClosureWithFreeTypeVariables( 1174 void registerClosureWithFreeTypeVariables(
1175 Element closure, 1175 Element closure,
1176 Enqueuer enqueuer, 1176 Enqueuer enqueuer,
1177 Registry registry) { 1177 Registry registry) {
1178 if (enqueuer.isResolutionQueue || methodNeedsRti(closure)) { 1178 if (enqueuer.isResolutionQueue || methodNeedsRti(closure)) {
1179 registerComputeSignature(enqueuer, registry); 1179 registerComputeSignature(enqueuer, registry);
1180 } 1180 }
1181 } 1181 }
1182 1182
1183 void registerBoundClosure(Enqueuer enqueuer) { 1183 void registerBoundClosure(Enqueuer enqueuer) {
1184 enqueuer.registerInstantiatedClass( 1184 boundClosureClass.ensureResolved(compiler);
1185 boundClosureClass, 1185 enqueuer.registerInstantiatedType(
1186 boundClosureClass.rawType,
1186 // Precise dependency is not important here. 1187 // Precise dependency is not important here.
1187 compiler.globalDependencies); 1188 compiler.globalDependencies);
1188 } 1189 }
1189 1190
1190 void registerGetOfStaticFunction(Enqueuer enqueuer) { 1191 void registerGetOfStaticFunction(Enqueuer enqueuer) {
1191 enqueuer.registerInstantiatedClass(closureClass, 1192 closureClass.ensureResolved(compiler);
1192 compiler.globalDependencies); 1193 enqueuer.registerInstantiatedType(
1194 closureClass.rawType, compiler.globalDependencies);
1193 } 1195 }
1194 1196
1195 void registerComputeSignature(Enqueuer enqueuer, Registry registry) { 1197 void registerComputeSignature(Enqueuer enqueuer, Registry registry) {
1196 // Calls to [:computeSignature:] are generated by the emitter and we 1198 // Calls to [:computeSignature:] are generated by the emitter and we
1197 // therefore need to enqueue the used elements in the codegen enqueuer as 1199 // therefore need to enqueue the used elements in the codegen enqueuer as
1198 // well as in the resolution enqueuer. 1200 // well as in the resolution enqueuer.
1199 enqueue(enqueuer, getSetRuntimeTypeInfo(), registry); 1201 enqueue(enqueuer, getSetRuntimeTypeInfo(), registry);
1200 enqueue(enqueuer, getGetRuntimeTypeInfo(), registry); 1202 enqueue(enqueuer, getGetRuntimeTypeInfo(), registry);
1201 enqueue(enqueuer, getComputeSignature(), registry); 1203 enqueue(enqueuer, getComputeSignature(), registry);
1202 enqueue(enqueuer, getGetRuntimeTypeArguments(), registry); 1204 enqueue(enqueuer, getGetRuntimeTypeArguments(), registry);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 /// This method calls [registerBackendUse]. 1366 /// This method calls [registerBackendUse].
1365 void enqueueInResolution(Element e, Registry registry) { 1367 void enqueueInResolution(Element e, Registry registry) {
1366 if (e == null) return; 1368 if (e == null) return;
1367 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution; 1369 ResolutionEnqueuer enqueuer = compiler.enqueuer.resolution;
1368 enqueue(enqueuer, e, registry); 1370 enqueue(enqueuer, e, registry);
1369 } 1371 }
1370 1372
1371 /// Register instantiation of [cls] in [enqueuer]. 1373 /// Register instantiation of [cls] in [enqueuer].
1372 /// 1374 ///
1373 /// This method calls [registerBackendUse]. 1375 /// This method calls [registerBackendUse].
1374 void enqueueClass(Enqueuer enqueuer, Element cls, Registry registry) { 1376 void enqueueClass(Enqueuer enqueuer, ClassElement cls, Registry registry) {
1375 if (cls == null) return; 1377 if (cls == null) return;
1376 registerBackendUse(cls); 1378 registerBackendUse(cls);
1377 helpersUsed.add(cls.declaration); 1379 helpersUsed.add(cls.declaration);
1378 if (cls.declaration != cls.implementation) { 1380 if (cls.declaration != cls.implementation) {
1379 helpersUsed.add(cls.implementation); 1381 helpersUsed.add(cls.implementation);
1380 } 1382 }
1381 enqueuer.registerInstantiatedClass(cls, registry); 1383 cls.ensureResolved(compiler);
1384 enqueuer.registerInstantiatedType(cls.rawType, registry);
1382 } 1385 }
1383 1386
1384 void codegen(CodegenWorkItem work) { 1387 WorldImpact codegen(CodegenWorkItem work) {
1385 Element element = work.element; 1388 Element element = work.element;
1386 if (compiler.elementHasCompileTimeError(element)) { 1389 if (compiler.elementHasCompileTimeError(element)) {
1387 generatedCode[element] = jsAst.js( 1390 generatedCode[element] = jsAst.js(
1388 "function () { throw new Error('Compile time error in $element') }"); 1391 "function () { throw new Error('Compile time error in $element') }");
1389 return; 1392 return const WorldImpact();
1390 } 1393 }
1391 var kind = element.kind; 1394 var kind = element.kind;
1392 if (kind == ElementKind.TYPEDEF) return; 1395 if (kind == ElementKind.TYPEDEF) {
1396 return const WorldImpact();
1397 }
1393 if (element.isConstructor && element.enclosingClass == jsNullClass) { 1398 if (element.isConstructor && element.enclosingClass == jsNullClass) {
1394 // Work around a problem compiling JSNull's constructor. 1399 // Work around a problem compiling JSNull's constructor.
1395 return; 1400 return const WorldImpact();
1396 } 1401 }
1397 if (kind.category == ElementCategory.VARIABLE) { 1402 if (kind.category == ElementCategory.VARIABLE) {
1398 ConstantExpression initialValue = 1403 ConstantExpression initialValue =
1399 constants.getConstantForVariable(element); 1404 constants.getConstantForVariable(element);
1400 if (initialValue != null) { 1405 if (initialValue != null) {
1401 registerCompileTimeConstant(initialValue.value, work.registry); 1406 registerCompileTimeConstant(initialValue.value, work.registry);
1402 constants.addCompileTimeConstantForEmission(initialValue.value); 1407 constants.addCompileTimeConstantForEmission(initialValue.value);
1403 // We don't need to generate code for static or top-level 1408 // We don't need to generate code for static or top-level
1404 // variables. For instance variables, we may need to generate 1409 // variables. For instance variables, we may need to generate
1405 // the checked setter. 1410 // the checked setter.
1406 if (Elements.isStaticOrTopLevel(element)) return; 1411 if (Elements.isStaticOrTopLevel(element)) {
1412 return const WorldImpact();
1413 }
1407 } else { 1414 } else {
1408 // If the constant-handler was not able to produce a result we have to 1415 // If the constant-handler was not able to produce a result we have to
1409 // go through the builder (below) to generate the lazy initializer for 1416 // go through the builder (below) to generate the lazy initializer for
1410 // the static variable. 1417 // the static variable.
1411 // We also need to register the use of the cyclic-error helper. 1418 // We also need to register the use of the cyclic-error helper.
1412 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper()); 1419 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper());
1413 } 1420 }
1414 } 1421 }
1415 generatedCode[element] = functionCompiler.compile(work); 1422 generatedCode[element] = functionCompiler.compile(work);
1423 return const WorldImpact();
1416 } 1424 }
1417 1425
1418 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { 1426 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) {
1419 return new native.NativeResolutionEnqueuer(world, compiler); 1427 return new native.NativeResolutionEnqueuer(world, compiler);
1420 } 1428 }
1421 1429
1422 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) { 1430 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) {
1423 return new native.NativeCodegenEnqueuer(world, compiler, emitter); 1431 return new native.NativeCodegenEnqueuer(world, compiler, emitter);
1424 } 1432 }
1425 1433
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2630 } 2638 }
2631 2639
2632 void registerAsyncMarker(FunctionElement element, 2640 void registerAsyncMarker(FunctionElement element,
2633 Enqueuer enqueuer, 2641 Enqueuer enqueuer,
2634 Registry registry) { 2642 Registry registry) {
2635 if (element.asyncMarker == AsyncMarker.ASYNC) { 2643 if (element.asyncMarker == AsyncMarker.ASYNC) {
2636 enqueue(enqueuer, getAsyncHelper(), registry); 2644 enqueue(enqueuer, getAsyncHelper(), registry);
2637 enqueue(enqueuer, getCompleterConstructor(), registry); 2645 enqueue(enqueuer, getCompleterConstructor(), registry);
2638 enqueue(enqueuer, getStreamIteratorConstructor(), registry); 2646 enqueue(enqueuer, getStreamIteratorConstructor(), registry);
2639 } else if (element.asyncMarker == AsyncMarker.SYNC_STAR) { 2647 } else if (element.asyncMarker == AsyncMarker.SYNC_STAR) {
2640 enqueuer.registerInstantiatedClass(getSyncStarIterable(), registry); 2648 ClassElement clsSyncStarIterable = getSyncStarIterable();
2649 clsSyncStarIterable.ensureResolved(compiler);
2650 enqueuer.registerInstantiatedType(clsSyncStarIterable.rawType, registry);
2641 enqueue(enqueuer, getSyncStarIterableConstructor(), registry); 2651 enqueue(enqueuer, getSyncStarIterableConstructor(), registry);
2642 enqueue(enqueuer, getEndOfIteration(), registry); 2652 enqueue(enqueuer, getEndOfIteration(), registry);
2643 enqueue(enqueuer, getYieldStar(), registry); 2653 enqueue(enqueuer, getYieldStar(), registry);
2644 enqueue(enqueuer, getSyncStarUncaughtError(), registry); 2654 enqueue(enqueuer, getSyncStarUncaughtError(), registry);
2645 } else if (element.asyncMarker == AsyncMarker.ASYNC_STAR) { 2655 } else if (element.asyncMarker == AsyncMarker.ASYNC_STAR) {
2646 enqueuer.registerInstantiatedClass(getASyncStarController(), registry); 2656 ClassElement clsASyncStarController = getASyncStarController();
2657 clsASyncStarController.ensureResolved(compiler);
2658 enqueuer.registerInstantiatedType(
2659 clsASyncStarController.rawType, registry);
2647 enqueue(enqueuer, getAsyncStarHelper(), registry); 2660 enqueue(enqueuer, getAsyncStarHelper(), registry);
2648 enqueue(enqueuer, getStreamOfController(), registry); 2661 enqueue(enqueuer, getStreamOfController(), registry);
2649 enqueue(enqueuer, getYieldSingle(), registry); 2662 enqueue(enqueuer, getYieldSingle(), registry);
2650 enqueue(enqueuer, getYieldStar(), registry); 2663 enqueue(enqueuer, getYieldStar(), registry);
2651 enqueue(enqueuer, getASyncStarControllerConstructor(), registry); 2664 enqueue(enqueuer, getASyncStarControllerConstructor(), registry);
2652 enqueue(enqueuer, getStreamIteratorConstructor(), registry); 2665 enqueue(enqueuer, getStreamIteratorConstructor(), registry);
2653 } 2666 }
2654 } 2667 }
2655 } 2668 }
2656 2669
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2929 } 2942 }
2930 } 2943 }
2931 2944
2932 /// Records that [constant] is used by the element behind [registry]. 2945 /// Records that [constant] is used by the element behind [registry].
2933 class Dependency { 2946 class Dependency {
2934 final ConstantValue constant; 2947 final ConstantValue constant;
2935 final Element annotatedElement; 2948 final Element annotatedElement;
2936 2949
2937 const Dependency(this.constant, this.annotatedElement); 2950 const Dependency(this.constant, this.annotatedElement);
2938 } 2951 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/enqueue.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698