Skip to content

AssociatedTypeInference: Delay substitutions into abstract type witnesses until after they have been computed #32752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2020

Conversation

AnthonyLatsis
Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis commented Jul 7, 2020

  • We were trying to substitute into default type witnesses without considering other tentative abstract type witnesses we may need to compute later, resulting in conformance errors whenever a default type witness referenced other associated types that are destined to resolve to abstract type witnesses.
    protocol P {
      associatedtype A = [B]
      associatedtype B = Never
    }
    struct Foo: P {} // used to be a conformance error
  • Bonus: fixed type witnesses are now getting substituted into as well and can finally reference other associated types without unconditional conformance errors.
    protocol P {
      associatedtype A = Never
      associatedtype B
    }
    protocol Q: P where B == [A] {}
    struct Foo: Q {} // used to be a conformance error

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test source compatibility release

const auto lookupConfFn = [&](CanType dependentType,
Type conformingReplacementType,
ProtocolDecl *conformedProtocol) {
if (conformedProtocol == proto &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? Conformance lookup doesn't trigger computation of anything, it just returns an existing conformance even if its type witnesses have not yet been filled in.

Copy link
Collaborator Author

@AnthonyLatsis AnthonyLatsis Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a paranoia I have about conformance lookup determinism dating back to this comment by Joe :) (though I must admit the question is still open to me – how we could end up with a different conformance –, given that we cache them for as long as the nominal decl exists).

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test source compatibility release

@AnthonyLatsis
Copy link
Collaborator Author

@slavapestov LMK what you think of the additional modeling. Seems an exaggeration for the purpose of removing the mapIntoContext call, but I believe it has the potential of becoming beneficial to diagnostics and dumping later on.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test source compatibility release

@AnthonyLatsis AnthonyLatsis merged commit 19f27d9 into swiftlang:master Jul 15, 2020
@AnthonyLatsis AnthonyLatsis deleted the plus-inference branch July 15, 2020 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants