8000 Fixing Print for inductive types with let-in in parameters by herbelin · Pull Request #1082 · rocq-prover/rocq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixing Print for inductive types with let-in in parameters #1082

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

Merged
merged 4 commits into from
Feb 13, 2018

Conversation

herbelin
Copy link
Member

@ppedrot mentioned the following printing bug:

Inductive foo (A : Type) (x : A) (y := x) := Foo.
Print foo.
(* Inductive foo (A : Type) (x : A) (y:=x) : let y := x in Prop := Foo : let y := x in foo A x *)

The first commit of this PR fixes this printing bug as well as a similar printing bug for records with trailing let-ins in parameters. The bug was caused by using hnf_prod_applist (on-the-fly substitution of products) which is not let-in aware.

In a second commit, I protectively changed a suspicious use of hnf_prod_applist in computing the type of a vm_computed match (if I understand correctly). I was not able to say at once if the function Vnorm.nf_predicate was doing the expected job w.r.t. let-ins (isn't a LetIn case missing? and what is this crazy_type?). I let it to the specialists.

The checker (and the kernel) are also using hnf_prod_applist but in situations where already only a subset of the signature of parameters is considered (the signature of recursively uniform parameters). So, it does not seem to be a problem to me. After all, it is equivalent to have trailing let-in parameters and to uniformly distribute these let-in parameters on the constructors and on the arities.

@herbelin herbelin added the kind: fix This fixes a bug or incorrect documentation. label Sep 23, 2017
@herbelin herbelin force-pushed the master+fix-let-in-inductive branch from 79bdff4 to 44cee4a Compare September 24, 2017 08:29
@maximedenes
Copy link
Member

I'll try to review at least the VM part.

@maximedenes maximedenes self-requested a review September 25, 2017 08:37
@herbelin
Copy link
Member Author

@maximedenes: If you could check whether it is normal that LetIn is not considered in Vnorm.nf_predicate, and maybe exhibit an example showing a problem, that would indeed be good. (Of course, if it is compatible with your priority list.)

@Zimmi48
Copy link
Member
Zimmi48 commented Oct 5, 2017

I missed this bugfix in the list for 8.7+beta2. @maximedenes what do we do about this?

@herbelin
Copy link
Member Author

@maximedenes: you intended to try to review at least the vm part of this PR at some time, right?

Otherwise, same question as in #873: who should feel responsible for the non-staling of need flags?

let rec app n subst t l =
if Int.equal n 0 then
if l == [] then substl subst t
else anomaly (Pp.str "Not enough arguments.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this rather too many arguments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted. The error actually also appears twice in term.ml. I fixed all of them.

@@ -103,6 +103,12 @@ val beta_app : constr -> constr -> constr
(** Pseudo-reduction rule Prod(x,A,B) a --> B[x\a] *)
val hnf_prod_applist : env -> types -> constr list -> types

(** In [hnf_prod_applist_assum n c args], [c] is supposed to (whd-)reduce to
the form [∀Γ.t] with [Γ] of length [m] and possibly with let-ins; it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m should be n.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem, was a copy-paste of the same typo in a comment of term.mli. Fixed here and in term.mli

kernel/term.mli Outdated
val prod_appvect : constr -> constr array -> constr
val prod_applist : constr -> constr list -> constr
val prod_appvect : types -> constr array -> types
val prod_applist : types -> constr list -> types

(** In [prod_appvect_assum n c args], [c] is supposed to have the
form [∀Γ.c] with [Γ] of length [m] and possibly with let-ins; it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m should be n.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem. Thanks!

@herbelin herbelin force-pushed the master+fix-let-in-inductive branch from 44cee4a to 26512eb Compare November 24, 2017 23:52
@herbelin
Copy link
Member Author
herbelin commented Dec 5, 2017

@maximedenes: Maybe can I remove the needs:review flag? You can still look at the vm part later on at the same time you shall work again on it?

@maximedenes
Copy link
Member

I just looked at it, the fix looks reasonable, but we are probably missing a similar one in nativenorm.ml. I'll try to produce a test now.

@@ -938,6 +938,18 @@ let hnf_prod_app env t n =
let hnf_prod_applist env t nl =
List.fold_left (hnf_prod_app env) t nl

let hnf_prod_applist_assum env n c l =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we take n? Is it just a safety measure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no, I understand now, it is to make sure that all local definitions are unfolded, if they are included in n.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly!

let pT =
hnf_prod_applist env (type_of_ind env (ind,u)) (Array.to_list params) in
hnf_prod_applist_assum env nparamdecls (type_of_ind env (ind,u)) (Array.to_list params) in
Copy link
Member
@maximedenes maximedenes Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to change anything? If I understand correctly, it could unfold more local definitions, if they come after the arguments. But the next line does a whd_all anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think I agree, this does not change the final semantics. The reason to do it is by separation of concerns. For instance, if you eventually change whd_all by some other reduction, or remove it, the instantiation of the telescope of the inductive type will remain correct while if the unfolding of the let's of the telescope is partly done by the function to instantiate the telescope and partly done with a further whd_all, this would not be true anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this morally replacing call by value by call by name on the LetIn part? I'm very tired so I may be completely wrong, but it seems that the new implementation will simply substitute the body of the LetIn before reducing it.

Copy link
Member
@maximedenes maximedenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the printing fix looks sound, it seems to me that the patch in vnorm.ml does not change anything (I'm not sure at all), since the predicate is anyway head normalized. If that is correct, I would prefer to keep the code in vnorm.ml as it is.

@Zimmi48 Zimmi48 added this to the 8.7.1 milestone Dec 6, 2017
@Zimmi48
Copy link
Member
Zimmi48 commented Dec 12, 2017

@herbelin Any plan to address @maximedenes' comment?

@maximedenes
Copy link
Member

@herbelin already replied, I need to read and think a bit. Sorry, I'm very overloaded.

@Zimmi48
Copy link
Member
Zimmi48 commented Dec 14, 2017

The linter fails and VST times out. I suppose we can ignore these errors, especially given that the 8.7.1 deadline is tomorrow (so merging today). @maximedenes this is just awaiting you to see if you understand Hugo's reply.

Adding a "let-in"-sensitive function hnf_prod_applist_assum to
instantiate parameters and using it for printing.

Thanks to PMP for reporting.
This enforces the intended meaning of the corresponding functions
(prod_appvect*/prod_applist*).
@herbelin herbelin force-pushed the master+fix-let-in-inductive branch from 26512eb to 42610a4 Compare December 14, 2017 14:58
@herbelin
Copy link
Member Author

I magically --whitespace=fix made it lint-compliant.

@Zimmi48 Zimmi48 modified the milestones: 8.7.1, 8.7.2 Dec 14, 2017
@herbelin herbelin dismissed maximedenes’s stale review January 17, 2018 18:33

I'm dismissing to make a step forward, but feel free to reopen to restart a discussion

@maximedenes
Copy link
Member

@herbelin did you see my comment about this patch turning call by value into call by name (substituting the body of let-ins before reducing it) ? Is that accurate?

@Zimmi48
Copy link
Member
Zimmi48 commented Feb 6, 2018

@herbelin Can you answer to @maximedenes latest comment?

@maximedenes
Copy link
Member

In fact I believe some of my comments above were wrong, so I'll have another look this week. Anyway this will be merged before 8.7.2.

@Zimmi48
Copy link
Member
Zimmi48 commented Feb 9, 2018

@maximedenes Sorry to add to your load. I know you are busy. But please review this ASAP if you don't want to have it miss 8.7.2. (We need to account for CI time and other things.)

@herbelin
Copy link
Member Author

@maximedenes:

did you see my comment about this patch turning call by value into call by name (substituting the body of let-ins before reducing it) ? Is that accurate?

Is this still an open question? (If yes, I do not see which comments you are talking about.)

@maximedenes
Copy link
Member

Will review today, as soon as I have a minute.

Copy link
Member
@maximedenes maximedenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I convinced myself that this patch is fine. Sorry for the delay.

maximedenes added a commit to maximedenes/coq that referenced this pull request Feb 12, 2018
@maximedenes maximedenes merged commit 42610a4 into rocq-prover:master Feb 13, 2018
Zimmi48 added a commit to Zimmi48/coq that referenced this pull request Feb 13, 2018
Zimmi48 added a commit to Zimmi48/coq that referenced this pull request Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: fix This fixes a bug or incorrect documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0