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

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

Issue 2000223002: Revert "Adjusts dart2js backend to handle method type arguments." (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 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 2560 matching lines...) Expand 10 before | Expand all | Expand 10 after
2571 bool assertTypeInContext(DartType type, [Spannable spannable]) { 2571 bool assertTypeInContext(DartType type, [Spannable spannable]) {
2572 return invariant(spannable == null ? CURRENT_ELEMENT_SPANNABLE : spannable, 2572 return invariant(spannable == null ? CURRENT_ELEMENT_SPANNABLE : spannable,
2573 () { 2573 () {
2574 ClassElement contextClass = Types.getClassContext(type); 2574 ClassElement contextClass = Types.getClassContext(type);
2575 return contextClass == null || contextClass == localsHandler.contextClass; 2575 return contextClass == null || contextClass == localsHandler.contextClass;
2576 }, 2576 },
2577 message: "Type '$type' is not valid context of " 2577 message: "Type '$type' is not valid context of "
2578 "${localsHandler.contextClass}."); 2578 "${localsHandler.contextClass}.");
2579 } 2579 }
2580 2580
2581 /// Build a [HTypeConversion] for converting [original] to type [type]. 2581 /// Build a [HTypeConversion] for convertion [original] to type [type].
2582 /// 2582 ///
2583 /// Invariant: [type] must be valid in the context. 2583 /// Invariant: [type] must be valid in the context.
2584 /// See [LocalsHandler.substInContext]. 2584 /// See [LocalsHandler.substInContext].
2585 HInstruction buildTypeConversion( 2585 HInstruction buildTypeConversion(
2586 HInstruction original, DartType type, int kind) { 2586 HInstruction original, DartType type, int kind) {
2587 if (type == null) return original; 2587 if (type == null) return original;
2588 // GENERIC_METHODS: The following statement was added for parsing and
2589 // ignoring method type variables; must be generalized for full support of
2590 // generic methods.
2591 type = type.dynamifyMethodTypeVariableType;
2592 type = type.unaliased; 2588 type = type.unaliased;
2593 assert(assertTypeInContext(type, original)); 2589 assert(assertTypeInContext(type, original));
2594 if (type.isInterfaceType && !type.treatAsRaw) { 2590 if (type.isInterfaceType && !type.treatAsRaw) {
2595 TypeMask subtype = new TypeMask.subtype(type.element, compiler.world); 2591 TypeMask subtype = new TypeMask.subtype(type.element, compiler.world);
2596 HInstruction representations = buildTypeArgumentRepresentations(type); 2592 HInstruction representations = buildTypeArgumentRepresentations(type);
2597 add(representations); 2593 add(representations);
2598 return new HTypeConversion.withTypeRepresentation( 2594 return new HTypeConversion.withTypeRepresentation(
2599 type, kind, subtype, original, representations); 2595 type, kind, subtype, original, representations);
2600 } else if (type.isTypeVariable) { 2596 } else if (type.isTypeVariable) {
2601 TypeMask subtype = original.instructionType; 2597 TypeMask subtype = original.instructionType;
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3802 code, backend.readableArrayType, inputs, 3798 code, backend.readableArrayType, inputs,
3803 nativeBehavior: native.NativeBehavior.PURE_ALLOCATION); 3799 nativeBehavior: native.NativeBehavior.PURE_ALLOCATION);
3804 return representation; 3800 return representation;
3805 } 3801 }
3806 } 3802 }
3807 3803
3808 @override 3804 @override
3809 void visitAs(ast.Send node, ast.Node expression, DartType type, _) { 3805 void visitAs(ast.Send node, ast.Node expression, DartType type, _) {
3810 HInstruction expressionInstruction = visitAndPop(expression); 3806 HInstruction expressionInstruction = visitAndPop(expression);
3811 if (type.isMalformed) { 3807 if (type.isMalformed) {
3812 String message; 3808 ErroneousElement element = type.element;
3813 if (type is MalformedType) { 3809 generateTypeError(node, element.message);
3814 ErroneousElement element = type.element;
3815 message = element.message;
3816 } else {
3817 assert(type is MethodTypeVariableType);
3818 message = "Method type variables are not reified.";
3819 }
3820 generateTypeError(node, message);
3821 } else { 3810 } else {
3822 HInstruction converted = buildTypeConversion(expressionInstruction, 3811 HInstruction converted = buildTypeConversion(expressionInstruction,
3823 localsHandler.substInContext(type), HTypeConversion.CAST_TYPE_CHECK); 3812 localsHandler.substInContext(type), HTypeConversion.CAST_TYPE_CHECK);
3824 if (converted != expressionInstruction) add(converted); 3813 if (converted != expressionInstruction) add(converted);
3825 stack.add(converted); 3814 stack.add(converted);
3826 } 3815 }
3827 } 3816 }
3828 3817
3829 @override 3818 @override
3830 void visitIs(ast.Send node, ast.Node expression, DartType type, _) { 3819 void visitIs(ast.Send node, ast.Node expression, DartType type, _) {
3831 HInstruction expressionInstruction = visitAndPop(expression); 3820 HInstruction expressionInstruction = visitAndPop(expression);
3832 push(buildIsNode(node, type, expressionInstruction)); 3821 push(buildIsNode(node, type, expressionInstruction));
3833 } 3822 }
3834 3823
3835 @override 3824 @override
3836 void visitIsNot(ast.Send node, ast.Node expression, DartType type, _) { 3825 void visitIsNot(ast.Send node, ast.Node expression, DartType type, _) {
3837 HInstruction expressionInstruction = visitAndPop(expression); 3826 HInstruction expressionInstruction = visitAndPop(expression);
3838 HInstruction instruction = buildIsNode(node, type, expressionInstruction); 3827 HInstruction instruction = buildIsNode(node, type, expressionInstruction);
3839 add(instruction); 3828 add(instruction);
3840 push(new HNot(instruction, backend.boolType)); 3829 push(new HNot(instruction, backend.boolType));
3841 } 3830 }
3842 3831
3843 HInstruction buildIsNode( 3832 HInstruction buildIsNode(
3844 ast.Node node, DartType type, HInstruction expression) { 3833 ast.Node node, DartType type, HInstruction expression) {
3845 type = localsHandler.substInContext(type).unaliased; 3834 type = localsHandler.substInContext(type).unaliased;
3846 if (type.isMalformed) { 3835 if (type.isFunctionType) {
3847 String message;
3848 if (type is MethodTypeVariableType) {
3849 message = "Method type variables are not reified, "
3850 "so they cannot be tested with an `is` expression.";
3851 } else {
3852 assert(type is MalformedType);
3853 ErroneousElement element = type.element;
3854 message = element.message;
3855 }
3856 generateTypeError(node, message);
3857 HInstruction call = pop();
3858 return new HIs.compound(type, expression, call, backend.boolType);
3859 } else if (type.isFunctionType) {
3860 List arguments = [buildFunctionType(type), expression]; 3836 List arguments = [buildFunctionType(type), expression];
3861 pushInvokeDynamic( 3837 pushInvokeDynamic(
3862 node, 3838 node,
3863 new Selector.call(new PrivateName('_isTest', helpers.jsHelperLibrary), 3839 new Selector.call(new PrivateName('_isTest', helpers.jsHelperLibrary),
3864 CallStructure.ONE_ARG), 3840 CallStructure.ONE_ARG),
3865 null, 3841 null,
3866 arguments); 3842 arguments);
3867 return new HIs.compound(type, expression, pop(), backend.boolType); 3843 return new HIs.compound(type, expression, pop(), backend.boolType);
3868 } else if (type.isTypeVariable) { 3844 } else if (type.isTypeVariable) {
3869 HInstruction runtimeType = addTypeVariableReference(type); 3845 HInstruction runtimeType = addTypeVariableReference(type);
(...skipping 14 matching lines...) Expand all
3884 : graph.addConstantNull(compiler); 3860 : graph.addConstantNull(compiler);
3885 List<HInstruction> inputs = <HInstruction>[ 3861 List<HInstruction> inputs = <HInstruction>[
3886 expression, 3862 expression,
3887 isFieldName, 3863 isFieldName,
3888 representations, 3864 representations,
3889 asFieldName 3865 asFieldName
3890 ]; 3866 ];
3891 pushInvokeStatic(node, helper, inputs, typeMask: backend.boolType); 3867 pushInvokeStatic(node, helper, inputs, typeMask: backend.boolType);
3892 HInstruction call = pop(); 3868 HInstruction call = pop();
3893 return new HIs.compound(type, expression, call, backend.boolType); 3869 return new HIs.compound(type, expression, call, backend.boolType);
3870 } else if (type.isMalformed) {
3871 ErroneousElement element = type.element;
3872 generateTypeError(node, element.message);
3873 HInstruction call = pop();
3874 return new HIs.compound(type, expression, call, backend.boolType);
3894 } else { 3875 } else {
3895 if (backend.hasDirectCheckFor(type)) { 3876 if (backend.hasDirectCheckFor(type)) {
3896 return new HIs.direct(type, expression, backend.boolType); 3877 return new HIs.direct(type, expression, backend.boolType);
3897 } 3878 }
3898 // The interceptor is not always needed. It is removed by optimization 3879 // The interceptor is not always needed. It is removed by optimization
3899 // when the receiver type or tested type permit. 3880 // when the receiver type or tested type permit.
3900 return new HIs.raw( 3881 return new HIs.raw(
3901 type, expression, invokeInterceptor(expression), backend.boolType); 3882 type, expression, invokeInterceptor(expression), backend.boolType);
3902 } 3883 }
3903 } 3884 }
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after
5349 // identifier that refers to the class/typedef) as a constant. 5330 // identifier that refers to the class/typedef) as a constant.
5350 stack.add(addConstant(node.selector)); 5331 stack.add(addConstant(node.selector));
5351 } else { 5332 } else {
5352 stack.add(addConstant(node)); 5333 stack.add(addConstant(node));
5353 } 5334 }
5354 } 5335 }
5355 5336
5356 /// Generate the literal for [typeVariable] in the current context. 5337 /// Generate the literal for [typeVariable] in the current context.
5357 void generateTypeVariableLiteral( 5338 void generateTypeVariableLiteral(
5358 ast.Send node, TypeVariableType typeVariable) { 5339 ast.Send node, TypeVariableType typeVariable) {
5359 // GENERIC_METHODS: This provides thin support for method type variables 5340 DartType type = localsHandler.substInContext(typeVariable);
5360 // by treating them as malformed when evaluated as a literal. For full 5341 HInstruction value = analyzeTypeArgument(type,
5361 // support of generic methods this must be revised. 5342 sourceInformation: sourceInformationBuilder.buildGet(node));
5362 if (typeVariable is MethodTypeVariableType) { 5343 pushInvokeStatic(node, helpers.runtimeTypeToString, [value],
5363 generateTypeError(node, "Method type variables are not reified"); 5344 typeMask: backend.stringType);
5364 } else { 5345 pushInvokeStatic(node, helpers.createRuntimeType, [pop()]);
5365 DartType type = localsHandler.substInContext(typeVariable);
5366 HInstruction value = analyzeTypeArgument(type,
5367 sourceInformation: sourceInformationBuilder.buildGet(node));
5368 pushInvokeStatic(node, helpers.runtimeTypeToString, [value],
5369 typeMask: backend.stringType);
5370 pushInvokeStatic(node, helpers.createRuntimeType, [pop()]);
5371 }
5372 } 5346 }
5373 5347
5374 /// Generate a call to a type literal. 5348 /// Generate a call to a type literal.
5375 void generateTypeLiteralCall(ast.Send node) { 5349 void generateTypeLiteralCall(ast.Send node) {
5376 // This send is of the form 'e(...)', where e is resolved to a type 5350 // This send is of the form 'e(...)', where e is resolved to a type
5377 // reference. We create a regular closure call on the result of the type 5351 // reference. We create a regular closure call on the result of the type
5378 // reference instead of creating a NoSuchMethodError to avoid pulling it 5352 // reference instead of creating a NoSuchMethodError to avoid pulling it
5379 // in if it is not used (e.g., in a try/catch). 5353 // in if it is not used (e.g., in a try/catch).
5380 HInstruction target = pop(); 5354 HInstruction target = pop();
5381 generateCallInvoke(node, target, 5355 generateCallInvoke(node, target,
(...skipping 3241 matching lines...) Expand 10 before | Expand all | Expand 10 after
8623 const _LoopTypeVisitor(); 8597 const _LoopTypeVisitor();
8624 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; 8598 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP;
8625 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; 8599 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP;
8626 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; 8600 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP;
8627 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; 8601 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP;
8628 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; 8602 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP;
8629 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; 8603 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP;
8630 int visitSwitchStatement(ast.SwitchStatement node) => 8604 int visitSwitchStatement(ast.SwitchStatement node) =>
8631 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; 8605 HLoopBlockInformation.SWITCH_CONTINUE_LOOP;
8632 } 8606 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/type_resolver.dart ('k') | pkg/compiler/lib/src/ssa/optimize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698