Skip to content

Commit 814a6a2

Browse files
authored
Merge pull request #1174 from hacspec/fix-1170
Remove rejected type ascription patterns from generated f*.
2 parents de59826 + 92e7d33 commit 814a6a2

File tree

7 files changed

+102
-31
lines changed

7 files changed

+102
-31
lines changed

engine/backends/fstar/fstar_backend.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ struct
401401
let ppat = ppat' false in
402402
match p.p with
403403
| PWild -> F.wild
404-
| PAscription { typ; pat } ->
404+
| PAscription { typ; pat = { p = PBinding _; _ } as pat } ->
405405
F.pat @@ F.AST.PatAscribed (ppat pat, (pty p.span typ, None))
406+
| PAscription { pat; _ } -> ppat pat
406407
| PBinding
407408
{
408409
mut = Immutable;

test-harness/src/snapshots/toolchain__literals into-fstar.snap

+25-25
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type t_Foo = { f_field:u8 }
3838
let v_CONSTANT: t_Foo = { f_field = 3uy } <: t_Foo
3939

4040
let casts (x8: u8) (x16: u16) (x32: u32) (x64: u64) (xs: usize) : Prims.unit =
41-
let (_: u64):u64 =
41+
let _:u64 =
4242
((((cast (x8 <: u8) <: u64) +! (cast (x16 <: u16) <: u64) <: u64) +! (cast (x32 <: u32) <: u64)
4343
<:
4444
u64) +!
@@ -47,28 +47,28 @@ let casts (x8: u8) (x16: u16) (x32: u32) (x64: u64) (xs: usize) : Prims.unit =
4747
u64) +!
4848
(cast (xs <: usize) <: u64)
4949
in
50-
let (_: u32):u32 =
50+
let _:u32 =
5151
((((cast (x8 <: u8) <: u32) +! (cast (x16 <: u16) <: u32) <: u32) +! x32 <: u32) +!
5252
(cast (x64 <: u64) <: u32)
5353
<:
5454
u32) +!
5555
(cast (xs <: usize) <: u32)
5656
in
57-
let (_: u16):u16 =
57+
let _:u16 =
5858
((((cast (x8 <: u8) <: u16) +! x16 <: u16) +! (cast (x32 <: u32) <: u16) <: u16) +!
5959
(cast (x64 <: u64) <: u16)
6060
<:
6161
u16) +!
6262
(cast (xs <: usize) <: u16)
6363
in
64-
let (_: u8):u8 =
64+
let _:u8 =
6565
(((x8 +! (cast (x16 <: u16) <: u8) <: u8) +! (cast (x32 <: u32) <: u8) <: u8) +!
6666
(cast (x64 <: u64) <: u8)
6767
<:
6868
u8) +!
6969
(cast (xs <: usize) <: u8)
7070
in
71-
let (_: i64):i64 =
71+
let _:i64 =
7272
((((cast (x8 <: u8) <: i64) +! (cast (x16 <: u16) <: i64) <: i64) +! (cast (x32 <: u32) <: i64)
7373
<:
7474
i64) +!
@@ -77,7 +77,7 @@ let casts (x8: u8) (x16: u16) (x32: u32) (x64: u64) (xs: usize) : Prims.unit =
7777
i64) +!
7878
(cast (xs <: usize) <: i64)
7979
in
80-
let (_: i32):i32 =
80+
let _:i32 =
8181
((((cast (x8 <: u8) <: i32) +! (cast (x16 <: u16) <: i32) <: i32) +! (cast (x32 <: u32) <: i32)
8282
<:
8383
i32) +!
@@ -86,7 +86,7 @@ let casts (x8: u8) (x16: u16) (x32: u32) (x64: u64) (xs: usize) : Prims.unit =
8686
i32) +!
8787
(cast (xs <: usize) <: i32)
8888
in
89-
let (_: i16):i16 =
89+
let _:i16 =
9090
((((cast (x8 <: u8) <: i16) +! (cast (x16 <: u16) <: i16) <: i16) +! (cast (x32 <: u32) <: i16)
9191
<:
9292
i16) +!
@@ -95,7 +95,7 @@ let casts (x8: u8) (x16: u16) (x32: u32) (x64: u64) (xs: usize) : Prims.unit =
9595
i16) +!
9696
(cast (xs <: usize) <: i16)
9797
in
98-
let (_: i8):i8 =
98+
let _:i8 =
9999
((((cast (x8 <: u8) <: i8) +! (cast (x16 <: u16) <: i8) <: i8) +! (cast (x32 <: u32) <: i8)
100100
<:
101101
i8) +!
@@ -115,7 +115,7 @@ let math_integers (x: Hax_lib.Int.t_Int)
115115
: Prims.Pure u8
116116
(requires x > (0 <: Hax_lib.Int.t_Int) && x < (16 <: Hax_lib.Int.t_Int))
117117
(fun _ -> Prims.l_True) =
118-
let (_: Hax_lib.Int.t_Int):Hax_lib.Int.t_Int = Rust_primitives.Hax.Int.from_machine (sz 3) in
118+
let _:Hax_lib.Int.t_Int = Rust_primitives.Hax.Int.from_machine (sz 3) in
119119
let _:bool =
120120
((-340282366920938463463374607431768211455000) <: Hax_lib.Int.t_Int) >
121121
(340282366920938463463374607431768211455000 <: Hax_lib.Int.t_Int)
@@ -129,26 +129,26 @@ let math_integers (x: Hax_lib.Int.t_Int)
129129
let _:Hax_lib.Int.t_Int = x - x in
130130
let _:Hax_lib.Int.t_Int = x * x in
131131
let _:Hax_lib.Int.t_Int = x / x in
132-
let (_: i16):i16 = Hax_lib.Int.impl__Int__to_i16 x in
133-
let (_: i32):i32 = Hax_lib.Int.impl__Int__to_i32 x in
134-
let (_: i64):i64 = Hax_lib.Int.impl__Int__to_i64 x in
135-
let (_: i128):i128 = Hax_lib.Int.impl__Int__to_i128 x in
136-
let (_: isize):isize = Hax_lib.Int.impl__Int__to_isize x in
137-
let (_: u16):u16 = Hax_lib.Int.impl__Int__to_u16 x in
138-
let (_: u32):u32 = Hax_lib.Int.impl__Int__to_u32 x in
139-
let (_: u64):u64 = Hax_lib.Int.impl__Int__to_u64 x in
140-
let (_: u128):u128 = Hax_lib.Int.impl__Int__to_u128 x in
141-
let (_: usize):usize = Hax_lib.Int.impl__Int__to_usize x in
132+
let _:i16 = Hax_lib.Int.impl__Int__to_i16 x in
133+
let _:i32 = Hax_lib.Int.impl__Int__to_i32 x in
134+
let _:i64 = Hax_lib.Int.impl__Int__to_i64 x in
135+
let _:i128 = Hax_lib.Int.impl__Int__to_i128 x in
136+
let _:isize = Hax_lib.Int.impl__Int__to_isize x in
137+
let _:u16 = Hax_lib.Int.impl__Int__to_u16 x in
138+
let _:u32 = Hax_lib.Int.impl__Int__to_u32 x in
139+
let _:u64 = Hax_lib.Int.impl__Int__to_u64 x in
140+
let _:u128 = Hax_lib.Int.impl__Int__to_u128 x in
141+
let _:usize = Hax_lib.Int.impl__Int__to_usize x in
142142
Hax_lib.Int.impl__Int__to_u8 (x + (x * x <: Hax_lib.Int.t_Int) <: Hax_lib.Int.t_Int)
143143

144144
let null: char = '\0'
145145

146146
let numeric (_: Prims.unit) : Prims.unit =
147-
let (_: usize):usize = sz 123 in
148-
let (_: isize):isize = isz (-42) in
149-
let (_: isize):isize = isz 42 in
150-
let (_: i32):i32 = (-42l) in
151-
let (_: u128):u128 = pub_u128 22222222222222222222 in
147+
let _:usize = sz 123 in
148+
let _:isize = isz (-42) in
149+
let _:isize = isz 42 in
150+
let _:i32 = (-42l) in
151+
let _:u128 = pub_u128 22222222222222222222 in
152152
()
153153

154154
let patterns (_: Prims.unit) : Prims.unit =
@@ -190,7 +190,7 @@ let panic_with_msg (_: Prims.unit) : Prims.unit =
190190
Rust_primitives.Hax.t_Never)
191191

192192
let empty_array (_: Prims.unit) : Prims.unit =
193-
let (_: t_Slice u8):t_Slice u8 =
193+
let _:t_Slice u8 =
194194
(let list:Prims.list u8 = [] in
195195
FStar.Pervasives.assert_norm (Prims.eq2 (List.Tot.length list) 0);
196196
Rust_primitives.Hax.array_of_list 0 list)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
source: test-harness/src/harness.rs
3+
expression: snapshot
4+
info:
5+
kind:
6+
Translate:
7+
backend: fstar
8+
info:
9+
name: patterns
10+
manifest: patterns/Cargo.toml
11+
description: ~
12+
spec:
13+
optional: false
14+
broken: false
15+
issue_id: ~
16+
positive: true
17+
snapshot:
18+
stderr: true
19+
stdout: true
20+
include_flag: ~
21+
backend_options: ~
22+
---
23+
exit = 0
24+
stderr = 'Finished `dev` profile [unoptimized + debuginfo] target(s) in XXs'
25+
26+
[stdout]
27+
diagnostics = []
28+
29+
[stdout.files]
30+
"Patterns.fst" = '''
31+
module Patterns
32+
#set-options "--fuel 0 --ifuel 1 --z3rlimit 15"
33+
open Core
34+
open FStar.Mul
35+
36+
type t_Other = | Other : i32 -> t_Other
37+
38+
type t_Test = | Test_C1 : t_Other -> t_Test
39+
40+
let impl__test (self: t_Test) : i32 = match self with | Test_C1 c -> c._0
41+
'''

tests/Cargo.lock

+9-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ members = [
2323
"dyn",
2424
"reordering",
2525
"nested-derefs",
26+
"patterns",
2627
"proverif-minimal",
2728
"proverif-basic-structs",
2829
"proverif-ping-pong",

tests/patterns/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "patterns"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
8+
[package.metadata.hax-tests]
9+
into."fstar" = { issue_id = "1170" }

tests/patterns/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![allow(dead_code)]
2+
3+
struct Other<'a>(&'a i32);
4+
5+
enum Test<'a> {
6+
C1(Other<'a>),
7+
}
8+
9+
impl<'a> Test<'a> {
10+
fn test(&self) -> i32 {
11+
match self {
12+
Self::C1(c) => *c.0,
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)