Skip to content
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

Inlining can fail due to global side effects of Require #41

Open
JasonGross opened this issue May 21, 2018 · 0 comments
Open

Inlining can fail due to global side effects of Require #41

JasonGross opened this issue May 21, 2018 · 0 comments

Comments

@JasonGross
Copy link
Owner

Consider this setup:
In _CoqProject:

-R . Foo
A.v
B.v
C.v

In A.v:

Global Set Universe Polymorphism.

Axiom A : Set.

In B.v:

Definition B := Type.

In C.v:

Require Import Foo.A Foo.B.

Check (A : (B : B)).
(* Error:
The term "B" has type "Type" while it is expected to have type
"B" (universe inconsistency). *)

Inlining will first split up requires and imports, giving

Require Foo.A.
Require Foo.B.
Import Foo.A.
Import Foo.B.

Check (A : (B : B)).

Then it will try to inline Foo.B, which fails because it removes the error, because after Require Foo.A, Universe Polymorphism is set, and so B would be universe polymorphic, which removes the error. In this case, running the minimizer twice will resolve the issue.


Sometimes, running the minimizer twice is not enough. For example, consider this setup:
In _CoqProject:

-R . Foo
D.v
E.v
F.v

In D.v:

Definition foo : 1 = 2 -> forall P, ~~P -> P.
Proof.
  intros.
  try tauto. (* no-op, unless Classical_Prop has been Required *)
  congruence.
Defined.

In E.v:

Require Import Coq.Logic.Classical_Prop.

Lemma npp : forall P, ~~P -> P.
Proof. tauto. Qed.

In F.v:

Require Import Foo.D Foo.E.

Definition bar := Eval unfold foo in foo.

Check (bar, npp) : Set.

Then if we run

find-bug.py F.v bug.v -f _CoqProject --no-admit-transparent --no-admit-opaque

we get a log ending with something like

Non-fatal error: Failed to validate all coq runs and preserve the error.
The new error was:
File "/tmp/tmpzrrXEA.v", line 20, characters 2-13:
Error: No such goal.


File not saved.
Fatal error: Sanity check failed.

which leaves over a file like

Require Import Coq.Init.Notations.
Module Export AdmitTactic.
Module Import LocalFalse.
Inductive False := .
End LocalFalse.
Axiom proof_admitted : False.
Tactic Notation "admit" := abstract case proof_admitted.
End AdmitTactic.
Require Coq.Init.Notations.
Require Coq.Logic.Classical_Prop.

(* -*- mode: coq; coq-prog-args: ("-emacs" "-R" "." "Foo" "-top" "F") -*- *)
(* File reduced by coq-bug-finder from original input, then from 22 lines to 11 lines, then from 39 lines to 16 lines, then from 45 lines to 19 lines *)
(* coqc version 8.8.0 (May 2018) compiled on May 2 2018 16:49:46 with OCaml 4.02.3
   coqtop version 8.8.0 (May 2018) *)
Definition foo : 1 = 2 -> forall P, ~~P -> P.
Proof.
  intros.
  try tauto.
  congruence.
Defined.

Lemma npp : forall P, ~~P -> P.
Proof.
tauto.
Qed.

Definition bar := Eval unfold foo in foo.

Check (bar, npp) : Set.

This is because moving the Requires up to the top is supposed to not break anything, but it does break things, because it changes the behavior of tactics.


I'm not sure how to go about fixing this, other than by asking the coqdevs for more fine-grained import control.

@JasonGross JasonGross changed the title Inlining can fail due to global side effects Inlining can fail due to global side effects of Require May 21, 2018
JasonGross added a commit that referenced this issue Jun 20, 2021
At least when the issue is that inlining a module failed.

Also add a test case involving the example of #41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant