Skip to content

Commit 3c3e316

Browse files
Merge branch 'main' into alex/blog-gcd
2 parents b87778c + 4019185 commit 3c3e316

File tree

101 files changed

+1639
-1150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1639
-1150
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ result
1010
.DS_Store
1111
.depend
1212
.cache
13+
.lake
1314
proof-libs/fstar/rust_primitives/#*#
1415
**/proofs/*/extraction/*
1516
!**/proofs/*/extraction/Makefile

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,23 @@ Change to cargo-hax:
2222

2323
Changes to hax-lib:
2424
- Add Lean core models for options, results, default (#1747)
25+
- F* lib: improved while loops support, additions of some specific arithmetic operations and fixed `TryInto` for integer types (#1742)
2526

2627
Changes to the Lean backend:
2728
- Support for constants with arbitrary computation (#1738)
2829
- Add support for base-expressions of structs (#1736)
2930
- Use the explicit monadic phase to insert `pure` and `` only on demand, and
3031
not introduce extra `do` block (#1746)
32+
- Rename `Result` monad to `RustM` to avoid confusion with Rust `Result` type (#1768)
33+
- Add support for shift-left (#1785)
34+
- Add support for default methods of traits (#1777)
35+
- Add support for floats (#1784)
36+
- Add support for pattern matching on constant literals (#1789)
37+
- Add support for binding subpatterns in match constructs (#1790)
38+
- Add error when using patterns in function parameters (#1792)
3139

3240
Miscellaneous:
41+
- Reserve extraction folder for auto-generated files in Lean examples (#1754)
3342

3443
## 0.3.5
3544

docs/blog/.authors.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ authors:
22
franziskus:
33
name: Franziskus Kiefer
44
description: Creator
5-
avatar: https://cryspen.com/images/franziskus_hu8239521875621889102.jpg
5+
avatar: /blog/avatars/franziskus.jpg
66
lucas:
77
name: Lucas Franceschino
88
description: Creator
9-
avatar: https://cryspen.com/images/lucas_hu1387702743353212719.jpg
9+
avatar: /blog/avatars/lucas.jpg
1010
clement:
1111
name: Clement Blaudeau
1212
description: Engineer
13-
avatar: https://cryspen.com/images/clement_hu_da447295a2bd189d.jpg
13+
avatar: /blog/avatars/clement.jpg
1414
maxime:
1515
name: Maxime Buyse
1616
description: Engineer
17-
avatar: https://cryspen.com/images/maxime_hu_8da610acc29fd826.png
17+
avatar: /blog/avatars/maxime.png
1818
alex:
1919
name: Alexander Bentkamp
2020
description: Engineer
21-
avatar: https://cryspen.com/images/posts/alex_hu_8751e8cc5106c694.jpg
21+
avatar: /blog/avatars/alex.png

docs/blog/avatars/clement.jpg

24 KB
Loading

docs/blog/avatars/franziskus.jpg

27.1 KB
Loading

docs/blog/avatars/lucas.jpg

12.6 KB
Loading

docs/blog/avatars/maxime.png

117 KB
Loading

docs/manual/lean/internals.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ inductive Error where
3939
| panic: Error
4040
| undef: Error
4141
42-
inductive Result.{u} (α : Type u) where
43-
| ok (v: α): Result α
44-
| fail (e: Error): Result α
42+
inductive RustM.{u} (α : Type u) where
43+
| ok (v: α): RustM α
44+
| fail (e: Error): RustM α
4545
| div
4646
```
4747

4848
This monadic encoding shows for simple expressions: the result of the lean
49-
extracted function is not `u32` but `Result u32`.
49+
extracted function is not `u32` but `RustM u32`.
5050

5151
/// html | div[style='float: left; width: 48%;']
5252
```rust
@@ -58,7 +58,7 @@ fn f (x: u32) -> u32 {
5858

5959
/// html | div[style='float: right;width: 48%;']
6060
```lean
61-
def f (x : u32) : Result u32
61+
def f (x : u32) : RustM u32
6262
:= do (← x +? (1 : u32))
6363
```
6464
///
@@ -73,9 +73,9 @@ actually be understood as bindings in the monad, propagating potential
7373
errors to the top.
7474

7575
The `do` keywords enables the lifting `` and the `pure` operators. Intuitively,
76-
lifting turns a value of type `Result T` into a value of type `T` by turning the
76+
lifting turns a value of type `RustM T` into a value of type `T` by turning the
7777
rest of the program into a use of `bind`. Conversely, `pure` turns a value of
78-
type `T` into a value of type `Result T`. This shows also for let-bindings :
78+
type `T` into a value of type `RustM T`. This shows also for let-bindings :
7979

8080

8181
/// html | div[style='float: left; width: 48%;']
@@ -90,7 +90,7 @@ fn f (x: u32) -> u32 {
9090

9191
/// html | div[style='float: right;width: 48%;']
9292
```lean
93-
def f (x : u32) : Result u32 := do
93+
def f (x : u32) : RustM u32 := do
9494
let y : u32 ← (pure
9595
(← x +? (1 : u32)));
9696
let z : u32 ← (pure
@@ -327,7 +327,7 @@ match e_v1 {
327327
/// html | div[style='float: right;width: 48%;']
328328
```lean
329329
def enums (_ : Tuple0)
330-
: Result Tuple0
330+
: RustM Tuple0
331331
:= do
332332
let e_v1 : E ← (pure E.V1);
333333
let e_v2 : E ← (pure E.V2);
@@ -413,8 +413,8 @@ fn f<T: T1>(x: T) -> usize {
413413
/// html | div[style='float: right;width: 48%;']
414414
```lean
415415
class T1 (Self : Type) where
416-
f1 : Self -> Result usize
417-
f2 : Self -> Self -> Result usize
416+
f1 : Self -> RustM usize
417+
f2 : Self -> Self -> RustM usize
418418
419419
structure S where
420420
@@ -425,7 +425,7 @@ instance Impl : T1 S where
425425
:= do (43 : usize)
426426
427427
def f (T : Type) [(T1 T)] (x : T)
428-
: Result usize
428+
: RustM usize
429429
:= do
430430
(← (← T1.f1 x) +? (← T1.f2 x x))
431431
```
@@ -459,7 +459,7 @@ class Test
459459
[_constr_7570495343596639253 :
460460
(T1 T)]
461461
f_test :
462-
Self -> T -> Result usize
462+
Self -> T -> RustM usize
463463
```
464464
///
465465

@@ -507,7 +507,7 @@ class Bar (Self : Type) where
507507
508508
class T1 (Self : Type) where
509509
T : Type
510-
f : Self -> T -> Result T
510+
f : Self -> T -> RustM T
511511
512512
class T3 (Self : Type) where
513513
T : Type
@@ -516,12 +516,12 @@ class T3 (Self : Type) where
516516
Tp : Type
517517
[_constr_15450263461214744089 : (Foo Tp T)]
518518
f (A : Type) [(Bar A)] :
519-
Self -> T -> Tp -> Result usize
519+
Self -> T -> Tp -> RustM usize
520520
521521
class T2 (Self : Type) where
522522
T : Type
523523
[_constr_18277713886489441014 : (T1 T)]
524-
f : Self -> T -> Result usize
524+
f : Self -> T -> RustM usize
525525
526526
```
527527
///

engine/backends/fstar/fstar_backend.ml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -700,15 +700,31 @@ struct
700700
in
701701
F.term @@ F.AST.LetOperator ([ (F.id op, p, pexpr rhs) ], pexpr body)
702702
| Let { lhs; rhs; body; monadic = None } ->
703-
let p =
704-
(* TODO: temp patch that remove annotation when we see an associated type *)
705-
if [%matches? TAssociatedType _] @@ U.remove_tuple1 lhs.typ then
706-
ppat lhs
707-
else
708-
F.pat @@ F.AST.PatAscribed (ppat lhs, (pty lhs.span lhs.typ, None))
703+
let rec ascribe_tuple_components pattern =
704+
match pattern with
705+
| { p = PConstruct { constructor = `TupleCons n1; fields; _ }; _ }
706+
when n1 > 1 ->
707+
(* F* type inference works better if the ascription is on each component intead of the whole tuple. *)
708+
F.pat
709+
@@ F.AST.PatTuple
710+
( List.map
711+
~f:(fun { pat } -> ascribe_tuple_components pat)
712+
fields,
713+
false )
714+
| _ ->
715+
(* TODO: temp patch that remove annotation when we see an associated type *)
716+
if [%matches? TAssociatedType _] @@ U.remove_tuple1 pattern.typ
717+
then ppat pattern
718+
else
719+
F.pat
720+
@@ F.AST.PatAscribed
721+
(ppat pattern, (pty pattern.span pattern.typ, None))
709722
in
710723
F.term
711-
@@ F.AST.Let (NoLetQualifier, [ (None, (p, pexpr rhs)) ], pexpr body)
724+
@@ F.AST.Let
725+
( NoLetQualifier,
726+
[ (None, (ascribe_tuple_components lhs, pexpr rhs)) ],
727+
pexpr body )
712728
| EffectAction _ -> .
713729
| Match { scrutinee; arms } ->
714730
F.term
@@ -1643,7 +1659,13 @@ struct
16431659
List.concat_map
16441660
~f:(fun { ii_span; ii_generics; ii_v; ii_ident } ->
16451661
let name = (RenderId.render ii_ident).name in
1646-
1662+
let ii_generics =
1663+
{
1664+
ii_generics with
1665+
constraints =
1666+
List.filter ~f:[%matches? GCType _] ii_generics.constraints;
1667+
}
1668+
in
16471669
match ii_v with
16481670
| IIFn { body; params } ->
16491671
let pats =

engine/backends/lean/lean_backend.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ include
1414
include On.Quote
1515
include On.Dyn
1616
include On.Unsafe
17+
include On.Trait_item_default
18+
include On.As_pattern
1719
end)
1820
(struct
1921
let backend = Diagnostics.Backend.FStar
@@ -32,7 +34,7 @@ module SubtypeToInputLanguage
3234
and type raw_pointer = Features.Off.raw_pointer
3335
and type early_exit = Features.Off.early_exit
3436
and type question_mark = Features.Off.question_mark
35-
and type as_pattern = Features.Off.as_pattern
37+
and type as_pattern = Features.On.as_pattern
3638
and type lifetime = Features.Off.lifetime
3739
and type monadic_action = Features.Off.monadic_action
3840
and type arbitrary_lhs = Features.Off.arbitrary_lhs
@@ -45,7 +47,7 @@ module SubtypeToInputLanguage
4547
and type state_passing_loop = Features.Off.state_passing_loop
4648
and type fold_like_loop = Features.Off.fold_like_loop
4749
and type match_guard = Features.Off.match_guard
48-
and type trait_item_default = Features.Off.trait_item_default) =
50+
and type trait_item_default = Features.On.trait_item_default) =
4951
struct
5052
module FB = InputLanguage
5153

@@ -116,11 +118,9 @@ module TransformToInputLanguage =
116118
|> Phases.Drop_return_break_continue
117119
|> Phases.Functionalize_loops
118120
|> Phases.Reject.Question_mark
119-
|> Phases.Reject.As_pattern
120121
|> Phases.Traits_specs
121122
|> Phases.Simplify_hoisting
122123
|> Phases.Newtype_as_refinement
123-
|> Phases.Reject.Trait_item_default
124124
|> Phases.Bundle_cycles
125125
|> Phases.Reorder_fields
126126
|> Phases.Sort_items

0 commit comments

Comments
 (0)