You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Problems with inconsistent constraints (was internal error) #2709
constraintsConstraints (postponed type checking problems, postponed unification problems, instance constraints)projectionsIssues relating to the treatment of projectionsrecordsRecord declarations, literals, constructors and updatestype: bugIssues and pull requests about actual bugs
I get an in internal error at src/full/Agda/TypeChecking/Substitute.hs:98 in this very complicated yet self-contained program, which I'll be happy to reduce to a small(er) test case if anyone asks. Please let me know if that would be helpful. (UPDATE: reduced test case coming soon.)
There are unsolved metas before the crash happens. I wonder if the crash will still happen if these metas are solved. (In any case, Agda should not crash even with unsolved metas.)
@andreasabel Those unsolved metas only came about while I was trying to reduce the test case, so yeah, it'll still crash. In addition to making a small, less-unicode test case, I'll make sure there are no unsolved metas in the type.
I stopped as soon as the program length (including the comment) was in the double-digits.
open importAgda.Primitiveinfixr5 _,_
recordPair
{a} (A :Set a) {b} (B :Set b)
:Set (a ⊔ b) whereconstructor_,_fieldfst : A
snd : B
dataConstraint
{a} {A :Set a} (x : A)
:Setwhereinstance _ : Constraint x
recordOuter
l {a} {A :Set a} (x : A)
:Set (lsuc l) whereconstructor#field type :Set l
recordInner
{l} {a} {A :Set a} (x : A) {{_ : Constraint x}} (outer : Outer l x)
:Set l wherefield value : Outer.type outer
moduleClass
{l} {a} {A :Set a} (x : A) (C :Set l)
where
class = Inner x (# C)
method : {{_ : class}} → C
method {{INSTANCE}} = Inner.value INSTANCE
moduleBeekeeper
{i} {I :Set i}
(A : I ->Set)
(B : I ->Set)
(x : I)
= Class (x , A , B)
(A x -> B x)
moduleIndexed
{a b b?} {I :Set}
{A : I ->Set a}
(mkA :∀ {x} -> A x)
(B : I ->Set b)
(toB :∀ {x} -> A x -> B x)
(B? :∀ {x} -> B x ->Set b?)
= Class ((λ {x} -> toB {x}) , (λ {x} -> B? {x}))
(∀ {x} -> B? (toB (mkA {x})))
moduleUnindexed
{a b}
{A :Set a}
(mkA : A)
{B :Set b}
(toB : A -> B)
(B? : B ->Set)
= Class (mkA , toB , B?)
(B? (toB mkA))
module_
{a b} {I :Set}
{A : I ->Set a}
{mkA :∀ {x} -> A x}
{B : I ->Set b}
{toB :∀ {x} -> A x -> B x}
{B? :∀ {x} -> B x ->Set}
{{_ : Indexed.class mkA B toB B?}}
wherepostulateinstance iToUnindexed :∀ {x} -> Unindexed.class (mkA {x}) toB B?
postulateI :SetdataA
a (x : I)
:Set a wheremkA : A a x
recordB
b (x : I)
:Set (lsuc b) wherefield ?? :Set b
openBpublicpostulatetoB :∀ {a b x} -> A a x -> B b x
instanceiIndexedAB :∀ {a b} -> Indexed.class (mkA {a}) (B b) toB (B.??)
b : Level
x : I
myB : B b x
error : myB .??
error = Beekeeper.method _ _ _ _ _
-- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:98
Honestly, I stopped b/c I don't know what else I can do to simplify the problem.
I got it a bit further, making the final B monomorphic and making a number of arguments visible.
The internal error is very brittle, many changes just turn it into a "No instance found" error.
open importAgda.Primitiveinfixr5 _,_
recordPair {a} (A :Set a) {b} (B :Set b) :Set (a ⊔ b) whereconstructor_,_fieldfst : A
snd : B
-- If we turn Contraint, mkConstraint into postulate-- we get "Failed to solve ... constraints" instead.dataConstraint {a} {A :Set a} (x : A) :SetwhereinstancemkConstraint : Constraint x
recordOuter l {a} {A :Set a} (x : A) :Set (lsuc l) whereconstructormkOuterfieldtype :Set l
recordInner {l} {a} {A :Set a} (x : A) {{_ : Constraint x}} (outer : Outer l x) :Set l wherefieldvalue : Outer.type outer
moduleClass {l} {a} {A :Set a} (x : A) (C :Set l) where
class = Inner x (mkOuter C)
method : {{_ : class}} → C
method {{INSTANCE}} = Inner.value INSTANCE
moduleBeekeeper {i} {I :Set i} (A : I →Set) (B : I →Set) (x : I)
= Class (x , A , B) (A x → B x)
moduleIndexed
a {I :Set}
(A : I →Set a)
(mkA :∀ (x : I) → A x)
(B : I →Set1)
(toB :∀ (x : I) → A x → B x)
(B? :∀ (x : I) → B x →Set)
= Class (toB , B?) (∀ x → B? x (toB x (mkA x)))
moduleUnindexed a (A :Set a) (mkA : A) (B :Set1) (toB : A → B) (B? : B →Set)
= Class (mkA , toB , B?) (B? (toB mkA))
postulateinstanceiToUnindexed :∀
a (I :Set)
(A : I →Set a)
(mkA :∀ (x : I) → A x)
(B : I →Set1)
(toB :∀ (x : I) → A x → B x)
(B? :∀ (x : I) → B x →Set)
{{_ : Indexed.class a A mkA B toB B?}}
(x : I) → Unindexed.class a (A x) (mkA x) (B x) (toB x) (B? x)
postulateI :Set-- If we make A and mkA postulates, we get the "No instance" error insteaddataA a : (x : I) →Set a wheremkA : (x : I) → A a x
-- If we turn B and fld into postulates, we get the "No instance" errorrecordB:Set1wherefield fld :SetopenBpostulatetoB :∀ {a : Level} (x : I) → A a x → B
instanceiIndexedAB :∀ {a : Level} →
Indexed.class a (A a) mkA (λ (x : I) → B) toB (λ (x : I) → fld)
myB : B
error : fld myB
error = Beekeeper.method _ _ _ _
-- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:98
The final message from Agda is:
conApp: constructor Issue2709a.A.mkA with fields [] projected by Issue2709a.B.fld
Further simplification: getting rid of the module applications, exposing the instance goal that triggers the error, and specialising some arguments:
open importAgda.Primitiveinfixr5 _,_
postulatePair :∀ {a} (A :Set a) {b} (B :Set b) →Set (a ⊔ b)
_,_ :∀ {a} {A :Set a} {b} {B :Set b} → A → B → Pair A B
-- If we turn Contraint, mkConstraint into postulate-- we get "Failed to solve ... constraints" instead.dataConstraint {a} {A :Set a} (x : A) :SetwheremkConstraint : Constraint x
recordInner {l a} {A :Set a} (x : A) (_ : Constraint x) (C :Set l) :Set l where-- no-eta-equality -- With no-eta we get "No instance" errorfieldvalue : C
Class :∀ {l a} {A :Set a} (x : A) (C :Set l) →Set l
Class x C = Inner x mkConstraint C
postulateI :Set-- If we make A and mkA postulates, we get the "No instance" error insteaddataA a : (x : I) →Set a wheremkA : (x : I) → A a x
-- If we turn B and fld into postulates, we get the "No instance" errorrecordB:Set1wherefield fld :SetopenBpostulatea : Level
toB : (x : I) → A a x → B
postulateinstanceiToUnindexed :∀
{B : I →Set1}
{toB :∀ (x : I) → A a x → B x}
{B? :∀ (x : I) → B x →Set}
{{_ : Class (toB , B?) (∀ x → B? x (toB x (mkA x)))}}
{x : I} → Class (mkA x , toB x , B? x) (B? x (toB x (mkA x)))
iIndexedAB : Class (toB , λ _ → fld) (∀ x → fld (toB x (mkA x)))
it :∀ {a} {A :Set a} {{x : A}} → A
it {{x}} = x
goal :let i = _
I :Set i
I = _
A : I →Set
A = _
B : I →Set
B = _
x : I
x = _
in Class (x , A , B) (A x → B x)
goal = it
-- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:95
More simplification, splitting Class into two separate types.
open importAgda.Primitiveinfixr5 _,_
postulatePair :∀ {a} (A :Set a) {b} (B :Set b) →Set (a ⊔ b)
_,_ :∀ {a} {A :Set a} {b} {B :Set b} → A → B → Pair A B
-- If we turn Contraint, mkConstraint into postulate-- we get "Failed to solve ... constraints" instead.dataConstraint {a} {A :Set a} (x : A) :SetwheremkConstraint : Constraint x
postulateInner :∀ {l a b} {A :Set a} {B :Set b} (x : A) (y : B) → Constraint x →Set l →Set l
recordInner' {l a b c} {A :Set a} {B :Set b} {C :Set c} (x : A) (y : B) (z : C)
(_ : Constraint (x , y , z)) (X :Set l) :Set l where-- no-eta-equality -- With no-eta we get "No instance" errorfieldvalue : X
Class :∀ {l a b} {A :Set a} {B :Set b} (x : A) (y : B) (X :Set l) →Set l
Class x y X = Inner x y mkConstraint X
Class' :∀ {l a b c} {A :Set a} {B :Set b} {C :Set c} (x : A) (y : B) (z : C) (X :Set l) →Set l
Class' x y z X = Inner' x y z mkConstraint X
postulateI :Set-- If we make A and mkA postulates, we get the "No instance" error insteaddataA a : (x : I) →Set a wheremkA : (x : I) → A a x
-- If we turn B and fld into postulates, we get the "No instance" errorrecordB:Set1wherefield fld :SetopenBpostulatea : Level
toB : (x : I) → A a x → B
postulateinstanceiToUnindexed :∀
{B : I →Set1}
{toB :∀ (x : I) → A a x → B x}
{B? :∀ (x : I) → B x →Set}
{{_ : Class toB B? (∀ x → B? x (toB x (mkA x)))}}
{x : I} → Class' (mkA x) (toB x) (B? x) (B? x (toB x (mkA x)))
iIndexedAB : Class toB (λ _ → fld) (∀ x → fld (toB x (mkA x)))
it :∀ {a} {A :Set a} {{x : A}} → A
it {{x}} = x
goal =let i = _
I :Set i
I = A _ _
A : I →Set
A = _
B : I →Set
B = _
x : I
x = mkA _
in it {A = Class' x A B (A x → B x)}
-- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:95
Much simplified this is what happens:
_f : A → Set
_Inst1 : Class A mkA _f (_f mkA)
_B : Set
_g : _B → Set
add constraint (1) A == _B
solve _f := _g : _B → Set (*)
_B := B, but don't recheck (1) yet
_g := B.fld
crash on _Inst1 : Class A mkA B.fld (B.fld mkA)
It looks like the problematic step is (*), but I haven't quite figured out what exactly we're doing wrong. (If you're following along in the debug output, (*) is really _147 := _B?_163 _x_143 : _171 → Set.)
I confirmed that this isn't an instance issue. You can also trigger the problem by filling in the instance argument interactively (first iToUnindexed and then iIndexedAB).
Basically we have a failure of protecting ourselves from inconsistent constraints. This is more severe in a situation with instance arguments, since we are going to try some incorrect instance candidates before finding the right one, so we expect to encounter type errors also for correct programs.
> ...This might also be a test case to try in `tog`.
What is `tog`?
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#2709 (comment)
changed the title [-]Internal error at src/full/Agda/TypeChecking/Substitute.hs:98[/-][+](No longer an) Internal error at src/full/Agda/TypeChecking/Substitute.hs:98[/+]on Nov 14, 2018
changed the title [-](No longer an) Internal error at src/full/Agda/TypeChecking/Substitute.hs:98[/-][+]Problems with inconsistent constraints (was internal error)[/+]on Jan 25, 2021
constraintsConstraints (postponed type checking problems, postponed unification problems, instance constraints)projectionsIssues relating to the treatment of projectionsrecordsRecord declarations, literals, constructors and updatestype: bugIssues and pull requests about actual bugs
Activity
UlfNorell commentedon Aug 19, 2017
See reply to mailing list: reduction to small test case is much appreciated.
andreasabel commentedon Aug 19, 2017
There are unsolved metas before the crash happens. I wonder if the crash will still happen if these metas are solved. (In any case, Agda should not crash even with unsolved metas.)
After refining
There are still unsolved metas in the type of
fact5⋆.Anyway, a smaller test case (with less unicode) would be greatly appreciated.
m0davis commentedon Aug 19, 2017
@andreasabel Those unsolved metas only came about while I was trying to reduce the test case, so yeah, it'll still crash. In addition to making a small, less-unicode test case, I'll make sure there are no unsolved metas in the type.
m0davis commentedon Aug 21, 2017
I stopped as soon as the program length (including the comment) was in the double-digits.
Honestly, I stopped b/c I don't know what else I can do to simplify the problem.
andreasabel commentedon Aug 21, 2017
Ok, great! I will do some further shrinking from here.
andreasabel commentedon Aug 21, 2017
I got it a bit further, making the final
Bmonomorphic and making a number of arguments visible.The internal error is very brittle, many changes just turn it into a "No instance found" error.
The final message from Agda is:
@UlfNorell : do you want to take over?
UlfNorell commentedon Aug 23, 2017
Further simplification: getting rid of the module applications, exposing the instance goal that triggers the error, and specialising some arguments:
UlfNorell commentedon Aug 23, 2017
More simplification, splitting
Classinto two separate types.Much simplified this is what happens:
It looks like the problematic step is
(*), but I haven't quite figured out what exactly we're doing wrong. (If you're following along in the debug output,(*)is really_147 := _B?_163 _x_143 : _171 → Set.)I confirmed that this isn't an instance issue. You can also trigger the problem by filling in the instance argument interactively (first
iToUnindexedand theniIndexedAB).Basically we have a failure of protecting ourselves from inconsistent constraints. This is more severe in a situation with instance arguments, since we are going to try some incorrect instance candidates before finding the right one, so we expect to encounter type errors also for correct programs.
13 remaining items
vlopezj commentedon Aug 25, 2017
[-]Internal error at src/full/Agda/TypeChecking/Substitute.hs:98[/-][+](No longer an) Internal error at src/full/Agda/TypeChecking/Substitute.hs:98[/+][-](No longer an) Internal error at src/full/Agda/TypeChecking/Substitute.hs:98[/-][+]Problems with inconsistent constraints (was internal error)[/+]