-
Notifications
You must be signed in to change notification settings - Fork 124
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: add support for vectors and register vectors #911
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
16a78ae
add support for vectors and register vectors
lfrenot cd67ee8
Fixing for effectful arguments of vectors
lfrenot 9301b62
Leo edits
lfrenot b54f179
removing a line that was committed by error
lfrenot f9f93cd
Fixing ite
lfrenot 65fe108
doc_val indentation fix
lfrenot cad2ca9
Type abbrevs to abbrev
lfrenot 2bf1cc8
formatting
lfrenot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ let opt_lean_output_dir : string option ref = ref None | |
|
||
let opt_lean_force_output : bool ref = ref false | ||
|
||
let lean_version : string = "lean4:nightly-2024-09-25" | ||
let lean_version : string = "lean4:nightly-2025-01-22" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this bumped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was bumped because nightly-2024-09-25 used a different implementation of |
||
|
||
let lean_options = | ||
[ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Out.Sail.Sail | ||
|
||
open Sail | ||
|
||
inductive Register : Type where | ||
| B | ||
| R | ||
deriving DecidableEq, Hashable | ||
open Register | ||
|
||
abbrev RegisterType : Register → Type | ||
| .B => Bool | ||
| .R => Nat | ||
|
||
abbrev SailM := PreSailM RegisterType | ||
|
||
open RegisterRef | ||
instance : Inhabited (RegisterRef RegisterType Bool) where | ||
default := .Reg B | ||
instance : Inhabited (RegisterRef RegisterType Nat) where | ||
default := .Reg R | ||
|
||
/-- Type quantifiers: n : Int, 0 ≤ n -/ | ||
def elif (n : Nat) : (BitVec 1) := | ||
if (Eq n 0) | ||
then 1#1 | ||
else if (Eq n 1) | ||
then 1#1 | ||
else 0#1 | ||
|
||
/-- Type quantifiers: n : Int, 0 ≤ n -/ | ||
def monadic_in_out (n : Nat) : SailM Nat := do | ||
if (← readReg B) | ||
then writeReg R n | ||
else (pure ()) | ||
readReg R | ||
|
||
/-- Type quantifiers: n : Int, 0 ≤ n -/ | ||
def monadic_lines (n : Nat) : SailM Unit := do | ||
let b := (Eq n 0) | ||
if b | ||
then writeReg R n | ||
writeReg B b | ||
else writeReg B b | ||
|
||
def initialize_registers : SailM Unit := do | ||
writeReg R sorry | ||
writeReg B sorry | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
default Order dec | ||
|
||
$include <prelude.sail> | ||
|
||
register R : nat | ||
register B : bool | ||
|
||
function elif(n : nat) -> bit = { | ||
if n == 0 then | ||
bitone | ||
else if n == 1 then | ||
bitone | ||
else | ||
bitzero | ||
} | ||
|
||
function monadic_in_out(n : nat) -> nat = { | ||
if B then | ||
R = n | ||
else | ||
(); | ||
R | ||
} | ||
|
||
function monadic_lines(n : nat) -> unit = { | ||
let b = n == 0; | ||
if b then { | ||
R = n; | ||
B = b | ||
} | ||
else | ||
B = b | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this still ignores the monadicity of the condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yes, let's ignore that for now and fix it when we need to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does because the condition should never be monadic (it should be a Bool and not a SailM Bool), instead the responsibility is on
doc_exp
, see line 352The responsibility needs to be moved like that, because we want to be able to handle both
if (Eq (← (rX r)) 0)
andif (← readReg B)