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

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

Issue 2864363002: Remove DartString from constants. (Closed)
Patch Set: Remove toDartString Created 3 years, 7 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:collection'; 5 import 'dart:collection';
6 6
7 import 'package:js_runtime/shared/embedded_names.dart'; 7 import 'package:js_runtime/shared/embedded_names.dart';
8 8
9 import '../closure.dart'; 9 import '../closure.dart';
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 <HInstruction>[idConstant, nameConstant], commonMasks.dynamicType)); 1463 <HInstruction>[idConstant, nameConstant], commonMasks.dynamicType));
1464 } 1464 }
1465 } 1465 }
1466 1466
1467 void assertIsSubtype(ast.Node node, ResolutionDartType subtype, 1467 void assertIsSubtype(ast.Node node, ResolutionDartType subtype,
1468 ResolutionDartType supertype, String message) { 1468 ResolutionDartType supertype, String message) {
1469 HInstruction subtypeInstruction = typeBuilder.analyzeTypeArgument( 1469 HInstruction subtypeInstruction = typeBuilder.analyzeTypeArgument(
1470 localsHandler.substInContext(subtype), sourceElement); 1470 localsHandler.substInContext(subtype), sourceElement);
1471 HInstruction supertypeInstruction = typeBuilder.analyzeTypeArgument( 1471 HInstruction supertypeInstruction = typeBuilder.analyzeTypeArgument(
1472 localsHandler.substInContext(supertype), sourceElement); 1472 localsHandler.substInContext(supertype), sourceElement);
1473 HInstruction messageInstruction = graph.addConstantString( 1473 HInstruction messageInstruction =
1474 new ast.DartString.literal(message), closedWorld); 1474 graph.addConstantString(message, closedWorld);
1475 MethodElement element = commonElements.assertIsSubtype; 1475 MethodElement element = commonElements.assertIsSubtype;
1476 var inputs = <HInstruction>[ 1476 var inputs = <HInstruction>[
1477 subtypeInstruction, 1477 subtypeInstruction,
1478 supertypeInstruction, 1478 supertypeInstruction,
1479 messageInstruction 1479 messageInstruction
1480 ]; 1480 ];
1481 HInstruction assertIsSubtype = 1481 HInstruction assertIsSubtype =
1482 new HInvokeStatic(element, inputs, subtypeInstruction.instructionType); 1482 new HInvokeStatic(element, inputs, subtypeInstruction.instructionType);
1483 registry?.registerTypeVariableBoundsSubtypeCheck(subtype, supertype); 1483 registry?.registerTypeVariableBoundsSubtypeCheck(subtype, supertype);
1484 add(assertIsSubtype); 1484 add(assertIsSubtype);
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
2813 HInstruction globalNameHNode = pop(); 2813 HInstruction globalNameHNode = pop();
2814 if (!globalNameHNode.isConstantString()) { 2814 if (!globalNameHNode.isConstantString()) {
2815 reporter.reportErrorMessage(arguments[1], MessageKind.GENERIC, { 2815 reporter.reportErrorMessage(arguments[1], MessageKind.GENERIC, {
2816 'text': 'Error: Expected String as second argument ' 2816 'text': 'Error: Expected String as second argument '
2817 'to JS_EMBEDDED_GLOBAL.' 2817 'to JS_EMBEDDED_GLOBAL.'
2818 }); 2818 });
2819 return; 2819 return;
2820 } 2820 }
2821 HConstant hConstant = globalNameHNode; 2821 HConstant hConstant = globalNameHNode;
2822 StringConstantValue constant = hConstant.constant; 2822 StringConstantValue constant = hConstant.constant;
2823 String globalName = constant.primitiveValue.slowToString(); 2823 String globalName = constant.primitiveValue;
2824 js.Template expr = js.js.expressionTemplateYielding( 2824 js.Template expr = js.js.expressionTemplateYielding(
2825 emitter.generateEmbeddedGlobalAccess(globalName)); 2825 emitter.generateEmbeddedGlobalAccess(globalName));
2826 native.NativeBehavior nativeBehavior = elements.getNativeData(node); 2826 native.NativeBehavior nativeBehavior = elements.getNativeData(node);
2827 assert(invariant(node, nativeBehavior != null, 2827 assert(invariant(node, nativeBehavior != null,
2828 message: "No NativeBehavior for $node")); 2828 message: "No NativeBehavior for $node"));
2829 TypeMask ssaType = 2829 TypeMask ssaType =
2830 TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); 2830 TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld);
2831 push(new HForeignCode(expr, ssaType, const [], 2831 push(new HForeignCode(expr, ssaType, const [],
2832 nativeBehavior: nativeBehavior)); 2832 nativeBehavior: nativeBehavior));
2833 } 2833 }
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2975 } 2975 }
2976 } 2976 }
2977 2977
2978 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader, 2978 generateDeferredLoaderGet(ast.Send node, FunctionElement deferredLoader,
2979 SourceInformation sourceInformation) { 2979 SourceInformation sourceInformation) {
2980 // Until now we only handle these as getters. 2980 // Until now we only handle these as getters.
2981 invariant(node, deferredLoader.isDeferredLoaderGetter); 2981 invariant(node, deferredLoader.isDeferredLoaderGetter);
2982 FunctionEntity loadFunction = commonElements.loadLibraryWrapper; 2982 FunctionEntity loadFunction = commonElements.loadLibraryWrapper;
2983 PrefixElement prefixElement = deferredLoader.enclosingElement; 2983 PrefixElement prefixElement = deferredLoader.enclosingElement;
2984 String loadId = deferredLoadTask.getImportDeferName(node, prefixElement); 2984 String loadId = deferredLoadTask.getImportDeferName(node, prefixElement);
2985 var inputs = [ 2985 var inputs = [graph.addConstantString(loadId, closedWorld)];
2986 graph.addConstantString(new ast.DartString.literal(loadId), closedWorld)
2987 ];
2988 push(new HInvokeStatic(loadFunction, inputs, commonMasks.nonNullType, 2986 push(new HInvokeStatic(loadFunction, inputs, commonMasks.nonNullType,
2989 targetCanThrow: false) 2987 targetCanThrow: false)
2990 ..sourceInformation = sourceInformation); 2988 ..sourceInformation = sourceInformation);
2991 } 2989 }
2992 2990
2993 generateSuperNoSuchMethodSend( 2991 generateSuperNoSuchMethodSend(
2994 ast.Send node, Selector selector, List<HInstruction> arguments) { 2992 ast.Send node, Selector selector, List<HInstruction> arguments) {
2995 String name = selector.name; 2993 String name = selector.name;
2996 2994
2997 ClassElement cls = currentNonClosureClass; 2995 ClassElement cls = currentNonClosureClass;
2998 MethodElement element = cls.lookupSuperMember(Identifiers.noSuchMethod_); 2996 MethodElement element = cls.lookupSuperMember(Identifiers.noSuchMethod_);
2999 if (!Selectors.noSuchMethod_.signatureApplies(element)) { 2997 if (!Selectors.noSuchMethod_.signatureApplies(element)) {
3000 ClassElement objectClass = commonElements.objectClass; 2998 ClassElement objectClass = commonElements.objectClass;
3001 element = objectClass.lookupMember(Identifiers.noSuchMethod_); 2999 element = objectClass.lookupMember(Identifiers.noSuchMethod_);
3002 } 3000 }
3003 if (backendUsage.isInvokeOnUsed && !element.enclosingClass.isObject) { 3001 if (backendUsage.isInvokeOnUsed && !element.enclosingClass.isObject) {
3004 // Register the call as dynamic if [noSuchMethod] on the super 3002 // Register the call as dynamic if [noSuchMethod] on the super
3005 // class is _not_ the default implementation from [Object], in 3003 // class is _not_ the default implementation from [Object], in
3006 // case the [noSuchMethod] implementation calls 3004 // case the [noSuchMethod] implementation calls
3007 // [JSInvocationMirror._invokeOn]. 3005 // [JSInvocationMirror._invokeOn].
3008 // TODO(johnniwinther): Register this more precisely. 3006 // TODO(johnniwinther): Register this more precisely.
3009 registry?.registerDynamicUse(new DynamicUse(selector, null)); 3007 registry?.registerDynamicUse(new DynamicUse(selector, null));
3010 } 3008 }
3011 String publicName = name; 3009 String publicName = name;
3012 if (selector.isSetter) publicName += '='; 3010 if (selector.isSetter) publicName += '=';
3013 3011
3014 ConstantValue nameConstant = 3012 ConstantValue nameConstant = constantSystem.createString(publicName);
3015 constantSystem.createString(new ast.DartString.literal(publicName));
3016 3013
3017 js.Name internalName = namer.invocationName(selector); 3014 js.Name internalName = namer.invocationName(selector);
3018 3015
3019 MethodElement createInvocationMirror = 3016 MethodElement createInvocationMirror =
3020 commonElements.createInvocationMirror; 3017 commonElements.createInvocationMirror;
3021 var argumentsInstruction = buildLiteralList(arguments); 3018 var argumentsInstruction = buildLiteralList(arguments);
3022 add(argumentsInstruction); 3019 add(argumentsInstruction);
3023 3020
3024 var argumentNames = new List<HInstruction>(); 3021 var argumentNames = new List<HInstruction>();
3025 for (String argumentName in selector.namedArguments) { 3022 for (String argumentName in selector.namedArguments) {
3026 ConstantValue argumentNameConstant = 3023 ConstantValue argumentNameConstant =
3027 constantSystem.createString(new ast.DartString.literal(argumentName)); 3024 constantSystem.createString(argumentName);
3028 argumentNames.add(graph.addConstant(argumentNameConstant, closedWorld)); 3025 argumentNames.add(graph.addConstant(argumentNameConstant, closedWorld));
3029 } 3026 }
3030 var argumentNamesInstruction = buildLiteralList(argumentNames); 3027 var argumentNamesInstruction = buildLiteralList(argumentNames);
3031 add(argumentNamesInstruction); 3028 add(argumentNamesInstruction);
3032 3029
3033 ConstantValue kindConstant = 3030 ConstantValue kindConstant =
3034 constantSystem.createInt(selector.invocationMirrorKind); 3031 constantSystem.createInt(selector.invocationMirrorKind);
3035 3032
3036 pushInvokeStatic( 3033 pushInvokeStatic(
3037 null, 3034 null,
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
3674 // resolved (a warning has been issued). 3671 // resolved (a warning has been issued).
3675 handleInvalidStaticInvoke(node, element); 3672 handleInvalidStaticInvoke(node, element);
3676 } else { 3673 } else {
3677 // TODO(ahe): Do something like [generateWrongArgumentCountError]. 3674 // TODO(ahe): Do something like [generateWrongArgumentCountError].
3678 stack.add(graph.addConstantNull(closedWorld)); 3675 stack.add(graph.addConstantNull(closedWorld));
3679 } 3676 }
3680 return; 3677 return;
3681 } 3678 }
3682 3679
3683 HConstant addConstantString(String string) { 3680 HConstant addConstantString(String string) {
3684 ast.DartString dartString = new ast.DartString.literal(string); 3681 return graph.addConstantString(string, closedWorld);
3685 return graph.addConstantString(dartString, closedWorld);
3686 } 3682 }
3687 3683
3688 HConstant addConstantStringFromName(js.Name name) { 3684 HConstant addConstantStringFromName(js.Name name) {
3689 return graph.addConstantStringFromName(name, closedWorld); 3685 return graph.addConstantStringFromName(name, closedWorld);
3690 } 3686 }
3691 3687
3692 visitClassTypeLiteralGet(ast.Send node, ConstantExpression constant, _) { 3688 visitClassTypeLiteralGet(ast.Send node, ConstantExpression constant, _) {
3693 generateConstantTypeLiteral(node); 3689 generateConstantTypeLiteral(node);
3694 } 3690 }
3695 3691
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3810 MethodElement helper = commonElements.throwAbstractClassInstantiationError; 3806 MethodElement helper = commonElements.throwAbstractClassInstantiationError;
3811 generateError(node, message, helper); 3807 generateError(node, message, helper);
3812 } 3808 }
3813 3809
3814 void generateThrowNoSuchMethod(ast.Node diagnosticNode, String methodName, 3810 void generateThrowNoSuchMethod(ast.Node diagnosticNode, String methodName,
3815 {Link<ast.Node> argumentNodes, 3811 {Link<ast.Node> argumentNodes,
3816 List<HInstruction> argumentValues, 3812 List<HInstruction> argumentValues,
3817 List<String> existingArguments, 3813 List<String> existingArguments,
3818 SourceInformation sourceInformation}) { 3814 SourceInformation sourceInformation}) {
3819 MethodElement helper = commonElements.throwNoSuchMethod; 3815 MethodElement helper = commonElements.throwNoSuchMethod;
3820 ConstantValue receiverConstant = 3816 ConstantValue receiverConstant = constantSystem.createString('');
3821 constantSystem.createString(new ast.DartString.empty());
3822 HInstruction receiver = graph.addConstant(receiverConstant, closedWorld); 3817 HInstruction receiver = graph.addConstant(receiverConstant, closedWorld);
3823 ast.DartString dartString = new ast.DartString.literal(methodName); 3818 ConstantValue nameConstant = constantSystem.createString(methodName);
3824 ConstantValue nameConstant = constantSystem.createString(dartString);
3825 HInstruction name = graph.addConstant(nameConstant, closedWorld); 3819 HInstruction name = graph.addConstant(nameConstant, closedWorld);
3826 if (argumentValues == null) { 3820 if (argumentValues == null) {
3827 argumentValues = <HInstruction>[]; 3821 argumentValues = <HInstruction>[];
3828 argumentNodes.forEach((argumentNode) { 3822 argumentNodes.forEach((argumentNode) {
3829 visit(argumentNode); 3823 visit(argumentNode);
3830 HInstruction value = pop(); 3824 HInstruction value = pop();
3831 argumentValues.add(value); 3825 argumentValues.add(value);
3832 }); 3826 });
3833 } 3827 }
3834 HInstruction arguments = buildLiteralList(argumentValues); 3828 HInstruction arguments = buildLiteralList(argumentValues);
3835 add(arguments); 3829 add(arguments);
3836 HInstruction existingNamesList; 3830 HInstruction existingNamesList;
3837 if (existingArguments != null) { 3831 if (existingArguments != null) {
3838 List<HInstruction> existingNames = <HInstruction>[]; 3832 List<HInstruction> existingNames = <HInstruction>[];
3839 for (String name in existingArguments) { 3833 for (String name in existingArguments) {
3840 HInstruction nameConstant = graph.addConstantString( 3834 HInstruction nameConstant = graph.addConstantString(name, closedWorld);
3841 new ast.DartString.literal(name), closedWorld);
3842 existingNames.add(nameConstant); 3835 existingNames.add(nameConstant);
3843 } 3836 }
3844 existingNamesList = buildLiteralList(existingNames); 3837 existingNamesList = buildLiteralList(existingNames);
3845 add(existingNamesList); 3838 add(existingNamesList);
3846 } else { 3839 } else {
3847 existingNamesList = graph.addConstantNull(closedWorld); 3840 existingNamesList = graph.addConstantNull(closedWorld);
3848 } 3841 }
3849 pushInvokeStatic( 3842 pushInvokeStatic(
3850 diagnosticNode, helper, [receiver, name, arguments, existingNamesList], 3843 diagnosticNode, helper, [receiver, name, arguments, existingNamesList],
3851 sourceInformation: sourceInformation); 3844 sourceInformation: sourceInformation);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3894 generateRuntimeError(node.send, message.toString()); 3887 generateRuntimeError(node.send, message.toString());
3895 } 3888 }
3896 } else if (Elements.isMalformed(element)) { 3889 } else if (Elements.isMalformed(element)) {
3897 // TODO(ahe): Do something like [generateWrongArgumentCountError]. 3890 // TODO(ahe): Do something like [generateWrongArgumentCountError].
3898 stack.add(graph.addConstantNull(closedWorld)); 3891 stack.add(graph.addConstantNull(closedWorld));
3899 } else if (node.isConst) { 3892 } else if (node.isConst) {
3900 stack.add(addConstant(node)); 3893 stack.add(addConstant(node));
3901 if (isSymbolConstructor) { 3894 if (isSymbolConstructor) {
3902 ConstructedConstantValue symbol = getConstantForNode(node); 3895 ConstructedConstantValue symbol = getConstantForNode(node);
3903 StringConstantValue stringConstant = symbol.fields.values.single; 3896 StringConstantValue stringConstant = symbol.fields.values.single;
3904 String nameString = stringConstant.toDartString().slowToString(); 3897 String nameString = stringConstant.primitiveValue;
3905 registry?.registerConstSymbol(nameString); 3898 registry?.registerConstSymbol(nameString);
3906 } 3899 }
3907 } else { 3900 } else {
3908 handleNewSend(node); 3901 handleNewSend(node);
3909 } 3902 }
3910 } 3903 }
3911 3904
3912 @override 3905 @override
3913 void errorNonConstantConstructorInvoke( 3906 void errorNonConstantConstructorInvoke(
3914 ast.NewExpression node, 3907 ast.NewExpression node,
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
4928 4921
4929 void visitLiteralDouble(ast.LiteralDouble node) { 4922 void visitLiteralDouble(ast.LiteralDouble node) {
4930 stack.add(graph.addConstantDouble(node.value, closedWorld)); 4923 stack.add(graph.addConstantDouble(node.value, closedWorld));
4931 } 4924 }
4932 4925
4933 void visitLiteralBool(ast.LiteralBool node) { 4926 void visitLiteralBool(ast.LiteralBool node) {
4934 stack.add(graph.addConstantBool(node.value, closedWorld)); 4927 stack.add(graph.addConstantBool(node.value, closedWorld));
4935 } 4928 }
4936 4929
4937 void visitLiteralString(ast.LiteralString node) { 4930 void visitLiteralString(ast.LiteralString node) {
4938 stack.add(graph.addConstantString(node.dartString, closedWorld)); 4931 stack.add(
4932 graph.addConstantString(node.dartString.slowToString(), closedWorld));
4939 } 4933 }
4940 4934
4941 void visitLiteralSymbol(ast.LiteralSymbol node) { 4935 void visitLiteralSymbol(ast.LiteralSymbol node) {
4942 stack.add(addConstant(node)); 4936 stack.add(addConstant(node));
4943 registry?.registerConstSymbol(node.slowNameString); 4937 registry?.registerConstSymbol(node.slowNameString);
4944 } 4938 }
4945 4939
4946 void visitStringJuxtaposition(ast.StringJuxtaposition node) { 4940 void visitStringJuxtaposition(ast.StringJuxtaposition node) {
4947 if (!node.isInterpolation) { 4941 if (!node.isInterpolation) {
4948 // This is a simple string with no interpolations. 4942 // This is a simple string with no interpolations.
4949 stack.add(graph.addConstantString(node.dartString, closedWorld)); 4943 stack.add(
4944 graph.addConstantString(node.dartString.slowToString(), closedWorld));
4950 return; 4945 return;
4951 } 4946 }
4952 StringBuilderVisitor stringBuilder = new StringBuilderVisitor(this, node); 4947 StringBuilderVisitor stringBuilder = new StringBuilderVisitor(this, node);
4953 stringBuilder.visit(node); 4948 stringBuilder.visit(node);
4954 stack.add(stringBuilder.result); 4949 stack.add(stringBuilder.result);
4955 } 4950 }
4956 4951
4957 void visitLiteralNull(ast.LiteralNull node) { 4952 void visitLiteralNull(ast.LiteralNull node) {
4958 stack.add(graph.addConstantNull(closedWorld)); 4953 stack.add(graph.addConstantNull(closedWorld));
4959 } 4954 }
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after
6743 this.oldReturnLocal, 6738 this.oldReturnLocal,
6744 this.oldReturnType, 6739 this.oldReturnType,
6745 this.oldResolvedAst, 6740 this.oldResolvedAst,
6746 this.oldStack, 6741 this.oldStack,
6747 this.oldLocalsHandler, 6742 this.oldLocalsHandler,
6748 this.inTryStatement, 6743 this.inTryStatement,
6749 this.allFunctionsCalledOnce, 6744 this.allFunctionsCalledOnce,
6750 this.oldElementInferenceResults) 6745 this.oldElementInferenceResults)
6751 : super(function); 6746 : super(function);
6752 } 6747 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/resolution_strategy.dart ('k') | pkg/compiler/lib/src/ssa/builder_kernel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698