-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refactoring the global object initialization checker #17996
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
Conversation
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.
We can discuss more in our meeting.
(outer.widen(1), Env.NoEnv) | ||
else | ||
// klass.enclosingMethod returns its primary constructor | ||
Env.resolveEnv(klass.owner.enclosingMethod, outer, summon[Env.Data]).getOrElse(Cold -> Env.NoEnv) | ||
Env.resolveEnv(klass.owner.enclosingMethod, outer.asInstanceOf[ValueElement], summon[Env.Data]).getOrElse(Cold -> Env.NoEnv) |
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.
Here, we know a more specific type of outer
because we pattern matched on it.
I'd suggest renaming value
in the pattern match case to outer
. Then we'd have the more specific type for it.
@liufengyun @olhotak @q-ata Could any of you review this PR again? I've made changes to the |
By the way, the |
@@ -161,32 +191,36 @@ object Objects: | |||
* | |||
* @param owner The static object whose initialization creates the array. | |||
*/ | |||
case class OfArray(owner: ClassSymbol, regions: Regions.Data)(using @constructorOnly ctx: Context) | |||
extends Ref(valsMap = mutable.Map.empty, varsMap = mutable.Map.empty, outersMap = mutable.Map.empty): | |||
case class OfArray(owner: ClassSymbol, regions: Regions.Data)(using @constructorOnly ctx: Context) extends ValueElement: |
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.
@liufengyun Now that OfArray
is not a subtype of Ref
, do we need to explicitly handle OfArray
in select
and assign
?
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.
As discussed in the meeting, for select
and assign
, we can issue an internal error (it should not be reachable). For call
, we can move the code currently in ref: Ref
to array: OfArray
.
Adding documentation for abstract syntax Removing warnings for returns in secondary constructors Removing assertions in call and eval Refactor type hierarchy for abstract value Adding comment for secondary constructor returns Rewriting widen as abstract method Removing original widen Resolving conflict Removing abstract widen
* refMap = Ref -> ( valsMap, varsMap, outersMap ) // refMap stores field informations of an object or instance | ||
* valsMap = valsym -> val // maps immutable fields to their values | ||
* varsMap = valsym -> addr // each mutable field has an abstract address | ||
* outersMap = class -> val // maps outer objects to their values |
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.
As we have discussed, outer
could be any possible value in our current implementation (see outerValue
)
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.
Otherwise LGTM. Can merge after review from @liufengyun .
Co-authored-by: Ondřej Lhoták <olhotak@uwaterloo.ca>
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.
Otherwise, LGTM, thank you @EnzeXing .
This PR refactors the global object initialization checker as implemented in
compiler/src/dotty/tools/dotc/transform/init/Objects.scala
with the following:ValueElement
which hasCold
andRef
as child classes. This separates the first-order abstract values (Cold
andRef
) from second-order abstract values (Refset
)tests/init-global/pos/secondary-constructor-return.scala