-
Notifications
You must be signed in to change notification settings - Fork 78
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
Remove global state for typechecking patterns #1281
Remove global state for typechecking patterns #1281
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.
I gave this a read and it looks good to me; while I don't understand the pattern-matching code, I believe this correctly refactors it to make all the mutable state local
84256e0
to
6f6c459
Compare
6f6c459
to
73e0da2
Compare
73e0da2
to
f67d084
Compare
I talked to Richard, and he doesn't feel like he needs to review this given Antal's and Leo's review. I'll merge this and prepare the corresponding upstream patch. |
ff538aa
into
nroberts.upstream-feedback.remove-typedtree-module-elaboration
This reverts commit ff538aa.
Ah, actually I spotted a bug in this. This hasn't yet been merged to main so this is easy to fix --- I'll do so in the branch I merged it into ( The new code only propagates the type 'a t = G of 'a
let f ((x : 'a) | (x : 'a t)) = ()
(* val f : 'a t -> unit *) (I don't understand |
* Remove global state for typechecking patterns * These comments can go * Two copies of `type_pat_state` when checking or-patterns
* Incorporate garrigue's comment It's closer to the old impl to check let-defs for scope escape rather than only let-bound vars. We might as well continue to do that. * Respond to more of garrigue's comments * Remove global state for typechecking patterns (#1281) * Remove global state for typechecking patterns * These comments can go * Two copies of `type_pat_state` when checking or-patterns * Fix bug where `pattern_force` was dropped in or-patterns * Respond to review * remove the (we believe) unneeded call to generalize_structure
Replace global variables managed by
type_pat
with a (mutable) state value that's explicitly passed around. There are a few benefits apart from the obvious "global mutable state is bad":module_patterns_restriction
argument frompartial_pred
, exposed in the mli. (And, I do remove it in this PR.) These two things don't interact in an interesting way (module patterns, exhaustivity checking), and the explicit scoping of thetype_pat_state
value makes it obvious that we can just ignore module patterns here.Implementation
The previous discipline was something like:
reset_pattern
to reset the global statetype_pat
(which writes into the global state)pattern_variables
,module_variables
, andpattern_force
)The discipline is now:
create_type_pat_state
to createtps
, a fresh copy of pattern-checking statetype_pat
ontps
(which writes into its fields)tps
Review
I think waiting for @goldfirere makes most sense here, but I'm open to suggestions.
Upstream status
I'm labeling this as "to upstream" but I have a patch ready to do this, so no further action from anyone else is required.