Middlend Fixes#216
Conversation
…structors/fields.
… a bind is part of a free variable set.
0a04fab to
5c2fd8f
Compare
|
Rebased this to account for new IL changes. Still leaves improve ids not entirely fixed, will be done in a separate pull request. |
|
@nomeata could you look into this PR please? Since the IL refactor is done, these PRs can finally go in. This one in particular is just really small changes so it shouldn't take long I hope. |
|
Hmm, I've paged out spectec stuff a bit these days, so I'm not eager and probably not able to give a good review. Maybe someone else whose currently playing with this could? |
|
Ah no worries then! |
…ome more misc changes to naming and letpr.
… type family ones.
…t have the correct substitution.
|
@rossberg can you take a look on this one? |
rossberg
left a comment
There was a problem hiding this comment.
Reviewed with a somewhat superficial understanding. :)
| { p with it = match p.it with | ||
| | ExpP (id, typ) -> ExpP (t.transform_var_id id, transform_typ t typ) | ||
| | TypP id -> TypP (t.transform_typ_id id) | ||
| | TypP id -> TypP (t.transform_var_id id) |
There was a problem hiding this comment.
Hm, this is odd. The id is a type identifier.
There was a problem hiding this comment.
Hmm, aren't type parameters considered type variables? Maybe I should have a separate transform function for type variables, but I don't think theres a way to distinguish between type variables and type identifiers in arguments.
There was a problem hiding this comment.
Well, no distinction is made between type names and type variables, it didn't seem necessary so far. The "sort" merely indicates the namespace, i.e., which component of the context binds it. I've exclusively used "var" for expression variables.
There was a problem hiding this comment.
Hmm, I tend to want to seperate them as they generally have different naming conventions. I'll keep it as t.transform_typ_id in order for it to make more sense.
There was a problem hiding this comment.
Made the change, now improveids makes even more of a disctinction between user defined types and relations, and type constructors, so that i.e. the type variable X does not clash with the type constructor X (from shape) :)
There was a problem hiding this comment.
Sorry, meant to say a term constructor. Either way, it clashes when it gets to Rocq, especially when you use X when pattern matching, it gets confused with the type variable X and the term constructor X. For example, in the function relaxed2:
def $relaxed2(relaxed2, syntax X, X, X) : X hint(show $relaxed(%1)#`[%3,%4])
def $relaxed2(i, syntax X, X_1, X_2) = (X_1 X_2)[i] -- if $ND
def $relaxed2(i, syntax X, X_1, X_2) = (X_1 X_2)[0] -- otherwise
would get converted as follows:
Definition fun_relaxed2 (v_relaxed2 : relaxed2) (v_X : eqType) (v_X_0 : v_X) (v_X_1 : v_X) {_ : Inhabited v_X} : v_X :=
match v_relaxed2, v_X, v_X_0, v_X_1 return v_X with
| i, X, X_1, X_2 => (if (ND ) then ([::X_1; X_2][| (i :> nat) |]) else ([::X_1; X_2][| 0 |]))
end.
There was a problem hiding this comment.
Where shape is defined as:
Inductive shape : Type :=
| X (v_lanetype : lanetype) (v_dim : dim) : shape.
Pretty sure rocq would complain that the X in the pattern must have two arguments or something like that.
(This might be simply a rocq-specific clash though)
There was a problem hiding this comment.
Ah, okay, so Is the improveid meant to remove all potential name clashes between different name spaces? It would be worth documenting that (and the renaming strategy) in the MLI.
There was a problem hiding this comment.
Ah you are right! I should document that on the MLI. Yes, the idea is to remove potential name clashes between name spaces (an obvious one being functions ids and type ids being able to have the same name, etc.). I'll document it soon!
| (* NOTE: for let since we only have expressions we cannot modify the env ever. *) | ||
| let _, new_quant_map = extend_quant_set env quant_map quants in |
There was a problem hiding this comment.
Maybe make that an assertion?
| *) | ||
|
|
||
| val transform : Il.Ast.script -> Il.Ast.script | ||
| val uncase_proj_hint_id : string No newline at end of file |
| | ALL (* Places wf premises whenever it encounters a term/variable that needs well-formedness check*) | ||
| | MINIMAL (* Places only wf premises in terms in relations and functions that do not appear in the conclusion *) | ||
| | NONE (* Does not place any wf premises in relations/functions *) |
There was a problem hiding this comment.
Nit: OCaml constructor name conventions are capitalisation but not all-caps.
| (* flag that deactivates adding wellformedness predicates to relations *) | ||
| let deactivate_wfness = false | ||
| (* State that indicates what the placement algorithm should do *) | ||
| let wf_state = MINIMAL |
There was a problem hiding this comment.
Should this perhaps be a (exported) ref, so that it's actually configurable?
|
Have done all of the changes, they all seem reasonable! Will update tests when all seems good. |
| | All (* Places wf premises whenever it encounters a term/variable that needs well-formedness check*) | ||
| | Minimal (* Places only wf premises in terms in relations and functions that do not appear in the conclusion *) | ||
| | Wfnone (* Does not place any wf premises in relations/functions *) |
There was a problem hiding this comment.
Nit: Perhaps prefix the constructors consistently?
…for wfstate consistent.
This pull request is for some middlend fixes/changes that were done in the Rocq backend (#207) and are now being backported.
Fixes include: