Skip to content

Could not resolve quantifiers for newtype #1323

Description

@trdthg
type regidx_range('n) = 'n <= 1 & 'n >= 0

newtype regidx('n), regidx_range('n) = Regidx : int('n)

type s_regidx = { 'n, regidx_range('n) . regidx('n) }

mapping int_string : int <-> string = {
  0 <-> "0",
  1 <-> "1",
}

mapping encdec_reg : s_regidx <-> string = { 
  forwards Regidx(r) => int_string(r),
  backwards int_string(c) => Regidx(c), // failed here
}

Logs sail -dtc_verbose 1

Binding int_string(c) to string
Unify string and string for 
Adding type variable '_#c : Int
Binding c to int('_#c)
Adding local binding c : int('_#c)
|   Check Regidx(c) <= s_regidx
|   Function Regidx
|   Adding type variable 'n : Int
|   Adding constraint ('n <= 1 & 'n >= 0)
|   Adding constraint ('n <= 1 & 'n >= 0)
|   |   Infer c => int('_#c)
|   Unify int('n) and int('_#c) for 'n
|   Adding constraint ('n <= 1 & 'n >= 0)
|   Prove  |- regidx_range('_#c)
Type error:
../sail/test/builtins/range.sail:21.29-38:
21 |  backwards int_string(c) => Regidx(c),
   |                             ^-------^
   | Could not resolve quantifiers for Regidx
   | * regidx_range('_#c)

Another case

mapping encdec_reg : s_regidx <-> string = { 
  Regidx(r) => int_string(r)
}

If you run sail --just-check, it works, but if you run sail with -c, it failed. 😵‍💫

if you comment the rewriter "realize_mappings" in c_plugin, it works.

Check function encdec_reg_backwards
Binding arg# to string
Adding local binding arg# : string
|   Check match arg# { int_string(r) => Regidx(r) } <= {('n : Int), ('n <= 1 & 'n >= 0). regidx('n)}
|   |   Infer arg# => string
|   Binding int_string(r) to string
|   Unify string and string for 
|   Adding type variable '_#r : Int
|   Binding r to int('_#r)
|   Adding local binding r : int('_#r)
|   |   Check Regidx(r) <= {('n : Int), ('n <= 1 & 'n >= 0). regidx('n)}
|   |   Function Regidx
|   |   Adding type variable 'n : Int
|   |   Adding constraint ('n <= 1 & 'n >= 0)
|   |   Adding constraint ('n <= 1 & 'n >= 0)
|   |   |   Infer r => int('_#r)
|   |   Unify int('n) and int('_#r) for 'n
|   |   Adding constraint ('n <= 1 & 'n >= 0)
|   |   Prove  |- regidx_range('_#r)
Type error:
../sail/test/builtins/range.sail:20.2-11:
20 |  Regidx(r) <-> int_string(r),
   |  ^-------^
   | Could not resolve quantifiers for Regidx
   | * regidx_range('_#r)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions