@@ -79,12 +79,6 @@ type signature_error =
7979 (UnsizedType .returntype * (UnsizedType .autodifftype * UnsizedType .t ) list )
8080 * function_mismatch
8181
82- type promotions =
83- | None
84- | IntToRealPromotion
85- | IntToComplexPromotion
86- | RealToComplexPromotion
87-
8882type ('unique, 'error) generic_match_result =
8983 | UniqueMatch of 'unique
9084 | AmbiguousMatch of
@@ -95,7 +89,7 @@ type ('unique, 'error) generic_match_result =
9589type match_result =
9690 ( UnsizedType .returntype
9791 * (bool Middle.Fun_kind .suffix -> Ast .fun_kind )
98- * promotions list
92+ * Promotion .t list
9993 , signature_error list * bool )
10094 generic_match_result
10195
@@ -133,10 +127,10 @@ let rec compare_errors e1 e2 =
133127let rec check_same_type depth t1 t2 =
134128 let wrap_func = Result. map_error ~f: (fun e -> TypeMismatch (t1, t2, Some e)) in
135129 match (t1, t2) with
136- | t1 , t2 when t1 = t2 -> Ok None
137- | UnsizedType. (UReal, UInt) when depth < 1 -> Ok IntToRealPromotion
138- | UnsizedType. (UComplex, UInt) when depth < 1 -> Ok IntToComplexPromotion
139- | UnsizedType. (UComplex, UReal) when depth < 1 -> Ok RealToComplexPromotion
130+ | t1 , t2 when t1 = t2 -> Ok Promotion. NoPromotion
131+ | UnsizedType. (UReal, UInt) when depth < 1 -> Ok IntToReal
132+ | UnsizedType. (UComplex, UInt) when depth < 1 -> Ok IntToComplex
133+ | UnsizedType. (UComplex, UReal) when depth < 1 -> Ok RealToComplex
140134 (* Arrays: Try to recursively promote, but make sure the error is for these types,
141135 not the recursive call *)
142136 | UArray nt1 , UArray nt2 ->
@@ -153,12 +147,12 @@ let rec check_same_type depth t1 t2 =
153147 Error (ReturnTypeMismatch (rt1, rt2)) |> wrap_func
154148 | UFun (l1 , _ , _ , _ ), UFun (l2 , _ , _ , _ ) -> (
155149 match check_compatible_arguments (depth + 1 ) l2 l1 with
156- | Ok _ -> Ok None
150+ | Ok _ -> Ok NoPromotion
157151 | Error e -> Error (InputMismatch e) |> wrap_func )
158152 | t1 , t2 -> Error (TypeMismatch (t1, t2, None ))
159153
160154and check_compatible_arguments depth typs args2 :
161- (promotions list , function_mismatch ) result =
155+ (Promotion. t list , function_mismatch ) result =
162156 match List. zip typs args2 with
163157 | List.Or_unequal_lengths. Unequal_lengths ->
164158 Error (ArgNumMismatch (List. length typs, List. length args2))
@@ -173,6 +167,7 @@ and check_compatible_arguments depth typs args2 :
173167 else Error (ArgError (i + 1 , DataOnlyError )) )
174168 |> Result. all
175169
170+ let check_of_same_type_mod_conv = check_same_type 0
176171let check_compatible_arguments_mod_conv = check_compatible_arguments 0
177172let max_n_errors = 5
178173
@@ -184,30 +179,9 @@ let extract_function_types f =
184179 Some (return, args, (fun x -> UserDefined x), mem)
185180 | _ -> None
186181
187- let promote es promotions =
188- List. map2_exn es promotions ~f: (fun (exp : Ast.typed_expression ) prom ->
189- let open UnsizedType in
190- let emeta = exp.emeta in
191- match prom with
192- | IntToRealPromotion when is_int_type emeta.type_ ->
193- Ast.
194- { expr= Ast. Promotion (exp, UReal , emeta.ad_level)
195- ; emeta= {emeta with type_= promote_array emeta.type_ UReal } }
196- | (IntToComplexPromotion | RealToComplexPromotion )
197- when not (is_complex_type emeta.type_) ->
198- { expr= Promotion (exp, UComplex , emeta.ad_level)
199- ; emeta= {emeta with type_= promote_array emeta.type_ UComplex } }
200- | _ -> exp )
201-
202- let promotion_cost p =
203- match p with
204- | None -> 0
205- | RealToComplexPromotion | IntToRealPromotion -> 1
206- | IntToComplexPromotion -> 2
207-
208182let unique_minimum_promotion promotion_options =
209183 let size (_ , p ) =
210- List. fold ~init: 0 ~f: (fun acc p -> acc + promotion_cost p) p in
184+ List. fold ~init: 0 ~f: (fun acc p -> acc + Promotion. promotion_cost p) p in
211185 let sizes = List. map ~f: size promotion_options in
212186 let min_promotion = List. min_elt ~compare: Int. compare sizes in
213187 let sizes_and_promotons = List. zip_exn sizes promotion_options in
0 commit comments