Description
I am trying to use interaction tree in my project and I encountered an universe inconsistency error.
I am reporting this issue because I am not sure if the problematic constraint is an essential one.
Here is a minimized example.
From ITree Require Export
ITree ITreeFacts.
Require Import List.
Set Printing Universes.
Record my_mod: Type := mk {
datatype: Type;
}.
Definition my_mods_uses_List (ms: my_mod) (mms: list my_mod): Prop := In ms mms.
Variant void1 : Type -> Type := .
Definition boo: my_mod := mk (itree void1 unit).
It fails to compile with the following error message.
(Note: If you do not import ITreeFacts
, it compiles.)
Error:
The term "itree void1 unit" has type
"Type@{max(Set,ITree.Core.ITreeDefinition.2,ITree.Core.ITreeDefinition.3,itreeF.u1+1)}"
while it is expected to have type "Type@{my_mod.u0}"
(universe inconsistency: Cannot enforce ITree.Core.ITreeDefinition.3 <= my_mod.u0 because
my_mod.u0 < Coq.Lists.List.1 <= MonadFix.MonadFix.u0 = ITree.Core.ITreeDefinition.3).
What is interesting here is that InteractionTrees repository does not import MonadFix
at all.
If these universe constraints are not essential and you can remove them, it will make my life easier.
I tested it in version: coq 8.10.1 // ext-lib 0.11.1 // itree 3.1.0 // paco 4.0.0
Also, interestingly, my colleague @kim-yoonseung tested the same code in older version of itree, and he says it compiled without an error.
The version he used is as follows: coq 8.9.1 // ext-lib 0.10.2 // itree 2.0.0 // paco 4.0.0
I would like to ask for some general advice when dealing with universe inconsistencies. (it seems you have a lot of experience with it :D)
-
Finding the root cause of an error.
Coq's messages (Print Universes
,Set Printing Universes
) are not very satisfactory in at least two ways:- I can't find where the constraints are introduced. (So I am trying similar things like this)
- The error message does not give a full cycle. For an instance, in the above error message, actually the constraint
MonadFix.MonadFix.u0 = ITree.Core.ITreeDefinition.3
does not appear directly inPrint Universes
. It is established by transitivity.
-
Solving the problem.
I tried to putSet Universe Polymorphism
only in the problematic cases but it was hard localize the use of universe polymorphism -- it enforced me to change some other monomorphic definitions to polymorphic ones. I didn't want to have too much headache with it, so I putSet Universe Polymorphism
everywhere, and it was also annoying. Universe polymorphic definitions does not work well withSet
sort, so I had to wrap existingSet
definitions toType
, which was not feasible because my project depends on a large codebase that I can't modify.
Now I am considering another approach -- just copy-pasting the problematic monomorphic code (e.g.,List
) as much as needed, instead of polymorphism.
Thanks for reading this!