Skip to content

Commit cd7aa38

Browse files
committed
link comments
1 parent 6607973 commit cd7aa38

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

compiler/ml/translcore.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ let transl_extension_constructor env path ext =
4949

5050
(* Translation of primitives *)
5151

52+
(** This is ad-hoc translation for unifying specific primitive operations
53+
See [Unified_ops] module for detailed explanation.
54+
*)
5255
let translate_unified_ops (prim : Primitive.description) (env : Env.t)
5356
(lhs_type : type_expr) : Lambda.primitive option =
5457
(* lhs_type is already unified in type-level *)

compiler/ml/typecore.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,9 @@ and is_automatic_curried_application env funct =
35633563
| Tarrow _ -> true
35643564
| _ -> false
35653565
3566+
(** This is ad-hoc translation for unifying specific primitive operations
3567+
See [Unified_ops] module for detailed explanation.
3568+
*)
35663569
and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
35673570
(sargs : sargs) : (targs * Types.type_expr) option =
35683571
match funct.exp_desc with
@@ -3601,7 +3604,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
36013604
let rhs = type_exp env rhs_expr in
36023605
let rhs_type = expand_head env rhs.exp_type in
36033606
let lhs, rhs, result_type =
3604-
(* rule 1. *)
3607+
(* Rule 1. Try unifying to lhs *)
36053608
match (lhs_type.desc, specialization) with
36063609
| Tconstr (path, _, _), _ when Path.same path Predef.path_int ->
36073610
let rhs = type_expect env rhs_expr Predef.type_int in
@@ -3623,7 +3626,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
36233626
let rhs = type_expect env rhs_expr Predef.type_string in
36243627
(lhs, rhs, Predef.type_string)
36253628
| _ -> (
3626-
(* rule 2. *)
3629+
(* Rule 2. Try unifying to rhs *)
36273630
match (rhs_type.desc, specialization) with
36283631
| Tconstr (path, _, _), _ when Path.same path Predef.path_int ->
36293632
let lhs = type_expect env lhs_expr Predef.type_int in
@@ -3645,7 +3648,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
36453648
let lhs = type_expect env lhs_expr Predef.type_string in
36463649
(lhs, rhs, Predef.type_string)
36473650
| _ ->
3648-
(* rule 3. *)
3651+
(* Rule 2. Fallback to int *)
36493652
let lhs = type_expect env lhs_expr Predef.type_int in
36503653
let rhs = type_expect env rhs_expr Predef.type_int in
36513654
(lhs, rhs, Predef.type_int))

compiler/ml/unified_ops.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ open Misc
3636

3737
type form = Unary | Binary
3838

39+
(* Note: unified op must support int type *)
3940
type specialization = {
4041
int: Lambda.primitive;
4142
bool: Lambda.primitive option;

0 commit comments

Comments
 (0)