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

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

Issue 1182913003: Split TypedSelector into Selector and TypeMask. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 5 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) 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; 5 library dart2js.ir_builder;
6 6
7 import '../compile_time_constants.dart' show BackendConstantEnvironment; 7 import '../compile_time_constants.dart' show BackendConstantEnvironment;
8 import '../constants/constant_system.dart'; 8 import '../constants/constant_system.dart';
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; 10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue;
11 import '../dart_types.dart'; 11 import '../dart_types.dart';
12 import '../dart2jslib.dart'; 12 import '../dart2jslib.dart';
13 import '../elements/elements.dart'; 13 import '../elements/elements.dart';
14 import '../io/source_information.dart'; 14 import '../io/source_information.dart';
15 import '../tree/tree.dart' as ast; 15 import '../tree/tree.dart' as ast;
16 import '../types/types.dart' show TypeMask;
16 import '../closure.dart' hide ClosureScope; 17 import '../closure.dart' hide ClosureScope;
17 import '../universe/universe.dart' show SelectorKind; 18 import '../universe/universe.dart' show SelectorKind;
18 import 'cps_ir_nodes.dart' as ir; 19 import 'cps_ir_nodes.dart' as ir;
19 import 'cps_ir_builder_task.dart' show DartCapturedVariables, 20 import 'cps_ir_builder_task.dart' show DartCapturedVariables,
20 GlobalProgramInformation; 21 GlobalProgramInformation;
21 22
22 /// A mapping from variable elements to their compile-time values. 23 /// A mapping from variable elements to their compile-time values.
23 /// 24 ///
24 /// Map elements denoted by parameters and local variables to the 25 /// Map elements denoted by parameters and local variables to the
25 /// [ir.Primitive] that is their value. Parameters and locals are 26 /// [ir.Primitive] that is their value. Parameters and locals are
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 List<ir.Primitive> arguments) { 647 List<ir.Primitive> arguments) {
647 assert(target.isInstanceMember); 648 assert(target.isInstanceMember);
648 assert(isOpen); 649 assert(isOpen);
649 return _continueWithExpression( 650 return _continueWithExpression(
650 (k) => new ir.InvokeMethodDirectly( 651 (k) => new ir.InvokeMethodDirectly(
651 buildThis(), target, selector, arguments, k)); 652 buildThis(), target, selector, arguments, k));
652 } 653 }
653 654
654 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver, 655 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver,
655 Selector selector, 656 Selector selector,
657 TypeMask mask,
656 List<ir.Primitive> arguments, 658 List<ir.Primitive> arguments,
657 {SourceInformation sourceInformation}) { 659 {SourceInformation sourceInformation}) {
658 assert(isOpen); 660 assert(isOpen);
659 return _continueWithExpression( 661 return _continueWithExpression(
660 (k) => new ir.InvokeMethod(receiver, selector, arguments, k, 662 (k) => new ir.InvokeMethod(receiver, selector, mask, arguments, k,
661 sourceInformation: sourceInformation)); 663 sourceInformation: sourceInformation));
662 } 664 }
663 665
664 ir.Primitive _buildInvokeCall(ir.Primitive target, 666 ir.Primitive _buildInvokeCall(ir.Primitive target,
665 CallStructure callStructure, 667 CallStructure callStructure,
668 TypeMask mask,
666 List<ir.Definition> arguments, 669 List<ir.Definition> arguments,
667 {SourceInformation sourceInformation}) { 670 {SourceInformation sourceInformation}) {
668 Selector selector = callStructure.callSelector; 671 Selector selector = callStructure.callSelector;
669 return _buildInvokeDynamic(target, selector, arguments, 672 return _buildInvokeDynamic(target, selector, mask, arguments,
670 sourceInformation: sourceInformation); 673 sourceInformation: sourceInformation);
671 } 674 }
672 675
673 676
674 /// Create a [ir.Constant] from [constant] and add it to the CPS term. 677 /// Create a [ir.Constant] from [constant] and add it to the CPS term.
675 // TODO(johnniwinther): Remove [value] when [ConstantValue] can be computed 678 // TODO(johnniwinther): Remove [value] when [ConstantValue] can be computed
676 // directly from [constant]. 679 // directly from [constant].
677 ir.Constant buildConstant(ConstantExpression constant, ConstantValue value) { 680 ir.Constant buildConstant(ConstantExpression constant, ConstantValue value) {
678 assert(isOpen); 681 assert(isOpen);
679 return addPrimitive(new ir.Constant(constant, value)); 682 return addPrimitive(new ir.Constant(constant, value));
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 _buildInvokeSuper(method, new Selector.indexSet(), 917 _buildInvokeSuper(method, new Selector.indexSet(),
915 <ir.Primitive>[index, value]); 918 <ir.Primitive>[index, value]);
916 return value; 919 return value;
917 } 920 }
918 921
919 /// Create a dynamic invocation on [receiver] where the method name and 922 /// Create a dynamic invocation on [receiver] where the method name and
920 /// argument structure are defined by [selector] and the argument values are 923 /// argument structure are defined by [selector] and the argument values are
921 /// defined by [arguments]. 924 /// defined by [arguments].
922 ir.Primitive buildDynamicInvocation(ir.Primitive receiver, 925 ir.Primitive buildDynamicInvocation(ir.Primitive receiver,
923 Selector selector, 926 Selector selector,
927 TypeMask mask,
924 List<ir.Primitive> arguments) { 928 List<ir.Primitive> arguments) {
925 return _buildInvokeDynamic(receiver, selector, arguments); 929 return _buildInvokeDynamic(receiver, selector, mask, arguments);
926 } 930 }
927 931
928 /// Create an if-null expression. This is equivalent to a conditional 932 /// Create an if-null expression. This is equivalent to a conditional
929 /// expression whose result is either [value] if [value] is not null, or 933 /// expression whose result is either [value] if [value] is not null, or
930 /// `right` if [value] is null. Only when [value] is null, [buildRight] is 934 /// `right` if [value] is null. Only when [value] is null, [buildRight] is
931 /// evaluated to produce the `right` value. 935 /// evaluated to produce the `right` value.
932 ir.Primitive buildIfNull(ir.Primitive value, 936 ir.Primitive buildIfNull(ir.Primitive value,
933 ir.Primitive buildRight(IrBuilder builder)); 937 ir.Primitive buildRight(IrBuilder builder));
934 938
935 /// Create a conditional send. This is equivalent to a conditional expression 939 /// Create a conditional send. This is equivalent to a conditional expression
936 /// that checks if [receiver] is null, if so, it returns null, otherwise it 940 /// that checks if [receiver] is null, if so, it returns null, otherwise it
937 /// evaluates the [buildSend] expression. 941 /// evaluates the [buildSend] expression.
938 ir.Primitive buildIfNotNullSend(ir.Primitive receiver, 942 ir.Primitive buildIfNotNullSend(ir.Primitive receiver,
939 ir.Primitive buildSend(IrBuilder builder)); 943 ir.Primitive buildSend(IrBuilder builder));
940 944
941 /// Create a dynamic getter invocation on [receiver] where the getter name is 945 /// Create a dynamic getter invocation on [receiver] where the getter name is
942 /// defined by [selector]. 946 /// defined by [selector].
943 ir.Primitive buildDynamicGet(ir.Primitive receiver, Selector selector) { 947 ir.Primitive buildDynamicGet(ir.Primitive receiver,
948 Selector selector,
949 TypeMask mask) {
944 assert(selector.isGetter); 950 assert(selector.isGetter);
945 return _buildInvokeDynamic(receiver, selector, const <ir.Primitive>[]); 951 return _buildInvokeDynamic(
952 receiver, selector, mask, const <ir.Primitive>[]);
946 } 953 }
947 954
948 /// Create a dynamic setter invocation on [receiver] where the setter name and 955 /// Create a dynamic setter invocation on [receiver] where the setter name and
949 /// argument are defined by [selector] and [value], respectively. 956 /// argument are defined by [selector] and [value], respectively.
950 ir.Primitive buildDynamicSet(ir.Primitive receiver, 957 ir.Primitive buildDynamicSet(ir.Primitive receiver,
951 Selector selector, 958 Selector selector,
959 TypeMask mask,
952 ir.Primitive value) { 960 ir.Primitive value) {
953 assert(selector.isSetter); 961 assert(selector.isSetter);
954 _buildInvokeDynamic(receiver, selector, <ir.Primitive>[value]); 962 _buildInvokeDynamic(receiver, selector, mask, <ir.Primitive>[value]);
955 return value; 963 return value;
956 } 964 }
957 965
958 /// Create a dynamic index set invocation on [receiver] with the provided 966 /// Create a dynamic index set invocation on [receiver] with the provided
959 /// [index] and [value]. 967 /// [index] and [value].
960 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver, 968 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver,
969 TypeMask mask,
961 ir.Primitive index, 970 ir.Primitive index,
962 ir.Primitive value) { 971 ir.Primitive value) {
963 _buildInvokeDynamic( 972 _buildInvokeDynamic(
964 receiver, new Selector.indexSet(), <ir.Primitive>[index, value]); 973 receiver, new Selector.indexSet(), mask, <ir.Primitive>[index, value]);
965 return value; 974 return value;
966 } 975 }
967 976
968 ir.Primitive _buildLocalGet(LocalElement element); 977 ir.Primitive _buildLocalGet(LocalElement element);
969 978
970 /// Create a read access of the [local] variable or parameter. 979 /// Create a read access of the [local] variable or parameter.
971 ir.Primitive buildLocalVariableGet(LocalElement local) { 980 ir.Primitive buildLocalVariableGet(LocalElement local) {
972 // TODO(johnniwinther): Separate function access from variable access. 981 // TODO(johnniwinther): Separate function access from variable access.
973 return _buildLocalGet(local); 982 return _buildLocalGet(local);
974 } 983 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 1097
1089 /// Create a string concatenation of the [arguments]. 1098 /// Create a string concatenation of the [arguments].
1090 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) { 1099 ir.Primitive buildStringConcatenation(List<ir.Primitive> arguments) {
1091 assert(isOpen); 1100 assert(isOpen);
1092 return _continueWithExpression( 1101 return _continueWithExpression(
1093 (k) => new ir.ConcatenateStrings(arguments, k)); 1102 (k) => new ir.ConcatenateStrings(arguments, k));
1094 } 1103 }
1095 1104
1096 /// Create an invocation of the `call` method of [functionExpression], where 1105 /// Create an invocation of the `call` method of [functionExpression], where
1097 /// the structure of arguments are given by [callStructure]. 1106 /// the structure of arguments are given by [callStructure].
1107 // TODO(johnniwinther): This should take a [TypeMask].
1098 ir.Primitive buildCallInvocation( 1108 ir.Primitive buildCallInvocation(
1099 ir.Primitive functionExpression, 1109 ir.Primitive functionExpression,
1100 CallStructure callStructure, 1110 CallStructure callStructure,
1101 List<ir.Definition> arguments, 1111 List<ir.Definition> arguments,
1102 {SourceInformation sourceInformation}) { 1112 {SourceInformation sourceInformation}) {
1103 return _buildInvokeCall(functionExpression, callStructure, arguments, 1113 return _buildInvokeCall(functionExpression, callStructure, null, arguments,
1104 sourceInformation: sourceInformation); 1114 sourceInformation: sourceInformation);
1105 } 1115 }
1106 1116
1107 /// Creates an if-then-else statement with the provided [condition] where the 1117 /// Creates an if-then-else statement with the provided [condition] where the
1108 /// then and else branches are created through the [buildThenPart] and 1118 /// then and else branches are created through the [buildThenPart] and
1109 /// [buildElsePart] functions, respectively. 1119 /// [buildElsePart] functions, respectively.
1110 /// 1120 ///
1111 /// An if-then statement is created if [buildElsePart] is a no-op. 1121 /// An if-then statement is created if [buildElsePart] is a no-op.
1112 // TODO(johnniwinther): Unify implementation with [buildConditional] and 1122 // TODO(johnniwinther): Unify implementation with [buildConditional] and
1113 // [_buildLogicalOperator]. 1123 // [_buildLogicalOperator].
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 /// variable element, and [variableSelector] defines its write access, 1354 /// variable element, and [variableSelector] defines its write access,
1345 /// 3) `v` is an instance variable in which case [variableSelector] 1355 /// 3) `v` is an instance variable in which case [variableSelector]
1346 /// defines its write access. 1356 /// defines its write access.
1347 /// [buildBody] creates the body, `b`, of the loop. The jump [target] is used 1357 /// [buildBody] creates the body, `b`, of the loop. The jump [target] is used
1348 /// to identify which `break` and `continue` statements that have this for-in 1358 /// to identify which `break` and `continue` statements that have this for-in
1349 /// statement as their target. 1359 /// statement as their target.
1350 void buildForIn({SubbuildFunction buildExpression, 1360 void buildForIn({SubbuildFunction buildExpression,
1351 SubbuildFunction buildVariableDeclaration, 1361 SubbuildFunction buildVariableDeclaration,
1352 Element variableElement, 1362 Element variableElement,
1353 Selector variableSelector, 1363 Selector variableSelector,
1364 TypeMask variableMask,
1365 TypeMask currentMask,
1366 TypeMask iteratorMask,
1367 TypeMask moveNextMask,
1354 SubbuildFunction buildBody, 1368 SubbuildFunction buildBody,
1355 JumpTarget target, 1369 JumpTarget target,
1356 ClosureScope closureScope}) { 1370 ClosureScope closureScope}) {
1357 // The for-in loop 1371 // The for-in loop
1358 // 1372 //
1359 // for (a in e) s; 1373 // for (a in e) s;
1360 // 1374 //
1361 // Is compiled analogously to: 1375 // Is compiled analogously to:
1362 // 1376 //
1363 // it = e.iterator; 1377 // it = e.iterator;
1364 // while (it.moveNext()) { 1378 // while (it.moveNext()) {
1365 // var a = it.current; 1379 // var a = it.current;
1366 // s; 1380 // s;
1367 // } 1381 // }
1368 1382
1369 // Fill the current hole with: 1383 // Fill the current hole with:
1370 // let prim expressionReceiver = [[e]] in 1384 // let prim expressionReceiver = [[e]] in
1371 // let cont iteratorInvoked(iterator) = 1385 // let cont iteratorInvoked(iterator) =
1372 // [ ] 1386 // [ ]
1373 // in expressionReceiver.iterator () iteratorInvoked 1387 // in expressionReceiver.iterator () iteratorInvoked
1374 ir.Primitive expressionReceiver = buildExpression(this); 1388 ir.Primitive expressionReceiver = buildExpression(this);
1375 List<ir.Primitive> emptyArguments = <ir.Primitive>[]; 1389 List<ir.Primitive> emptyArguments = <ir.Primitive>[];
1376 ir.Parameter iterator = new ir.Parameter(null); 1390 ir.Parameter iterator = new ir.Parameter(null);
1377 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]); 1391 ir.Continuation iteratorInvoked = new ir.Continuation([iterator]);
1378 add(new ir.LetCont(iteratorInvoked, 1392 add(new ir.LetCont(iteratorInvoked,
1379 new ir.InvokeMethod(expressionReceiver, 1393 new ir.InvokeMethod(expressionReceiver,
1380 new Selector.getter("iterator", null), 1394 new Selector.getter("iterator", null),
1395 iteratorMask,
1381 emptyArguments, 1396 emptyArguments,
1382 iteratorInvoked))); 1397 iteratorInvoked)));
1383 1398
1384 // Fill with: 1399 // Fill with:
1385 // let cont loop(x, ...) = 1400 // let cont loop(x, ...) =
1386 // let cont moveNextInvoked(condition) = 1401 // let cont moveNextInvoked(condition) =
1387 // [ ] 1402 // [ ]
1388 // in iterator.moveNext () moveNextInvoked 1403 // in iterator.moveNext () moveNextInvoked
1389 // in loop(v, ...) 1404 // in loop(v, ...)
1390 JumpCollector loop = new BackwardJumpCollector(environment, target: target); 1405 JumpCollector loop = new BackwardJumpCollector(environment, target: target);
1391 addRecursiveContinuation(loop); 1406 addRecursiveContinuation(loop);
1392 ir.Parameter condition = new ir.Parameter(null); 1407 ir.Parameter condition = new ir.Parameter(null);
1393 ir.Continuation moveNextInvoked = new ir.Continuation([condition]); 1408 ir.Continuation moveNextInvoked = new ir.Continuation([condition]);
1394 add(new ir.LetCont(moveNextInvoked, 1409 add(new ir.LetCont(moveNextInvoked,
1395 new ir.InvokeMethod(iterator, 1410 new ir.InvokeMethod(iterator,
1396 new Selector.call("moveNext", null, 0), 1411 new Selector.call("moveNext", null, 0),
1412 moveNextMask,
1397 emptyArguments, 1413 emptyArguments,
1398 moveNextInvoked))); 1414 moveNextInvoked)));
1399 1415
1400 // As a delimited term, build: 1416 // As a delimited term, build:
1401 // <<BODY>> = 1417 // <<BODY>> =
1402 // _enterScope(); 1418 // _enterScope();
1403 // [[variableDeclaration]] 1419 // [[variableDeclaration]]
1404 // let cont currentInvoked(currentValue) = 1420 // let cont currentInvoked(currentValue) =
1405 // [[a = currentValue]]; 1421 // [[a = currentValue]];
1406 // [ ] 1422 // [ ]
1407 // in iterator.current () currentInvoked 1423 // in iterator.current () currentInvoked
1408 IrBuilder bodyBuilder = makeDelimitedBuilder(); 1424 IrBuilder bodyBuilder = makeDelimitedBuilder();
1409 bodyBuilder._enterScope(closureScope); 1425 bodyBuilder._enterScope(closureScope);
1410 if (buildVariableDeclaration != null) { 1426 if (buildVariableDeclaration != null) {
1411 buildVariableDeclaration(bodyBuilder); 1427 buildVariableDeclaration(bodyBuilder);
1412 } 1428 }
1413 ir.Parameter currentValue = new ir.Parameter(null); 1429 ir.Parameter currentValue = new ir.Parameter(null);
1414 ir.Continuation currentInvoked = new ir.Continuation([currentValue]); 1430 ir.Continuation currentInvoked = new ir.Continuation([currentValue]);
1415 bodyBuilder.add(new ir.LetCont(currentInvoked, 1431 bodyBuilder.add(new ir.LetCont(currentInvoked,
1416 new ir.InvokeMethod(iterator, new Selector.getter("current", null), 1432 new ir.InvokeMethod(
1433 iterator,
1434 new Selector.getter("current", null),
1435 currentMask,
1417 emptyArguments, currentInvoked))); 1436 emptyArguments, currentInvoked)));
1418 // TODO(sra): Does this cover all cases? The general setter case include 1437 // TODO(sra): Does this cover all cases? The general setter case include
1419 // super. 1438 // super.
1420 // TODO(johnniwinther): Extract this as a provided strategy. 1439 // TODO(johnniwinther): Extract this as a provided strategy.
1421 if (Elements.isLocal(variableElement)) { 1440 if (Elements.isLocal(variableElement)) {
1422 bodyBuilder.buildLocalVariableSet(variableElement, currentValue); 1441 bodyBuilder.buildLocalVariableSet(variableElement, currentValue);
1423 } else if (Elements.isErroneous(variableElement)) { 1442 } else if (Elements.isErroneous(variableElement)) {
1424 bodyBuilder.buildErroneousInvocation(variableElement, 1443 bodyBuilder.buildErroneousInvocation(variableElement,
1425 new Selector.setter(variableElement.name, variableElement.library), 1444 new Selector.setter(variableElement.name, variableElement.library),
1426 <ir.Primitive>[currentValue]); 1445 <ir.Primitive>[currentValue]);
1427 } else if (Elements.isStaticOrTopLevel(variableElement)) { 1446 } else if (Elements.isStaticOrTopLevel(variableElement)) {
1428 if (variableElement.isField) { 1447 if (variableElement.isField) {
1429 bodyBuilder.buildStaticFieldSet(variableElement, currentValue); 1448 bodyBuilder.buildStaticFieldSet(variableElement, currentValue);
1430 } else { 1449 } else {
1431 bodyBuilder.buildStaticSetterSet(variableElement, currentValue); 1450 bodyBuilder.buildStaticSetterSet(variableElement, currentValue);
1432 } 1451 }
1433 } else { 1452 } else {
1434 ir.Primitive receiver = bodyBuilder.buildThis(); 1453 ir.Primitive receiver = bodyBuilder.buildThis();
1435 assert(receiver != null); 1454 assert(receiver != null);
1436 bodyBuilder.buildDynamicSet(receiver, variableSelector, currentValue); 1455 bodyBuilder.buildDynamicSet(
1456 receiver, variableSelector, variableMask, currentValue);
1437 } 1457 }
1438 1458
1439 // Translate the body in the hole in the delimited term above, and add 1459 // Translate the body in the hole in the delimited term above, and add
1440 // a jump to the loop if control flow is live after the body. 1460 // a jump to the loop if control flow is live after the body.
1441 JumpCollector breakCollector = 1461 JumpCollector breakCollector =
1442 new ForwardJumpCollector(environment, target: target); 1462 new ForwardJumpCollector(environment, target: target);
1443 state.breakCollectors.add(breakCollector); 1463 state.breakCollectors.add(breakCollector);
1444 state.continueCollectors.add(loop); 1464 state.continueCollectors.add(loop);
1445 buildBody(bodyBuilder); 1465 buildBody(bodyBuilder);
1446 assert(state.breakCollectors.last == breakCollector); 1466 assert(state.breakCollectors.last == breakCollector);
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
2524 final DartType type; 2544 final DartType type;
2525 final LocalVariableElement exceptionVariable; 2545 final LocalVariableElement exceptionVariable;
2526 final LocalVariableElement stackTraceVariable; 2546 final LocalVariableElement stackTraceVariable;
2527 final SubbuildFunction buildCatchBlock; 2547 final SubbuildFunction buildCatchBlock;
2528 2548
2529 CatchClauseInfo({this.type, 2549 CatchClauseInfo({this.type,
2530 this.exceptionVariable, 2550 this.exceptionVariable,
2531 this.stackTraceVariable, 2551 this.stackTraceVariable,
2532 this.buildCatchBlock}); 2552 this.buildCatchBlock});
2533 } 2553 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698