-
Notifications
You must be signed in to change notification settings - Fork 97
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
feat: add prim call_raw : (Principal, Text, Blob) -> async Blob #3086
Conversation
Claudio/raw call experiment
The new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable
Ah, I see why, because you construct such a function ref pair in the backend. I don't think it's clearly defined what the representation is yet, presumably, so far only flat text values occurred. So the value needs to flattened at the right place… |
let add_cycles = Internals.add_cycles env ae in | ||
compile_exp_vanilla env ae p ^^ | ||
compile_exp_vanilla env ae m ^^ | ||
Tuple.from_stack env 2 ^^ set_meth_pair ^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you need to turn the text into a blob, because above we have
(* The method name *)
get_meth_pair ^^ Arr.load_field 1l ^^ Blob.as_ptr_len env ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks. That's precisely what I was worried about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
}; | ||
|
||
do { | ||
let m = "super"#"cali"#"fragilisticexpialidocious"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just being curious, did you see this crashing before it started working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I tried it locally before fixing
@@ -406,3 +406,8 @@ func @create_actor_helper(wasm_module_ : Blob, arg_ : Blob) : async Principal = | |||
}); | |||
return canister_id_; | |||
}; | |||
|
|||
// raw calls | |||
func @call_raw(p : Principal, m : Text, a : Blob) : async Blob { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not define this in prim.mo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but our checker complains about await's in prim, so I just moved it here instead. Sneaky.
@@ -593,6 +593,14 @@ let rec check_exp env (exp:Ir.exp) : unit = | |||
error env exp1.at "expected function type, but expression produces type\n %s" | |||
(T.string_of_typ_expand t1) | |||
end | |||
(* TODO: T.unit <: t ? *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still relevant? for ICCallPrim
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just noticed the missing check
(* TODO: T.unit <: t ? *) | ||
| ICCallRawPrim, [exp1; exp2; exp3; k; r] -> | ||
typ exp1 <: T.principal; | ||
typ exp2 <: T.text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not make this T.blob
and normalise Text
-> Blob
in Motoko?
For the record, I'm really concerned about the slippery slope this creates towards leaking and breaking more abstractions. |
Maybe there is a way to close the abstraction later? This is exactly what we need right now to develop some things on our road map using motoko that have been blocked since launch. Thank you! |
Objection noted. However, we had promised a solution for ages and never delivered one, so offering this as an experimental feature while we come up with something better seems reasonable to me. Given that you can already achieve this (modulo a change in caller) by bouncing off Rust, I don't really see it compromising more than we have already across the company. |
Fixes #2703 (by lowering ourselves to the level of Rust).
Adds a prim to dynamically invoke a method by name with an already serialized blob and get the raw (undeserialized) blob back asynchronously:
The function can only be called in an asynchronous context and this is enforced by the type system.
There is no assumption that the contents of either blob is Candid, so this could also be used to talk to non-Candid endpoints.
This should be sufficient to implement the call-forwarding functionality of the Rust cycles wallet.
request
,send
,call
,invoke
,call_dynamic
spring to mind