-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Type completeness in extend #6395
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
base: trunk
Are you sure you want to change the base?
Conversation
5074db7 to
cc668b4
Compare
cc668b4 to
5e9d9ae
Compare
5e9d9ae to
16bdf5f
Compare
16bdf5f to
7adc915
Compare
chandlerc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally LG on my end.
danakj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
| [#2760](https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p2760.md): | ||
| Consistent class and interface syntax | ||
|
|
||
| ## Proposal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we already have a rule for extend base and extend adapt declarations? If not, would it be worth adding them here too, so that we have complete coverage of all extend declarations?
| We call a `extend require` declaration _extend-reachable_ from a facet type if | ||
| it's enclosing interface or named constraint is part of that facet type, or if | ||
| its enclosing interface or named constraint is named by another | ||
| _extend-reachable_ declaration. That is, we can find a path from the facet type | ||
| to the `extend require` declaration through other `extend require` declarations. | ||
|
|
||
| We say that a facet type is complete if: | ||
|
|
||
| - All its _extend-reachable_ `extend require` declarations are complete. This | ||
| follows from the enclosing interface or named constraint being complete. | ||
| - We are able to form a specific for each interface and named constraint | ||
| extended by the facet type. | ||
| - We are able to form a specific for each _extend-reachable_ `extend require` | ||
| declaration in the context of the specific facet type being completed, | ||
| without monomorphization errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice if we could say something broader here, and while I don't think we can avoid facet types being a special case, perhaps we can make them reuse the broader notion. What I'm thinking is something along the lines of:
"""
An extend declaration
extend base: X;
extend adapt X;
extend impl as X;
extend require impls X;
declares that the enclosing scope extends the scope associated with X. The extend declaration requires X to be complete, or, if X is a generic parameter, requires the type of X to be complete.
The scope of a facet type formed by a where declaration extends the scope of its first operand. The scope of a facet type formed by an & operator extends the scopes of both of its operands. In either case, the facet type is complete if every scope it extends is complete. The facet type type is associated with an empty scope and is complete.
"""
| ## Details | ||
|
|
||
| To `extend` an entity `Y` with another `Z` means that name lookups into `Y` will | ||
| also look into `Z`. At the end of the definition of `Y`, we expect to be able to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect this to apply immediately, not at the end of the definition of Y. For example:
base class Z {
class X {}
}
class Y {
extend base: Z;
// Finds `X` in `Z`.
fn F() -> X;
}
Define rules for
extenddeclarations (extend requireandextend impl as) that say the facet type they name must be complete at the point of the declaration. Define completeness for a facet type to include all interfaces and named constraints that can be reached thoughextend requiredeclarations.