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

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

Issue 2994383003: Avoid crash for type variables in mixed in fields. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | tests/language/closure_in_field_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 928
929 /** 929 /**
930 * Documentation wanted -- johnniwinther 930 * Documentation wanted -- johnniwinther
931 * 931 *
932 * Invariant: [constructors] must contain only implementation elements. 932 * Invariant: [constructors] must contain only implementation elements.
933 */ 933 */
934 void inlineSuperOrRedirect( 934 void inlineSuperOrRedirect(
935 ResolvedAst constructorResolvedAst, 935 ResolvedAst constructorResolvedAst,
936 List<HInstruction> compiledArguments, 936 List<HInstruction> compiledArguments,
937 List<ResolvedAst> constructorResolvedAsts, 937 List<ResolvedAst> constructorResolvedAsts,
938 Map<Element, HInstruction> fieldValues, 938 Map<FieldElement, HInstruction> fieldValues,
939 FunctionElement caller) { 939 FunctionElement caller) {
940 ConstructorElement callee = constructorResolvedAst.element.implementation; 940 ConstructorElement callee = constructorResolvedAst.element.implementation;
941
941 reporter.withCurrentElement(callee, () { 942 reporter.withCurrentElement(callee, () {
943 Set<ClassElement> includedClasses = new Set<ClassElement>();
942 constructorResolvedAsts.add(constructorResolvedAst); 944 constructorResolvedAsts.add(constructorResolvedAst);
943 ClassElement enclosingClass = callee.enclosingClass; 945 ClassElement currentClass = caller.enclosingClass;
944 if (rtiNeed.classNeedsRti(enclosingClass)) { 946
945 // If [enclosingClass] needs RTI, we have to give a value to its 947 /// Include locals for type variable used in [member].
946 // type parameters. 948 void includeTypeVariables(MemberElement member) {
947 ClassElement currentClass = caller.enclosingClass; 949 ClassElement enclosingClass = member.enclosingClass;
948 // For a super constructor call, the type is the supertype of 950 if (!includedClasses.add(enclosingClass)) return;
949 // [currentClass]. For a redirecting constructor, the type is 951
950 // the current type. [InterfaceType.asInstanceOf] takes care 952 if (rtiNeed.classNeedsRti(enclosingClass)) {
951 // of both. 953 // If [enclosingClass] needs RTI, we have to give a value to its
952 ResolutionInterfaceType type = 954 // type parameters.
953 currentClass.thisType.asInstanceOf(enclosingClass); 955 // For a super constructor call, the type is the supertype of
954 type = localsHandler.substInContext(type); 956 // [currentClass]. For a redirecting constructor, the type is
955 List<ResolutionDartType> arguments = type.typeArguments; 957 // the current type. [InterfaceType.asInstanceOf] takes care
956 List<ResolutionDartType> typeVariables = enclosingClass.typeVariables; 958 // of both.
957 if (!type.isRaw) { 959 ResolutionInterfaceType type =
958 assert(arguments.length == typeVariables.length); 960 currentClass.thisType.asInstanceOf(enclosingClass);
959 Iterator<ResolutionDartType> variables = typeVariables.iterator; 961 type = localsHandler.substInContext(type);
960 type.typeArguments.forEach((ResolutionDartType argument) { 962 List<ResolutionDartType> arguments = type.typeArguments;
961 variables.moveNext(); 963 List<ResolutionDartType> typeVariables = enclosingClass.typeVariables;
962 ResolutionTypeVariableType typeVariable = variables.current; 964 if (!type.isRaw) {
963 localsHandler.updateLocal( 965 assert(arguments.length == typeVariables.length);
964 localsHandler.getTypeVariableAsLocal(typeVariable), 966 Iterator<ResolutionDartType> variables = typeVariables.iterator;
965 typeBuilder.analyzeTypeArgument(argument, sourceElement)); 967 type.typeArguments.forEach((ResolutionDartType argument) {
966 }); 968 variables.moveNext();
967 } else { 969 ResolutionTypeVariableType typeVariable = variables.current;
968 // If the supertype is a raw type, we need to set to null the 970 localsHandler.updateLocal(
969 // type variables. 971 localsHandler.getTypeVariableAsLocal(typeVariable),
970 for (ResolutionTypeVariableType variable in typeVariables) { 972 typeBuilder.analyzeTypeArgument(argument, sourceElement));
971 localsHandler.updateLocal( 973 });
972 localsHandler.getTypeVariableAsLocal(variable), 974 } else {
973 graph.addConstantNull(closedWorld)); 975 // If the supertype is a raw type, we need to set to null the
976 // type variables.
977 for (ResolutionTypeVariableType variable in typeVariables) {
978 localsHandler.updateLocal(
979 localsHandler.getTypeVariableAsLocal(variable),
980 graph.addConstantNull(closedWorld));
981 }
974 } 982 }
975 } 983 }
976 } 984 }
977 985
986 includeTypeVariables(callee);
987
978 // For redirecting constructors, the fields will be initialized later 988 // For redirecting constructors, the fields will be initialized later
979 // by the effective target. 989 // by the effective target.
980 if (!callee.isRedirectingGenerative) { 990 if (!callee.isRedirectingGenerative) {
991 callee.enclosingClass.implementation.forEachInstanceField(
992 (ClassElement enclosingClass, FieldElement member) {
993 includeTypeVariables(member);
Siggi Cherem (dart-lang) 2017/08/17 18:44:50 any reason why this shouldn't be done in buildFiel
Johnni Winther 2017/08/18 14:09:34 [inlinedFrom] accesses the missing values before t
994 });
981 inlinedFrom(constructorResolvedAst, () { 995 inlinedFrom(constructorResolvedAst, () {
982 buildFieldInitializers( 996 buildFieldInitializers(
983 callee.enclosingClass.implementation, fieldValues); 997 callee.enclosingClass.implementation, fieldValues);
984 }); 998 });
985 } 999 }
986 1000
987 int index = 0; 1001 int index = 0;
988 FunctionSignature params = callee.functionSignature; 1002 FunctionSignature params = callee.functionSignature;
989 params.orderedForEachParameter((_parameter) { 1003 params.orderedForEachParameter((_parameter) {
990 ParameterElement parameter = _parameter; 1004 ParameterElement parameter = _parameter;
(...skipping 26 matching lines...) Expand all
1017 buildInitializers(callee, constructorResolvedAsts, fieldValues); 1031 buildInitializers(callee, constructorResolvedAsts, fieldValues);
1018 localsHandler.scopeInfo = oldScopeInfo; 1032 localsHandler.scopeInfo = oldScopeInfo;
1019 resolvedAst = oldResolvedAst; 1033 resolvedAst = oldResolvedAst;
1020 elementInferenceResults = oldElementInferenceResults; 1034 elementInferenceResults = oldElementInferenceResults;
1021 }); 1035 });
1022 } 1036 }
1023 1037
1024 void buildInitializers( 1038 void buildInitializers(
1025 ConstructorElement constructor, 1039 ConstructorElement constructor,
1026 List<ResolvedAst> constructorResolvedAsts, 1040 List<ResolvedAst> constructorResolvedAsts,
1027 Map<Element, HInstruction> fieldValues) { 1041 Map<FieldElement, HInstruction> fieldValues) {
1028 assert( 1042 assert(
1029 resolvedAst.element == constructor.declaration, 1043 resolvedAst.element == constructor.declaration,
1030 failedAt(constructor, 1044 failedAt(constructor,
1031 "Expected ResolvedAst for $constructor, found $resolvedAst")); 1045 "Expected ResolvedAst for $constructor, found $resolvedAst"));
1032 if (resolvedAst.kind == ResolvedAstKind.PARSED) { 1046 if (resolvedAst.kind == ResolvedAstKind.PARSED) {
1033 buildParsedInitializers( 1047 buildParsedInitializers(
1034 constructor, constructorResolvedAsts, fieldValues); 1048 constructor, constructorResolvedAsts, fieldValues);
1035 } else { 1049 } else {
1036 buildSynthesizedConstructorInitializers( 1050 buildSynthesizedConstructorInitializers(
1037 constructor, constructorResolvedAsts, fieldValues); 1051 constructor, constructorResolvedAsts, fieldValues);
1038 } 1052 }
1039 } 1053 }
1040 1054
1041 void buildSynthesizedConstructorInitializers( 1055 void buildSynthesizedConstructorInitializers(
1042 ConstructorElement constructor, 1056 ConstructorElement constructor,
1043 List<ResolvedAst> constructorResolvedAsts, 1057 List<ResolvedAst> constructorResolvedAsts,
1044 Map<Element, HInstruction> fieldValues) { 1058 Map<FieldElement, HInstruction> fieldValues) {
1045 assert( 1059 assert(
1046 constructor.isSynthesized, 1060 constructor.isSynthesized,
1047 failedAt( 1061 failedAt(
1048 constructor, "Unexpected unsynthesized constructor: $constructor")); 1062 constructor, "Unexpected unsynthesized constructor: $constructor"));
1049 List<HInstruction> arguments = <HInstruction>[]; 1063 List<HInstruction> arguments = <HInstruction>[];
1050 HInstruction compileArgument(ParameterElement parameter) { 1064 HInstruction compileArgument(ParameterElement parameter) {
1051 return localsHandler.readLocal(parameter); 1065 return localsHandler.readLocal(parameter);
1052 } 1066 }
1053 1067
1054 ConstructorElement target = constructor.definingConstructor.implementation; 1068 ConstructorElement target = constructor.definingConstructor.implementation;
(...skipping 25 matching lines...) Expand all
1080 * 1094 *
1081 * The constructors of the inlined initializers is added to [constructors] 1095 * The constructors of the inlined initializers is added to [constructors]
1082 * with sub constructors having a lower index than super constructors. 1096 * with sub constructors having a lower index than super constructors.
1083 * 1097 *
1084 * Invariant: The [constructor] and elements in [constructors] must all be 1098 * Invariant: The [constructor] and elements in [constructors] must all be
1085 * implementation elements. 1099 * implementation elements.
1086 */ 1100 */
1087 void buildParsedInitializers( 1101 void buildParsedInitializers(
1088 ConstructorElement constructor, 1102 ConstructorElement constructor,
1089 List<ResolvedAst> constructorResolvedAsts, 1103 List<ResolvedAst> constructorResolvedAsts,
1090 Map<Element, HInstruction> fieldValues) { 1104 Map<FieldElement, HInstruction> fieldValues) {
1091 assert( 1105 assert(
1092 resolvedAst.element == constructor.declaration, failedAt(constructor)); 1106 resolvedAst.element == constructor.declaration, failedAt(constructor));
1093 assert(constructor.isImplementation, failedAt(constructor)); 1107 assert(constructor.isImplementation, failedAt(constructor));
1094 assert( 1108 assert(
1095 !constructor.isSynthesized, 1109 !constructor.isSynthesized,
1096 failedAt( 1110 failedAt(
1097 constructor, "Unexpected synthesized constructor: $constructor")); 1111 constructor, "Unexpected synthesized constructor: $constructor"));
1098 ast.FunctionExpression functionNode = resolvedAst.node; 1112 ast.FunctionExpression functionNode = resolvedAst.node;
1099 1113
1100 bool foundSuperOrRedirect = false; 1114 bool foundSuperOrRedirect = false;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 1234
1221 // Note that constructors (like any other static function) do not need 1235 // Note that constructors (like any other static function) do not need
1222 // to deal with optional arguments. It is the callers job to provide all 1236 // to deal with optional arguments. It is the callers job to provide all
1223 // arguments as if they were positional. 1237 // arguments as if they were positional.
1224 1238
1225 if (inliningStack.isEmpty) { 1239 if (inliningStack.isEmpty) {
1226 // The initializer list could contain closures. 1240 // The initializer list could contain closures.
1227 openFunction(functionElement, function); 1241 openFunction(functionElement, function);
1228 } 1242 }
1229 1243
1230 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); 1244 Map<FieldElement, HInstruction> fieldValues =
1245 new Map<FieldElement, HInstruction>();
1231 1246
1232 // Compile the possible initialization code for local fields and 1247 // Compile the possible initialization code for local fields and
1233 // super fields, unless this is a redirecting constructor, in which case 1248 // super fields, unless this is a redirecting constructor, in which case
1234 // the effective target will initialize these. 1249 // the effective target will initialize these.
1235 if (!functionElement.isRedirectingGenerative) { 1250 if (!functionElement.isRedirectingGenerative) {
1236 buildFieldInitializers(classElement, fieldValues); 1251 buildFieldInitializers(classElement, fieldValues);
1237 } 1252 }
1238 1253
1239 // Compile field-parameters such as [:this.x:]. 1254 // Compile field-parameters such as [:this.x:].
1240 FunctionSignature params = functionElement.functionSignature; 1255 FunctionSignature params = functionElement.functionSignature;
(...skipping 5599 matching lines...) Expand 10 before | Expand all | Expand 10 after
6840 this.oldReturnLocal, 6855 this.oldReturnLocal,
6841 this.oldReturnType, 6856 this.oldReturnType,
6842 this.oldResolvedAst, 6857 this.oldResolvedAst,
6843 this.oldStack, 6858 this.oldStack,
6844 this.oldLocalsHandler, 6859 this.oldLocalsHandler,
6845 this.inTryStatement, 6860 this.inTryStatement,
6846 this.allFunctionsCalledOnce, 6861 this.allFunctionsCalledOnce,
6847 this.oldElementInferenceResults) 6862 this.oldElementInferenceResults)
6848 : super(function); 6863 : super(function);
6849 } 6864 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | tests/language/closure_in_field_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698