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

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

Issue 2974803002: Store FunctionType(s) of local functions by value. (Closed)
Patch Set: Store FunctionElement(s) by value, but keep also 'localIndex'. Created 3 years, 5 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/lib/src/summary/resynthesize.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) 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 if (element is FunctionTypeAliasElementForLink) { 218 if (element is FunctionTypeAliasElementForLink) {
219 result.reference = compilationUnit.addReference(element); 219 result.reference = compilationUnit.addReference(element);
220 _storeTypeArguments( 220 _storeTypeArguments(
221 type.typeArguments, result, compilationUnit, typeParameterContext); 221 type.typeArguments, result, compilationUnit, typeParameterContext);
222 return result; 222 return result;
223 } 223 }
224 if (element is FunctionElement && element.enclosingElement == null) { 224 if (element is FunctionElement && element.enclosingElement == null) {
225 // Element is a synthetic function element that was generated on the fly 225 // Element is a synthetic function element that was generated on the fly
226 // to represent a type that has no associated source code location. 226 // to represent a type that has no associated source code location.
227 result.syntheticReturnType = _createLinkedType( 227 _storeFunctionElementByValue(result, element, compilationUnit);
228 element.returnType, compilationUnit, typeParameterContext);
229 result.entityKind =
230 element.returnType?.element is GenericFunctionTypeElement
231 ? EntityRefKind.genericFunctionType
232 : EntityRefKind.syntheticFunction;
233 result.syntheticParams = element.parameters
234 .map((ParameterElement param) => _serializeSyntheticParam(
235 param, compilationUnit, typeParameterContext))
236 .toList();
237 return result; 228 return result;
238 } 229 }
239 if (element is FunctionElement) { 230 if (element is FunctionElement) {
240 // Element is a local function inside another executable. 231 // Element is a local function inside another executable.
241 result.reference = compilationUnit.addReference(element); 232 result.reference = compilationUnit.addReference(element);
233 _storeFunctionElementByValue(result, element, compilationUnit);
242 // TODO(paulberry): do I need to store type arguments? 234 // TODO(paulberry): do I need to store type arguments?
243 return result; 235 return result;
244 } 236 }
245 if (element is GenericFunctionTypeElement) { 237 if (element is GenericFunctionTypeElement) {
246 result.entityKind = EntityRefKind.genericFunctionType; 238 result.entityKind = EntityRefKind.genericFunctionType;
247 result.syntheticReturnType = _createLinkedType( 239 result.syntheticReturnType = _createLinkedType(
248 type.returnType, compilationUnit, typeParameterContext); 240 type.returnType, compilationUnit, typeParameterContext);
249 result.syntheticParams = type.parameters 241 result.syntheticParams = type.parameters
250 .map((ParameterElement param) => _serializeSyntheticParam( 242 .map((ParameterElement param) => _serializeSyntheticParam(
251 param, compilationUnit, typeParameterContext)) 243 param, compilationUnit, typeParameterContext))
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 parameter, compilationUnit, typeParameterContext)) 292 parameter, compilationUnit, typeParameterContext))
301 .toList(); 293 .toList();
302 } else { 294 } else {
303 b.type = _createLinkedType(type, compilationUnit, typeParameterContext); 295 b.type = _createLinkedType(type, compilationUnit, typeParameterContext);
304 } 296 }
305 } 297 }
306 return b; 298 return b;
307 } 299 }
308 300
309 /** 301 /**
302 * Create an [UnlinkedTypeParamBuilder] representing the given [typeParameter],
303 * which should be a type parameter of a synthetic function type (e.g. one
304 * produced during type inference as a result of computing the least upper
305 * bound of two function types).
306 */
307 UnlinkedTypeParamBuilder _serializeSyntheticTypeParameter(
308 TypeParameterElement typeParameter,
309 CompilationUnitElementInBuildUnit compilationUnit,
310 TypeParameterizedElementMixin typeParameterContext) {
311 TypeParameterElementImpl impl = typeParameter as TypeParameterElementImpl;
312 EntityRefBuilder boundBuilder = typeParameter.bound != null
313 ? _createLinkedType(
314 typeParameter.bound, compilationUnit, typeParameterContext)
315 : null;
316 CodeRangeBuilder codeRangeBuilder =
317 new CodeRangeBuilder(offset: impl.codeOffset, length: impl.codeLength);
318 return new UnlinkedTypeParamBuilder(
319 name: typeParameter.name,
320 nameOffset: typeParameter.nameOffset,
321 bound: boundBuilder,
322 codeRange: codeRangeBuilder);
323 }
324
325 /**
326 * Store the given function [element] into the [entity] by value.
327 */
328 void _storeFunctionElementByValue(
329 EntityRefBuilder entity,
330 FunctionElement element,
331 CompilationUnitElementInBuildUnit compilationUnit) {
332 // Element is a local function, or a synthetic function element that was
333 // generated on the fly to represent a type that has no associated source
334 // code location. Store it as value.
335 if (element is FunctionElementImpl) {
336 entity.syntheticReturnType =
337 _createLinkedType(element.returnType, compilationUnit, element);
338 entity.entityKind = EntityRefKind.syntheticFunction;
339 entity.syntheticParams = element.parameters
340 .map((ParameterElement param) =>
341 _serializeSyntheticParam(param, compilationUnit, element))
342 .toList();
343 entity.typeParameters = element.typeParameters
344 .map((TypeParameterElement e) =>
345 _serializeSyntheticTypeParameter(e, compilationUnit, element))
346 .toList();
347 }
348 }
349
350 /**
310 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and 351 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and
311 * [typeParameterContext] to serialize them. 352 * [typeParameterContext] to serialize them.
312 */ 353 */
313 void _storeTypeArguments( 354 void _storeTypeArguments(
314 List<DartType> typeArguments, 355 List<DartType> typeArguments,
315 EntityRefBuilder encodedType, 356 EntityRefBuilder encodedType,
316 CompilationUnitElementInBuildUnit compilationUnit, 357 CompilationUnitElementInBuildUnit compilationUnit,
317 TypeParameterizedElementMixin typeParameterContext) { 358 TypeParameterizedElementMixin typeParameterContext) {
318 int count = typeArguments.length; 359 int count = typeArguments.length;
319 List<EntityRefBuilder> encodedTypeArguments = 360 List<EntityRefBuilder> encodedTypeArguments =
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 return VoidTypeImpl.instance; 1137 return VoidTypeImpl.instance;
1097 } else { 1138 } else {
1098 return DynamicTypeImpl.instance; 1139 return DynamicTypeImpl.instance;
1099 } 1140 }
1100 } 1141 }
1101 if (entity.paramReference != 0) { 1142 if (entity.paramReference != 0) {
1102 return context.typeParameterContext 1143 return context.typeParameterContext
1103 .getTypeParameterType(entity.paramReference); 1144 .getTypeParameterType(entity.paramReference);
1104 } else if (entity.entityKind == EntityRefKind.genericFunctionType) { 1145 } else if (entity.entityKind == EntityRefKind.genericFunctionType) {
1105 return new GenericFunctionTypeElementForLink(this, context, entity).type; 1146 return new GenericFunctionTypeElementForLink(this, context, entity).type;
1106 } else if (entity.syntheticReturnType != null) { 1147 } else if (entity.syntheticReturnType != null && entity.reference == 0) {
1148 // TODO(scheglov): Remove "&& entity.reference == 0" condition after
1149 // rolling SDK with this change internally, so that we always store
1150 // synthetic and local function types by value.
1151
1107 // TODO(paulberry): implement. 1152 // TODO(paulberry): implement.
1108 throw new UnimplementedError(); 1153 throw new UnimplementedError();
1109 } else if (entity.implicitFunctionTypeIndices.isNotEmpty) { 1154 } else if (entity.implicitFunctionTypeIndices.isNotEmpty) {
1110 DartType type = resolveRef(entity.reference).asStaticType; 1155 DartType type = resolveRef(entity.reference).asStaticType;
1111 for (int index in entity.implicitFunctionTypeIndices) { 1156 for (int index in entity.implicitFunctionTypeIndices) {
1112 type = (type as FunctionType).parameters[index].type; 1157 type = (type as FunctionType).parameters[index].type;
1113 } 1158 }
1114 return type; 1159 return type;
1115 } else { 1160 } else {
1116 ReferenceableElementForLink element = resolveRef(entity.reference); 1161 ReferenceableElementForLink element = resolveRef(entity.reference);
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 2919
2875 @override 2920 @override
2876 final TypeParameterizedElementMixin typeParameterContext; 2921 final TypeParameterizedElementMixin typeParameterContext;
2877 2922
2878 @override 2923 @override
2879 final List<UnlinkedParam> unlinkedParameters; 2924 final List<UnlinkedParam> unlinkedParameters;
2880 2925
2881 DartType _returnType; 2926 DartType _returnType;
2882 List<int> _implicitFunctionTypeIndices; 2927 List<int> _implicitFunctionTypeIndices;
2883 2928
2929 @override
2930 bool get isSynthetic => true;
2931
2884 FunctionElementForLink_FunctionTypedParam(this.enclosingElement, 2932 FunctionElementForLink_FunctionTypedParam(this.enclosingElement,
2885 this.typeParameterContext, this.unlinkedParameters); 2933 this.typeParameterContext, this.unlinkedParameters);
2886 2934
2887 @override 2935 @override
2888 List<int> get implicitFunctionTypeIndices { 2936 List<int> get implicitFunctionTypeIndices {
2889 if (_implicitFunctionTypeIndices == null) { 2937 if (_implicitFunctionTypeIndices == null) {
2890 _implicitFunctionTypeIndices = enclosingElement 2938 _implicitFunctionTypeIndices = enclosingElement
2891 .enclosingElement.implicitFunctionTypeIndices 2939 .enclosingElement.implicitFunctionTypeIndices
2892 .toList(); 2940 .toList();
2893 _implicitFunctionTypeIndices.add(enclosingElement._parameterIndex); 2941 _implicitFunctionTypeIndices.add(enclosingElement._parameterIndex);
(...skipping 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after
5407 } 5455 }
5408 5456
5409 /** 5457 /**
5410 * This exception is thrown when [ExprTypeComputer] cannot inference the type. 5458 * This exception is thrown when [ExprTypeComputer] cannot inference the type.
5411 */ 5459 */
5412 class _InferenceFailedError { 5460 class _InferenceFailedError {
5413 final String message; 5461 final String message;
5414 5462
5415 _InferenceFailedError(this.message); 5463 _InferenceFailedError(this.message);
5416 } 5464 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/resynthesize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698