Skip to content

Commit

Permalink
Merge pull request #487 from FStarLang/afromher_rs
Browse files Browse the repository at this point in the history
Rust backend: allow const_item_mutation warning, simplify deref_addrof pattern
  • Loading branch information
msprotz authored Sep 24, 2024
2 parents baec61d + e9dbb05 commit 5fdba7f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/OptimizeMiniRust.ml
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,15 @@ let rewrite_nonminimal_bool = object
| _ -> Call (e, tys, args)
end

let remove_deref_addrof = object
inherit [_] map_expr as super
method! visit_Deref _ e =
let e = super#visit_expr () e in
match e with
| Borrow (_, e) -> e
| _ -> Deref e
end

let map_funs f_map files =
let files =
List.fold_left (fun files (filename, decls) ->
Expand All @@ -907,6 +916,7 @@ let simplify_minirust files =
let files = map_funs remove_auto_deref#visit_expr files in
let files = map_funs rewrite_assign_op#visit_expr files in
let files = map_funs rewrite_nonminimal_bool#visit_expr files in
let files = map_funs remove_deref_addrof#visit_expr files in
(* We do this simplification last, as the previous passes might
have introduced unit statements *)
let files = map_funs remove_trailing_unit#visit_expr files in
Expand Down
1 change: 0 additions & 1 deletion lib/OutputRust.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ let directives = String.trim {|
#![allow(non_camel_case_types)]
#![allow(unused_assignments)]
#![allow(unreachable_patterns)]
#![allow(const_item_mutation)]
|}

let rust_name f = f ^ ".rs"
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ WasmTrap.wasm-test: NEGATIVE = true
%.rs: $(ALL_KRML_FILES) $(KRML_BIN)
$(KRML) -minimal -bundle $(notdir $(subst rust,Rust,$*))=\* \
-backend rust $(EXTRA) -tmpdir $(dir $@) $(filter %.krml,$^)
$(SED) -i 's/\(mutation..\)/\1\nmod lowstar { pub mod ignore { pub fn ignore<T>(_x: T) {}}}\n/' $@
$(SED) -i 's/\(patterns..\)/\1\nmod lowstar { pub mod ignore { pub fn ignore<T>(_x: T) {}}}\n/' $@
echo 'fn main () { let r = main_ (); if r != 0 { println!("main_ returned: {}\\n", r); panic!() } }' >> $@

%.rust-test: $(OUTPUT_DIR)/%.rs
Expand Down

0 comments on commit 5fdba7f

Please sign in to comment.