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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1558353002: cpsir: add support for deferred code (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | tests/language/language_dart2js.status » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.ir_builder_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closurelib; 7 import '../closure.dart' as closurelib;
8 import '../closure.dart' hide ClosureScope; 8 import '../closure.dart' hide ClosureScope;
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart' show 10 import '../common/names.dart' show
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 // in production mode. 699 // in production mode.
700 // Assertions can only occur in expression statements, so no value needs 700 // Assertions can only occur in expression statements, so no value needs
701 // to be returned. 701 // to be returned.
702 return null; 702 return null;
703 } 703 }
704 } 704 }
705 705
706 // ## Sends ## 706 // ## Sends ##
707 @override 707 @override
708 void previsitDeferredAccess(ast.Send node, PrefixElement prefix, _) { 708 void previsitDeferredAccess(ast.Send node, PrefixElement prefix, _) {
709 giveup(node, 'deferred access is not implemented'); 709 if (prefix != null) buildCheckDeferredIsLoaded(prefix, node);
710 }
711
712 /// Create a call to check that a deferred import has already been loaded.
713 ir.Primitive buildCheckDeferredIsLoaded(PrefixElement prefix, ast.Send node) {
714 SourceInformation sourceInformation =
715 sourceInformationBuilder.buildCall(node, node.selector);
716 JavaScriptBackend backend = compiler.backend;
717 return irBuilder.buildStaticFunctionInvocation(
718 backend.helpers.checkDeferredIsLoaded,
719 CallStructure.TWO_ARGS, <ir.Primitive>[
720 irBuilder.buildStringConstant(
721 compiler.deferredLoadTask.getImportDeferName(node, prefix)),
722 irBuilder.buildStringConstant('${prefix.deferredImport.uri}'),
723 ], sourceInformation: sourceInformation);
710 } 724 }
711 725
712 ir.Primitive visitNamedArgument(ast.NamedArgument node) { 726 ir.Primitive visitNamedArgument(ast.NamedArgument node) {
713 assert(irBuilder.isOpen); 727 assert(irBuilder.isOpen);
714 return visit(node.expression); 728 return visit(node.expression);
715 } 729 }
716 730
717 @override 731 @override
718 ir.Primitive visitExpressionInvoke(ast.Send node, 732 ir.Primitive visitExpressionInvoke(ast.Send node,
719 ast.Node expression, 733 ast.Node expression,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 MethodElement function, 832 MethodElement function,
819 _) { 833 _) {
820 return irBuilder.buildStaticFunctionGet(function); 834 return irBuilder.buildStaticFunctionGet(function);
821 } 835 }
822 836
823 @override 837 @override
824 ir.Primitive handleStaticGetterGet( 838 ir.Primitive handleStaticGetterGet(
825 ast.Send node, 839 ast.Send node,
826 FunctionElement getter, 840 FunctionElement getter,
827 _) { 841 _) {
828 return irBuilder.buildStaticGetterGet( 842 return buildStaticGetterGet(getter, node);
829 getter, sourceInformationBuilder.buildGet(node)); 843 }
844
845 /// Create a getter invocation of the static getter [getter]. This also
846 /// handles the special case where [getter] is the `loadLibrary`
847 /// pseudo-function on library prefixes of deferred imports.
848 ir.Primitive buildStaticGetterGet(MethodElement getter, ast.Send node) {
849 SourceInformation sourceInformation =
850 sourceInformationBuilder.buildGet(node);
851 if (getter.isDeferredLoaderGetter) {
852 PrefixElement prefix = getter.enclosingElement;
853 ir.Primitive loadId = irBuilder.buildStringConstant(
854 compiler.deferredLoadTask.getImportDeferName(node, prefix));
855 return irBuilder.buildStaticFunctionInvocation(
856 compiler.loadLibraryFunction,
857 CallStructure.ONE_ARG, <ir.Primitive>[loadId],
858 sourceInformation: sourceInformation);
859 } else {
860 return irBuilder.buildStaticGetterGet(getter, sourceInformation);
861 }
830 } 862 }
831 863
832 @override 864 @override
833 ir.Primitive visitSuperFieldGet( 865 ir.Primitive visitSuperFieldGet(
834 ast.Send node, 866 ast.Send node,
835 FieldElement field, 867 FieldElement field,
836 _) { 868 _) {
837 return irBuilder.buildSuperFieldGet(field); 869 return irBuilder.buildSuperFieldGet(field);
838 } 870 }
839 871
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 arguments.nodes.mapToList(visit)); 1282 arguments.nodes.mapToList(visit));
1251 } 1283 }
1252 1284
1253 @override 1285 @override
1254 ir.Primitive handleStaticGetterInvoke( 1286 ir.Primitive handleStaticGetterInvoke(
1255 ast.Send node, 1287 ast.Send node,
1256 FunctionElement getter, 1288 FunctionElement getter,
1257 ast.NodeList argumentsNode, 1289 ast.NodeList argumentsNode,
1258 CallStructure callStructure, 1290 CallStructure callStructure,
1259 _) { 1291 _) {
1260 ir.Primitive target = irBuilder.buildStaticGetterGet(getter, 1292 ir.Primitive target = buildStaticGetterGet(getter, node);
1261 sourceInformationBuilder.buildGet(node));
1262 List<ir.Primitive> arguments = <ir.Primitive>[]; 1293 List<ir.Primitive> arguments = <ir.Primitive>[];
1263 callStructure = 1294 callStructure =
1264 translateDynamicArguments(argumentsNode, callStructure, arguments); 1295 translateDynamicArguments(argumentsNode, callStructure, arguments);
1265 return irBuilder.buildCallInvocation( 1296 return irBuilder.buildCallInvocation(
1266 target, 1297 target,
1267 callStructure, 1298 callStructure,
1268 arguments, 1299 arguments,
1269 sourceInformation: 1300 sourceInformation:
1270 sourceInformationBuilder.buildCall(node, argumentsNode)); 1301 sourceInformationBuilder.buildCall(node, argumentsNode));
1271 } 1302 }
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 CompoundRhs rhs, 1752 CompoundRhs rhs,
1722 arg) { 1753 arg) {
1723 return translateCompounds( 1754 return translateCompounds(
1724 node, 1755 node,
1725 getValue: () { 1756 getValue: () {
1726 switch (getterKind) { 1757 switch (getterKind) {
1727 case CompoundGetter.FIELD: 1758 case CompoundGetter.FIELD:
1728 SourceInformation src = sourceInformationBuilder.buildGet(node); 1759 SourceInformation src = sourceInformationBuilder.buildGet(node);
1729 return buildStaticFieldGet(getter, src); 1760 return buildStaticFieldGet(getter, src);
1730 case CompoundGetter.GETTER: 1761 case CompoundGetter.GETTER:
1731 return irBuilder.buildStaticGetterGet( 1762 return buildStaticGetterGet(getter, node);
1732 getter, sourceInformationBuilder.buildGet(node));
1733 case CompoundGetter.METHOD: 1763 case CompoundGetter.METHOD:
1734 return irBuilder.buildStaticFunctionGet(getter); 1764 return irBuilder.buildStaticFunctionGet(getter);
1735 case CompoundGetter.UNRESOLVED: 1765 case CompoundGetter.UNRESOLVED:
1736 return buildStaticNoSuchGetter(getter); 1766 return buildStaticNoSuchGetter(getter);
1737 } 1767 }
1738 }, 1768 },
1739 rhs: rhs, 1769 rhs: rhs,
1740 setValue: (ir.Primitive result) { 1770 setValue: (ir.Primitive result) {
1741 switch (setterKind) { 1771 switch (setterKind) {
1742 case CompoundSetter.FIELD: 1772 case CompoundSetter.FIELD:
(...skipping 16 matching lines...) Expand all
1759 ast.Node rhs, 1789 ast.Node rhs,
1760 _) { 1790 _) {
1761 return translateSetIfNull( 1791 return translateSetIfNull(
1762 node, 1792 node,
1763 getValue: () { 1793 getValue: () {
1764 switch (getterKind) { 1794 switch (getterKind) {
1765 case CompoundGetter.FIELD: 1795 case CompoundGetter.FIELD:
1766 SourceInformation src = sourceInformationBuilder.buildGet(node); 1796 SourceInformation src = sourceInformationBuilder.buildGet(node);
1767 return buildStaticFieldGet(getter, src); 1797 return buildStaticFieldGet(getter, src);
1768 case CompoundGetter.GETTER: 1798 case CompoundGetter.GETTER:
1769 return irBuilder.buildStaticGetterGet( 1799 return buildStaticGetterGet(getter, node);
1770 getter, sourceInformationBuilder.buildGet(node));
1771 case CompoundGetter.METHOD: 1800 case CompoundGetter.METHOD:
1772 return irBuilder.buildStaticFunctionGet(getter); 1801 return irBuilder.buildStaticFunctionGet(getter);
1773 case CompoundGetter.UNRESOLVED: 1802 case CompoundGetter.UNRESOLVED:
1774 return buildStaticNoSuchGetter(getter); 1803 return buildStaticNoSuchGetter(getter);
1775 } 1804 }
1776 }, 1805 },
1777 rhs: rhs, 1806 rhs: rhs,
1778 setValue: (ir.Primitive result) { 1807 setValue: (ir.Primitive result) {
1779 switch (setterKind) { 1808 switch (setterKind) {
1780 case CompoundSetter.FIELD: 1809 case CompoundSetter.FIELD:
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
3337 } 3366 }
3338 3367
3339 @override 3368 @override
3340 ir.Primitive handleConstructorInvoke( 3369 ir.Primitive handleConstructorInvoke(
3341 ast.NewExpression node, 3370 ast.NewExpression node,
3342 ConstructorElement constructor, 3371 ConstructorElement constructor,
3343 DartType type, 3372 DartType type,
3344 ast.NodeList argumentsNode, 3373 ast.NodeList argumentsNode,
3345 CallStructure callStructure, 3374 CallStructure callStructure,
3346 _) { 3375 _) {
3376
3377 ast.Send send = node.send;
3378 // If an allocation refers to a type using a deferred import prefix (e.g.
3379 // `new lib.A()`), we must ensure that the deferred import has already been
3380 // loaded.
3381 var prefix = compiler.deferredLoadTask.deferredPrefixElement(
3382 send, elements);
3383 if (prefix != null) buildCheckDeferredIsLoaded(prefix, send);
asgerf 2016/01/06 02:34:21 I think we need to evaluate the arguments before t
Siggi Cherem (dart-lang) 2016/01/06 03:08:00 Interesting - that's how I thought it should be an
3384
3347 List<ir.Primitive> arguments = argumentsNode.nodes.mapToList(visit); 3385 List<ir.Primitive> arguments = argumentsNode.nodes.mapToList(visit);
3348 // Use default values from the effective target, not the immediate target. 3386 // Use default values from the effective target, not the immediate target.
3349 ConstructorElement target = constructor.effectiveTarget; 3387 ConstructorElement target = constructor.effectiveTarget;
3350 callStructure = 3388
3351 normalizeStaticArguments(callStructure, target, arguments); 3389 // We also emit deferred import checks when using redirecting factories that
3390 // refer to deferred prefixes.
3391 if (constructor.isRedirectingFactory && !constructor.isCyclicRedirection) {
3392 ConstructorElement current = constructor;
3393 while (current.isRedirectingFactory) {
3394 var prefix = current.redirectionDeferredPrefix;
3395 if (prefix != null) buildCheckDeferredIsLoaded(prefix, send);
3396 current = current.immediateRedirectionTarget;
3397 }
3398 }
3399
3400 callStructure = normalizeStaticArguments(callStructure, target, arguments);
3352 TypeMask allocationSiteType; 3401 TypeMask allocationSiteType;
3353 ast.Node send = node.send; 3402
3354 if (Elements.isFixedListConstructorCall(constructor, send, compiler) || 3403 if (Elements.isFixedListConstructorCall(constructor, send, compiler) ||
3355 Elements.isGrowableListConstructorCall(constructor, send, compiler) || 3404 Elements.isGrowableListConstructorCall(constructor, send, compiler) ||
3356 Elements.isFilledListConstructorCall(constructor, send, compiler) || 3405 Elements.isFilledListConstructorCall(constructor, send, compiler) ||
3357 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) { 3406 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) {
3358 allocationSiteType = getAllocationSiteType(send); 3407 allocationSiteType = getAllocationSiteType(send);
3359 } 3408 }
3360 return irBuilder.buildConstructorInvocation( 3409 return irBuilder.buildConstructorInvocation(
3361 target, 3410 target,
3362 callStructure, 3411 callStructure,
3363 constructor.computeEffectiveTargetType(type), 3412 constructor.computeEffectiveTargetType(type),
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
3664 callStructure = translateStaticArguments(argumentsNode, function, 3713 callStructure = translateStaticArguments(argumentsNode, function,
3665 callStructure, arguments); 3714 callStructure, arguments);
3666 return irBuilder.buildStaticFunctionInvocation(function, 3715 return irBuilder.buildStaticFunctionInvocation(function,
3667 callStructure, 3716 callStructure,
3668 arguments, 3717 arguments,
3669 sourceInformation: 3718 sourceInformation:
3670 sourceInformationBuilder.buildCall(node, node.selector)); 3719 sourceInformationBuilder.buildCall(node, node.selector));
3671 } 3720 }
3672 } 3721 }
3673 } 3722 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698