Skip to content

Commit

Permalink
Fix elision of unit. Change rule for reduction of polyrecords.
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Sep 5, 2022
1 parent 2c04361 commit 7dd71de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/compiler/flx_core/flx_btype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -740,26 +740,29 @@ otherwise the polyrecord will survive to the back end which cannot handle
polyrecords. Use Flx_btype_subst.neuter_polyrecord to strip the name out!
*)

let btyp_polyrecord ts s v =
let rec btyp_polyrecord fields s v =
(*
print_endline ("Constructing polyrecord, extensions=" ^ catmap "," (fun (s,t) -> s^":"^str_of_btype t) ts);
print_endline (" ... core = " ^ st v);
*)
match ts with [] -> v | _ ->
match fields with [] -> v | _ ->
match s,v with
| "",BTYP_record flds ->
btyp_record (ts @ flds)

| _,BTYP_void -> btyp_record ts

| "",BTYP_polyrecord (flds,s2,v2) ->
let cmp (s1,t1) (s2, t2) = compare s1 s2 in
let fields = List.stable_sort cmp (ts @ flds) in
BTYP_polyrecord (fields,s2,v2)
| _ ->
let cmp (s1,t1) (s2, t2) = compare s1 s2 in
let ts = List.stable_sort cmp ts in
BTYP_polyrecord (ts,s,v)

(* this is the ONLY case the polyrecord survives, when
the type variable is a row variable *)
| _, BTYP_type_var _ ->
BTYP_polyrecord (fields,s,v)

| _,BTYP_record fields2 ->
btyp_record (fields @ fields2 )

| _,BTYP_void -> btyp_record fields (* ?? *)

| _,BTYP_polyrecord (fields2,s2,v2) ->
btyp_polyrecord (fields @ fields2) s2 v2

| _,v ->
btyp_record ((s,v)::fields)


(* FIXME: Idiot Ocaml strikes again. We need to minimise t before hashing
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/flx_cpp_backend/flx_egen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,9 @@ print_endline ("Coercion uses reinterpret cast!");
ctyp ^ "(" ^
fold_left
(fun s e ->
match snd e with
| BTYP_tuple [] -> s (* unit arguments in records are elided *)
| _ ->
let s = name s in
let x = ge_arg e in
if String.length x = 0 then s else
Expand Down

0 comments on commit 7dd71de

Please sign in to comment.