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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2585223002: Access ConstantSystem through ClosedWorld. (Closed)
Patch Set: Created 4 years 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 import 'package:kernel/text/ast_to_text.dart' show debugNodeToString; 6 import 'package:kernel/text/ast_to_text.dart' show debugNodeToString;
7 7
8 import '../closure.dart'; 8 import '../closure.dart';
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 10 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 void buildField(ir.Field field) { 194 void buildField(ir.Field field) {
195 openFunction(); 195 openFunction();
196 if (field.initializer != null) { 196 if (field.initializer != null) {
197 field.initializer.accept(this); 197 field.initializer.accept(this);
198 HInstruction fieldValue = pop(); 198 HInstruction fieldValue = pop();
199 HInstruction checkInstruction = typeBuilder.potentiallyCheckOrTrustType( 199 HInstruction checkInstruction = typeBuilder.potentiallyCheckOrTrustType(
200 fieldValue, astAdapter.getDartType(field.type)); 200 fieldValue, astAdapter.getDartType(field.type));
201 stack.add(checkInstruction); 201 stack.add(checkInstruction);
202 } else { 202 } else {
203 stack.add(graph.addConstantNull(compiler)); 203 stack.add(graph.addConstantNull(closedWorld));
204 } 204 }
205 HInstruction value = pop(); 205 HInstruction value = pop();
206 closeAndGotoExit(new HReturn(value, null)); 206 closeAndGotoExit(new HReturn(value, null));
207 closeFunction(); 207 closeFunction();
208 } 208 }
209 209
210 /// Pops the most recent instruction from the stack and 'boolifies' it. 210 /// Pops the most recent instruction from the stack and 'boolifies' it.
211 /// 211 ///
212 /// Boolification is checking if the value is '=== true'. 212 /// Boolification is checking if the value is '=== true'.
213 @override 213 @override
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 closeAndGotoExit(new HReturn(create, null)); 268 closeAndGotoExit(new HReturn(create, null));
269 closeFunction(); 269 closeFunction();
270 } 270 }
271 271
272 /// Maps the fields of a class to their SSA values. 272 /// Maps the fields of a class to their SSA values.
273 Map<ir.Field, HInstruction> _collectFieldValues(ir.Class clazz) { 273 Map<ir.Field, HInstruction> _collectFieldValues(ir.Class clazz) {
274 final fieldValues = <ir.Field, HInstruction>{}; 274 final fieldValues = <ir.Field, HInstruction>{};
275 275
276 for (var field in clazz.fields) { 276 for (var field in clazz.fields) {
277 if (field.initializer == null) { 277 if (field.initializer == null) {
278 fieldValues[field] = graph.addConstantNull(compiler); 278 fieldValues[field] = graph.addConstantNull(closedWorld);
279 } else { 279 } else {
280 field.initializer.accept(this); 280 field.initializer.accept(this);
281 fieldValues[field] = pop(); 281 fieldValues[field] = pop();
282 } 282 }
283 } 283 }
284 284
285 return fieldValues; 285 return fieldValues;
286 } 286 }
287 287
288 /// Collects field initializers all the way up the inheritance chain. 288 /// Collects field initializers all the way up the inheritance chain.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (!signature.optionalParametersAreNamed) { 333 if (!signature.optionalParametersAreNamed) {
334 signature.forEachOptionalParameter((ParameterElement element) { 334 signature.forEachOptionalParameter((ParameterElement element) {
335 if (positionalIndex < arguments.positional.length) { 335 if (positionalIndex < arguments.positional.length) {
336 arguments.positional[positionalIndex++].accept(this); 336 arguments.positional[positionalIndex++].accept(this);
337 builtArguments.add(pop()); 337 builtArguments.add(pop());
338 } else { 338 } else {
339 var constantValue = 339 var constantValue =
340 backend.constants.getConstantValue(element.constant); 340 backend.constants.getConstantValue(element.constant);
341 assert(invariant(element, constantValue != null, 341 assert(invariant(element, constantValue != null,
342 message: 'No constant computed for $element')); 342 message: 'No constant computed for $element'));
343 builtArguments.add(graph.addConstant(constantValue, compiler)); 343 builtArguments.add(graph.addConstant(constantValue, closedWorld));
344 } 344 }
345 }); 345 });
346 } else { 346 } else {
347 signature.orderedOptionalParameters.forEach((ParameterElement element) { 347 signature.orderedOptionalParameters.forEach((ParameterElement element) {
348 var correspondingNamed = arguments.named.firstWhere( 348 var correspondingNamed = arguments.named.firstWhere(
349 (named) => named.name == element.name, 349 (named) => named.name == element.name,
350 orElse: () => null); 350 orElse: () => null);
351 if (correspondingNamed != null) { 351 if (correspondingNamed != null) {
352 correspondingNamed.value.accept(this); 352 correspondingNamed.value.accept(this);
353 builtArguments.add(pop()); 353 builtArguments.add(pop());
354 } else { 354 } else {
355 var constantValue = 355 var constantValue =
356 backend.constants.getConstantValue(element.constant); 356 backend.constants.getConstantValue(element.constant);
357 assert(invariant(element, constantValue != null, 357 assert(invariant(element, constantValue != null,
358 message: 'No constant computed for $element')); 358 message: 'No constant computed for $element'));
359 builtArguments.add(graph.addConstant(constantValue, compiler)); 359 builtArguments.add(graph.addConstant(constantValue, closedWorld));
360 } 360 }
361 }); 361 });
362 } 362 }
363 363
364 return builtArguments; 364 return builtArguments;
365 } 365 }
366 366
367 /// Inlines the given super [constructor]'s initializers by collecting it's 367 /// Inlines the given super [constructor]'s initializers by collecting it's
368 /// field values and building its constructor initializers. We visit super 368 /// field values and building its constructor initializers. We visit super
369 /// constructors all the way up to the [Object] constructor. 369 /// constructors all the way up to the [Object] constructor.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 open(block); 429 open(block);
430 } 430 }
431 431
432 void closeFunction() { 432 void closeFunction() {
433 if (!isAborted()) closeAndGotoExit(new HGoto()); 433 if (!isAborted()) closeAndGotoExit(new HGoto());
434 graph.finalize(); 434 graph.finalize();
435 } 435 }
436 436
437 /// Pushes a boolean checking [expression] against null. 437 /// Pushes a boolean checking [expression] against null.
438 pushCheckNull(HInstruction expression) { 438 pushCheckNull(HInstruction expression) {
439 push(new HIdentity(expression, graph.addConstantNull(compiler), null, 439 push(new HIdentity(expression, graph.addConstantNull(closedWorld), null,
440 commonMasks.boolType)); 440 commonMasks.boolType));
441 } 441 }
442 442
443 @override 443 @override
444 void defaultExpression(ir.Expression expression) { 444 void defaultExpression(ir.Expression expression) {
445 // TODO(het): This is only to get tests working. 445 // TODO(het): This is only to get tests working.
446 _trap('Unhandled ir.${expression.runtimeType} $expression'); 446 _trap('Unhandled ir.${expression.runtimeType} $expression');
447 } 447 }
448 448
449 @override 449 @override
450 void defaultStatement(ir.Statement statement) { 450 void defaultStatement(ir.Statement statement) {
451 _trap('Unhandled ir.${statement.runtimeType} $statement'); 451 _trap('Unhandled ir.${statement.runtimeType} $statement');
452 pop(); 452 pop();
453 } 453 }
454 454
455 void _trap(String message) { 455 void _trap(String message) {
456 HInstruction nullValue = graph.addConstantNull(compiler); 456 HInstruction nullValue = graph.addConstantNull(closedWorld);
457 HInstruction errorMessage = 457 HInstruction errorMessage =
458 graph.addConstantString(new DartString.literal(message), compiler); 458 graph.addConstantString(new DartString.literal(message), closedWorld);
459 HInstruction trap = new HForeignCode(js.js.parseForeignJS("#.#"), 459 HInstruction trap = new HForeignCode(js.js.parseForeignJS("#.#"),
460 commonMasks.dynamicType, <HInstruction>[nullValue, errorMessage]); 460 commonMasks.dynamicType, <HInstruction>[nullValue, errorMessage]);
461 trap.sideEffects 461 trap.sideEffects
462 ..setAllSideEffects() 462 ..setAllSideEffects()
463 ..setDependsOnSomething(); 463 ..setDependsOnSomething();
464 push(trap); 464 push(trap);
465 } 465 }
466 466
467 /// Returns the current source element. 467 /// Returns the current source element.
468 /// 468 ///
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } else { 508 } else {
509 expression.accept(this); 509 expression.accept(this);
510 pop(); 510 pop();
511 } 511 }
512 } 512 }
513 513
514 @override 514 @override
515 void visitReturnStatement(ir.ReturnStatement returnStatement) { 515 void visitReturnStatement(ir.ReturnStatement returnStatement) {
516 HInstruction value; 516 HInstruction value;
517 if (returnStatement.expression == null) { 517 if (returnStatement.expression == null) {
518 value = graph.addConstantNull(compiler); 518 value = graph.addConstantNull(closedWorld);
519 } else { 519 } else {
520 assert(_targetFunction != null && _targetFunction is ir.FunctionNode); 520 assert(_targetFunction != null && _targetFunction is ir.FunctionNode);
521 returnStatement.expression.accept(this); 521 returnStatement.expression.accept(this);
522 value = typeBuilder.potentiallyCheckOrTrustType( 522 value = typeBuilder.potentiallyCheckOrTrustType(
523 pop(), astAdapter.getFunctionReturnType(_targetFunction)); 523 pop(), astAdapter.getFunctionReturnType(_targetFunction));
524 } 524 }
525 // TODO(het): Add source information 525 // TODO(het): Add source information
526 // TODO(het): Set a return value instead of closing the function when we 526 // TODO(het): Set a return value instead of closing the function when we
527 // support inlining. 527 // support inlining.
528 closeAndGotoExit(new HReturn(value, null)); 528 closeAndGotoExit(new HReturn(value, null));
529 } 529 }
530 530
531 @override 531 @override
532 void visitForStatement(ir.ForStatement forStatement) { 532 void visitForStatement(ir.ForStatement forStatement) {
533 assert(isReachable); 533 assert(isReachable);
534 assert(forStatement.body != null); 534 assert(forStatement.body != null);
535 void buildInitializer() { 535 void buildInitializer() {
536 for (ir.VariableDeclaration declaration in forStatement.variables) { 536 for (ir.VariableDeclaration declaration in forStatement.variables) {
537 declaration.accept(this); 537 declaration.accept(this);
538 } 538 }
539 } 539 }
540 540
541 HInstruction buildCondition() { 541 HInstruction buildCondition() {
542 if (forStatement.condition == null) { 542 if (forStatement.condition == null) {
543 return graph.addConstantBool(true, compiler); 543 return graph.addConstantBool(true, closedWorld);
544 } 544 }
545 forStatement.condition.accept(this); 545 forStatement.condition.accept(this);
546 return popBoolified(); 546 return popBoolified();
547 } 547 }
548 548
549 void buildUpdate() { 549 void buildUpdate() {
550 for (ir.Expression expression in forStatement.updates) { 550 for (ir.Expression expression in forStatement.updates) {
551 expression.accept(this); 551 expression.accept(this);
552 assert(!isAborted()); 552 assert(!isAborted());
553 // The result of the update instruction isn't used, and can just 553 // The result of the update instruction isn't used, and can just
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 [pop(), array], 620 [pop(), array],
621 astAdapter.checkConcurrentModificationErrorReturnType); 621 astAdapter.checkConcurrentModificationErrorReturnType);
622 pop(); 622 pop();
623 } 623 }
624 624
625 void buildInitializer() { 625 void buildInitializer() {
626 forInStatement.iterable.accept(this); 626 forInStatement.iterable.accept(this);
627 array = pop(); 627 array = pop();
628 isFixed = astAdapter.isFixedLength(array.instructionType, closedWorld); 628 isFixed = astAdapter.isFixedLength(array.instructionType, closedWorld);
629 localsHandler.updateLocal( 629 localsHandler.updateLocal(
630 indexVariable, graph.addConstantInt(0, compiler)); 630 indexVariable, graph.addConstantInt(0, closedWorld));
631 originalLength = buildGetLength(); 631 originalLength = buildGetLength();
632 } 632 }
633 633
634 HInstruction buildCondition() { 634 HInstruction buildCondition() {
635 HInstruction index = localsHandler.readLocal(indexVariable); 635 HInstruction index = localsHandler.readLocal(indexVariable);
636 HInstruction length = buildGetLength(); 636 HInstruction length = buildGetLength();
637 HInstruction compare = 637 HInstruction compare =
638 new HLess(index, length, null, commonMasks.boolType); 638 new HLess(index, length, null, commonMasks.boolType);
639 add(compare); 639 add(compare);
640 return compare; 640 return compare;
(...skipping 24 matching lines...) Expand all
665 665
666 void buildUpdate() { 666 void buildUpdate() {
667 // See buildBody as to why we check here. 667 // See buildBody as to why we check here.
668 buildConcurrentModificationErrorCheck(); 668 buildConcurrentModificationErrorCheck();
669 669
670 // TODO(sra): It would be slightly shorter to generate `a[i++]` in the 670 // TODO(sra): It would be slightly shorter to generate `a[i++]` in the
671 // body (and that more closely follows what an inlined iterator would do) 671 // body (and that more closely follows what an inlined iterator would do)
672 // but the code is horrible as `i+1` is carried around the loop in an 672 // but the code is horrible as `i+1` is carried around the loop in an
673 // additional variable. 673 // additional variable.
674 HInstruction index = localsHandler.readLocal(indexVariable); 674 HInstruction index = localsHandler.readLocal(indexVariable);
675 HInstruction one = graph.addConstantInt(1, compiler); 675 HInstruction one = graph.addConstantInt(1, closedWorld);
676 HInstruction addInstruction = 676 HInstruction addInstruction =
677 new HAdd(index, one, null, commonMasks.positiveIntType); 677 new HAdd(index, one, null, commonMasks.positiveIntType);
678 add(addInstruction); 678 add(addInstruction);
679 localsHandler.updateLocal(indexVariable, addInstruction); 679 localsHandler.updateLocal(indexVariable, addInstruction);
680 } 680 }
681 681
682 loopHandler.handleLoop(forInStatement, buildInitializer, buildCondition, 682 loopHandler.handleLoop(forInStatement, buildInitializer, buildCondition,
683 buildUpdate, buildBody); 683 buildUpdate, buildBody);
684 } 684 }
685 685
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 HTypeConversion.CAST_TYPE_CHECK); 784 HTypeConversion.CAST_TYPE_CHECK);
785 if (converted != expressionInstruction) { 785 if (converted != expressionInstruction) {
786 add(converted); 786 add(converted);
787 } 787 }
788 stack.add(converted); 788 stack.add(converted);
789 } 789 }
790 } 790 }
791 791
792 void generateError(ir.Node node, String message, TypeMask typeMask) { 792 void generateError(ir.Node node, String message, TypeMask typeMask) {
793 HInstruction errorMessage = 793 HInstruction errorMessage =
794 graph.addConstantString(new DartString.literal(message), compiler); 794 graph.addConstantString(new DartString.literal(message), closedWorld);
795 _pushStaticInvocation(node, [errorMessage], typeMask); 795 _pushStaticInvocation(node, [errorMessage], typeMask);
796 } 796 }
797 797
798 void generateTypeError(ir.Node node, String message) { 798 void generateTypeError(ir.Node node, String message) {
799 generateError(node, message, astAdapter.throwTypeErrorType); 799 generateError(node, message, astAdapter.throwTypeErrorType);
800 } 800 }
801 801
802 @override 802 @override
803 void visitAssertStatement(ir.AssertStatement assertStatement) { 803 void visitAssertStatement(ir.AssertStatement assertStatement) {
804 if (!compiler.options.enableUserAssertions) return; 804 if (!compiler.options.enableUserAssertions) return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 @override 839 @override
840 void visitLogicalExpression(ir.LogicalExpression logicalExpression) { 840 void visitLogicalExpression(ir.LogicalExpression logicalExpression) {
841 SsaBranchBuilder brancher = new SsaBranchBuilder(this, compiler); 841 SsaBranchBuilder brancher = new SsaBranchBuilder(this, compiler);
842 brancher.handleLogicalBinary(() => logicalExpression.left.accept(this), 842 brancher.handleLogicalBinary(() => logicalExpression.left.accept(this),
843 () => logicalExpression.right.accept(this), 843 () => logicalExpression.right.accept(this),
844 isAnd: logicalExpression.operator == '&&'); 844 isAnd: logicalExpression.operator == '&&');
845 } 845 }
846 846
847 @override 847 @override
848 void visitIntLiteral(ir.IntLiteral intLiteral) { 848 void visitIntLiteral(ir.IntLiteral intLiteral) {
849 stack.add(graph.addConstantInt(intLiteral.value, compiler)); 849 stack.add(graph.addConstantInt(intLiteral.value, closedWorld));
850 } 850 }
851 851
852 @override 852 @override
853 void visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) { 853 void visitDoubleLiteral(ir.DoubleLiteral doubleLiteral) {
854 stack.add(graph.addConstantDouble(doubleLiteral.value, compiler)); 854 stack.add(graph.addConstantDouble(doubleLiteral.value, closedWorld));
855 } 855 }
856 856
857 @override 857 @override
858 void visitBoolLiteral(ir.BoolLiteral boolLiteral) { 858 void visitBoolLiteral(ir.BoolLiteral boolLiteral) {
859 stack.add(graph.addConstantBool(boolLiteral.value, compiler)); 859 stack.add(graph.addConstantBool(boolLiteral.value, closedWorld));
860 } 860 }
861 861
862 @override 862 @override
863 void visitStringLiteral(ir.StringLiteral stringLiteral) { 863 void visitStringLiteral(ir.StringLiteral stringLiteral) {
864 stack.add(graph.addConstantString( 864 stack.add(graph.addConstantString(
865 new DartString.literal(stringLiteral.value), compiler)); 865 new DartString.literal(stringLiteral.value), closedWorld));
866 } 866 }
867 867
868 @override 868 @override
869 void visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) { 869 void visitSymbolLiteral(ir.SymbolLiteral symbolLiteral) {
870 stack.add(graph.addConstant( 870 stack.add(graph.addConstant(
871 astAdapter.getConstantForSymbol(symbolLiteral), compiler)); 871 astAdapter.getConstantForSymbol(symbolLiteral), closedWorld));
872 registry?.registerConstSymbol(symbolLiteral.value); 872 registry?.registerConstSymbol(symbolLiteral.value);
873 } 873 }
874 874
875 @override 875 @override
876 void visitNullLiteral(ir.NullLiteral nullLiteral) { 876 void visitNullLiteral(ir.NullLiteral nullLiteral) {
877 stack.add(graph.addConstantNull(compiler)); 877 stack.add(graph.addConstantNull(closedWorld));
878 } 878 }
879 879
880 /// Set the runtime type information if necessary. 880 /// Set the runtime type information if necessary.
881 HInstruction setListRuntimeTypeInfoIfNeeded( 881 HInstruction setListRuntimeTypeInfoIfNeeded(
882 HInstruction object, ir.ListLiteral listLiteral) { 882 HInstruction object, ir.ListLiteral listLiteral) {
883 InterfaceType type = localsHandler 883 InterfaceType type = localsHandler
884 .substInContext(astAdapter.getDartTypeOfListLiteral(listLiteral)); 884 .substInContext(astAdapter.getDartTypeOfListLiteral(listLiteral));
885 if (!backend.classNeedsRti(type.element) || type.treatAsRaw) { 885 if (!backend.classNeedsRti(type.element) || type.treatAsRaw) {
886 return object; 886 return object;
887 } 887 }
888 List<HInstruction> arguments = <HInstruction>[]; 888 List<HInstruction> arguments = <HInstruction>[];
889 for (DartType argument in type.typeArguments) { 889 for (DartType argument in type.typeArguments) {
890 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement)); 890 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement));
891 } 891 }
892 // TODO(15489): Register at codegen. 892 // TODO(15489): Register at codegen.
893 registry?.registerInstantiation(type); 893 registry?.registerInstantiation(type);
894 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object); 894 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object);
895 } 895 }
896 896
897 @override 897 @override
898 void visitListLiteral(ir.ListLiteral listLiteral) { 898 void visitListLiteral(ir.ListLiteral listLiteral) {
899 HInstruction listInstruction; 899 HInstruction listInstruction;
900 if (listLiteral.isConst) { 900 if (listLiteral.isConst) {
901 listInstruction = 901 listInstruction = graph.addConstant(
902 graph.addConstant(astAdapter.getConstantFor(listLiteral), compiler); 902 astAdapter.getConstantFor(listLiteral), closedWorld);
903 } else { 903 } else {
904 List<HInstruction> elements = <HInstruction>[]; 904 List<HInstruction> elements = <HInstruction>[];
905 for (ir.Expression element in listLiteral.expressions) { 905 for (ir.Expression element in listLiteral.expressions) {
906 element.accept(this); 906 element.accept(this);
907 elements.add(pop()); 907 elements.add(pop());
908 } 908 }
909 listInstruction = 909 listInstruction =
910 new HLiteralList(elements, commonMasks.extendableArrayType); 910 new HLiteralList(elements, commonMasks.extendableArrayType);
911 add(listInstruction); 911 add(listInstruction);
912 listInstruction = 912 listInstruction =
913 setListRuntimeTypeInfoIfNeeded(listInstruction, listLiteral); 913 setListRuntimeTypeInfoIfNeeded(listInstruction, listLiteral);
914 } 914 }
915 915
916 TypeMask type = 916 TypeMask type =
917 astAdapter.typeOfListLiteral(targetElement, listLiteral, closedWorld); 917 astAdapter.typeOfListLiteral(targetElement, listLiteral, closedWorld);
918 if (!type.containsAll(closedWorld)) { 918 if (!type.containsAll(closedWorld)) {
919 listInstruction.instructionType = type; 919 listInstruction.instructionType = type;
920 } 920 }
921 stack.add(listInstruction); 921 stack.add(listInstruction);
922 } 922 }
923 923
924 @override 924 @override
925 void visitMapLiteral(ir.MapLiteral mapLiteral) { 925 void visitMapLiteral(ir.MapLiteral mapLiteral) {
926 if (mapLiteral.isConst) { 926 if (mapLiteral.isConst) {
927 stack.add( 927 stack.add(graph.addConstant(
928 graph.addConstant(astAdapter.getConstantFor(mapLiteral), compiler)); 928 astAdapter.getConstantFor(mapLiteral), closedWorld));
929 return; 929 return;
930 } 930 }
931 931
932 // The map literal constructors take the key-value pairs as a List 932 // The map literal constructors take the key-value pairs as a List
933 List<HInstruction> constructorArgs = <HInstruction>[]; 933 List<HInstruction> constructorArgs = <HInstruction>[];
934 for (ir.MapEntry mapEntry in mapLiteral.entries) { 934 for (ir.MapEntry mapEntry in mapLiteral.entries) {
935 mapEntry.accept(this); 935 mapEntry.accept(this);
936 constructorArgs.add(pop()); 936 constructorArgs.add(pop());
937 constructorArgs.add(pop()); 937 constructorArgs.add(pop());
938 } 938 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 // stack, so when we pop them off, the key is popped first, then the value. 1003 // stack, so when we pop them off, the key is popped first, then the value.
1004 mapEntry.value.accept(this); 1004 mapEntry.value.accept(this);
1005 mapEntry.key.accept(this); 1005 mapEntry.key.accept(this);
1006 } 1006 }
1007 1007
1008 @override 1008 @override
1009 void visitTypeLiteral(ir.TypeLiteral typeLiteral) { 1009 void visitTypeLiteral(ir.TypeLiteral typeLiteral) {
1010 ir.DartType type = typeLiteral.type; 1010 ir.DartType type = typeLiteral.type;
1011 if (type is ir.InterfaceType) { 1011 if (type is ir.InterfaceType) {
1012 ConstantValue constant = astAdapter.getConstantForType(type); 1012 ConstantValue constant = astAdapter.getConstantForType(type);
1013 stack.add(graph.addConstant(constant, compiler)); 1013 stack.add(graph.addConstant(constant, closedWorld));
1014 return; 1014 return;
1015 } 1015 }
1016 if (type is ir.TypeParameterType) { 1016 if (type is ir.TypeParameterType) {
1017 // TODO(sra): Convert the type logic here to use ir.DartType. 1017 // TODO(sra): Convert the type logic here to use ir.DartType.
1018 DartType dartType = astAdapter.getDartType(type); 1018 DartType dartType = astAdapter.getDartType(type);
1019 dartType = localsHandler.substInContext(dartType); 1019 dartType = localsHandler.substInContext(dartType);
1020 HInstruction value = typeBuilder.analyzeTypeArgument( 1020 HInstruction value = typeBuilder.analyzeTypeArgument(
1021 dartType, sourceElement, 1021 dartType, sourceElement,
1022 sourceInformation: null); 1022 sourceInformation: null);
1023 _pushStaticInvocation(astAdapter.runtimeTypeToString, 1023 _pushStaticInvocation(astAdapter.runtimeTypeToString,
(...skipping 11 matching lines...) Expand all
1035 void visitStaticGet(ir.StaticGet staticGet) { 1035 void visitStaticGet(ir.StaticGet staticGet) {
1036 ir.Member staticTarget = staticGet.target; 1036 ir.Member staticTarget = staticGet.target;
1037 if (staticTarget is ir.Procedure && 1037 if (staticTarget is ir.Procedure &&
1038 staticTarget.kind == ir.ProcedureKind.Getter) { 1038 staticTarget.kind == ir.ProcedureKind.Getter) {
1039 // Invoke the getter 1039 // Invoke the getter
1040 _pushStaticInvocation(staticTarget, const <HInstruction>[], 1040 _pushStaticInvocation(staticTarget, const <HInstruction>[],
1041 astAdapter.returnTypeOf(staticTarget)); 1041 astAdapter.returnTypeOf(staticTarget));
1042 } else if (staticTarget is ir.Field && staticTarget.isConst) { 1042 } else if (staticTarget is ir.Field && staticTarget.isConst) {
1043 assert(staticTarget.initializer != null); 1043 assert(staticTarget.initializer != null);
1044 stack.add(graph.addConstant( 1044 stack.add(graph.addConstant(
1045 astAdapter.getConstantFor(staticTarget.initializer), compiler)); 1045 astAdapter.getConstantFor(staticTarget.initializer), closedWorld));
1046 } else { 1046 } else {
1047 if (_isLazyStatic(staticTarget)) { 1047 if (_isLazyStatic(staticTarget)) {
1048 push(new HLazyStatic(astAdapter.getField(staticTarget), 1048 push(new HLazyStatic(astAdapter.getField(staticTarget),
1049 astAdapter.inferredTypeOf(staticTarget))); 1049 astAdapter.inferredTypeOf(staticTarget)));
1050 } else { 1050 } else {
1051 push(new HStatic(astAdapter.getMember(staticTarget), 1051 push(new HStatic(astAdapter.getMember(staticTarget),
1052 astAdapter.inferredTypeOf(staticTarget))); 1052 astAdapter.inferredTypeOf(staticTarget)));
1053 } 1053 }
1054 } 1054 }
1055 } 1055 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 void visitVariableSet(ir.VariableSet variableSet) { 1120 void visitVariableSet(ir.VariableSet variableSet) {
1121 variableSet.value.accept(this); 1121 variableSet.value.accept(this);
1122 HInstruction value = pop(); 1122 HInstruction value = pop();
1123 _visitLocalSetter(variableSet.variable, value); 1123 _visitLocalSetter(variableSet.variable, value);
1124 } 1124 }
1125 1125
1126 @override 1126 @override
1127 void visitVariableDeclaration(ir.VariableDeclaration declaration) { 1127 void visitVariableDeclaration(ir.VariableDeclaration declaration) {
1128 Local local = astAdapter.getLocal(declaration); 1128 Local local = astAdapter.getLocal(declaration);
1129 if (declaration.initializer == null) { 1129 if (declaration.initializer == null) {
1130 HInstruction initialValue = graph.addConstantNull(compiler); 1130 HInstruction initialValue = graph.addConstantNull(closedWorld);
1131 localsHandler.updateLocal(local, initialValue); 1131 localsHandler.updateLocal(local, initialValue);
1132 } else { 1132 } else {
1133 declaration.initializer.accept(this); 1133 declaration.initializer.accept(this);
1134 HInstruction initialValue = pop(); 1134 HInstruction initialValue = pop();
1135 1135
1136 _visitLocalSetter(declaration, initialValue); 1136 _visitLocalSetter(declaration, initialValue);
1137 1137
1138 // Ignore value 1138 // Ignore value
1139 pop(); 1139 pop();
1140 } 1140 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 namedValues.remove(parameter.name); 1235 namedValues.remove(parameter.name);
1236 } 1236 }
1237 } 1237 }
1238 assert(namedValues.isEmpty); 1238 assert(namedValues.isEmpty);
1239 1239
1240 return values; 1240 return values;
1241 } 1241 }
1242 1242
1243 HInstruction _defaultValueForParameter(ir.VariableDeclaration parameter) { 1243 HInstruction _defaultValueForParameter(ir.VariableDeclaration parameter) {
1244 ir.Expression initializer = parameter.initializer; 1244 ir.Expression initializer = parameter.initializer;
1245 if (initializer == null) return graph.addConstantNull(compiler); 1245 if (initializer == null) return graph.addConstantNull(closedWorld);
1246 // TODO(sra): Evaluate constant in ir.Node domain. 1246 // TODO(sra): Evaluate constant in ir.Node domain.
1247 ConstantValue constant = 1247 ConstantValue constant =
1248 astAdapter.getConstantForParameterDefaultValue(initializer); 1248 astAdapter.getConstantForParameterDefaultValue(initializer);
1249 if (constant == null) return graph.addConstantNull(compiler); 1249 if (constant == null) return graph.addConstantNull(closedWorld);
1250 return graph.addConstant(constant, compiler); 1250 return graph.addConstant(constant, closedWorld);
1251 } 1251 }
1252 1252
1253 @override 1253 @override
1254 void visitStaticInvocation(ir.StaticInvocation invocation) { 1254 void visitStaticInvocation(ir.StaticInvocation invocation) {
1255 ir.Procedure target = invocation.target; 1255 ir.Procedure target = invocation.target;
1256 if (astAdapter.isInForeignLibrary(target)) { 1256 if (astAdapter.isInForeignLibrary(target)) {
1257 handleInvokeStaticForeign(invocation, target); 1257 handleInvokeStaticForeign(invocation, target);
1258 return; 1258 return;
1259 } 1259 }
1260 TypeMask typeMask = astAdapter.returnTypeOf(target); 1260 TypeMask typeMask = astAdapter.returnTypeOf(target);
(...skipping 25 matching lines...) Expand all
1286 handleForeignJsGetStaticState(invocation); 1286 handleForeignJsGetStaticState(invocation);
1287 } else if (name == 'JS_GET_NAME') { 1287 } else if (name == 'JS_GET_NAME') {
1288 handleForeignJsGetName(invocation); 1288 handleForeignJsGetName(invocation);
1289 } else if (name == 'JS_EMBEDDED_GLOBAL') { 1289 } else if (name == 'JS_EMBEDDED_GLOBAL') {
1290 handleForeignJsEmbeddedGlobal(invocation); 1290 handleForeignJsEmbeddedGlobal(invocation);
1291 } else if (name == 'JS_BUILTIN') { 1291 } else if (name == 'JS_BUILTIN') {
1292 handleForeignJsBuiltin(invocation); 1292 handleForeignJsBuiltin(invocation);
1293 } else if (name == 'JS_GET_FLAG') { 1293 } else if (name == 'JS_GET_FLAG') {
1294 handleForeignJsGetFlag(invocation); 1294 handleForeignJsGetFlag(invocation);
1295 } else if (name == 'JS_EFFECT') { 1295 } else if (name == 'JS_EFFECT') {
1296 stack.add(graph.addConstantNull(compiler)); 1296 stack.add(graph.addConstantNull(closedWorld));
1297 } else if (name == 'JS_INTERCEPTOR_CONSTANT') { 1297 } else if (name == 'JS_INTERCEPTOR_CONSTANT') {
1298 handleJsInterceptorConstant(invocation); 1298 handleJsInterceptorConstant(invocation);
1299 } else if (name == 'JS_STRING_CONCAT') { 1299 } else if (name == 'JS_STRING_CONCAT') {
1300 handleJsStringConcat(invocation); 1300 handleJsStringConcat(invocation);
1301 } else { 1301 } else {
1302 compiler.reporter.internalError( 1302 compiler.reporter.internalError(
1303 astAdapter.getNode(invocation), "Unknown foreign: ${name}"); 1303 astAdapter.getNode(invocation), "Unknown foreign: ${name}");
1304 } 1304 }
1305 } 1305 }
1306 1306
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 return null; 1372 return null;
1373 } 1373 }
1374 1374
1375 HConstant hConstant = instruction; 1375 HConstant hConstant = instruction;
1376 StringConstantValue stringConstant = hConstant.constant; 1376 StringConstantValue stringConstant = hConstant.constant;
1377 return stringConstant.primitiveValue.slowToString(); 1377 return stringConstant.primitiveValue.slowToString();
1378 } 1378 }
1379 1379
1380 void handleForeignJsCurrentIsolateContext(ir.StaticInvocation invocation) { 1380 void handleForeignJsCurrentIsolateContext(ir.StaticInvocation invocation) {
1381 if (_unexpectedForeignArguments(invocation, 0, 0)) { 1381 if (_unexpectedForeignArguments(invocation, 0, 0)) {
1382 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1382 // Result expected on stack.
1383 stack.add(graph.addConstantNull(closedWorld));
1383 return; 1384 return;
1384 } 1385 }
1385 1386
1386 if (!backend.hasIsolateSupport) { 1387 if (!backend.hasIsolateSupport) {
1387 // If the isolate library is not used, we just generate code 1388 // If the isolate library is not used, we just generate code
1388 // to fetch the static state. 1389 // to fetch the static state.
1389 String name = backend.namer.staticStateHolder; 1390 String name = backend.namer.staticStateHolder;
1390 push(new HForeignCode( 1391 push(new HForeignCode(
1391 js.js.parseForeignJS(name), commonMasks.dynamicType, <HInstruction>[], 1392 js.js.parseForeignJS(name), commonMasks.dynamicType, <HInstruction>[],
1392 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER)); 1393 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER));
1393 } else { 1394 } else {
1394 // Call a helper method from the isolate library. The isolate library uses 1395 // Call a helper method from the isolate library. The isolate library uses
1395 // its own isolate structure that encapsulates the isolate structure used 1396 // its own isolate structure that encapsulates the isolate structure used
1396 // for binding to methods. 1397 // for binding to methods.
1397 ir.Procedure target = astAdapter.currentIsolate; 1398 ir.Procedure target = astAdapter.currentIsolate;
1398 if (target == null) { 1399 if (target == null) {
1399 compiler.reporter.internalError(astAdapter.getNode(invocation), 1400 compiler.reporter.internalError(astAdapter.getNode(invocation),
1400 'Isolate library and compiler mismatch.'); 1401 'Isolate library and compiler mismatch.');
1401 } 1402 }
1402 _pushStaticInvocation(target, <HInstruction>[], commonMasks.dynamicType); 1403 _pushStaticInvocation(target, <HInstruction>[], commonMasks.dynamicType);
1403 } 1404 }
1404 } 1405 }
1405 1406
1406 void handleForeignJsCallInIsolate(ir.StaticInvocation invocation) { 1407 void handleForeignJsCallInIsolate(ir.StaticInvocation invocation) {
1407 if (_unexpectedForeignArguments(invocation, 2, 2)) { 1408 if (_unexpectedForeignArguments(invocation, 2, 2)) {
1408 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1409 // Result expected on stack.
1410 stack.add(graph.addConstantNull(closedWorld));
1409 return; 1411 return;
1410 } 1412 }
1411 1413
1412 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments); 1414 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments);
1413 1415
1414 if (!backend.hasIsolateSupport) { 1416 if (!backend.hasIsolateSupport) {
1415 // If the isolate library is not used, we ignore the isolate argument and 1417 // If the isolate library is not used, we ignore the isolate argument and
1416 // just invoke the closure. 1418 // just invoke the closure.
1417 push(new HInvokeClosure(new Selector.callClosure(0), 1419 push(new HInvokeClosure(new Selector.callClosure(0),
1418 <HInstruction>[inputs[1]], commonMasks.dynamicType)); 1420 <HInstruction>[inputs[1]], commonMasks.dynamicType));
(...skipping 11 matching lines...) Expand all
1430 void handleForeignDartClosureToJs( 1432 void handleForeignDartClosureToJs(
1431 ir.StaticInvocation invocation, String name) { 1433 ir.StaticInvocation invocation, String name) {
1432 // TODO(sra): Do we need to wrap the closure in something that saves the 1434 // TODO(sra): Do we need to wrap the closure in something that saves the
1433 // current isolate? 1435 // current isolate?
1434 handleForeignRawFunctionRef(invocation, name); 1436 handleForeignRawFunctionRef(invocation, name);
1435 } 1437 }
1436 1438
1437 void handleForeignRawFunctionRef( 1439 void handleForeignRawFunctionRef(
1438 ir.StaticInvocation invocation, String name) { 1440 ir.StaticInvocation invocation, String name) {
1439 if (_unexpectedForeignArguments(invocation, 1, 1)) { 1441 if (_unexpectedForeignArguments(invocation, 1, 1)) {
1440 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1442 // Result expected on stack.
1443 stack.add(graph.addConstantNull(closedWorld));
1441 return; 1444 return;
1442 } 1445 }
1443 1446
1444 ir.Expression closure = invocation.arguments.positional.single; 1447 ir.Expression closure = invocation.arguments.positional.single;
1445 String problem = 'requires a static method or top-level method'; 1448 String problem = 'requires a static method or top-level method';
1446 if (closure is ir.StaticGet) { 1449 if (closure is ir.StaticGet) {
1447 ir.Member staticTarget = closure.target; 1450 ir.Member staticTarget = closure.target;
1448 if (staticTarget is ir.Procedure) { 1451 if (staticTarget is ir.Procedure) {
1449 if (staticTarget.kind == ir.ProcedureKind.Method) { 1452 if (staticTarget.kind == ir.ProcedureKind.Method) {
1450 ir.FunctionNode function = staticTarget.function; 1453 ir.FunctionNode function = staticTarget.function;
(...skipping 11 matching lines...) Expand all
1462 nativeBehavior: native.NativeBehavior.PURE)); 1465 nativeBehavior: native.NativeBehavior.PURE));
1463 return; 1466 return;
1464 } 1467 }
1465 problem = 'does not handle a closure with optional parameters'; 1468 problem = 'does not handle a closure with optional parameters';
1466 } 1469 }
1467 } 1470 }
1468 } 1471 }
1469 1472
1470 compiler.reporter.reportErrorMessage(astAdapter.getNode(invocation), 1473 compiler.reporter.reportErrorMessage(astAdapter.getNode(invocation),
1471 MessageKind.GENERIC, {'text': "'$name' $problem."}); 1474 MessageKind.GENERIC, {'text': "'$name' $problem."});
1472 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1475 stack.add(graph.addConstantNull(closedWorld)); // Result expected on stack.
1473 return; 1476 return;
1474 } 1477 }
1475 1478
1476 void handleForeignJsSetStaticState(ir.StaticInvocation invocation) { 1479 void handleForeignJsSetStaticState(ir.StaticInvocation invocation) {
1477 if (_unexpectedForeignArguments(invocation, 1, 1)) { 1480 if (_unexpectedForeignArguments(invocation, 1, 1)) {
1478 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1481 // Result expected on stack.
1482 stack.add(graph.addConstantNull(closedWorld));
1479 return; 1483 return;
1480 } 1484 }
1481 1485
1482 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments); 1486 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments);
1483 1487
1484 String isolateName = backend.namer.staticStateHolder; 1488 String isolateName = backend.namer.staticStateHolder;
1485 SideEffects sideEffects = new SideEffects.empty(); 1489 SideEffects sideEffects = new SideEffects.empty();
1486 sideEffects.setAllSideEffects(); 1490 sideEffects.setAllSideEffects();
1487 push(new HForeignCode(js.js.parseForeignJS("$isolateName = #"), 1491 push(new HForeignCode(js.js.parseForeignJS("$isolateName = #"),
1488 commonMasks.dynamicType, inputs, 1492 commonMasks.dynamicType, inputs,
1489 nativeBehavior: native.NativeBehavior.CHANGES_OTHER, 1493 nativeBehavior: native.NativeBehavior.CHANGES_OTHER,
1490 effects: sideEffects)); 1494 effects: sideEffects));
1491 } 1495 }
1492 1496
1493 void handleForeignJsGetStaticState(ir.StaticInvocation invocation) { 1497 void handleForeignJsGetStaticState(ir.StaticInvocation invocation) {
1494 if (_unexpectedForeignArguments(invocation, 0, 0)) { 1498 if (_unexpectedForeignArguments(invocation, 0, 0)) {
1495 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1499 // Result expected on stack.
1500 stack.add(graph.addConstantNull(closedWorld));
1496 return; 1501 return;
1497 } 1502 }
1498 1503
1499 push(new HForeignCode(js.js.parseForeignJS(backend.namer.staticStateHolder), 1504 push(new HForeignCode(js.js.parseForeignJS(backend.namer.staticStateHolder),
1500 commonMasks.dynamicType, <HInstruction>[], 1505 commonMasks.dynamicType, <HInstruction>[],
1501 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER)); 1506 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER));
1502 } 1507 }
1503 1508
1504 void handleForeignJsGetName(ir.StaticInvocation invocation) { 1509 void handleForeignJsGetName(ir.StaticInvocation invocation) {
1505 if (_unexpectedForeignArguments(invocation, 1, 1)) { 1510 if (_unexpectedForeignArguments(invocation, 1, 1)) {
1506 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1511 // Result expected on stack.
1512 stack.add(graph.addConstantNull(closedWorld));
1507 return; 1513 return;
1508 } 1514 }
1509 1515
1510 ir.Node argument = invocation.arguments.positional.first; 1516 ir.Node argument = invocation.arguments.positional.first;
1511 argument.accept(this); 1517 argument.accept(this);
1512 HInstruction instruction = pop(); 1518 HInstruction instruction = pop();
1513 1519
1514 if (instruction is HConstant) { 1520 if (instruction is HConstant) {
1515 js.Name name = 1521 js.Name name =
1516 astAdapter.getNameForJsGetName(argument, instruction.constant); 1522 astAdapter.getNameForJsGetName(argument, instruction.constant);
1517 stack.add(graph.addConstantStringFromName(name, compiler)); 1523 stack.add(graph.addConstantStringFromName(name, closedWorld));
1518 return; 1524 return;
1519 } 1525 }
1520 1526
1521 compiler.reporter.reportErrorMessage( 1527 compiler.reporter.reportErrorMessage(
1522 astAdapter.getNode(argument), 1528 astAdapter.getNode(argument),
1523 MessageKind.GENERIC, 1529 MessageKind.GENERIC,
1524 {'text': 'Error: Expected a JsGetName enum value.'}); 1530 {'text': 'Error: Expected a JsGetName enum value.'});
1525 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1531 // Result expected on stack.
1532 stack.add(graph.addConstantNull(closedWorld));
1526 } 1533 }
1527 1534
1528 void handleForeignJsEmbeddedGlobal(ir.StaticInvocation invocation) { 1535 void handleForeignJsEmbeddedGlobal(ir.StaticInvocation invocation) {
1529 if (_unexpectedForeignArguments(invocation, 2, 2)) { 1536 if (_unexpectedForeignArguments(invocation, 2, 2)) {
1530 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1537 // Result expected on stack.
1538 stack.add(graph.addConstantNull(closedWorld));
1531 return; 1539 return;
1532 } 1540 }
1533 String globalName = _foreignConstantStringArgument( 1541 String globalName = _foreignConstantStringArgument(
1534 invocation, 1, 'JS_EMBEDDED_GLOBAL', 'second '); 1542 invocation, 1, 'JS_EMBEDDED_GLOBAL', 'second ');
1535 js.Template expr = js.js.expressionTemplateYielding( 1543 js.Template expr = js.js.expressionTemplateYielding(
1536 backend.emitter.generateEmbeddedGlobalAccess(globalName)); 1544 backend.emitter.generateEmbeddedGlobalAccess(globalName));
1537 1545
1538 native.NativeBehavior nativeBehavior = 1546 native.NativeBehavior nativeBehavior =
1539 astAdapter.getNativeBehavior(invocation); 1547 astAdapter.getNativeBehavior(invocation);
1540 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null, 1548 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null,
1541 message: "No NativeBehavior for $invocation")); 1549 message: "No NativeBehavior for $invocation"));
1542 1550
1543 TypeMask ssaType = 1551 TypeMask ssaType =
1544 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld); 1552 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld);
1545 push(new HForeignCode(expr, ssaType, const <HInstruction>[], 1553 push(new HForeignCode(expr, ssaType, const <HInstruction>[],
1546 nativeBehavior: nativeBehavior)); 1554 nativeBehavior: nativeBehavior));
1547 } 1555 }
1548 1556
1549 void handleForeignJsBuiltin(ir.StaticInvocation invocation) { 1557 void handleForeignJsBuiltin(ir.StaticInvocation invocation) {
1550 if (_unexpectedForeignArguments(invocation, 2)) { 1558 if (_unexpectedForeignArguments(invocation, 2)) {
1551 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1559 // Result expected on stack.
1560 stack.add(graph.addConstantNull(closedWorld));
1552 return; 1561 return;
1553 } 1562 }
1554 1563
1555 List<ir.Expression> arguments = invocation.arguments.positional; 1564 List<ir.Expression> arguments = invocation.arguments.positional;
1556 ir.Expression nameArgument = arguments[1]; 1565 ir.Expression nameArgument = arguments[1];
1557 1566
1558 nameArgument.accept(this); 1567 nameArgument.accept(this);
1559 HInstruction instruction = pop(); 1568 HInstruction instruction = pop();
1560 1569
1561 js.Template template; 1570 js.Template template;
1562 if (instruction is HConstant) { 1571 if (instruction is HConstant) {
1563 template = astAdapter.getJsBuiltinTemplate(instruction.constant); 1572 template = astAdapter.getJsBuiltinTemplate(instruction.constant);
1564 } 1573 }
1565 if (template == null) { 1574 if (template == null) {
1566 compiler.reporter.reportErrorMessage( 1575 compiler.reporter.reportErrorMessage(
1567 astAdapter.getNode(nameArgument), 1576 astAdapter.getNode(nameArgument),
1568 MessageKind.GENERIC, 1577 MessageKind.GENERIC,
1569 {'text': 'Error: Expected a JsBuiltin enum value.'}); 1578 {'text': 'Error: Expected a JsBuiltin enum value.'});
1570 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1579 // Result expected on stack.
1580 stack.add(graph.addConstantNull(closedWorld));
1571 return; 1581 return;
1572 } 1582 }
1573 1583
1574 List<HInstruction> inputs = <HInstruction>[]; 1584 List<HInstruction> inputs = <HInstruction>[];
1575 for (ir.Expression argument in arguments.skip(2)) { 1585 for (ir.Expression argument in arguments.skip(2)) {
1576 argument.accept(this); 1586 argument.accept(this);
1577 inputs.add(pop()); 1587 inputs.add(pop());
1578 } 1588 }
1579 1589
1580 native.NativeBehavior nativeBehavior = 1590 native.NativeBehavior nativeBehavior =
1581 astAdapter.getNativeBehavior(invocation); 1591 astAdapter.getNativeBehavior(invocation);
1582 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null, 1592 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null,
1583 message: "No NativeBehavior for $invocation")); 1593 message: "No NativeBehavior for $invocation"));
1584 1594
1585 TypeMask ssaType = 1595 TypeMask ssaType =
1586 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld); 1596 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld);
1587 push(new HForeignCode(template, ssaType, inputs, 1597 push(new HForeignCode(template, ssaType, inputs,
1588 nativeBehavior: nativeBehavior)); 1598 nativeBehavior: nativeBehavior));
1589 } 1599 }
1590 1600
1591 void handleForeignJsGetFlag(ir.StaticInvocation invocation) { 1601 void handleForeignJsGetFlag(ir.StaticInvocation invocation) {
1592 if (_unexpectedForeignArguments(invocation, 1, 1)) { 1602 if (_unexpectedForeignArguments(invocation, 1, 1)) {
1593 stack.add( 1603 stack.add(
1594 graph.addConstantBool(false, compiler)); // Result expected on stack. 1604 // Result expected on stack.
1605 graph.addConstantBool(false, closedWorld));
1595 return; 1606 return;
1596 } 1607 }
1597 String name = _foreignConstantStringArgument(invocation, 0, 'JS_GET_FLAG'); 1608 String name = _foreignConstantStringArgument(invocation, 0, 'JS_GET_FLAG');
1598 bool value = false; 1609 bool value = false;
1599 switch (name) { 1610 switch (name) {
1600 case 'MUST_RETAIN_METADATA': 1611 case 'MUST_RETAIN_METADATA':
1601 value = backend.mustRetainMetadata; 1612 value = backend.mustRetainMetadata;
1602 break; 1613 break;
1603 case 'USE_CONTENT_SECURITY_POLICY': 1614 case 'USE_CONTENT_SECURITY_POLICY':
1604 value = compiler.options.useContentSecurityPolicy; 1615 value = compiler.options.useContentSecurityPolicy;
1605 break; 1616 break;
1606 default: 1617 default:
1607 compiler.reporter.reportErrorMessage( 1618 compiler.reporter.reportErrorMessage(
1608 astAdapter.getNode(invocation), 1619 astAdapter.getNode(invocation),
1609 MessageKind.GENERIC, 1620 MessageKind.GENERIC,
1610 {'text': 'Error: Unknown internal flag "$name".'}); 1621 {'text': 'Error: Unknown internal flag "$name".'});
1611 } 1622 }
1612 stack.add(graph.addConstantBool(value, compiler)); 1623 stack.add(graph.addConstantBool(value, closedWorld));
1613 } 1624 }
1614 1625
1615 void handleJsInterceptorConstant(ir.StaticInvocation invocation) { 1626 void handleJsInterceptorConstant(ir.StaticInvocation invocation) {
1616 // Single argument must be a TypeConstant which is converted into a 1627 // Single argument must be a TypeConstant which is converted into a
1617 // InterceptorConstant. 1628 // InterceptorConstant.
1618 if (_unexpectedForeignArguments(invocation, 1, 1)) { 1629 if (_unexpectedForeignArguments(invocation, 1, 1)) {
1619 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1630 // Result expected on stack.
1631 stack.add(graph.addConstantNull(closedWorld));
1620 return; 1632 return;
1621 } 1633 }
1622 ir.Expression argument = invocation.arguments.positional.single; 1634 ir.Expression argument = invocation.arguments.positional.single;
1623 argument.accept(this); 1635 argument.accept(this);
1624 HInstruction argumentInstruction = pop(); 1636 HInstruction argumentInstruction = pop();
1625 if (argumentInstruction is HConstant) { 1637 if (argumentInstruction is HConstant) {
1626 ConstantValue argumentConstant = argumentInstruction.constant; 1638 ConstantValue argumentConstant = argumentInstruction.constant;
1627 if (argumentConstant is TypeConstantValue) { 1639 if (argumentConstant is TypeConstantValue) {
1628 // TODO(sra): Check that type is a subclass of [Interceptor]. 1640 // TODO(sra): Check that type is a subclass of [Interceptor].
1629 ConstantValue constant = 1641 ConstantValue constant =
1630 new InterceptorConstantValue(argumentConstant.representedType); 1642 new InterceptorConstantValue(argumentConstant.representedType);
1631 HInstruction instruction = graph.addConstant(constant, compiler); 1643 HInstruction instruction = graph.addConstant(constant, closedWorld);
1632 stack.add(instruction); 1644 stack.add(instruction);
1633 return; 1645 return;
1634 } 1646 }
1635 } 1647 }
1636 1648
1637 compiler.reporter.reportErrorMessage(astAdapter.getNode(invocation), 1649 compiler.reporter.reportErrorMessage(astAdapter.getNode(invocation),
1638 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); 1650 MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT);
1639 stack.add(graph.addConstantNull(compiler)); 1651 stack.add(graph.addConstantNull(closedWorld));
1640 } 1652 }
1641 1653
1642 void handleForeignJs(ir.StaticInvocation invocation) { 1654 void handleForeignJs(ir.StaticInvocation invocation) {
1643 if (_unexpectedForeignArguments(invocation, 2)) { 1655 if (_unexpectedForeignArguments(invocation, 2)) {
1644 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1656 // Result expected on stack.
1657 stack.add(graph.addConstantNull(closedWorld));
1645 return; 1658 return;
1646 } 1659 }
1647 1660
1648 native.NativeBehavior nativeBehavior = 1661 native.NativeBehavior nativeBehavior =
1649 astAdapter.getNativeBehaviorForJsCall(invocation); 1662 astAdapter.getNativeBehaviorForJsCall(invocation);
1650 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null, 1663 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null,
1651 message: "No NativeBehavior for $invocation")); 1664 message: "No NativeBehavior for $invocation"));
1652 1665
1653 List<HInstruction> inputs = <HInstruction>[]; 1666 List<HInstruction> inputs = <HInstruction>[];
1654 for (ir.Expression argument in invocation.arguments.positional.skip(2)) { 1667 for (ir.Expression argument in invocation.arguments.positional.skip(2)) {
1655 argument.accept(this); 1668 argument.accept(this);
1656 inputs.add(pop()); 1669 inputs.add(pop());
1657 } 1670 }
1658 1671
1659 if (nativeBehavior.codeTemplate.positionalArgumentCount != inputs.length) { 1672 if (nativeBehavior.codeTemplate.positionalArgumentCount != inputs.length) {
1660 compiler.reporter.reportErrorMessage( 1673 compiler.reporter.reportErrorMessage(
1661 astAdapter.getNode(invocation), MessageKind.GENERIC, { 1674 astAdapter.getNode(invocation), MessageKind.GENERIC, {
1662 'text': 'Mismatch between number of placeholders' 1675 'text': 'Mismatch between number of placeholders'
1663 ' and number of arguments.' 1676 ' and number of arguments.'
1664 }); 1677 });
1665 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1678 // Result expected on stack.
1679 stack.add(graph.addConstantNull(closedWorld));
1666 return; 1680 return;
1667 } 1681 }
1668 1682
1669 if (native.HasCapturedPlaceholders.check(nativeBehavior.codeTemplate.ast)) { 1683 if (native.HasCapturedPlaceholders.check(nativeBehavior.codeTemplate.ast)) {
1670 compiler.reporter.reportErrorMessage( 1684 compiler.reporter.reportErrorMessage(
1671 astAdapter.getNode(invocation), MessageKind.JS_PLACEHOLDER_CAPTURE); 1685 astAdapter.getNode(invocation), MessageKind.JS_PLACEHOLDER_CAPTURE);
1672 } 1686 }
1673 1687
1674 TypeMask ssaType = 1688 TypeMask ssaType =
1675 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld); 1689 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld);
1676 1690
1677 SourceInformation sourceInformation = null; 1691 SourceInformation sourceInformation = null;
1678 push(new HForeignCode(nativeBehavior.codeTemplate, ssaType, inputs, 1692 push(new HForeignCode(nativeBehavior.codeTemplate, ssaType, inputs,
1679 isStatement: !nativeBehavior.codeTemplate.isExpression, 1693 isStatement: !nativeBehavior.codeTemplate.isExpression,
1680 effects: nativeBehavior.sideEffects, 1694 effects: nativeBehavior.sideEffects,
1681 nativeBehavior: nativeBehavior)..sourceInformation = sourceInformation); 1695 nativeBehavior: nativeBehavior)..sourceInformation = sourceInformation);
1682 } 1696 }
1683 1697
1684 void handleJsStringConcat(ir.StaticInvocation invocation) { 1698 void handleJsStringConcat(ir.StaticInvocation invocation) {
1685 if (_unexpectedForeignArguments(invocation, 2, 2)) { 1699 if (_unexpectedForeignArguments(invocation, 2, 2)) {
1686 stack.add(graph.addConstantNull(compiler)); // Result expected on stack. 1700 // Result expected on stack.
1701 stack.add(graph.addConstantNull(closedWorld));
1687 return; 1702 return;
1688 } 1703 }
1689 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments); 1704 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments);
1690 push(new HStringConcat(inputs[0], inputs[1], commonMasks.stringType)); 1705 push(new HStringConcat(inputs[0], inputs[1], commonMasks.stringType));
1691 } 1706 }
1692 1707
1693 void _pushStaticInvocation( 1708 void _pushStaticInvocation(
1694 ir.Node target, List<HInstruction> arguments, TypeMask typeMask) { 1709 ir.Node target, List<HInstruction> arguments, TypeMask typeMask) {
1695 HInvokeStatic instruction = new HInvokeStatic( 1710 HInvokeStatic instruction = new HInvokeStatic(
1696 astAdapter.getMember(target), arguments, typeMask, 1711 astAdapter.getMember(target), arguments, typeMask,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 } 1889 }
1875 1890
1876 HInstruction buildIsNode( 1891 HInstruction buildIsNode(
1877 ir.Node node, ir.DartType dart_type, HInstruction expression) { 1892 ir.Node node, ir.DartType dart_type, HInstruction expression) {
1878 // TODO(sra): Convert the type testing logic here to use ir.DartType. 1893 // TODO(sra): Convert the type testing logic here to use ir.DartType.
1879 DartType type = astAdapter.getDartType(dart_type); 1894 DartType type = astAdapter.getDartType(dart_type);
1880 1895
1881 type = localsHandler.substInContext(type).unaliased; 1896 type = localsHandler.substInContext(type).unaliased;
1882 1897
1883 if (type is MethodTypeVariableType) { 1898 if (type is MethodTypeVariableType) {
1884 return graph.addConstantBool(true, compiler); 1899 return graph.addConstantBool(true, closedWorld);
1885 } 1900 }
1886 1901
1887 if (type is MalformedType) { 1902 if (type is MalformedType) {
1888 ErroneousElement element = type.element; 1903 ErroneousElement element = type.element;
1889 generateTypeError(node, element.message); 1904 generateTypeError(node, element.message);
1890 return new HIs.compound(type, expression, pop(), commonMasks.boolType); 1905 return new HIs.compound(type, expression, pop(), commonMasks.boolType);
1891 } 1906 }
1892 1907
1893 if (type.isFunctionType) { 1908 if (type.isFunctionType) {
1894 List arguments = <HInstruction>[buildFunctionType(type), expression]; 1909 List arguments = <HInstruction>[buildFunctionType(type), expression];
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 HInvokeStatic unwrappedException = kernelBuilder.pop(); 2146 HInvokeStatic unwrappedException = kernelBuilder.pop();
2132 tryInstruction.exception = exception; 2147 tryInstruction.exception = exception;
2133 int catchesIndex = 0; 2148 int catchesIndex = 0;
2134 2149
2135 void pushCondition(ir.Catch catchBlock) { 2150 void pushCondition(ir.Catch catchBlock) {
2136 if (catchBlock.guard is! ir.DynamicType) { 2151 if (catchBlock.guard is! ir.DynamicType) {
2137 HInstruction condition = kernelBuilder.buildIsNode( 2152 HInstruction condition = kernelBuilder.buildIsNode(
2138 catchBlock.exception, catchBlock.guard, unwrappedException); 2153 catchBlock.exception, catchBlock.guard, unwrappedException);
2139 kernelBuilder.push(condition); 2154 kernelBuilder.push(condition);
2140 } else { 2155 } else {
2141 kernelBuilder.stack.add( 2156 kernelBuilder.stack.add(kernelBuilder.graph
2142 kernelBuilder.graph.addConstantBool(true, kernelBuilder.compiler)); 2157 .addConstantBool(true, kernelBuilder.closedWorld));
2143 } 2158 }
2144 } 2159 }
2145 2160
2146 void visitThen() { 2161 void visitThen() {
2147 ir.Catch catchBlock = tryCatch.catches[catchesIndex]; 2162 ir.Catch catchBlock = tryCatch.catches[catchesIndex];
2148 catchesIndex++; 2163 catchesIndex++;
2149 if (catchBlock.exception != null) { 2164 if (catchBlock.exception != null) {
2150 LocalVariableElement exceptionVariable = 2165 LocalVariableElement exceptionVariable =
2151 kernelBuilder.astAdapter.getElement(catchBlock.exception); 2166 kernelBuilder.astAdapter.getElement(catchBlock.exception);
2152 kernelBuilder.localsHandler 2167 kernelBuilder.localsHandler
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 kernelBuilder.open(exitBlock); 2226 kernelBuilder.open(exitBlock);
2212 enterBlock.setBlockFlow( 2227 enterBlock.setBlockFlow(
2213 new HTryBlockInformation( 2228 new HTryBlockInformation(
2214 kernelBuilder.wrapStatementGraph(bodyGraph), 2229 kernelBuilder.wrapStatementGraph(bodyGraph),
2215 exception, 2230 exception,
2216 kernelBuilder.wrapStatementGraph(catchGraph), 2231 kernelBuilder.wrapStatementGraph(catchGraph),
2217 kernelBuilder.wrapStatementGraph(finallyGraph)), 2232 kernelBuilder.wrapStatementGraph(finallyGraph)),
2218 exitBlock); 2233 exitBlock);
2219 } 2234 }
2220 } 2235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698