-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allowing local variables to be initialized with non-hot values in initialization checker #12867
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
9 commits
Select commit
Hold shift + click to select a range
c886d5a
Allowing non-hot assignment to local val and updating tests
EnzeXing 2560f15
Try early promotion before updating env
EnzeXing 0f1586d
Evaluate local variable during access
EnzeXing fef4ddf
Resolving cases for def-tree
EnzeXing ccab4eb
Synchronize Symbol.defTree before analysis
liufengyun ba5f4f0
Refactoring accessLocal
EnzeXing 6cbfd9a
Update tests
EnzeXing a59e6a3
Handle OuterSelect in init checker
liufengyun e901a36
Fix join of values
liufengyun 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
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,28 @@ | ||
trait Reporter: | ||
def report(m: String): Unit | ||
|
||
class Dummy extends Reporter: | ||
def report(m: String) = () | ||
|
||
object ABug { | ||
sealed trait Nat { | ||
transparent inline def ++ : Succ[this.type] = Succ(this) | ||
|
||
transparent inline def +(inline that: Nat): Nat = | ||
inline this match { | ||
case Zero => that | ||
case Succ(p) => p + that.++ | ||
} | ||
} | ||
|
||
case object Zero extends Nat | ||
case class Succ[N <: Nat](p: N) extends Nat | ||
|
||
transparent inline def toIntg(inline n: Nat): Int = | ||
inline n match { | ||
case Zero => 0 | ||
case Succ(p) => toIntg(p) + 1 | ||
} | ||
|
||
val j31 = toIntg(Zero.++.++.++ + Zero.++) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
-- Error: tests/init/neg/closureLeak.scala:11:14 ----------------------------------------------------------------------- | ||
11 | l.foreach(a => a.addX(this)) // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| Cannot prove that the value is fully-initialized. May only use initialized value as arguments. | ||
| Cannot prove that the value is fully-initialized. May only use initialized value as arguments. | ||
| | ||
| The unsafe promotion may cause the following problem: | ||
| Promote the value under initialization to fully-initialized. May only use initialized value as arguments. | ||
| The unsafe promotion may cause the following problem: | ||
| Cannot prove that the value is fully initialized. May only use initialized value as arguments. |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
-- Error: tests/init/neg/cycle-structure.scala:3:14 -------------------------------------------------------------------- | ||
3 | val x = B(this) // error | ||
| ^^^^ | ||
| Promote the value under initialization to fully-initialized. May only use initialized value as arguments. | ||
| Cannot prove that the value is fully initialized. May only use initialized value as arguments. | ||
-- Error: tests/init/neg/cycle-structure.scala:9:14 -------------------------------------------------------------------- | ||
9 | val x = A(this) // error | ||
| ^^^^ | ||
| Promote the value under initialization to fully-initialized. May only use initialized value as arguments. | ||
| Cannot prove that the value is fully initialized. May only use initialized value as arguments. |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-- Error: tests/init/neg/default-this.scala:9:8 ------------------------------------------------------------------------ | ||
9 | compare() // error | ||
| ^^^^^^^ | ||
|Promote the value under initialization to fully-initialized. May only use initialized value as arguments. Calling trace: | ||
| -> val result = updateThenCompare(5) [ default-this.scala:11 ] | ||
| Cannot prove that the value is fully initialized. May only use initialized value as arguments. Calling trace: | ||
| -> val result = updateThenCompare(5) [ default-this.scala:11 ] |
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,16 @@ | ||
-- Error: tests/init/neg/inherit-non-hot.scala:6:34 -------------------------------------------------------------------- | ||
6 | if b == null then b = new B(this) // error | ||
| ^^^^^^^^^^^ | ||
| Cannot prove that the value is fully-initialized. May only assign fully initialized value. | ||
| Calling trace: | ||
| -> val c = new C [ inherit-non-hot.scala:19 ] | ||
| -> class C extends A { [ inherit-non-hot.scala:15 ] | ||
| -> val bAgain = toB.getBAgain [ inherit-non-hot.scala:16 ] | ||
| | ||
| The unsafe promotion may cause the following problem: | ||
| Call method Foo.B.this.aCopy.toB on a value with an unknown initialization. Calling trace: | ||
| -> val c = new C [ inherit-non-hot.scala:19 ] | ||
| -> class C extends A { [ inherit-non-hot.scala:15 ] | ||
| -> val bAgain = toB.getBAgain [ inherit-non-hot.scala:16 ] | ||
| -> if b == null then b = new B(this) // error [ inherit-non-hot.scala:6 ] | ||
| -> def getBAgain: B = aCopy.toB [ inherit-non-hot.scala:12 ] |
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,21 @@ | ||
// This is a minimized test for the warning in Names.scala:174 | ||
object Foo { | ||
abstract class A { | ||
var b: B = null | ||
def toB: B = | ||
if b == null then b = new B(this) // error | ||
b | ||
} | ||
|
||
class B(a: A) { | ||
var aCopy: A = a | ||
def getBAgain: B = aCopy.toB | ||
} | ||
|
||
class C extends A { | ||
val bAgain = toB.getBAgain | ||
} | ||
|
||
val c = new C | ||
assert(c.b == c.bAgain) | ||
} |
Oops, something went wrong.
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.
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.
For parameters for normal method calls, we just return
Result(Hot, Nil)
since we expect that those arguments have been promoted inCall
, right?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, that's correct.