Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion analysis/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
lsp
rescript_printer
rescript_parser
outcome_printer
reanalyze))
49 changes: 0 additions & 49 deletions compiler/backend/matching_polyfill.ml

This file was deleted.

25 changes: 0 additions & 25 deletions compiler/backend/matching_polyfill.mli

This file was deleted.

1 change: 0 additions & 1 deletion compiler/bsc/dune
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
depends
flow_parser
gentype
outcome_printer
rescript_printer
rescript_parser
unix))
Expand Down
3 changes: 0 additions & 3 deletions compiler/bsc/rescript_compiler_driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ let set_abs_input_name sourcefile =
in
Loc_report.set_input_name sourcefile;
sourcefile
let setup_outcome_printer () = Lazy.force Res_outcome_printer.setup

let setup_runtime_path path = Runtime_package.set_path path

let process_file sourcefile ppf =
(* The input name must identify the source when writing the binary AST. *)
setup_outcome_printer ();
Error_message_utils_support.setup ();
let kind =
Ext_file_extensions.classify_input
Expand Down Expand Up @@ -546,7 +544,6 @@ let file_level_flags_handler (e : Parsetree.expression option) =
on a first request. *)
let () =
Bs_conditional_initial.setup_env ();
setup_outcome_printer ();
Error_message_utils_support.install_parser ();
let flags = "flags" in
Ast_config.add_structure flags file_level_flags_handler;
Expand Down
1 change: 0 additions & 1 deletion compiler/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
gentype
jsoo
jsx
outcome_printer
sync
syntax_cli
typing)
Expand Down
1 change: 0 additions & 1 deletion compiler/jsoo/dune
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
rescript_parser
typing
gentype
outcome_printer
js_of_ocaml))
3 changes: 1 addition & 2 deletions compiler/jsoo/jsoo_playground_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ end
let () =
Bs_conditional_initial.setup_env ();
(Clflags.current ()).binary_annotations := false;
(Clflags.current ()).color := Some Always;
Lazy.force Res_outcome_printer.setup
(Clflags.current ()).color := Some Always

let error_of_exn e =
match Loc_report.error_of_exn e with
Expand Down
11 changes: 0 additions & 11 deletions compiler/outcome_printer/dune

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@
let setup_env () =
Env.Persistent_signature.load := Bs_cmi_load.load_cmi;
Build_file_store.set_disk_reader Bs_cmi_load.read_file;
Matching.make_test_sequence_variant_constant :=
Polyvar_pattern_match.make_test_sequence_variant_constant;
Matching.call_switcher_variant_constant :=
Polyvar_pattern_match.call_switcher_variant_constant;
Matching.call_switcher_variant_constr :=
Polyvar_pattern_match.call_switcher_variant_constr;
Ctype.variant_is_subtype := Matching_polyfill.variant_is_subtype;
(* bsc's defaults, which differ from OCaml's in [Clflags.create]. *)
Clflags.reset ();
Parmatch.print_res_pat := Pattern_printer.print_pattern;
Printtyp.print_res_poly_identifier := Res_printer.polyvar_ident_to_string
Clflags.reset ()
(*; Switch.cut := 100*)
(* tweakable but not very useful *)

Expand Down
110 changes: 76 additions & 34 deletions compiler/typing/ctype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ let unification_settings =
let umode () = (Domain.DLS.get unification_settings).mode
let generate_equations () = (Domain.DLS.get unification_settings).equations
let assume_injective () = (Domain.DLS.get unification_settings).injective
let variant_is_subtype = ref (fun _env _row _p1 -> false)
let set_mode_pattern ~generate ~injective f =
let old_unification_mode = !(umode ())
and old_gen = !(generate_equations ())
Expand Down Expand Up @@ -3639,6 +3638,81 @@ type constructor_coercion =
| Fails_with of subtype_context
| Fails_unexplained

(* We use the expand_head_opt version of expand_head to get access
to the manifest type of private abbreviations. *)
let rec get_unboxed_type_representation env ty fuel =
if fuel < 0 then None
else
let ty = repr (expand_head_opt env ty) in
match ty.desc with
| Tconstr (p, args, _) -> (
match Env.find_type p env with
| exception Not_found -> Some ty
| {type_representation = Boxed} -> Some ty
| {
type_params;
type_kind =
( Type_record ([{ld_type = ty2; _}], _)
| Type_variant ([{cd_args = Cstr_tuple [ty2]; _}], _)
| Type_variant ([{cd_args = Cstr_record [{ld_type = ty2; _}]; _}], _) );
} ->
get_unboxed_type_representation env
(apply env type_params ty2 args)
(fuel - 1)
| {type_kind = Type_abstract} ->
None
(* This case can occur when checking a recursive unboxed type
declaration. *)
| _ -> assert false (* only the above can be unboxed *))
| _ -> Some ty

let get_unboxed_type_representation env ty =
(* Do not give too much fuel: PR#7424 *)
get_unboxed_type_representation env ty 100

(* Whether a closed polymorphic variant whose constructors have no payload is
a subtype of [ty]: of int when all constructors are numbers (#1, #2), of
string when none is. A row with type variables is not supported. *)
let variant_is_subtype env (row_desc : row_desc) (ty : type_expr) =
let is_base_type base_ty_path =
let ty = expand_head_opt env (correct_levels ty) in
let ty =
match ty.desc with
| Tconstr (p, _, _) -> (
match Env.find_type p env with
| {type_representation = Unboxed} -> (
match get_unboxed_type_representation env ty with
| None -> ty
| Some ty2 -> ty2)
| _ -> ty
| exception Not_found -> ty)
| _ -> ty
in
match ty.desc with
| Tconstr (p, _, _) -> Path.same p base_ty_path
| _ -> false
in
match row_desc with
| {row_closed = true; row_fields = (name, (Rabsent | Rpresent None)) :: rest}
->
if Ext_string.is_valid_hash_number name then
List.for_all
(function
| name, (Rabsent | Rpresent None) ->
Ext_string.is_valid_hash_number name
| _ -> false)
rest
&& is_base_type Predef.path_int
else
List.for_all
(function
| name, (Rabsent | Rpresent None) ->
not (Ext_string.is_valid_hash_number name)
| _ -> false)
rest
&& is_base_type Predef.path_string
| _ -> false

let rec subtype_rec env trace t1 t2 cstrs =
let t1 = repr t1 in
let t2 = repr t2 in
Expand Down Expand Up @@ -4058,7 +4132,7 @@ let rec subtype_rec env trace t1 t2 cstrs =
| Error _ ->
(trace, t1, t2, !(current_univar_pairs ()), None) :: cstrs)
| _ -> (trace, t1, t2, !(current_univar_pairs ()), None) :: cstrs)
| Tvariant v, _ when !variant_is_subtype env (row_repr v) t2 -> cstrs
| Tvariant v, _ when variant_is_subtype env (row_repr v) t2 -> cstrs
| Tpoly (u1, []), Tpoly (u2, []) -> subtype_rec env trace u1 u2 cstrs
| Tpoly (u1, tl1), Tpoly (u2, []) ->
let _, u1' = instance_poly ~fixed:false tl1 u1 in
Expand Down Expand Up @@ -4586,35 +4660,3 @@ let get_arity env typ =
module For_test = struct
let previous_env_is_empty () = !(previous_env ()) == Env.empty
end

(* We use the expand_head_opt version of expand_head to get access
to the manifest type of private abbreviations. *)
let rec get_unboxed_type_representation env ty fuel =
if fuel < 0 then None
else
let ty = repr (expand_head_opt env ty) in
match ty.desc with
| Tconstr (p, args, _) -> (
match Env.find_type p env with
| exception Not_found -> Some ty
| {type_representation = Boxed} -> Some ty
| {
type_params;
type_kind =
( Type_record ([{ld_type = ty2; _}], _)
| Type_variant ([{cd_args = Cstr_tuple [ty2]; _}], _)
| Type_variant ([{cd_args = Cstr_record [{ld_type = ty2; _}]; _}], _) );
} ->
get_unboxed_type_representation env
(apply env type_params ty2 args)
(fuel - 1)
| {type_kind = Type_abstract} ->
None
(* This case can occur when checking a recursive unboxed type
declaration. *)
| _ -> assert false (* only the above can be unboxed *))
| _ -> Some ty

let get_unboxed_type_representation env ty =
(* Do not give too much fuel: PR#7424 *)
get_unboxed_type_representation env ty 100
3 changes: 0 additions & 3 deletions compiler/typing/ctype.mli
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ val package_subtype :
bool)
ref

val variant_is_subtype :
(Env.t -> Types.row_desc -> Types.type_expr -> bool) ref

val get_arity : Env.t -> type_expr -> int option

module For_test : sig
Expand Down
60 changes: 10 additions & 50 deletions compiler/typing/matching.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1987,9 +1987,6 @@ let as_interval_ranges fail low high l =
| None -> as_interval_nofail l
| Some act -> as_interval_canfail act low high l )

let as_interval fail low high l =
as_interval_ranges fail low high (List.map (fun (i, act) -> (i, i, act)) l)

let call_switcher_ranges fail arg low high range_lambda_list =
let edges, (cases, actions) =
as_interval_ranges fail low high range_lambda_list
Expand Down Expand Up @@ -2403,49 +2400,6 @@ let combine_constructor loc arg ex_pat cstr partial ctx def
let lambda1 = lower_constructor_matching_plan ~loc ~arg plan in
(lambda1, jumps_union local_jumps total1)

let make_test_sequence_variant_constant fail arg int_lambda_list =
let _, (cases, actions) =
as_interval fail int32_low int32_high
(List.map (fun (a, (_, c)) -> (a, c)) int_lambda_list)
in
Switch.test_sequence arg cases actions

let call_switcher_variant_constant fail arg int_lambda_list =
call_switcher fail arg int32_low int32_high
(List.map (fun (a, (_, c)) -> (a, c)) int_lambda_list)

let call_switcher_variant_constr loc fail arg int_lambda_list =
let v = Ident.create "variant" in
let_ Alias v
(prim ~primitive:(Pfield (0, Fld_poly_var_tag)) ~args:[arg] loc)
(call_switcher fail (var v) int32_low int32_high
(List.map (fun (a, (_, c)) -> (a, c)) int_lambda_list))

let call_switcher_variant_constant :
(Lambda.t option ->
Lambda.t ->
(int * (string * Lambda.t)) list ->
Lambda.t)
ref =
ref call_switcher_variant_constant

let call_switcher_variant_constr :
(Location.t ->
Lambda.t option ->
Lambda.t ->
(int * (string * Lambda.t)) list ->
Lambda.t)
ref =
ref call_switcher_variant_constr

let make_test_sequence_variant_constant :
(Lambda.t option ->
Lambda.t ->
(int * (string * Lambda.t)) list ->
Lambda.t)
ref =
ref make_test_sequence_variant_constant

let combine_variant loc row arg partial ctx def (tag_lambda_list, total1, _pats)
=
let row = Btype.row_repr row in
Expand Down Expand Up @@ -2484,17 +2438,23 @@ let combine_variant loc row arg partial ctx def (tag_lambda_list, total1, _pats)
test_int_or_block arg act1 act2
| _, [] ->
(* One can compare integers and pointers *)
!make_test_sequence_variant_constant fail arg consts
Polyvar_pattern_match.make_test_sequence_variant_constant fail arg
consts
| [], _ -> (
let lam = !call_switcher_variant_constr loc fail arg nonconsts in
let lam =
Polyvar_pattern_match.call_switcher_variant_constr loc fail arg
nonconsts
in
(* One must not dereference integers *)
match fail with
| None -> lam
| Some fail -> test_int_or_block arg fail lam)
| _, _ ->
let lam_const = !call_switcher_variant_constant fail arg consts
let lam_const =
Polyvar_pattern_match.call_switcher_variant_constant fail arg consts
and lam_nonconst =
!call_switcher_variant_constr loc fail arg nonconsts
Polyvar_pattern_match.call_switcher_variant_constr loc fail arg
nonconsts
in
test_int_or_block arg lam_const lam_nonconst)
in
Expand Down
Loading
Loading