-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
How do we match forward declarations with their definitions? #1132
Comments
In open discussion on 2022-03-14 we came to some initial conclusions:
The principle we wanted to follow for this is to make it as minimal as we can. This is intended to give the compiler the best change at producing good diagnostics. For most cases, this means we match based on only the name. The main exception is for constructs that don't have a name, like interface implementations.
There is a spectrum here, from textual matching to semantic matching. Textual matching is very simple, both to understand and to implement in the compiler, but has two downsides:
These can be addressed by semantic matching, but measuring complete semantic equivalence is prohibitive from a compiler implementation perspective and obscures which declarations would match to human readers. Instead we decided on something in between:
Otherwise Carbon would not attempt to determine any other semantic equivalence.
For functions we decided we wanted parameter names to match if they were specified, but they could be omitted. We wanted this consistency based on:
It is still an open question how omitted parameter names would be written (using In general we wanted to start with a restrictive approach and see how it went. For this reason, we don't think deduced parameters should be allowed to be reordered. We were undecided about what to do about |
I think we have consensus around the solution @josh11b wrote up. This doesn't include a decision around particular syntax choices (although I'm personally happy w/ what's here at least to start), but includes the rest of this:
Re-open if more detailed things come up that we need to handle. |
What agreement rule do we want for the case where the forward declaration and definition are in different scopes -- specifically, when checking whether a declaration of a member function in a class (or a defaulted function in an interface or a member of an impl) agrees with a definition written outside that class? For example: class A {
fn F();
}
let T:! type = A;
// OK?
fn T.F() {}
class B(T:! type) {
fn F();
}
constraint Type {}
// OK?
fn B(T:! Type).F() {} I suggest we require the part before the |
I agree. |
With the decision on #472 , Carbon has separate forward declarations from definitions and we need some way to match them up. This comes up for functions, classes, interfaces, named constraints, interface implementations, and probably others.
There are a three main components to this question:
The text was updated successfully, but these errors were encountered: