From ee58d358b18fccab227bf583e1503191bec0e423 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 6 Jul 2023 19:47:05 +0200 Subject: [PATCH] chore: slight cleanup in the wake of #4103 (#4108) reacting to the https://github.com/dfinity/motoko/pull/4103#discussion_r1254161115 Turns out that the backend generates quite some code to build the caller principal, so we do it only once now. --- src/lowering/desugar.ml | 13 ++++++++----- src/mo_types/type.ml | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lowering/desugar.ml b/src/lowering/desugar.ml index fdbc5b44c4b..d2006b61651 100644 --- a/src/lowering/desugar.ml +++ b/src/lowering/desugar.ml @@ -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 @@ -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}; diff --git a/src/mo_types/type.ml b/src/mo_types/type.ml index aa02cf12024..74db125c7ea 100644 --- a/src/mo_types/type.ml +++ b/src/mo_types/type.ml @@ -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