Remove most uses of uncheckedNN#26239
Merged
Merged
Conversation
SolalPirelli
commented
Jun 5, 2026
| if (ctx.settings.YretainTrees.value) { | ||
| if (myTrees == null) myTrees = computeRootTrees | ||
| myTrees.uncheckedNN | ||
| initialize(myTrees, myTrees = _, computeRootTrees) |
Contributor
Author
There was a problem hiding this comment.
(scroll to the last file in this diff view to see the definition of this -- it's as you'd expect, hopefully)
SolalPirelli
commented
Jun 5, 2026
| protected def computeRootTrees(using Context): List[Tree] | ||
|
|
||
| private var myTrees: List[Tree] | Null = uninitialized | ||
| private var myTrees: List[Tree] | Null = null |
Contributor
Author
There was a problem hiding this comment.
no point in uninitialized for explicitly nullable stuff
7bc072e to
79e6ca5
Compare
sjrd
requested changes
Jun 5, 2026
Comment on lines
+29
to
+34
| inline def initialize[T](getter: T | Null, setter: T => Unit, inline value: T): T = getter match | ||
| case v: T => v | ||
| case null => | ||
| val res = value | ||
| setter(res) | ||
| res |
Member
There was a problem hiding this comment.
This does not produce good code because it performs a type test on : T rather than a single null test. The best code is obtained with
inline def initialize[T](getter: T | Null, inline setter: T => Unit, inline value: => T): T =
if getter != null then
getter
else
val res = value
setter(res)
res(note also the signature. setter must be inline)
Contributor
Author
There was a problem hiding this comment.
OK, thanks. I wonder if that's something we could improve in the compiler.
| end comparing | ||
|
|
||
| @sharable val NoContext: Context = new FreshContext((null: ContextBase | Null).uncheckedNN) { | ||
| @sharable val NoContext: Context = new FreshContext(null.asInstanceOf[ContextBase]) { |
Member
There was a problem hiding this comment.
Ugh. This is just wrong :(
(not that it was better before your PR)
93a1f6d to
6258af3
Compare
sjrd
approved these changes
Jun 8, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Removed all of the ones that are locally easy to remove, i.e., no complex invariants across methods or fields.
Remaining:
These are all more complex invariants.
Plus the def:
How much have you relied on LLM-based tools in this contribution?
Not at all
How was the solution tested?
Covered by existing tests (this is a refactoring)