Skip to content

[Experiment] GSB: Disable conditional requirement inference in protocols #40466

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Dec 8, 2021

If you have a pair of requirements T : P and T == G, the conformance
G : P might be conditional, imposing arbitrary requirements on U.

In particular, these conditional requirements can mention arbitrary
protocols on the right hand side.

Introducing these conformance requirements during property map construction
is totally fine when building a top-level generic signature, but when
building a protocol requirement signature, things get a bit tricky.

Because of the design of the requirement machine, it is better if the set
of protocols appearing on the right hand side of conformance requirements
in another protocol (the "protocol dependencies") are known before we
start building the requirement signature, because we build the requirement
signatures of all protocols in a connected component of this graph
simultaneously.

Introducing conformance requirements to hithero-unseen protocols after
the graph of connected components had already been built would require
mutating it in a tricky way, and possibly merging connected components.

I didn't find any examples of protocols that rely on conditional
requirement inference in our test suite, or in the source compatibility
suite.

So for now, I'm going to try to disable this feature inside protocols.

Another argument in favor of not doing conditional requirement
inference in protocols is that we don't do the ordinary kind of requirement
inference there either. That is, the following is an error:

protocol P {
  associatedtype T == Set<U>
  associatedtype U
}

Unlike with an ordinary top-level generic signature, we don't infer
'U : Hashable' here. So arguably the current behavior of protocols inferring
these requirements in the case of a conditional conformance only is also
rather odd.

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov force-pushed the gsb-no-requirement-inference-in-protocols branch 2 times, most recently from f93328e to 62c892e Compare December 8, 2021 21:34
If you have a pair of requirements T : P and T == G<U>, the conformance
G : P might be conditional, imposing arbitrary requirements on U.

In particular, these conditional requirements can mention arbitrary
protocols on the right hand side.

Introducing these conformance requirements during property map construction
is totally fine when building a top-level generic signature, but when
building a protocol requirement signature, things get a bit tricky.

Because of the design of the requirement machine, it is better if the set
of protocols appearing on the right hand side of conformance requirements
in another protocol (the "protocol dependencies") are known *before* we
start building the requirement signature, because we build the requirement
signatures of all protocols in a connected component of this graph
simultaneously.

Introducing conformance requirements to hithero-unseen protocols after
the graph of connected components had already been built would require
mutating it in a tricky way, and possibly merging connected components.

I didn't find any examples of protocols that rely on conditional
requirement inference in our test suite, or in the source compatibility
suite.

So for now, I'm going to try to disable this feature inside protocols.

Another argument in favor of not doing conditional requirement
inference in protocols is that we don't do the ordinary kind of requirement
inference there either. That is, the following is an error:

    protocol P {
      associatedtype T == Set<U>
      associatedtype U
    }

Unlike with an ordinary top-level generic signature, we don't infer
'U : Hashable' here. So arguably the current behavior of protocols inferring
these requirements in the case of a conditional conformance only is also
rather odd.
@slavapestov slavapestov force-pushed the gsb-no-requirement-inference-in-protocols branch from 62c892e to d993e02 Compare December 8, 2021 21:36
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit ddd746b into swiftlang:main Dec 9, 2021
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.

1 participant