Agda: Internal error (Rewriting.hs:395) with generalize and rewrite rules

Created on 21 Dec 2019  ยท  3Comments  ยท  Source: agda/agda

The internal error occurs at the last line and goes away if we explicitly quantify on n and m (and it fails as expected).

{-# OPTIONS --rewriting #-}

open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite

variable
  n m : Nat

postulate
  +S : {n m : Nat} โ†’ (n + suc m) โ‰ก suc (n + m)
  {-# REWRITE +S #-}

  P : Nat โ†’ Nat โ†’ Set
  Q : Nat โ†’ Set

  R : {n m : Nat} โ†’ P n m โ†’ Q (m + n) โ†’ Set

  bug : (p : P n m) (q : Q n) โ†’ R p q
An internal error has occurred. Please report this as a bug.
Location of the error: src/full/Agda/TypeChecking/Rewriting.hs:395
builtin generalize rewriting bug

All 3 comments

This seems to interact with the BUILTIN feature for natural numbers. If you take away the declaration {-# BUILTIN NATPLUS _+_ #-}, the internal error disappears.

Here is a smaller test case.

{-# OPTIONS --rewriting #-}

data Nat : Set where
  zero : Nat
  suc : Nat โ†’ Nat
{-# BUILTIN NATURAL Nat #-}

_+_ : Nat โ†’ Nat โ†’ Nat
zero + m = m
suc n + m = suc (n + m)
{-# BUILTIN NATPLUS _+_ #-} -- Without this, the internal error disappears.

postulate
  _โ‰ก_ : Nat โ†’ Nat โ†’ Set
{-# BUILTIN REWRITE _โ‰ก_ #-}

postulate
  a b n : Nat
  Q : Nat โ†’ Set
  R : (m n : Nat) โ†’ Q (m + n) โ†’ Set
  +S : (n + a) โ‰ก b
{-# REWRITE +S #-}

variable
  m : Nat -- Explicitly quantifying over m, the internal error disappears.

postulate
  bug : (q : Q n) โ†’ R m n q

Good catch!

Was this page helpful?
0 / 5 - 0 ratings