Skip to content

Commit

Permalink
Merge pull request #565 from hacspec/type-ascription
Browse files Browse the repository at this point in the history
feat(engine/import): support `ValueTypeAscription`
  • Loading branch information
W95Psp authored Mar 12, 2024
2 parents e3aac4c + 88ecf77 commit e9e26d4
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 3 deletions.
3 changes: 1 addition & 2 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,7 @@ end) : EXPR = struct
| StaticRef { def_id = id; _ } -> GlobalVar (def_id Value id)
| PlaceTypeAscription _ ->
unimplemented [ e.span ] "expression PlaceTypeAscription"
| ValueTypeAscription _ ->
unimplemented [ e.span ] "expression ValueTypeAscription"
| ValueTypeAscription { source; _ } -> (c_expr source).e
| ZstLiteral _ -> unimplemented [ e.span ] "expression ZstLiteral"
| Yield _ -> unimplemented [ e.span ] "expression Yield"
| Todo payload -> unimplemented [ e.span ] ("expression Todo\n" ^ payload)
Expand Down
54 changes: 54 additions & 0 deletions test-harness/src/snapshots/toolchain__slices into-coq.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
source: test-harness/src/harness.rs
expression: snapshot
info:
kind:
Translate:
backend: coq
info:
name: slices
manifest: slices/Cargo.toml
description: ~
spec:
optional: false
broken: false
issue_id: ~
positive: true
snapshot:
stderr: true
stdout: true
include_flag: ~
backend_options: ~
---
exit = 0
stderr = '''
Compiling slices v0.1.0 (WORKSPACE_ROOT/slices)
Finished dev [unoptimized + debuginfo] target(s) in XXs'''
[stdout]
diagnostics = []

[stdout.files]
"Slices.v" = '''
(* File automatically generated by Hacspec *)
From Hacspec Require Import Hacspec_Lib MachineIntegers.
From Coq Require Import ZArith.
Import List.ListNotations.
Open Scope Z_scope.
Open Scope bool_scope.

(*Not implemented yet? todo(item)*)

Definition v_VERSION : seq int8 :=
unsize (array_from_list [(@repr WORDSIZE8 118);
(@repr WORDSIZE8 49)]).

Definition do_something (_ : seq int8) : unit :=
tt.

Definition r#unsized (_ : nseq (seq int8) TODO: Int.to_string length) : unit :=
tt.

Definition sized (x : nseq (nseq int8 TODO: Int.to_string length) TODO: Int.to_string length) : unit :=
r#unsized (array_from_list [unsize (x.[(@repr WORDSIZE32 0)])]).
'''
51 changes: 51 additions & 0 deletions test-harness/src/snapshots/toolchain__slices into-fstar.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
source: test-harness/src/harness.rs
expression: snapshot
info:
kind:
Translate:
backend: fstar
info:
name: slices
manifest: slices/Cargo.toml
description: ~
spec:
optional: false
broken: false
issue_id: ~
positive: true
snapshot:
stderr: true
stdout: true
include_flag: ~
backend_options: ~
---
exit = 0
stderr = '''
Compiling slices v0.1.0 (WORKSPACE_ROOT/slices)
Finished dev [unoptimized + debuginfo] target(s) in XXs'''
[stdout]
diagnostics = []

[stdout.files]
"Slices.fst" = '''
module Slices
#set-options "--fuel 0 --ifuel 1 --z3rlimit 15"
open Core
open FStar.Mul

let v_VERSION: t_Slice u8 =
Rust_primitives.unsize (let list = [118uy; 49uy] in
FStar.Pervasives.assert_norm (Prims.eq2 (List.Tot.length list) 2);
Rust_primitives.Hax.array_of_list 2 list)

let do_something (_: t_Slice u8) : Prims.unit = ()

let r#unsized (_: t_Array (t_Slice u8) (sz 1)) : Prims.unit = ()

let sized (x: t_Array (t_Array u8 (sz 4)) (sz 1)) : Prims.unit =
r#unsized (let list = [Rust_primitives.unsize (x.[ sz 0 ] <: t_Array u8 (sz 4)) <: t_Slice u8] in
FStar.Pervasives.assert_norm (Prims.eq2 (List.Tot.length list) 1);
Rust_primitives.Hax.array_of_list 1 list)
'''
2 changes: 1 addition & 1 deletion tests/slices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
[dependencies]

[package.metadata.hax-tests]
into."fstar+coq" = { broken = false, snapshot = "none", issue_id = "85" }
into."fstar+coq" = { broken = false, issue_id = "85" }
6 changes: 6 additions & 0 deletions tests/slices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ const VERSION: &[u8] = b"v1";
// This panics
// thread 'rustc' panicked at 'hax-engine exited with non-zero code', cli/driver/src/exporter.rs:217:2
pub fn do_something(_: &[u8]) {}

pub fn sized(x: &[&[u8; 4]; 1]) {
r#unsized(&[(x[0] as &[u8])])
}

pub fn r#unsized(_: &[&[u8]; 1]) {}

0 comments on commit e9e26d4

Please sign in to comment.