Skip to content

[ConstraintSystem] Introduce a notion of a "hole" #26798

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 3 commits into from
Aug 27, 2019

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Aug 23, 2019

A "hole" is a type variable which type couldn't be determined
due to an inference failure e.g. missing member, ambiguous generic
parameter which hasn't been explicitly specified.

It is used to propagate information about failures and avoid
recording fixes which are a consequence of earlier failures e.g.

func foo<T: BinaryInteger>(_: T) {}

struct S {}

 foo(S.bar) // Actual failure here is that `S` doesn't have a member
            // `bar` but a consequence of that failure is that generic
            // parameter `T` doesn't conform to `BinaryInteger`.

xedin added 3 commits August 22, 2019 17:24
A "hole" is a type variable which type couldn't be determined
due to an inference failure e.g. missing member, ambiguous generic
parameter which hasn't been explicitly specified.

It is used to propagate information about failures and avoid
recording fixes which are a consequence of earlier failures e.g.

```swift
func foo<T: BinaryInteger>(_: T) {}

struct S {}

foo(S.bar) // Actual failure here is that `S` doesn't have a member
           // `bar` but a consequence of that failure is that generic
           // parameter `T` doesn't conform to `BinaryInteger`.
```
Replace specialized `MissingMembers` tracking with more general
constraint system "holes" which simplifies solver logic.
@xedin xedin requested review from DougGregor and hborla August 23, 2019 00:25
@xedin
Copy link
Contributor Author

xedin commented Aug 23, 2019

/cc @hborla this could also be used to properly diagnose situations like Optional(.none) when you have encountered, all of the defaulted generic parameters have to be recorded as "holes".

@xedin
Copy link
Contributor Author

xedin commented Aug 23, 2019

@swift-ci please smoke test

@varungandhi-apple
Copy link
Contributor

Sorry to butt in but can we use some terminology other than "hole" if it's not too late already? In Agda/Idris/Haskell/Scala/Purescript, a "hole" represents "I don't know what term I should write here, but compiler, you know the type of the expression that should appear here, as well as the types of the different terms in scope, so give me suggestions for what term I should write here". Perhaps "invalid type variable" or "illegal type variable"?

@xedin
Copy link
Contributor Author

xedin commented Aug 23, 2019

@varungandhi-apple It's not actually an invalid or illegal type variable, but the one which solver couldn't infer a type for hence a hole. I believe that this is actually a term used in the type system related papers too, at least ones I saw about diagnostics.

@varungandhi-apple
Copy link
Contributor

@xedin thanks for clarifying! I misunderstood the original comment.

@xedin
Copy link
Contributor Author

xedin commented Aug 27, 2019

Let's smoke test it once again just in case since it's been a while.

@xedin
Copy link
Contributor Author

xedin commented Aug 27, 2019

@swift-ci please smoke test

@xedin xedin merged commit d0530b9 into swiftlang:master Aug 27, 2019
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.

4 participants