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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 2837963002: Fix for indirect recursion in resynthesizing function type aliases. (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 * Otherwise `null`. 1222 * Otherwise `null`.
1223 */ 1223 */
1224 DartType _type; 1224 DartType _type;
1225 1225
1226 /** 1226 /**
1227 * The number of type parameters accepted by the entity referred to by this 1227 * The number of type parameters accepted by the entity referred to by this
1228 * reference, or zero if it doesn't accept any type parameters. 1228 * reference, or zero if it doesn't accept any type parameters.
1229 */ 1229 */
1230 final int numTypeParameters; 1230 final int numTypeParameters;
1231 1231
1232 bool _isBeingInstantiatedToBounds = false;
1233 bool _isRecursiveWhileInstantiateToBounds = false;
1234
1232 /** 1235 /**
1233 * Create a new [_ReferenceInfo] object referring to an element called [name] 1236 * Create a new [_ReferenceInfo] object referring to an element called [name]
1234 * via the element handle [element], and having [numTypeParameters] type 1237 * via the element handle [element], and having [numTypeParameters] type
1235 * parameters. 1238 * parameters.
1236 * 1239 *
1237 * For the special types `dynamic` and `void`, [specialType] should point to 1240 * For the special types `dynamic` and `void`, [specialType] should point to
1238 * the type itself. Otherwise, pass `null` and the type will be computed 1241 * the type itself. Otherwise, pass `null` and the type will be computed
1239 * when appropriate. 1242 * when appropriate.
1240 */ 1243 */
1241 _ReferenceInfo( 1244 _ReferenceInfo(
(...skipping 13 matching lines...) Expand all
1255 * If this reference refers to a non-generic type, the type it refers to. 1258 * If this reference refers to a non-generic type, the type it refers to.
1256 * Otherwise `null`. 1259 * Otherwise `null`.
1257 */ 1260 */
1258 DartType get type { 1261 DartType get type {
1259 if (_type == null) { 1262 if (_type == null) {
1260 _type = _buildType(true, 0, (_) => DynamicTypeImpl.instance, const []); 1263 _type = _buildType(true, 0, (_) => DynamicTypeImpl.instance, const []);
1261 } 1264 }
1262 return _type; 1265 return _type;
1263 } 1266 }
1264 1267
1268 List<DartType> get _dynamicTypeArguments =>
1269 new List<DartType>.filled(numTypeParameters, DynamicTypeImpl.instance);
1270
1265 /** 1271 /**
1266 * Build a [DartType] corresponding to the result of applying some type 1272 * Build a [DartType] corresponding to the result of applying some type
1267 * arguments to the entity referred to by this [_ReferenceInfo]. The type 1273 * arguments to the entity referred to by this [_ReferenceInfo]. The type
1268 * arguments are retrieved by calling [getTypeArgument]. 1274 * arguments are retrieved by calling [getTypeArgument].
1269 * 1275 *
1270 * If [implicitFunctionTypeIndices] is not empty, a [DartType] should be 1276 * If [implicitFunctionTypeIndices] is not empty, a [DartType] should be
1271 * created which refers to a function type implicitly defined by one of the 1277 * created which refers to a function type implicitly defined by one of the
1272 * element's parameters. [implicitFunctionTypeIndices] is interpreted as in 1278 * element's parameters. [implicitFunctionTypeIndices] is interpreted as in
1273 * [EntityRef.implicitFunctionTypeIndices]. 1279 * [EntityRef.implicitFunctionTypeIndices].
1274 * 1280 *
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 InterfaceTypeImpl type = 1321 InterfaceTypeImpl type =
1316 new InterfaceTypeImpl.elementWithNameAndArgs(element, name, () { 1322 new InterfaceTypeImpl.elementWithNameAndArgs(element, name, () {
1317 if (typeArguments == null) { 1323 if (typeArguments == null) {
1318 if (libraryResynthesizer.summaryResynthesizer.strongMode && 1324 if (libraryResynthesizer.summaryResynthesizer.strongMode &&
1319 instantiateToBoundsAllowed) { 1325 instantiateToBoundsAllowed) {
1320 InterfaceType instantiatedToBounds = libraryResynthesizer 1326 InterfaceType instantiatedToBounds = libraryResynthesizer
1321 .summaryResynthesizer.context.typeSystem 1327 .summaryResynthesizer.context.typeSystem
1322 .instantiateToBounds(element.type) as InterfaceType; 1328 .instantiateToBounds(element.type) as InterfaceType;
1323 return instantiatedToBounds.typeArguments; 1329 return instantiatedToBounds.typeArguments;
1324 } else { 1330 } else {
1325 return new List<DartType>.filled( 1331 return _dynamicTypeArguments;
1326 numTypeParameters, DynamicTypeImpl.instance);
1327 } 1332 }
1328 } 1333 }
1329 return typeArguments; 1334 return typeArguments;
1330 }); 1335 });
1331 // Mark the type as having implicit type arguments, so that we don't 1336 // Mark the type as having implicit type arguments, so that we don't
1332 // attempt to request them during constant expression resynthesizing. 1337 // attempt to request them during constant expression resynthesizing.
1333 if (typeArguments == null) { 1338 if (typeArguments == null) {
1334 libraryResynthesizer.typesWithImplicitTypeArguments.add(type); 1339 libraryResynthesizer.typesWithImplicitTypeArguments.add(type);
1335 } 1340 }
1336 // Done. 1341 // Done.
1337 return type; 1342 return type;
1338 } else if (element is GenericTypeAliasElementHandle) { 1343 } else if (element is GenericTypeAliasElementHandle) {
1339 GenericTypeAliasElementImpl actualElement = element.actualElement; 1344 GenericTypeAliasElementImpl actualElement = element.actualElement;
1340 List<DartType> argumentTypes = 1345 List<DartType> argumentTypes =
1341 new List.generate(numTypeArguments, getTypeArgument); 1346 new List.generate(numTypeArguments, getTypeArgument);
1342 return actualElement.typeAfterSubstitution(argumentTypes); 1347 return actualElement.typeAfterSubstitution(argumentTypes);
1343 } else if (element is FunctionTypedElement) { 1348 } else if (element is FunctionTypedElement) {
1344 if (element is FunctionTypeAliasElementHandle) { 1349 if (element is FunctionTypeAliasElementHandle) {
1345 List<DartType> typeArguments; 1350 List<DartType> typeArguments;
1346 if (numTypeArguments == numTypeParameters) { 1351 if (numTypeArguments == numTypeParameters) {
1347 typeArguments = 1352 typeArguments =
1348 _buildTypeArguments(numTypeArguments, getTypeArgument); 1353 _buildTypeArguments(numTypeArguments, getTypeArgument);
1349 } else if (libraryResynthesizer.summaryResynthesizer.strongMode && 1354 } else if (libraryResynthesizer.summaryResynthesizer.strongMode &&
1350 instantiateToBoundsAllowed) { 1355 instantiateToBoundsAllowed) {
1351 FunctionType instantiatedToBounds = libraryResynthesizer 1356 if (!_isBeingInstantiatedToBounds) {
1352 .summaryResynthesizer.context.typeSystem 1357 _isBeingInstantiatedToBounds = true;
1353 .instantiateToBounds(element.type) as FunctionType; 1358 _isRecursiveWhileInstantiateToBounds = false;
1354 typeArguments = instantiatedToBounds.typeArguments; 1359 try {
1360 FunctionType instantiatedToBounds = libraryResynthesizer
1361 .summaryResynthesizer.context.typeSystem
1362 .instantiateToBounds(element.type) as FunctionType;
1363 if (!_isRecursiveWhileInstantiateToBounds) {
1364 typeArguments = instantiatedToBounds.typeArguments;
1365 } else {
1366 typeArguments = _dynamicTypeArguments;
1367 }
1368 } finally {
1369 _isBeingInstantiatedToBounds = false;
1370 }
1371 } else {
1372 _isRecursiveWhileInstantiateToBounds = true;
1373 typeArguments = _dynamicTypeArguments;
1374 }
1355 } else { 1375 } else {
1356 typeArguments = new List<DartType>.filled( 1376 typeArguments = _dynamicTypeArguments;
1357 numTypeParameters, DynamicTypeImpl.instance);
1358 } 1377 }
1359 return new FunctionTypeImpl.elementWithNameAndArgs( 1378 return new FunctionTypeImpl.elementWithNameAndArgs(
1360 element, name, typeArguments, numTypeParameters != 0); 1379 element, name, typeArguments, numTypeParameters != 0);
1361 } else { 1380 } else {
1362 FunctionTypedElementComputer computer; 1381 FunctionTypedElementComputer computer;
1363 if (implicitFunctionTypeIndices.isNotEmpty) { 1382 if (implicitFunctionTypeIndices.isNotEmpty) {
1364 numTypeArguments = numTypeParameters; 1383 numTypeArguments = numTypeParameters;
1365 computer = () { 1384 computer = () {
1366 FunctionTypedElement element = this.element; 1385 FunctionTypedElement element = this.element;
1367 for (int index in implicitFunctionTypeIndices) { 1386 for (int index in implicitFunctionTypeIndices) {
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 static String _getElementIdentifier(String name, ReferenceKind kind) { 2012 static String _getElementIdentifier(String name, ReferenceKind kind) {
1994 if (kind == ReferenceKind.topLevelPropertyAccessor || 2013 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1995 kind == ReferenceKind.propertyAccessor) { 2014 kind == ReferenceKind.propertyAccessor) {
1996 if (!name.endsWith('=')) { 2015 if (!name.endsWith('=')) {
1997 return name + '?'; 2016 return name + '?';
1998 } 2017 }
1999 } 2018 }
2000 return name; 2019 return name;
2001 } 2020 }
2002 } 2021 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698