Remove global state for typechecking patterns#1281
Conversation
antalsz
left a comment
There was a problem hiding this comment.
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_patwith 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_restrictionargument 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_statevalue makes it obvious that we can just ignore module patterns here.Implementation
The previous discipline was something like:
reset_patternto reset the global statetype_pat(which writes into the global state)pattern_variables,module_variables, andpattern_force)The discipline is now:
create_type_pat_stateto createtps, a fresh copy of pattern-checking statetype_patontps(which writes into its fields)tpsReview
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.