-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Split out immutable GadtConstraint #16602
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
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! 👍
sealed trait GadtConstraintHandling(private var myGadt: GadtConstraint) { | ||
this: ConstraintHandling => | ||
|
||
def gadt: GadtConstraint = myGadt | ||
private def gadt_=(g: GadtConstraint) = myGadt = g |
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.
Maybe we should not make GadtConstraint
a private variable in GadtConstraintHandling
, but declare two methods for retrieving and updating GADT constraints in this trait, and require the class that extends this trait to provide this two methods, just like what we do in ConstraintHandling
(here). Then GadtConstraintHandling
will be a stateless mixin for GADT constraint manipulation, and Context.fresh
would do the job of GadtConstraint.fresh
as long as we put the GadtConstraint
in the context.
So that doesn't work, because we want code that's running in an inner context to have changes apply to an outer context. |
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.
Thanks for the explanation. LGTM!
This change eagerly allocates a GadtConstraint whenever its state is changed, rather than simply changing the reference(s) in, what's now called,
GadtConstraintHandling
, such asconstraint
. Previous to a recent change, in order to restore the GADT constraints, a fresh copy was eagerly created in a number of cases, just so it can be used to restore, for the cases in which it must be restored. The recent change exposed the underlying pieces of the GADT constraint and allowed those to be restored as components. Now we still do that, but as a packaged up GadtConstraint that we created once, eagerly. That also makes sure that invariants in components are upheld, like the mappings.