From 2d40f372d5d750b53d3605a284e6f8662f832389 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Mon, 1 Apr 2019 23:19:36 +0200 Subject: [PATCH 1/2] Serialize a funcref argument directly as a funcref so that callbacks from our `async` translation are compatible with what the hypervisor passes us. --- design/TmpWireFormat.md | 4 ++++ src/compile.ml | 3 +++ src/customSections.ml | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/design/TmpWireFormat.md b/design/TmpWireFormat.md index 7138f18574e..42a151d6524 100644 --- a/design/TmpWireFormat.md +++ b/design/TmpWireFormat.md @@ -36,6 +36,10 @@ A message entry point with an argument of type `Text` is represented as a `datab Note that there is no terminating `\0`, and the length is implicit as the length of the `databuf`. +Specialized argument format: `actor {…}` and `shared … -> …` +------------------------------------------------------------ + +A message entry point with an argument of actor type or of shared function type is represented as an `actorref` resp. `funcref.` General argument format (without references) -------------------------------------------- diff --git a/src/compile.ml b/src/compile.ml index 9943db9ea22..b10ae65a85f 100644 --- a/src/compile.ml +++ b/src/compile.ml @@ -3019,6 +3019,7 @@ module Serialization = struct | Type.Prim Type.Text -> get_x ^^ Dfinity.compile_databuf_of_text env | Type.Prim Type.Word32 -> get_x ^^ BoxedSmallWord.unbox env | Type.Obj (Type.Actor, _) -> get_x ^^ Dfinity.unbox_reference env + | Type.Func (Type.Sharable, _, _, _, _) -> get_x ^^ Dfinity.unbox_reference env | _ -> let (set_data_size, get_data_size) = new_local env "data_size" in let (set_refs_size, get_refs_size) = new_local env "refs_size" in @@ -3114,6 +3115,7 @@ module Serialization = struct | Type.Prim Type.Text -> deserialize_text env get_elembuf | Type.Prim Type.Word32 -> get_elembuf ^^ BoxedSmallWord.box env | Type.Obj (Type.Actor, _) -> get_elembuf ^^ Dfinity.box_reference env + | Type.Func (Type.Sharable, _, _, _, _) -> get_elembuf ^^ Dfinity.box_reference env | _ -> let (set_data_size, get_data_size) = new_local env "data_size" in let (set_refs_size, get_refs_size) = new_local env "refs_size" in @@ -3183,6 +3185,7 @@ module Serialization = struct | Type.Prim Type.Text -> CustomSections.DataBuf | Type.Prim Type.Word32 -> CustomSections.I32 | Type.Obj (Type.Actor, _) -> CustomSections.ActorRef + | Type.Func (Type.Sharable, _, _, _, _) -> CustomSections.FuncRef | t' when has_no_references t' -> CustomSections.DataBuf | _ -> CustomSections.ElemBuf diff --git a/src/customSections.ml b/src/customSections.ml index 93094f0038a..2281b2d1bc1 100644 --- a/src/customSections.ml +++ b/src/customSections.ml @@ -1,6 +1,6 @@ (* Some data type to represent custom sectoins *) -type type_ = I32 | DataBuf | ElemBuf | ActorRef +type type_ = I32 | DataBuf | ElemBuf | ActorRef | FuncRef (* Some Code copied from encodeMap.ml *) type stream = @@ -81,6 +81,7 @@ let encode | DataBuf -> vu32 0x6cl | ElemBuf -> vu32 0x6bl | ActorRef -> vu32 0x6fl + | FuncRef -> vu32 0x6dl in section 0 (fun _ -> From 38d99c4670f7e1af4c057547d3c6b45a668d64ea Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Tue, 2 Apr 2019 09:19:01 +0200 Subject: [PATCH 2/2] Serialization: Remove special argument format for `Word32` we no longer pass the nonce through to ActorScript, and it adds non-uniformity, so lets remove it. --- design/TmpWireFormat.md | 6 ------ src/compile.ml | 13 +++++-------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/design/TmpWireFormat.md b/design/TmpWireFormat.md index 42a151d6524..783d9b08789 100644 --- a/design/TmpWireFormat.md +++ b/design/TmpWireFormat.md @@ -22,12 +22,6 @@ defined with a list of arguments, these all become arguments of the WebAssembly function. See the [ActorScript guide](https://hydra.oregon.dfinity.build//job/dfinity-ci-build/actorscript.pr-252/users-guide/latest/download/1/guide/#function-types) for the precise rules for function arities. -Specialized argument format: `Word32` -------------------------------------- - -A message entry point with an argument of type `Word32` is directly represented -as a `I32`. - Specialized argument format: `Text` ------------------------------------- diff --git a/src/compile.ml b/src/compile.ml index b10ae65a85f..f17075e2daf 100644 --- a/src/compile.ml +++ b/src/compile.ml @@ -2621,9 +2621,9 @@ module Serialization = struct Also see (and update) `design/TmpWireFormat.md`, which documents the format in a “user-facing” way. - We have a specific serialization strategy for `Text`, `Word32` and - references for easier interop with the console and the nonce. This is a - stop-gap measure until we have nailed down IDL and Bidirectional Messaging. + We have a specific serialization strategy for `Text` and references for + easier interop with the console and the nonce. This is a stop-gap measure + until we have nailed down IDL and Bidirectional Messaging. The general serialization strategy is as follows: * We traverse the data to calculate the size needed for the data buffer and the @@ -3017,8 +3017,7 @@ module Serialization = struct else Func.share_code1 env name ("x", I32Type) [I32Type] (fun env get_x -> match Type.normalize t with | Type.Prim Type.Text -> get_x ^^ Dfinity.compile_databuf_of_text env - | Type.Prim Type.Word32 -> get_x ^^ BoxedSmallWord.unbox env - | Type.Obj (Type.Actor, _) -> get_x ^^ Dfinity.unbox_reference env + | Type.Obj (Type.Actor, _) | Type.Func (Type.Sharable, _, _, _, _) -> get_x ^^ Dfinity.unbox_reference env | _ -> let (set_data_size, get_data_size) = new_local env "data_size" in @@ -3113,8 +3112,7 @@ module Serialization = struct Func.share_code1 env name ("elembuf", I32Type) [I32Type] (fun env get_elembuf -> match Type.normalize t with | Type.Prim Type.Text -> deserialize_text env get_elembuf - | Type.Prim Type.Word32 -> get_elembuf ^^ BoxedSmallWord.box env - | Type.Obj (Type.Actor, _) -> get_elembuf ^^ Dfinity.box_reference env + | Type.Obj (Type.Actor, _) | Type.Func (Type.Sharable, _, _, _, _) -> get_elembuf ^^ Dfinity.box_reference env | _ -> let (set_data_size, get_data_size) = new_local env "data_size" in @@ -3183,7 +3181,6 @@ module Serialization = struct let dfinity_type t = match Type.normalize t with | Type.Prim Type.Text -> CustomSections.DataBuf - | Type.Prim Type.Word32 -> CustomSections.I32 | Type.Obj (Type.Actor, _) -> CustomSections.ActorRef | Type.Func (Type.Sharable, _, _, _, _) -> CustomSections.FuncRef | t' when has_no_references t' -> CustomSections.DataBuf