-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a better inference rule for vector literals
Mostly this improves typechecking in situations like the following, where we are returning a bitvector with some length that satisfied a property. In the example below, we are returning a vector of length `'n` containing bitvectors of length `'m`, where `'n == 'm` and `'n > 1`. Sail can now type-check this without any annotations. ``` register R : bool register X : bits(32) val test : unit -> {'n 'm, 'n > 1 & 'n == 'm. vector('n, bits('m))} function test() = { if R then { [0b00, 0b11] } else { [match X { _ => 0b000 }, 0b001, 0b100] } } ``` Previously one would need a lot of annotations to convince Sail that this was ok, one on each vector literal. Note that we don't rely on inferring the first element (any element can be inferred), as can be seen in the second literal with the match.
- Loading branch information
Showing
19 changed files
with
144 additions
and
33 deletions.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
default Order dec | ||
|
||
$include <prelude.sail> | ||
|
||
register R : bool | ||
|
||
register X : bits(32) | ||
|
||
val test : unit -> {'n 'm, 'n > 1 & 'n == 'm. vector('n, bits('m))} | ||
|
||
function test() = { | ||
if R then { | ||
[0b00, 0b11] | ||
} else { | ||
[match X { _ => 0b000 }, 0b001, 0b100] | ||
} | ||
} |
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,5 @@ | ||
[93mType error[0m: | ||
[96mpass/ex_vector_infer/v1.sail[0m:13.4-9: | ||
13[96m |[0m [0b1] | ||
[91m |[0m [91m^---^[0m | ||
[91m |[0m This vector literal does not satisfy the constraint in {('n : Int) ('m : Int), ('n > 1 & 'n == 'm). vector('n, bitvector('m))} |
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,17 @@ | ||
default Order dec | ||
|
||
$include <prelude.sail> | ||
|
||
register R : bool | ||
|
||
register X : bits(32) | ||
|
||
val test : unit -> {'n 'm, 'n > 1 & 'n == 'm. vector('n, bits('m))} | ||
|
||
function test() = { | ||
if R then { | ||
[0b1] | ||
} else { | ||
[match X { _ => 0b000 }, 0b001, 0b100] | ||
} | ||
} |
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,5 @@ | ||
[93mType error[0m: | ||
[96mpass/ex_vector_infer/v2.sail[0m:13.11-16: | ||
13[96m |[0m [0b00, 0b111] | ||
[91m |[0m [91m^---^[0m | ||
[91m |[0m Failed to prove constraint: 3 == 2 |
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,17 @@ | ||
default Order dec | ||
|
||
$include <prelude.sail> | ||
|
||
register R : bool | ||
|
||
register X : bits(32) | ||
|
||
val test : unit -> {'n 'm, 'n > 1 & 'n == 'm. vector('n, bits('m))} | ||
|
||
function test() = { | ||
if R then { | ||
[0b00, 0b111] | ||
} else { | ||
[match X { _ => 0b000 }, 0b001, 0b100] | ||
} | ||
} |
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
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