Skip to content

Remove ml support #6852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 4, 2024
Merged
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Remove deprecated -bs-super-errors option. https://github.com/rescript-lang/rescript-compiler/pull/6814
- Some global names and old keywords are no longer prefixed. https://github.com/rescript-lang/rescript-compiler/pull/6831
- Remove ml parsing tests and conversion from `.ml` to `.res` via format. https://github.com/rescript-lang/rescript-compiler/pull/6848
- Remove support for compiling `.ml` files, and general cleanup. https://github.com/rescript-lang/rescript-compiler/pull/6852

#### :bug: Bug Fix

Expand Down
16 changes: 5 additions & 11 deletions jscomp/bsb/bsb_db_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ let sanity_check (map : t) =
(* invariant check:
ml and mli should have the same case, same path
*)
let check (x : module_info) name_sans_extension case syntax_kind
let check (x : module_info) name_sans_extension case
(module_info : Bsb_db.info) =
let x_ml_info = x.info in
if
x.name_sans_extension <> name_sans_extension
|| x.case <> case
|| x.syntax_kind <> syntax_kind
|| x_ml_info = module_info || x_ml_info = Impl_intf
then
Bsb_exception.invalid_spec
Expand Down Expand Up @@ -75,19 +74,14 @@ let add_basename ~(dir : string) (map : t) ?error_on_invalid_suffix basename : t
if is_editor_temporary_files basename then map
else
let info = ref Bsb_db.Impl in
let syntax_kind = ref Bsb_db.Ml in
let invalid_suffix = ref false in
let file_suffix = Ext_filename.get_extension_maybe basename in
(match () with
| _ when file_suffix = Literals.suffix_ml -> ()
| _ when file_suffix = Literals.suffix_res -> syntax_kind := Res
| _ when file_suffix = Literals.suffix_mli -> info := Intf
| _ when file_suffix = Literals.suffix_res -> ()
| _ when file_suffix = Literals.suffix_resi ->
info := Intf;
syntax_kind := Res
info := Intf
| _ -> invalid_suffix := true);
let info = !info in
let syntax_kind = !syntax_kind in
let invalid_suffix = !invalid_suffix in
if invalid_suffix then
match error_on_invalid_suffix with
Expand All @@ -105,5 +99,5 @@ let add_basename ~(dir : string) (map : t) ?error_on_invalid_suffix basename : t
let dir = Filename.dirname name_sans_extension in
Map_string.adjust map module_name (fun opt_module_info ->
match opt_module_info with
| None -> { dir; name_sans_extension; info; syntax_kind; case }
| Some x -> check x name_sans_extension case syntax_kind info)
| None -> { dir; name_sans_extension; info; case }
| Some x -> check x name_sans_extension case info)
9 changes: 1 addition & 8 deletions jscomp/bsb/bsb_ninja_file_groups.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,13 @@ let handle_generators oc (group : Bsb_file_groups.file_group) custom_rules =

type suffixes = { impl : string; intf : string }

let ml_suffixes = { impl = Literals.suffix_ml; intf = Literals.suffix_mli }

let res_suffixes = { impl = Literals.suffix_res; intf = Literals.suffix_resi }

let emit_module_build (rules : Bsb_ninja_rule.builtin)
(package_specs : Bsb_package_specs.t) (is_dev : bool) oc namespace
(module_info : Bsb_db.module_info) : unit =
let has_intf_file = module_info.info = Impl_intf in
let config, ast_rule =
match module_info.syntax_kind with
| Ml -> (ml_suffixes, rules.build_ast)
| Res -> (res_suffixes, rules.build_ast_from_re)
(* FIXME: better names *)
in
let config, ast_rule = (res_suffixes, rules.build_ast_from_re) in
let filename_sans_extension = module_info.name_sans_extension in
let input_impl =
Bsb_config.proj_rel (filename_sans_extension ^ config.impl)
Expand Down
18 changes: 5 additions & 13 deletions jscomp/bsb/bsb_ninja_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ let output_installation_file cwd_lib_bs namespace files_to_install =
let essentials = Ext_buffer.create 1_000 in
files_to_install
|> Queue.iter
(fun ({ name_sans_extension; syntax_kind; info } : Bsb_db.module_info) ->
(fun ({ name_sans_extension; info } : Bsb_db.module_info) ->
let base = Filename.basename name_sans_extension in
let dest = Ext_namespace_encode.make ?ns:namespace base in
let ns_origin =
Expand All @@ -110,22 +110,14 @@ let output_installation_file cwd_lib_bs namespace files_to_install =
Ext_buffer.add_string essentials dest;
Ext_buffer.add_string_char essentials Literals.suffix_cmj ' ';

let suffix =
match syntax_kind with
| Ml -> Literals.suffix_ml
| Res -> Literals.suffix_res
in
oo suffix ~dest:base ~src:(sb // name_sans_extension);
let suffix_impl = Literals.suffix_res in
oo suffix_impl ~dest:base ~src:(sb // name_sans_extension);
match info with
| Intf -> assert false
| Impl -> ()
| Impl_intf ->
let suffix_b =
match syntax_kind with
| Ml -> Literals.suffix_mli
| Res -> Literals.suffix_resi
in
oo suffix_b ~dest:base ~src:(sb // name_sans_extension);
let suffix_intf = Literals.suffix_resi in
oo suffix_intf ~dest:base ~src:(sb // name_sans_extension);
oo Literals.suffix_cmti ~dest ~src);
(match namespace with
| None -> ()
Expand Down
3 changes: 0 additions & 3 deletions jscomp/bsb/bsb_ninja_rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ let define ~command ?dyndep ?restat rule_name : t =
type command = string

type builtin = {
build_ast : t; (** TODO: Implement it on top of pp_flags *)
build_ast_from_re : t;
(* build_ast_from_rei : t ; *)
(* platform dependent, on Win32,
Expand Down Expand Up @@ -179,7 +178,6 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
Ext_buffer.add_string buf " -absname -bs-ast -o $out $i";
Ext_buffer.contents buf
in
let build_ast = define ~command:mk_ast "ast" in
let build_ast_from_re = define ~command:mk_ast "astj" in

let copy_resources =
Expand Down Expand Up @@ -223,7 +221,6 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
~restat:() "build_package"
in
{
build_ast;
build_ast_from_re;
(* platform dependent, on Win32,
invoking cmd.exe
Expand Down
1 change: 0 additions & 1 deletion jscomp/bsb/bsb_ninja_rule.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ val get_name : t -> out_channel -> string
(***********************************************************)

type builtin = {
build_ast : t;
build_ast_from_re : t;
(* platform dependent, on Win32,
invoking cmd.exe
Expand Down
12 changes: 5 additions & 7 deletions jscomp/bsb_exe/rescript_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,12 @@ let info_subcommand ~start argv =
| Some { file_groups = { files } } ->
Ext_list.iter files (fun { sources } ->
Map_string.iter sources
(fun _ { info; syntax_kind; name_sans_extension } ->
(fun _ { info; name_sans_extension } ->
let extensions =
match (syntax_kind, info) with
| _, Intf -> assert false
| Ml, Impl -> [ ".ml" ]
| Ml, Impl_intf -> [ ".ml"; ".mli" ]
| Res, Impl -> [ ".res" ]
| Res, Impl_intf -> [ ".res"; ".resi" ]
match info with
| Intf -> assert false
| Impl -> [ ".res" ]
| Impl_intf -> [ ".res"; ".resi" ]
in
Ext_list.iter extensions (fun x ->
print_endline (name_sans_extension ^ x)))))
Expand Down
61 changes: 8 additions & 53 deletions jscomp/bsc/rescript_compiler_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,8 @@ let set_abs_input_name sourcefile =
else sourcefile in
Location.set_input_name sourcefile;
sourcefile

type syntax_kind = [`ml | `rescript]
let setup_compiler_printer (syntax_kind : [ syntax_kind | `default])=
(match syntax_kind with
| `default -> ()
| #syntax_kind as k -> Config.syntax_kind := k);
let syntax_kind = !Config.syntax_kind in
if syntax_kind = `rescript then begin
Lazy.force Res_outcome_printer.setup
end


let setup_outcome_printer () =
Lazy.force Res_outcome_printer.setup

let setup_runtime_path path =
let u0 = Filename.dirname path in
Expand All @@ -51,53 +41,37 @@ let process_file sourcefile ?(kind ) ppf =
properly
*)
let uncurried = !Config.uncurried in
setup_outcome_printer ();
let kind =
match kind with
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
| Some kind -> kind in
let res = match kind with
| Ml ->
let sourcefile = set_abs_input_name sourcefile in
setup_compiler_printer `ml;
Js_implementation.implementation
~parser:Pparse_driver.parse_implementation
ppf sourcefile
| Mli ->
let sourcefile = set_abs_input_name sourcefile in
setup_compiler_printer `ml;
Js_implementation.interface
~parser:Pparse_driver.parse_interface
ppf sourcefile
| Res ->
let sourcefile = set_abs_input_name sourcefile in
setup_compiler_printer `rescript;
Js_implementation.implementation
~parser:(Res_driver.parse_implementation ~ignore_parse_errors:!Clflags.ignore_parse_errors)
ppf sourcefile
| Resi ->
let sourcefile = set_abs_input_name sourcefile in
setup_compiler_printer `rescript;
Js_implementation.interface
~parser:(Res_driver.parse_interface ~ignore_parse_errors:!Clflags.ignore_parse_errors)
ppf sourcefile
| Intf_ast
->
Js_implementation.interface_mliast ppf sourcefile
setup_compiler_printer
(* The printer setup is done in the runtime depends on
the content of ast
*)
| Impl_ast
->
Js_implementation.implementation_mlast ppf sourcefile
setup_compiler_printer
Js_implementation.implementation_mlast ppf sourcefile
| Mlmap
->
Location.set_input_name sourcefile;
Js_implementation.implementation_map ppf sourcefile
| Cmi
->
setup_compiler_printer `default;
let cmi_sign = (Cmi_format.read_cmi sourcefile).cmi_sign in
Printtyp.signature Format.std_formatter cmi_sign ;
Format.pp_print_newline Format.std_formatter ()
Expand Down Expand Up @@ -182,22 +156,12 @@ let anonymous ~(rev_args : string list) =
Bsc_args.bad_arg "can not handle multiple files"
end

(** used by -impl -intf *)
let impl filename =
Js_config.js_stdout := false;
process_file filename ~kind:Ml ppf ;;
let intf filename =
Js_config.js_stdout := false ;
process_file filename ~kind:Mli ppf;;


let format_file input =
let ext = Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe input) in
let syntax =
match ext with
| Res | Resi -> `res
| _ -> Bsc_args.bad_arg ("don't know what to do with " ^ input) in
let formatted = Res_multi_printer.print ~ignore_parse_errors:!Clflags.ignore_parse_errors syntax ~input in
( match ext with
| Res | Resi -> ()
| _ -> Bsc_args.bad_arg ("don't know what to do with " ^ input) );
let formatted = Res_multi_printer.print ~ignore_parse_errors:!Clflags.ignore_parse_errors input in
match !Clflags.output_name with
| None ->
output_string stdout formatted
Expand Down Expand Up @@ -342,9 +306,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
"-unboxed-types", set Clflags.unboxed_types,
"*internal* Unannotated unboxable types will be unboxed";

"-bs-ml-out", unit_call (fun _ -> Config.syntax_kind := `ml),
"*internal* Print compiler output in ML syntax";

"-bs-D", string_call define_variable,
"Define conditional variable e.g, -D DEBUG=true";

Expand Down Expand Up @@ -407,12 +368,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
"-bs-loc", set Clflags.dump_location,
"*internal* dont display location with -dtypedtree, -dparsetree";

"-impl", string_call impl,
"*internal* <file> Compile <file> as a .ml file";

"-intf", string_call intf,
"*internal* <file> Compile <file> as a .mli file";

"-dtypedtree", set Clflags.dump_typedtree,
"*internal* debug typedtree";

Expand Down
1 change: 0 additions & 1 deletion jscomp/core/bs_conditional_initial.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ let setup_env () =
Matching.call_switcher_variant_constr := Polyvar_pattern_match.call_switcher_variant_constr;
Ctype.variant_is_subtype := Matching_polyfill.variant_is_subtype;
Clflags.dump_location := false;
Config.syntax_kind := `rescript;
Parmatch.print_res_pat := Pattern_printer.print_pattern;
(* default true
otherwise [bsc -I sc src/hello.ml ] will include current directory to search path
Expand Down
8 changes: 4 additions & 4 deletions jscomp/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ let interface ~parser ppf ?outputprefix fname =
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
|> after_parsing_sig ppf outputprefix

let interface_mliast ppf fname setup =
let interface_mliast ppf fname =
Res_compmisc.init_path ();
Binary_ast.read_ast_exn ~fname Mli setup
Binary_ast.read_ast_exn ~fname Mli
|> print_if_pipe ppf Clflags.dump_parsetree Printast.interface
|> print_if_pipe ppf Clflags.dump_source Pprintast.signature
|> after_parsing_sig ppf (Config_util.output_prefix fname)
Expand Down Expand Up @@ -187,9 +187,9 @@ let implementation ~parser ppf ?outputprefix fname =
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
|> after_parsing_impl ppf outputprefix

let implementation_mlast ppf fname setup =
let implementation_mlast ppf fname =
Res_compmisc.init_path ();
Binary_ast.read_ast_exn ~fname Ml setup
Binary_ast.read_ast_exn ~fname Ml
|> print_if_pipe ppf Clflags.dump_parsetree Printast.implementation
|> print_if_pipe ppf Clflags.dump_source Pprintast.structure
|> after_parsing_impl ppf (Config_util.output_prefix fname)
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_implementation.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ val interface :
*)

val interface_mliast :
Format.formatter -> string -> ([ `ml | `rescript | `default ] -> unit) -> unit
Format.formatter -> string -> unit

(* val after_parsing_impl :
Format.formatter ->
Expand All @@ -57,6 +57,6 @@ val implementation :
(** [implementation ppf sourcefile outprefix] compiles to JS directly *)

val implementation_mlast :
Format.formatter -> string -> ([ `ml | `rescript | `default ] -> unit) -> unit
Format.formatter -> string -> unit

val implementation_map : Format.formatter -> string -> unit
Loading