Skip to content

Commit

Permalink
chore: slight cleanup in the wake of #4103 (#4108)
Browse files Browse the repository at this point in the history
reacting to the #4103 (comment)

Turns out that the backend generates quite some code to build the caller principal, so we do it only once now.
  • Loading branch information
ggreif authored Jul 6, 2023
1 parent 1a7fdce commit ee58d35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/lowering/desugar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ and call_system_func_opt name es obj_typ =
(unitE ())
| "inspect" ->
let _, tfs = T.as_obj obj_typ in
let caller = fresh_var "caller" T.principal in
let caller = fresh_var "caller" T.caller in
let arg = fresh_var "arg" T.blob in
let msg_typ = T.decode_msg_typ tfs in
let msg = fresh_var "msg" msg_typ in
Expand Down Expand Up @@ -435,13 +435,16 @@ and export_footprint self_id expr =
let bind1 = typ_arg scope_con1 Scope scope_bound in
let bind2 = typ_arg scope_con2 Scope scope_bound in
let ret_typ = T.Obj(Object,[{lab = "size"; typ = T.nat64; depr = None}]) in
let caller = fresh_var "caller" caller in
([ letD (var v typ) (
funcE v (Shared Query) Promises [bind1] [] [ret_typ] (
(asyncE T.Fut bind2
(blockE [expD (assertE (orE (primE (I.RelPrim (caller, Operator.EqOp))
[primE I.ICCallerPrim []; selfRefE caller])
(primE (I.OtherPrim "is_controller") [primE I.ICCallerPrim []])));
letD size (primE (I.ICStableSize expr.note.Note.typ) [expr])
(blockE [
letD caller (primE I.ICCallerPrim []);
expD (assertE (orE (primE (I.RelPrim (principal, Operator.EqOp))
[varE caller; selfRefE principal])
(primE (I.OtherPrim "is_controller") [varE caller])));
letD size (primE (I.ICStableSize expr.note.Note.typ) [expr])
]
(newObjE T.Object
[{ it = Ir.{name = "size"; var = id_of_var size};
Expand Down
2 changes: 1 addition & 1 deletion src/mo_types/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ let catch = Prim Error

(* Shared call context *)

let caller = Prim Principal
let caller = principal
let ctxt = Obj (Object,[{ lab = "caller"; typ = caller; depr = None}])

let prim = function
Expand Down

0 comments on commit ee58d35

Please sign in to comment.