Skip to content

Commit

Permalink
add rts_in_install prim; working
Browse files Browse the repository at this point in the history
  • Loading branch information
crusso committed Dec 19, 2024
1 parent 82f1c51 commit 2b860e0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion rts/motoko-rts/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ pub unsafe fn assign_stable_type<M: Memory>(
(*metadata).stable_type.assign(mem, &new_type);
}


pub(crate) unsafe fn stable_type_descriptor() -> &'static mut TypeDescriptor {
let metadata = PersistentMetadata::get();
&mut (*metadata).stable_type
Expand Down
9 changes: 9 additions & 0 deletions src/codegen/compile_classical.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11616,6 +11616,15 @@ and compile_prim_invocation (env : E.t) ae p es at =
SR.Vanilla,
StableMem.get_mem_size env ^^ BigNum.from_word64 env

| OtherPrim "rts_in_install", [] -> (* classical specific *)
assert (not !Flags.enhanced_orthogonal_persistence);
SR.Vanilla,
StableMem.stable64_size env ^^
G.i (Test (Wasm_exts.Values.I64 I64Op.Eqz)) ^^
G.if1 I32Type
(Bool.lit true)
(Bool.lit false)

(* Regions *)

| OtherPrim "regionNew", [] ->
Expand Down
12 changes: 12 additions & 0 deletions src/codegen/compile_enhanced.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8757,6 +8757,7 @@ module EnhancedOrthogonalPersistence = struct

let initialize env actor_type =
register_stable_type env actor_type

end (* EnhancedOrthogonalPersistence *)

(* As fallback when doing persistent memory layout changes. *)
Expand Down Expand Up @@ -11684,6 +11685,15 @@ and compile_prim_invocation (env : E.t) ae p es at =
SR.Vanilla,
StableMem.get_mem_size env ^^ BigNum.from_word64 env

| OtherPrim "rts_in_install", [] -> (* EOP specific *)
assert (!Flags.enhanced_orthogonal_persistence);
SR.Vanilla,
EnhancedOrthogonalPersistence.load_stable_actor env ^^
compile_test I64Op.Eqz ^^
E.if1 I64Type
(Bool.lit true)
(Bool.lit false)

(* Regions *)

| OtherPrim "regionNew", [] ->
Expand Down Expand Up @@ -12258,9 +12268,11 @@ and compile_prim_invocation (env : E.t) ae p es at =

| ICStableRead ty, [] ->
SR.Vanilla,
(* IC.compile_static_print env ("ICStableRead" ^ Type.string_of_typ ty) ^^ *)
Persistence.load env ty
| ICStableWrite ty, [] ->
SR.unit,
(* IC.compile_static_print env ("ICStableWrite" ^ Type.string_of_typ ty) ^^ *)
Persistence.save env ty

(* Cycles *)
Expand Down
1 change: 1 addition & 0 deletions src/ir_def/construct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ let primE prim es =
| OtherPrim "rts_max_stack_size" -> T.nat
| OtherPrim "rts_callback_table_count" -> T.nat
| OtherPrim "rts_callback_table_size" -> T.nat
| OtherPrim "rts_in_install" -> T.bool
| _ -> assert false (* implement more as needed *)
in
let eff = map_max_effs eff es in
Expand Down
4 changes: 1 addition & 3 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,7 @@ and build_actor at ts exp_opt self_id es obj_typ =
let v_dom = fresh_var "v_dom" dom in
let v_rng = fresh_var "v_rng" rng in
I.{pre = ty'; post = ty},
ifE (primE (Ir.RelPrim (T.nat, Operator.EqOp)) [
primE (I.OtherPrim "rts_stable_memory_size") [];
natE Numerics.Nat.zero])
ifE (primE (I.OtherPrim "rts_in_install") [])
(primE (I.ICStableRead ty) [])
(letE v (primE (I.ICStableRead ty') [])
(letE v_dom
Expand Down

0 comments on commit 2b860e0

Please sign in to comment.