-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Init check: Early Promotion of fields #11533
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
40d7506
Move rule 1 logic to `canDirectlyPromote`
natsukagami 5af41fe
WIP: Rule 2 implementation
natsukagami 35b796b
Add checks for member classes
natsukagami 1874233
Add expand logic to canDirectlyPromote
natsukagami dffcc6e
Add more tests
natsukagami e2b758e
Mitigate infinite recursion on canDirectlyPromote
natsukagami fb48e37
Fix comment style
natsukagami ccbd3eb
Match Scala 3 style
natsukagami e7e6e7c
Fix nit on comment indentation
natsukagami 270a886
Move directlyPromote check up
natsukagami 259a2ab
Fix init tests
natsukagami 363f8b6
Short circuit if we find a problematic promotion
natsukagami 1d2688e
Update Checking.scala
natsukagami File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class Y { | ||
class X { | ||
class B { | ||
def g = f | ||
def g2 = n | ||
} | ||
val f = 42 | ||
val b = new B // warm(B, X.this) | ||
} | ||
|
||
val n = 10 | ||
val x = new X | ||
List(x.b) // unsafe promotion | ||
|
||
} | ||
|
||
class A { // checking A | ||
class B { | ||
def bf = 42 | ||
class C { | ||
def x = bf // uses outer[C], but never outer[B] | ||
} | ||
List((new C).x) | ||
def c = new C | ||
} | ||
val b = new B() | ||
List(b) // Direct promotion works here | ||
val af = 42 | ||
} | ||
|
||
class RecursiveF { | ||
val a = f | ||
def f: RecursiveF = f | ||
class B(x: Int) | ||
|
||
println(new a.B(5)) | ||
val n = 10 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 will lead to infinite loops. The following might be a test case:
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.
Mitigating this with a
visited
set. I think it's easier to just set a maximum recursion depth though, because this is only a speed-up measure most of the time...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.
Yes, you can play with it and see which works better for the tests we have.