-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Defer overload ordering until all types are fully defined #11840
base: master
Are you sure you want to change the base?
Defer overload ordering until all types are fully defined #11840
Conversation
I'm on mobile and don't have much time to look closer. Does this have any implications on #10986 ? |
Would it be unreasonable to have both changes use the same flag? |
For it to happen the compiler must traverse the list of overloads up to three times per method call (for each visibility), or the lists must be maintained separately. This is not done here.
In principle the two features are completely independent from each other; if they truly are, sharing the same flag shouldn't complicate troubleshooting, but I think the granularity here wouldn't hurt. |
…overload-ordering
…overload-ordering
…overload-ordering
@@ -904,28 +904,34 @@ module Crystal | |||
getter hooks : Array(Hook)? | |||
getter(parents) { [] of Type } | |||
|
|||
def add_def(a_def) | |||
def add_def(a_def : Def, *, ordered = true) |
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.
The parameter name ordered
seems a bit unclear to me. As a participle it suggests that some ordering is already applied. Instead, it expresses a request to perform a sort.
Maybe a better name would be order_overloads
?
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.
However, another thought is that maybe they should even be two entirely different methods. Both variants' behaviour is significantly different. Without overload ordering, the return type is Nil
, not Def?
.
So maybe having add_def
and add_def_with_overload_ordering
would be a more suitable API?
@@ -904,28 +904,34 @@ module Crystal | |||
getter hooks : Array(Hook)? | |||
getter(parents) { [] of Type } | |||
|
|||
def add_def(a_def) | |||
def add_def(a_def : Def, *, ordered = true) |
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.
Also, IMO it would be better to consider the new behaviour (i.e. what you get with -Dpreview_overload_ordering
) as the new default. Thus the default value should be false
.
Closes #11692. The new semantics are only available if
-Dpreview_overload_order
is defined. This conflicts with the flag used for #10711, so suggestions are welcome. I was thinking about an opt-out-Dno_defer_overload_order
flag, but I am not too confortable about that. This phase is done as part of the "type declarations" semantic stage; building an empty file and the standard library specs took about +0.08s and +0.2s respectively.Fixes #4897. Suppose the forward declarations in
src/big.cr
are removed. Before:After: (the
BigRational
overload is at the correct location)Fixes #7579:
Fixes part of #10518:
Fixes #11678:
For this example,
A
andB
will be printed regardless of the declaration order ofFoo#foo
's overloads.Does not affect #8771.
Again, all these examples work only if
-Dpreview_overload_order
is specified during compilation.