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

Unified Diff: pkg/analyzer/lib/src/summary/summarize_elements.dart

Issue 1740923002: Propertly summarize LUB function types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/summary/summarize_elements.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_elements.dart b/pkg/analyzer/lib/src/summary/summarize_elements.dart
index bef46a9abe41649c9d866b5e338f0efa79dcd45f..b854352a08a5ca5c68a3fe6b3324c0623040264a 100644
--- a/pkg/analyzer/lib/src/summary/summarize_elements.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_elements.dart
@@ -240,6 +240,12 @@ class _CompilationUnitSerializer {
*/
int bottomReferenceIndex = null;
+ /**
+ * If `true`, we are currently generating linked references, so new
+ * references will be not stored in [unlinkedReferences].
+ */
+ bool buildingLinkedReferences = false;
+
_CompilationUnitSerializer(
this.librarySerializer, this.compilationUnit, this.unitNum);
@@ -372,9 +378,11 @@ class _CompilationUnitSerializer {
* found during [addCompilationUnitElements].
*/
void createLinkedTypes() {
+ buildingLinkedReferences = true;
linkedUnit.types = deferredLinkedTypes
.map((_SerializeTypeRef closure) => closure())
.toList();
+ buildingLinkedReferences = false;
}
/**
@@ -783,7 +791,7 @@ class _CompilationUnitSerializer {
context ??= parameter;
UnlinkedParamBuilder b = new UnlinkedParamBuilder();
b.name = parameter.name;
- b.nameOffset = parameter.nameOffset;
+ b.nameOffset = parameter.nameOffset >= 0 ? parameter.nameOffset : 0;
switch (parameter.parameterKind) {
case ParameterKind.REQUIRED:
b.kind = UnlinkedParamKind.required;
@@ -849,11 +857,8 @@ class _CompilationUnitSerializer {
/**
* Compute the reference index which should be stored in a [EntityRef].
- *
- * If [linked] is true, and a new reference has to be created, the reference
- * will only be stored in [linkedReferences].
*/
- int serializeReferenceForType(DartType type, bool linked) {
+ int serializeReferenceForType(DartType type) {
Element element = type.element;
LibraryElement dependentLibrary = element?.library;
if (dependentLibrary == null) {
@@ -861,7 +866,7 @@ class _CompilationUnitSerializer {
// References to the "bottom" type are always implicit, since there is
// no way to explicitly refer to the "bottom" type. Therefore they
// should always be linked.
- assert(linked);
+ assert(buildingLinkedReferences);
return serializeBottomReference();
}
assert(type.isDynamic || type.isVoid);
@@ -871,7 +876,7 @@ class _CompilationUnitSerializer {
// Note: for a type which is truly `dynamic` or `void`, fall through to
// use [_getElementReferenceId].
}
- return _getElementReferenceId(element, linked: linked);
+ return _getElementReferenceId(element);
}
/**
@@ -908,26 +913,36 @@ class _CompilationUnitSerializer {
/**
* Serialize the given [type] into a [EntityRef]. If [slot] is provided,
- * it should be included in the [EntityRef]. If [linked] is true, any
- * references that are created will be populated into [linkedReferences] but
- * not [unlinkedReferences].
+ * it should be included in the [EntityRef].
*
* [context] is the element within which the [EntityRef] will be
* interpreted; this is used to serialize type parameters.
*/
EntityRefBuilder serializeTypeRef(DartType type, Element context,
- {bool linked: false, int slot}) {
+ {int slot}) {
+ if (slot != null) {
+ assert(buildingLinkedReferences);
+ }
EntityRefBuilder b = new EntityRefBuilder(slot: slot);
+ Element typeElement = type.element;
if (type is TypeParameterType) {
b.paramReference = findTypeParameterIndex(type, context);
+ } else if (type is FunctionType &&
+ typeElement is FunctionElement &&
+ typeElement.enclosingElement == null) {
+ b.syntheticReturnType =
+ serializeTypeRef(typeElement.returnType, typeElement);
+ b.syntheticParams = typeElement.parameters
+ .map((ParameterElement param) => serializeParam(param, context))
+ .toList();
} else {
if (type is FunctionType &&
- type.element.enclosingElement is ParameterElement) {
+ typeElement.enclosingElement is ParameterElement) {
// Code cannot refer to function types implicitly defined by parameters
// directly, so if we get here, we must be serializing a linked
// reference from type inference.
- assert(linked);
- ParameterElement parameterElement = type.element.enclosingElement;
+ assert(buildingLinkedReferences);
+ ParameterElement parameterElement = typeElement.enclosingElement;
while (true) {
Element parent = parameterElement.enclosingElement;
if (parent is ExecutableElement) {
@@ -940,7 +955,7 @@ class _CompilationUnitSerializer {
continue;
} else {
// Function-typed parameter inside a top level function or method.
- b.reference = _getElementReferenceId(parent, linked: linked);
+ b.reference = _getElementReferenceId(parent);
break;
}
} else {
@@ -949,7 +964,7 @@ class _CompilationUnitSerializer {
}
}
} else {
- b.reference = serializeReferenceForType(type, linked);
+ b.reference = serializeReferenceForType(type);
}
List<DartType> typeArguments = getTypeArguments(type);
if (typeArguments != null) {
@@ -962,8 +977,8 @@ class _CompilationUnitSerializer {
if (numArgsToSerialize > 0) {
List<EntityRefBuilder> serializedArguments = <EntityRefBuilder>[];
for (int i = 0; i < numArgsToSerialize; i++) {
- serializedArguments.add(
- serializeTypeRef(typeArguments[i], context, linked: linked));
+ serializedArguments
+ .add(serializeTypeRef(typeArguments[i], context));
}
b.typeArguments = serializedArguments;
}
@@ -1082,12 +1097,12 @@ class _CompilationUnitSerializer {
int slot = ++numSlots;
if (type != null) {
deferredLinkedTypes
- .add(() => serializeTypeRef(type, context, linked: true, slot: slot));
+ .add(() => serializeTypeRef(type, context, slot: slot));
}
return slot;
}
- int _getElementReferenceId(Element element, {bool linked: false}) {
+ int _getElementReferenceId(Element element) {
return referenceMap.putIfAbsent(element, () {
LibraryElement dependentLibrary = librarySerializer.libraryElement;
int unit = 0;
@@ -1104,13 +1119,13 @@ class _CompilationUnitSerializer {
String name = element == null ? 'void' : element.name;
int index;
LinkedReferenceBuilder linkedReference;
- if (linked) {
+ if (buildingLinkedReferences) {
linkedReference =
new LinkedReferenceBuilder(kind: kind, unit: unit, name: name);
if (enclosingElement != null &&
enclosingElement is! CompilationUnitElement) {
linkedReference.containingReference =
- _getElementReferenceId(enclosingElement, linked: linked);
+ _getElementReferenceId(enclosingElement);
if (enclosingElement is ClassElement) {
// Nothing to do.
} else if (enclosingElement is ExecutableElement) {
@@ -1150,7 +1165,7 @@ class _CompilationUnitSerializer {
prefixReference = serializePrefix(prefix);
}
} else {
- prefixReference = _getElementReferenceId(enclosing, linked: linked);
+ prefixReference = _getElementReferenceId(enclosing);
}
index = serializeUnlinkedReference(name, kind,
prefixReference: prefixReference, unit: unit);
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698