Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust backend: allow const_item_mutation warning, simplify deref_addrof pattern #487

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading