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: support for implicit arguments in function application #955

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

javra
Copy link
Collaborator

@javra javra commented Feb 4, 2025

This closes #948.

Translates

default Order dec

$include <prelude.sail>

val EXTZ : forall 'n 'm, 'm >= 'n. (implicit('m), bits('n)) -> bits('m)
function EXTZ(m, v) = sail_zero_extend(v, m)

val foo : bits(8) -> bits(16)
function foo x = {
  EXTZ(x)
}

to

import Out.Sail.Sail

open Sail

abbrev SailM := StateM Unit

/-- Type quantifiers: k_n : Int, m : Int, m ≥ k_n -/
def EXTZ {m : _} (v : (BitVec k_n)) : (BitVec m) :=
  (Sail.BitVec.zeroExtend v m)

def foo (x : (BitVec 8)) : (BitVec 16) :=
  (EXTZ x)

def initialize_registers (lit : Unit) : Unit :=
  ()

@javra javra added the Lean Issues with Sail to Lean translation label Feb 4, 2025
Copy link

github-actions bot commented Feb 4, 2025

Test Results

   12 files  ±0     25 suites  ±0   0s ⏱️ ±0s
  763 tests +1    763 ✅ +1  0 💤 ±0  0 ❌ ±0 
2 707 runs  +1  2 707 ✅ +1  0 💤 ±0  0 ❌ ±0 

Results for commit 72a0c10. ± Comparison against base commit e4386bb.

♻️ This comment has been updated with latest results.

@javra javra marked this pull request as ready for review February 4, 2025 09:57
@bacam
Copy link
Contributor

bacam commented Feb 4, 2025

It would be rare / non-existant, but I think this might break on mutually recursive functions with implicit arguments because one of the functions wouldn't be added until after it is used. If so, we could query the function's type to find the implicit arguments at the point of use.

@javra
Copy link
Collaborator Author

javra commented Feb 4, 2025

Do you think querying the type on the call site might be the better approach generally?

@bacam
Copy link
Contributor

bacam commented Feb 4, 2025

It would involve less plumbing, certainly.

@javra
Copy link
Collaborator Author

javra commented Feb 4, 2025

What would be the canonical way to lookup the type?

@bacam
Copy link
Contributor

bacam commented Feb 4, 2025

What would be the canonical way to lookup the type?

Env.get_val_spec

@bacam bacam merged commit c2d58d8 into rems-project:sail2 Feb 6, 2025
3 checks passed
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 this pull request may close these issues.

sail-to-lean: fix implicit arguments
3 participants