-
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
[breaking-change-request] Report all top-level inference circularities #50383
Comments
What message will we show in the analyzer and what message will we show in the compiler? |
The analyzer:
|
SGTM. |
lgtm |
@grouma have you had a chance to take a look at this? |
@MaryaBelanger and @atsansone FYI. |
Can these be preemptively cleaned up? |
The internal problems have been fixed. @scheglov Can you land the change in the analyzer before the stable cut? |
It was already landed as dab3697. |
I see no arguments against performing this breaking change. @johnniwinther, @scheglov, it sounds like this work is already well underway, and #46579 was used to handle some work on the analyzer. Is there a need for any further separate implementation issues? |
My understand is that I implemented all what was necessary in the analyzer. |
This has landed. |
I have just hit the introduced error when trying to analyze a sample code from "Real-World Flutter by Tutorials: Materials" gives:
I think the error message message could be improved in both analyzer and CFE (the latter reports: "Can't infer the type of '...': circularity found during type inference."). Error message should probably link to some documentation on
|
@mraleph I had the same concern a couple months ago. Some diagnostic messages point to the Fixing type promotion failures page on dart.dev, where I think this explanation could go. In
I'm happy to add the section to the dart.dev page based on the details in your comment. In fact, I think it needs to be done. What I'm not capable of is adding a whole class to ~ nothing in this issue points me to the actual commit that corresponds with this work so I can't find that out myself either, is it this class? |
@scheglov Who can probably answer the question of where the addition of the context message would need to happen. |
In the analyzer we report this as |
Cf. dart-lang/language#1650.
Change in behavior
The proposed change is that top-level inference shall report a compile-time error for all cyclic dependencies, based on references from the body of one declaration to another declaration. The previous behavior included ignoring subterms (expressions or statements) in cases where inference on said subterms would not influence the type which is currently being inferred.
Justification/rationale
The previous behavior is complex, it is not consistent among all tools, and the complexity of the approach has been rising as flow analysis and other language mechanisms have evolved over time.
A software engineering rationale exists as well: In the situations where top-level type inference would succeed because of a subtle analysis that allowed certain parts of the code to be ignored, the types of the declarations in the given cycle would be rather difficult to discern for a human reader as well. With this change, types must be given explicitly in those situations, and this could improve both the readability, comprehensibility, and maintainability of the code.
Expected impact
The impact is that new compile-time errors will be emitted for dependency cycles that used to be accepted (because some subterms of the declarations were ignored).
The number of locations which would be affected is expected to be very low. Internally it is believed that only a couple of such locations exist.
Mitigation
For each dependency cycle which was previously accepted and which is now a compile-time error, add a declared type to at least one of the declarations in the cycle.
Example
Here is an example showing that a cyclic dependency can exist, and the program can be executed without entering into an infinite loop, but the circularity does not actually matter in relation to the inferred types:
With the proposed change, an explicit type must be given to either
a
orb
.This program is currently accepted by the common front end (version 2.19.0-331.0.dev accepts it), but work is ongoing (and the bleeding edge CFE rejects it). This breaking-change procedure is needed in order to make sure that the breakage is announced and discussed as it should be. If the change is accepted then the implementation in the CFE is basically ready. The analyzer currently rejects the above program, but needs some adjustments as well.
The text was updated successfully, but these errors were encountered: