Skip to content

Commit c9576a1

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
Reland "[cfe] Make fast path for adding simple member signatures"
Change-Id: If9aa575308a3932988259f36d217f6d402136388 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162749 Reviewed-by: Jens Johansen <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 644df9b commit c9576a1

10 files changed

+401
-68
lines changed

pkg/front_end/lib/src/fasta/kernel/class_hierarchy_builder.dart

Lines changed: 74 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,76 +2965,84 @@ class InterfaceConflict extends DelayedMember {
29652965
return combinedMemberSignatureResult =
29662966
declarations.first.getMember(hierarchy);
29672967
}
2968-
bool isNonNullableByDefault = classBuilder.library.isNonNullableByDefault;
2969-
DartType thisType = hierarchy.coreTypes
2970-
.thisInterfaceType(classBuilder.cls, classBuilder.library.nonNullable);
2971-
List<DartType> candidateTypes = new List<DartType>(declarations.length);
29722968
ClassMember bestSoFar;
29732969
int bestSoFarIndex;
2974-
DartType bestTypeSoFar;
29752970
Map<DartType, int> mutualSubtypes;
2976-
for (int candidateIndex = declarations.length - 1;
2977-
candidateIndex >= 0;
2978-
candidateIndex--) {
2979-
ClassMember candidate = declarations[candidateIndex];
2980-
Member target = candidate.getMember(hierarchy);
2981-
assert(target != null,
2982-
"No member computed for ${candidate} (${candidate.runtimeType})");
2983-
DartType candidateType = computeMemberType(hierarchy, thisType, target);
2984-
if (!isNonNullableByDefault) {
2985-
candidateType = legacyErasure(hierarchy.coreTypes, candidateType);
2986-
}
2987-
candidateTypes[candidateIndex] = candidateType;
2988-
if (bestSoFar == null) {
2989-
bestSoFar = candidate;
2990-
bestTypeSoFar = candidateType;
2991-
bestSoFarIndex = candidateIndex;
2992-
} else {
2993-
if (isMoreSpecific(hierarchy, candidateType, bestTypeSoFar)) {
2994-
debug?.log("Combined Member Signature: ${candidate.fullName} "
2995-
"${candidateType} <: ${bestSoFar.fullName} ${bestTypeSoFar}");
2996-
if (isNonNullableByDefault &&
2997-
isMoreSpecific(hierarchy, bestTypeSoFar, candidateType)) {
2998-
if (mutualSubtypes == null) {
2999-
mutualSubtypes = {
3000-
bestTypeSoFar: bestSoFarIndex,
3001-
candidateType: candidateIndex
3002-
};
2971+
if (declarations.length == 1) {
2972+
bestSoFar = declarations[0];
2973+
bestSoFarIndex = 0;
2974+
} else {
2975+
DartType thisType = hierarchy.coreTypes.thisInterfaceType(
2976+
classBuilder.cls, classBuilder.library.nonNullable);
2977+
bool isNonNullableByDefault = classBuilder.library.isNonNullableByDefault;
2978+
2979+
DartType bestTypeSoFar;
2980+
List<DartType> candidateTypes = new List<DartType>(declarations.length);
2981+
for (int candidateIndex = declarations.length - 1;
2982+
candidateIndex >= 0;
2983+
candidateIndex--) {
2984+
ClassMember candidate = declarations[candidateIndex];
2985+
Member target = candidate.getMember(hierarchy);
2986+
assert(target != null,
2987+
"No member computed for ${candidate} (${candidate.runtimeType})");
2988+
DartType candidateType = computeMemberType(hierarchy, thisType, target);
2989+
if (!isNonNullableByDefault) {
2990+
candidateType = legacyErasure(hierarchy.coreTypes, candidateType);
2991+
}
2992+
candidateTypes[candidateIndex] = candidateType;
2993+
if (bestSoFar == null) {
2994+
bestSoFar = candidate;
2995+
bestTypeSoFar = candidateType;
2996+
bestSoFarIndex = candidateIndex;
2997+
} else {
2998+
if (isMoreSpecific(hierarchy, candidateType, bestTypeSoFar)) {
2999+
debug?.log("Combined Member Signature: ${candidate.fullName} "
3000+
"${candidateType} <: ${bestSoFar.fullName} ${bestTypeSoFar}");
3001+
if (isNonNullableByDefault &&
3002+
isMoreSpecific(hierarchy, bestTypeSoFar, candidateType)) {
3003+
if (mutualSubtypes == null) {
3004+
mutualSubtypes = {
3005+
bestTypeSoFar: bestSoFarIndex,
3006+
candidateType: candidateIndex
3007+
};
3008+
} else {
3009+
mutualSubtypes[candidateType] = candidateIndex;
3010+
}
30033011
} else {
3004-
mutualSubtypes[candidateType] = candidateIndex;
3012+
mutualSubtypes = null;
30053013
}
3014+
bestSoFarIndex = candidateIndex;
3015+
bestSoFar = candidate;
3016+
bestTypeSoFar = candidateType;
30063017
} else {
3007-
mutualSubtypes = null;
3018+
debug?.log("Combined Member Signature: "
3019+
"${candidate.fullName} !<: ${bestSoFar.fullName}");
30083020
}
3009-
bestSoFarIndex = candidateIndex;
3010-
bestSoFar = candidate;
3011-
bestTypeSoFar = candidateType;
3012-
} else {
3013-
debug?.log("Combined Member Signature: "
3014-
"${candidate.fullName} !<: ${bestSoFar.fullName}");
30153021
}
30163022
}
3017-
}
3018-
if (bestSoFar != null) {
3019-
debug?.log("Combined Member Signature bestSoFar: ${bestSoFar.fullName}");
3020-
for (int candidateIndex = 0;
3021-
candidateIndex < declarations.length;
3022-
candidateIndex++) {
3023-
ClassMember candidate = declarations[candidateIndex];
3024-
DartType candidateType = candidateTypes[candidateIndex];
3025-
if (!isMoreSpecific(hierarchy, bestTypeSoFar, candidateType)) {
3026-
debug?.log("Combined Member Signature: "
3027-
"${bestSoFar.fullName} !<: ${candidate.fullName}");
3028-
3029-
if (!shouldOverrideProblemBeOverlooked(classBuilder)) {
3030-
bestSoFar = null;
3031-
bestTypeSoFar = null;
3032-
mutualSubtypes = null;
3023+
if (bestSoFar != null) {
3024+
debug?.log("Combined Member Signature bestSoFar: "
3025+
"${bestSoFar.fullName}");
3026+
for (int candidateIndex = 0;
3027+
candidateIndex < declarations.length;
3028+
candidateIndex++) {
3029+
ClassMember candidate = declarations[candidateIndex];
3030+
DartType candidateType = candidateTypes[candidateIndex];
3031+
if (!isMoreSpecific(hierarchy, bestTypeSoFar, candidateType)) {
3032+
debug?.log("Combined Member Signature: "
3033+
"${bestSoFar.fullName} !<: ${candidate.fullName}");
3034+
3035+
if (!shouldOverrideProblemBeOverlooked(classBuilder)) {
3036+
bestSoFar = null;
3037+
bestTypeSoFar = null;
3038+
mutualSubtypes = null;
3039+
}
3040+
break;
30333041
}
3034-
break;
30353042
}
30363043
}
30373044
}
3045+
30383046
if (bestSoFar == null) {
30393047
String name = classBuilder.fullNameForErrors;
30403048
int length = classBuilder.isAnonymousMixinApplication ? 1 : name.length;
@@ -3058,16 +3066,16 @@ class InterfaceConflict extends DelayedMember {
30583066
debug?.log("Combined Member Signature of ${fullNameForErrors}: "
30593067
"${bestSoFar.fullName}");
30603068

3061-
ProcedureKind kind = ProcedureKind.Method;
3062-
Member bestMemberSoFar = bestSoFar.getMember(hierarchy);
3063-
if (bestSoFar.isProperty) {
3064-
kind = isSetter ? ProcedureKind.Setter : ProcedureKind.Getter;
3065-
} else if (bestMemberSoFar is Procedure &&
3066-
bestMemberSoFar.kind == ProcedureKind.Operator) {
3067-
kind = ProcedureKind.Operator;
3068-
}
3069-
30703069
if (modifyKernel) {
3070+
ProcedureKind kind = ProcedureKind.Method;
3071+
Member bestMemberSoFar = bestSoFar.getMember(hierarchy);
3072+
if (bestSoFar.isProperty) {
3073+
kind = isSetter ? ProcedureKind.Setter : ProcedureKind.Getter;
3074+
} else if (bestMemberSoFar is Procedure &&
3075+
bestMemberSoFar.kind == ProcedureKind.Operator) {
3076+
kind = ProcedureKind.Operator;
3077+
}
3078+
30713079
debug?.log("Combined Member Signature of ${fullNameForErrors}: new "
30723080
"ForwardingNode($classBuilder, $bestSoFar, $declarations, $kind)");
30733081
Member stub = new ForwardingNode(

0 commit comments

Comments
 (0)