Optimize gatherMixinSupertypeConstraints for new mixin syntax.

Since this method is only used to find supertype constraints that are
relevant for mixin inference, it can save its caller from doing extra
work by filtering out mixins that don't take type parameters.
Previously, we were doing that when supporting the old "--supermixin"
feature, but not when using the new mixin syntax.

The method has been renamed to
gatherMixinSupertypeConstraintsForInference so that it's less
surprising that it doesn't return *all* supertype constraints.

Change-Id: I33c5cf20bb4955a19ef0f7dc2425fefc26cf4d39
Reviewed-on: https://dart-review.googlesource.com/75983
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2018-09-21 18:53:03 +00:00 committed by commit-bot@chromium.org
parent 5cf0d9e844
commit e9ff597673
3 changed files with 12 additions and 11 deletions

View file

@ -5819,8 +5819,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
var mixinElement = mixinType.element;
if (mixinElement is ClassElement) {
if (typeName.typeArguments == null) {
var mixinSupertypeConstraints =
_typeSystem.gatherMixinSupertypeConstraints(mixinElement);
var mixinSupertypeConstraints = _typeSystem
.gatherMixinSupertypeConstraintsForInference(mixinElement);
if (mixinSupertypeConstraints.isNotEmpty) {
var matchingInterfaceTypes = _findInterfaceTypesForConstraints(
typeName,

View file

@ -1757,16 +1757,17 @@ abstract class TypeSystem {
*/
TypeProvider get typeProvider;
List<InterfaceType> gatherMixinSupertypeConstraints(
List<InterfaceType> gatherMixinSupertypeConstraintsForInference(
ClassElement mixinElement) {
List<InterfaceType> candidates;
if (mixinElement.isMixin) {
return mixinElement.superclassConstraints;
}
var candidates = [mixinElement.supertype];
candidates.addAll(mixinElement.mixins);
if (mixinElement.isMixinApplication) {
candidates.removeLast();
candidates = mixinElement.superclassConstraints;
} else {
candidates = [mixinElement.supertype];
candidates.addAll(mixinElement.mixins);
if (mixinElement.isMixinApplication) {
candidates.removeLast();
}
}
return candidates
.where((type) => type.element.typeParameters.isNotEmpty)

View file

@ -715,7 +715,7 @@ class ClassElementForLink_Class extends ClassElementForLink
this.enclosingElement;
if (enclosingElement is CompilationUnitElementInBuildUnit) {
var mixinSupertypeConstraints = context.typeSystem
.gatherMixinSupertypeConstraints(mixinElement);
.gatherMixinSupertypeConstraintsForInference(mixinElement);
if (mixinSupertypeConstraints.isNotEmpty) {
if (supertypesForMixinInference == null) {
supertypesForMixinInference = <InterfaceType>[];