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

Internal error when trying to overflow levels #5705

Closed
ksqsf opened this issue Dec 22, 2021 · 1 comment · Fixed by #5707
Closed

Internal error when trying to overflow levels #5705

ksqsf opened this issue Dec 22, 2021 · 1 comment · Fixed by #5707
Assignees
Labels
internal-error Concerning internal errors of Agda levels regression in 2.6.2 Regression that first appeared in Agda 2.6.2
Milestone

Comments

@ksqsf
Copy link

ksqsf commented Dec 22, 2021

The following code will cause an internal error:

module Test where

import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)

_ : Set1Set18446744073709551615
_ = refl
An internal error has occurred. Please report this as a bug.
Location of the error: __IMPOSSIBLE__, called at src/full/Agda/Utils/Suffix.hs:23:17 in Agd-2.6.2-d23be80f:Agda.Utils.Suffix

Information:

  • Agda version 2.6.2
  • MacOS 12.1
@andreasabel andreasabel added internal-error Concerning internal errors of Agda levels labels Dec 22, 2021
@andreasabel andreasabel added this to the 2.6.3 milestone Dec 22, 2021
@andreasabel
Copy link
Member

andreasabel commented Dec 22, 2021

This is Int overflow,

ghci> 18446744073709551615 :: Int

<interactive>:1:1: warning: [-Woverflowed-literals]
    Literal 18446744073709551615 is out of the Int range -9223372036854775808..9223372036854775807
-1

because suffixes are Int:

data Suffix
= Prime Int -- ^ Identifier ends in @Int@ many primes.
| Index Int -- ^ Identifier ends in number @Int@ (ordinary digits).
| Subscript Int -- ^ Identifier ends in number @Int@ (subscript digits).

Actually, we already get the crash at (maxBound :: Int) + 1:

crash' : SetSet9223372036854775808
crash' = refl

There are two avenues to fix this:

  1. Relax suffixes to Integer. Then you can have as many concrete universes as number of atoms in the physical universe, and more.
  2. Give a proper error stating that Agda does not support so many concrete universes.

Alt 1 will possibly come with performance penalties, but these might be small.

Alt 2 might be doable in the parser. Note that in the Set l form, we might never reach Int overflow. At least I think I will probably die before this computation finishes:

open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
open import Agda.Primitive

natToLevel : Nat  Level
natToLevel zero = lzero
natToLevel (suc n) = lsuc (natToLevel n)

endOfUniverse : Set1Set (natToLevel 18446744073709551615)
endOfUniverse = refl

The question is whether we can get from the Set l form to the Set_l internally. Yes, we do:

foo : Set (natToLevel 1) ≡ Set (natToLevel 2)
foo = refl
Set₃ != Set₂

CONCLUSION: The easiest and most robust fix is Alt 1 (Integer).

@andreasabel andreasabel self-assigned this Dec 22, 2021
@andreasabel andreasabel added the regression in 2.6.2 Regression that first appeared in Agda 2.6.2 label Dec 22, 2021
andreasabel added a commit that referenced this issue Dec 22, 2021
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
andreasabel added a commit that referenced this issue Dec 23, 2021
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
@andreasabel andreasabel modified the milestones: 2.6.3, 2.6.2.2 Mar 14, 2022
@andreasabel andreasabel mentioned this issue Mar 14, 2022
41 tasks
andreasabel added a commit that referenced this issue Mar 15, 2022
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
andreasabel added a commit that referenced this issue Mar 16, 2022
`Int` suffixes could be exploited by overflow to get Set:Set in Agda
2.6.2(.1).  This is fixed by switching to `Integer` suffixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal-error Concerning internal errors of Agda levels regression in 2.6.2 Regression that first appeared in Agda 2.6.2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants