-
-
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
Separate top-level semantic phase for overload reordering #11692
Comments
Another breaking change is that, I think, That said, I think we should do it, even if it's a breaking change. I don't think |
I believe
|
This sounds like a good idea. Maybe it could be worth considering elimination of obvious redefinitions. |
Ref: #10071 |
It is, in fact, not that obvious because defs that yield are not required to have a |
It's confusing for What's even the purpose of making overload ordering observable here? I would consider this an unintended spillover effect of the implementation. I have actually never noticed that. It's not documented. And it's probably not very useful. But the order of I don't think this should be handled in #11840. It works well as a follow-up. However, a relevant aspect is what happens about redefinitions. I still think it would be nice if they can be eliminated right away. If requiring a |
If the defs do not follow overload ordering it would become more difficult for me to diagnose the ordering-related issues right here 😂 A purely syntactic approach to detecting redefinitions "right away", i.e. in the top-level phase, would definitely miss redefinitions that require resolving |
This is a more complete proposal of an idea that has been mentioned in several PRs.
Currently, whenever the top-level visitor encounters a new overload of a method, it reorders the overloads immediately, and in doing so it resolves the type restrictions in the def at that point of visitation; types and type relations that are declared later would not affect the order of the overload being added. This leads to problems such as #4897, #7579, #10518, and #11678.
The compiler should defer overload reordering to a distinct phase after top-level declarations are processed. What it means is:
previous_def
s are registered.Crystal::TopLevelVisitor#visit(node : Def)
into a new visitor. This makesTypeNode#methods
completely empty in top-level macros though.method_missing
happens during main analysis, so it continues to trigger overload reordering every time a corresponding def is generated.This would be a breaking change because top-level macros cannot observe the intermediate overload ordering: (contrast with
TypeNode#instance_vars
)An alternative solution would be #10723, but it requires changes to user code and probably a lot more effort to implement that feature.
The text was updated successfully, but these errors were encountered: