Skip to content

Commit

Permalink
Backend: Implement eq on Principal (#1206)
Browse files Browse the repository at this point in the history
fixing an omission from #1128
this was reported by @stanleygjones in
https://dfinity.slack.com/archives/CGA566TPV/p1581702931005500
  • Loading branch information
nomeata authored Feb 18, 2020
1 parent 7ce3acc commit 3f9bb99
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 41 deletions.
18 changes: 9 additions & 9 deletions src/codegen/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ module Tagged = struct
| Blob ->
begin match normalize ty with
| (Con _ | Any) -> true
| (Prim Text) -> true
| (Prim (Text|Blob|Principal)) -> true
| (Prim _ | Obj _ | Array _ | Tup _ | Opt _ | Variant _ | Func _ | Non) -> false
| (Pre | Async _ | Mut _ | Var _ | Typ _) -> assert false
end
Expand Down Expand Up @@ -3397,7 +3397,7 @@ module Serialization = struct
let rec add_typ t =
match t with
| Non -> assert false
| Prim Blob | Prim Principal ->
| Prim (Blob|Principal) ->
add_typ Type.(Array (Prim Word8))
| Prim _ -> assert false
| Tup ts ->
Expand Down Expand Up @@ -3519,7 +3519,7 @@ module Serialization = struct
get_x ^^ get_i ^^ Arr.idx env ^^ load_ptr ^^
size env t
)
| Prim Blob | Prim Principal ->
| Prim (Blob|Principal) ->
let (set_len, get_len) = new_local env "len" in
get_x ^^ Heap.load_field Blob.len_field ^^ set_len ^^
size_word env get_len ^^
Expand Down Expand Up @@ -3676,7 +3676,7 @@ module Serialization = struct
)
( List.mapi (fun i (_h, f) -> (i,f)) (sort_by_hash vs) )
( E.trap_with env "serialize_go: unexpected variant" )
| Prim (Blob | Principal) ->
| Prim (Blob|Principal) ->
let (set_len, get_len) = new_local env "len" in
get_x ^^ Heap.load_field Blob.len_field ^^ set_len ^^
write_word get_len ^^
Expand Down Expand Up @@ -3873,7 +3873,7 @@ module Serialization = struct

(* Any vanilla value works here *)
Opt.null
| Prim Blob ->
| Prim (Blob|Principal) ->
assert_blob_typ env ^^
read_blob ()
| Prim Text ->
Expand Down Expand Up @@ -4359,8 +4359,8 @@ module StackRep = struct
| Prim (Nat64 | Int64 | Word64) -> UnboxedWord64
| Prim (Nat32 | Int32 | Word32) -> UnboxedWord32
| Prim (Nat8 | Nat16 | Int8 | Int16 | Word8 | Word16 | Char) -> Vanilla
| Prim (Text | Blob) -> Vanilla
| p -> todo "of_type" (Arrange_ir.typ p) Vanilla
| Prim (Text | Blob | Principal) -> Vanilla
| p -> todo "StackRep.of_type" (Arrange_ir.typ p) Vanilla

let to_block_type env = function
| Vanilla -> [I32Type]
Expand Down Expand Up @@ -5801,7 +5801,7 @@ let compile_binop env t op =

let compile_eq env = function
| Type.(Prim Text) -> Text.compare env Operator.EqOp
| Type.(Prim Blob) -> Blob.compare env Operator.EqOp
| Type.(Prim (Blob|Principal)) -> Blob.compare env Operator.EqOp
| Type.(Prim Bool) -> G.i (Compare (Wasm.Values.I32 I32Op.Eq))
| Type.(Prim (Nat | Int)) -> BigNum.compile_eq env
| Type.(Prim (Int64 | Nat64 | Word64)) -> G.i (Compare (Wasm.Values.I64 I64Op.Eq))
Expand Down Expand Up @@ -5834,7 +5834,7 @@ let compile_relop env t op =
let open Operator in
match t, op with
| Type.(Prim Text), _ -> Text.compare env op
| Type.(Prim Blob), _ -> Blob.compare env op
| Type.(Prim (Blob|Principal)), _ -> Blob.compare env op
| _, EqOp -> compile_eq env t
| _, NeqOp -> compile_eq env t ^^
G.i (Test (Wasm.Values.I32 I32Op.Eqz))
Expand Down
40 changes: 20 additions & 20 deletions test/run/ok/numeric-ops.comp.ok
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
compile_unop: NegOp
compile_unop: NegOp
compile_binop: AddOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: AddOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: SubOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: SubOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: MulOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: MulOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: DivOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: DivOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: PowOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
compile_binop: PowOp
of_type: Float
of_type: Float
StackRep.of_type: Float
StackRep.of_type: Float
24 changes: 12 additions & 12 deletions test/run/ok/relational-ops.comp.ok
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
compile_eq: EqOp
of_type: Float
StackRep.of_type: Float
compile_eq: EqOp
of_type: Float
StackRep.of_type: Float
compile_eq: EqOp
of_type: Float
StackRep.of_type: Float
compile_eq: EqOp
of_type: Float
StackRep.of_type: Float
compile_relop: LtOp
of_type: Float
StackRep.of_type: Float
compile_relop: LtOp
of_type: Float
StackRep.of_type: Float
compile_relop: LeOp
of_type: Float
StackRep.of_type: Float
compile_relop: LeOp
of_type: Float
StackRep.of_type: Float
compile_relop: GtOp
of_type: Float
StackRep.of_type: Float
compile_relop: GtOp
of_type: Float
StackRep.of_type: Float
compile_relop: GeOp
of_type: Float
StackRep.of_type: Float
compile_relop: GeOp
of_type: Float
StackRep.of_type: Float
3 changes: 3 additions & 0 deletions test/run/principal.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func isEq(x : Principal, y : Principal) : Bool { x == y };


0 comments on commit 3f9bb99

Please sign in to comment.