From 4d84e785661f09068cf8ab5c69809af5e535606f Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Tue, 10 Oct 2023 23:13:06 +0100 Subject: [PATCH] fix candid decoding at immutable array type to handle defaulting under opt correctly --- src/codegen/compile.ml | 10 +++++++--- test/run/ok/idl-decoding-bug.wasm-run.ok | 15 --------------- test/run/ok/idl-decoding-bug.wasm-run.ret.ok | 1 - test/run/ok/idl-opt-tests.wasm-run.ok | 17 ++--------------- test/run/ok/idl-opt-tests.wasm-run.ret.ok | 1 - 5 files changed, 9 insertions(+), 35 deletions(-) delete mode 100644 test/run/ok/idl-decoding-bug.wasm-run.ok delete mode 100644 test/run/ok/idl-decoding-bug.wasm-run.ret.ok delete mode 100644 test/run/ok/idl-opt-tests.wasm-run.ret.ok diff --git a/src/codegen/compile.ml b/src/codegen/compile.ml index b2e73ca6e10..d96eb08e3a3 100644 --- a/src/codegen/compile.ml +++ b/src/codegen/compile.ml @@ -6693,7 +6693,7 @@ module MakeSerialization (Strm : Stream) = struct begin code0 end begin get_b ^^ compile_eq_const 1l ^^ - E.else_trap_with env ("IDL error: byte tag not 0 or 1") ^^ + E.else_trap_with env ("IDL error: byte tag not 0 or 1") ^^ code1 end | _ -> assert false; (* can be generalized later as needed *) @@ -7062,6 +7062,8 @@ module MakeSerialization (Strm : Stream) = struct let (set_x, get_x) = new_local env "x" in let (set_val, get_val) = new_local env "val" in let (set_arg_typ, get_arg_typ) = new_local env "arg_typ" in + (* TODO: if possible refactor to match new Array t code, + (though probably unnecessary for extended candid due to lack of fancy opt subtyping) *) with_composite_arg_typ get_array_typ idl_vec (ReadBuf.read_sleb128 env) ^^ set_arg_typ ^^ ReadBuf.read_leb128 env get_data_buf ^^ set_len ^^ get_len ^^ Arr.alloc env ^^ set_x ^^ @@ -7102,7 +7104,9 @@ module MakeSerialization (Strm : Stream) = struct let (set_x, get_x) = new_local env "x" in let (set_val, get_val) = new_local env "val" in let (set_arg_typ, get_arg_typ) = new_local env "arg_typ" in - with_composite_typ idl_vec (ReadBuf.read_sleb128 env) ^^ set_arg_typ ^^ + with_composite_typ idl_vec (fun get_typ_buf -> + ReadBuf.read_sleb128 env get_typ_buf ^^ + set_arg_typ ^^ ReadBuf.read_leb128 env get_data_buf ^^ set_len ^^ get_len ^^ Arr.alloc env ^^ set_x ^^ get_len ^^ from_0_to_n env (fun get_i -> @@ -7112,7 +7116,7 @@ module MakeSerialization (Strm : Stream) = struct get_val ^^ store_ptr ) ^^ get_x ^^ - Tagged.allocation_barrier env + Tagged.allocation_barrier env) | Opt t -> check_prim_typ (Prim Null) ^^ G.if1 I32Type (Opt.null_lit env) diff --git a/test/run/ok/idl-decoding-bug.wasm-run.ok b/test/run/ok/idl-decoding-bug.wasm-run.ok deleted file mode 100644 index dae8dc28b37..00000000000 --- a/test/run/ok/idl-decoding-bug.wasm-run.ok +++ /dev/null @@ -1,15 +0,0 @@ -IDL error: byte read out of buffer -Error: failed to run main module `_out/idl-decoding-bug.wasm` - -Caused by: - 0: failed to invoke command default - 1: error while executing at wasm backtrace: - 0: rts_trap - 1: motoko_rts::trap_with_prefix::h757ee6d860f5c7ff - 2: motoko_rts::idl_trap_with::h539f381c213e508f - 3: leb128_decode - 4: @deserialize_go - 5: @deserialize - 6: init - 7: _start - 2: wasm trap: unreachable diff --git a/test/run/ok/idl-decoding-bug.wasm-run.ret.ok b/test/run/ok/idl-decoding-bug.wasm-run.ret.ok deleted file mode 100644 index 8209aecf795..00000000000 --- a/test/run/ok/idl-decoding-bug.wasm-run.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 134 diff --git a/test/run/ok/idl-opt-tests.wasm-run.ok b/test/run/ok/idl-opt-tests.wasm-run.ok index 53eb0101c85..baca9cad704 100644 --- a/test/run/ok/idl-opt-tests.wasm-run.ok +++ b/test/run/ok/idl-opt-tests.wasm-run.ok @@ -3,18 +3,5 @@ null null null ?null -IDL error: byte read out of buffer -Error: failed to run main module `_out/idl-opt-tests.wasm` - -Caused by: - 0: failed to invoke command default - 1: error while executing at wasm backtrace: - 0: rts_trap - 1: motoko_rts::trap_with_prefix::h757ee6d860f5c7ff - 2: motoko_rts::idl_trap_with::h539f381c213e508f - 3: leb128_decode - 4: @deserialize_go - 5: @deserialize - 6: init - 7: _start - 2: wasm trap: unreachable +null +null diff --git a/test/run/ok/idl-opt-tests.wasm-run.ret.ok b/test/run/ok/idl-opt-tests.wasm-run.ret.ok deleted file mode 100644 index 8209aecf795..00000000000 --- a/test/run/ok/idl-opt-tests.wasm-run.ret.ok +++ /dev/null @@ -1 +0,0 @@ -Return code 134