|
@@ -93,9 +93,13 @@ module Monomorph = struct
|
|
let create () = {
|
|
let create () = {
|
|
tm_type = None;
|
|
tm_type = None;
|
|
tm_down_constraints = [];
|
|
tm_down_constraints = [];
|
|
- tm_up_constraints = []
|
|
|
|
|
|
+ tm_up_constraints = [];
|
|
|
|
+ tm_modifiers = [];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ let add_modifier m modi =
|
|
|
|
+ m.tm_modifiers <- modi :: m.tm_modifiers
|
|
|
|
+
|
|
(* constraining *)
|
|
(* constraining *)
|
|
|
|
|
|
let add_up_constraint m ((t,name) as constr) =
|
|
let add_up_constraint m ((t,name) as constr) =
|
|
@@ -127,21 +131,18 @@ module Monomorph = struct
|
|
|
|
|
|
(* Note: This function is called by printing and others and should thus not modify state. *)
|
|
(* Note: This function is called by printing and others and should thus not modify state. *)
|
|
|
|
|
|
- let rec classify_down_constraints' m =
|
|
|
|
|
|
+ let rec classify_down_constraints m =
|
|
let types = DynArray.create () in
|
|
let types = DynArray.create () in
|
|
let fields = ref PMap.empty in
|
|
let fields = ref PMap.empty in
|
|
let is_open = ref false in
|
|
let is_open = ref false in
|
|
- let monos = ref [] in
|
|
|
|
let rec check constr = match constr with
|
|
let rec check constr = match constr with
|
|
| MMono(m2,name) ->
|
|
| MMono(m2,name) ->
|
|
begin match m2.tm_type with
|
|
begin match m2.tm_type with
|
|
| None ->
|
|
| None ->
|
|
- let more_monos,kind = classify_down_constraints' m2 in
|
|
|
|
- monos := !monos @ more_monos;
|
|
|
|
|
|
+ let kind = classify_down_constraints m2 in
|
|
begin match kind with
|
|
begin match kind with
|
|
| CUnknown ->
|
|
| CUnknown ->
|
|
- (* Collect unconstrained monomorphs because we have to bind them. *)
|
|
|
|
- monos := m2 :: !monos;
|
|
|
|
|
|
+ ()
|
|
| _ ->
|
|
| _ ->
|
|
(* Recursively inherit constraints. *)
|
|
(* Recursively inherit constraints. *)
|
|
List.iter check m2.tm_down_constraints
|
|
List.iter check m2.tm_down_constraints
|
|
@@ -153,11 +154,16 @@ module Monomorph = struct
|
|
fields := PMap.add cf.cf_name cf !fields;
|
|
fields := PMap.add cf.cf_name cf !fields;
|
|
| MType(t2,name) ->
|
|
| MType(t2,name) ->
|
|
DynArray.add types (t2,name)
|
|
DynArray.add types (t2,name)
|
|
- | MOpenStructure
|
|
|
|
| MEmptyStructure ->
|
|
| MEmptyStructure ->
|
|
is_open := true
|
|
is_open := true
|
|
in
|
|
in
|
|
List.iter check m.tm_down_constraints;
|
|
List.iter check m.tm_down_constraints;
|
|
|
|
+ List.iter (function
|
|
|
|
+ | MNullable _ ->
|
|
|
|
+ ()
|
|
|
|
+ | MOpenStructure ->
|
|
|
|
+ is_open := true
|
|
|
|
+ ) m.tm_modifiers;
|
|
let kind =
|
|
let kind =
|
|
let k1 =
|
|
let k1 =
|
|
if DynArray.length types > 0 then
|
|
if DynArray.length types > 0 then
|
|
@@ -173,9 +179,7 @@ module Monomorph = struct
|
|
else
|
|
else
|
|
k1
|
|
k1
|
|
in
|
|
in
|
|
- !monos,kind
|
|
|
|
-
|
|
|
|
- let classify_down_constraints m = snd (classify_down_constraints' m)
|
|
|
|
|
|
+ kind
|
|
|
|
|
|
let rec check_down_constraints constr t =
|
|
let rec check_down_constraints constr t =
|
|
match constr with
|
|
match constr with
|
|
@@ -225,13 +229,17 @@ module Monomorph = struct
|
|
|
|
|
|
let do_bind m t =
|
|
let do_bind m t =
|
|
(* assert(m.tm_type = None); *) (* TODO: should be here, but matcher.ml does some weird bind handling at the moment. *)
|
|
(* assert(m.tm_type = None); *) (* TODO: should be here, but matcher.ml does some weird bind handling at the moment. *)
|
|
|
|
+ let t = List.fold_left (fun t modi -> match modi with
|
|
|
|
+ | MNullable f -> f t
|
|
|
|
+ | MOpenStructure -> t
|
|
|
|
+ ) t m.tm_modifiers in
|
|
m.tm_type <- Some t;
|
|
m.tm_type <- Some t;
|
|
m.tm_down_constraints <- [];
|
|
m.tm_down_constraints <- [];
|
|
m.tm_up_constraints <- []
|
|
m.tm_up_constraints <- []
|
|
|
|
|
|
let rec bind m t =
|
|
let rec bind m t =
|
|
begin match t with
|
|
begin match t with
|
|
- | TAnon _ when List.mem MOpenStructure m.tm_down_constraints ->
|
|
|
|
|
|
+ | TAnon _ when List.mem MOpenStructure m.tm_modifiers ->
|
|
(* If we assign an open structure monomorph to another structure, the semantics want us to merge the
|
|
(* If we assign an open structure monomorph to another structure, the semantics want us to merge the
|
|
fields. This is kinda weird, but that's how it has always worked. *)
|
|
fields. This is kinda weird, but that's how it has always worked. *)
|
|
constrain_to_type m None t;
|
|
constrain_to_type m None t;
|
|
@@ -272,8 +280,7 @@ module Monomorph = struct
|
|
with Type_exception t ->
|
|
with Type_exception t ->
|
|
Some t
|
|
Some t
|
|
in
|
|
in
|
|
- (* TODO: we never do anything with monos, I think *)
|
|
|
|
- let monos,constraints = classify_down_constraints' m in
|
|
|
|
|
|
+ let constraints = classify_down_constraints m in
|
|
match constraints with
|
|
match constraints with
|
|
| CUnknown ->
|
|
| CUnknown ->
|
|
()
|
|
()
|