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

Lean: Matches on heterogeneous bitvector lengths #1070

Open
javra opened this issue Feb 25, 2025 · 0 comments · May be fixed by #1071
Open

Lean: Matches on heterogeneous bitvector lengths #1070

javra opened this issue Feb 25, 2025 · 0 comments · May be fixed by #1071
Assignees
Labels
Lean Issues with Sail to Lean translation

Comments

@javra
Copy link
Collaborator

javra commented Feb 25, 2025

Problem can be exposed via

function const16() -> (bitvector(16), bool) = {
  (0xFFFF, true)
}

function const32() -> (bitvector(32), bool) = {
  (0xEEEE_EEEE, false)
}

val match_width : forall 'n, 'n >= 0. bitvector('n) -> bitvector(2 * 'n)
function match_width x = {
  let (foo, _) : (bitvector('n), bool) = match 'n {
    16 => const16(),
    32 => const32(),
    n => (sail_zeros(n), false)
  } in
  bitvector_concat(foo, foo)
}

which gets translated to

...

/-- Type quantifiers: k_n : Nat, k_n ≥ 0 -/
def match_width (x : (BitVec k_n)) : (BitVec (2 * k_n)) :=
  let (foo, _) :=
    match (Sail.BitVec.length x) with
    | 16 => (const16 ())
    | 32 => (const32 ())
    | n => ((BitVec.zero n), false)
  (foo ++ foo)

The solution is to

  1. keep the type ascription
  2. add instances to carry our new coercions over products
@javra javra added the Lean Issues with Sail to Lean translation label Feb 25, 2025
@javra javra self-assigned this Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lean Issues with Sail to Lean translation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant