Skip to content

Commit ea6bbfb

Browse files
authored
Merge pull request #4828 from rescript-lang/mark_rescript
better inferences when -o not passed
2 parents 224a31f + 68133f4 commit ea6bbfb

File tree

4 files changed

+104
-118
lines changed

4 files changed

+104
-118
lines changed

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ let make_custom_rules
121121
~(digest : string)
122122
~(refmt : string option) (* set refmt path when needed *)
123123
~(package_specs: Bsb_package_specs.t)
124-
~namespace
124+
~(namespace : string option)
125125
~package_name
126126
~bsc
127127
~warnings
@@ -172,7 +172,7 @@ let make_custom_rules
172172
Ext_buffer.add_string buf package_name;
173173
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d")
174174
end;
175-
Ext_buffer.add_string buf " -o $out $i";
175+
Ext_buffer.add_string buf " $i";
176176
begin match postbuild with
177177
| None -> ()
178178
| Some cmd ->

jscomp/main/js_main.ml

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@
1111
(***********************************************************************)
1212

1313
let output_prefix name =
14-
let oname =
15-
match !Clflags.output_name with
16-
| None -> name
17-
| Some n -> (Clflags.output_name := None; n) in
18-
Filename.remove_extension oname
14+
match !Clflags.output_name with
15+
| None ->
16+
Ext_namespace_encode.make
17+
(Filename.remove_extension name)
18+
?ns:!Clflags.dont_record_crc_unit
19+
| Some oname ->
20+
Filename.remove_extension oname
1921

2022

21-
let process_interface_file ppf name =
22-
Js_implementation.interface ppf name
23-
~parser:Pparse_driver.parse_interface
24-
(output_prefix name)
25-
let process_implementation_file ppf name =
26-
Js_implementation.implementation ppf name
27-
~parser:Pparse_driver.parse_implementation
28-
(output_prefix name)
2923

3024

3125
let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])=
@@ -67,20 +61,19 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref =
6761

6862

6963

70-
71-
72-
73-
74-
let process_file ppf sourcefile =
64+
let process_file sourcefile
65+
?(kind ) ppf =
7566
(* This is a better default then "", it will be changed later
7667
The {!Location.input_name} relies on that we write the binary ast
7768
properly
7869
*)
79-
Location.set_input_name sourcefile;
80-
let ext = Ext_filename.get_extension_maybe sourcefile in
81-
let input = Ext_file_extensions.classify_input ext in
70+
Location.set_input_name sourcefile;
8271
let opref = output_prefix sourcefile in
83-
match input with
72+
let kind =
73+
match kind with
74+
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
75+
| Some kind -> kind in
76+
match kind with
8477
| Re -> handle_reason Ml sourcefile ppf opref
8578
| Rei ->
8679
handle_reason Mli sourcefile ppf opref
@@ -139,7 +132,7 @@ let anonymous ~(rev_args : string list) =
139132
begin
140133
match rev_args with
141134
| [filename] ->
142-
process_file ppf filename
135+
process_file filename ppf
143136
| [] -> ()
144137
| _ ->
145138
Bsc_args.bad_arg "can not handle multiple files"
@@ -148,10 +141,10 @@ let anonymous ~(rev_args : string list) =
148141
(** used by -impl -intf *)
149142
let impl filename =
150143
Js_config.js_stdout := false;
151-
process_implementation_file ppf filename;;
144+
process_file filename ~kind:Ml ppf ;;
152145
let intf filename =
153146
Js_config.js_stdout := false ;
154-
process_interface_file ppf filename;;
147+
process_file filename ~kind:Mli ppf;;
155148

156149

157150
let format_file input =

lib/4.06.1/bsb.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12948,7 +12948,7 @@ let make_custom_rules
1294812948
~(digest : string)
1294912949
~(refmt : string option) (* set refmt path when needed *)
1295012950
~(package_specs: Bsb_package_specs.t)
12951-
~namespace
12951+
~(namespace : string option)
1295212952
~package_name
1295312953
~bsc
1295412954
~warnings
@@ -12999,7 +12999,7 @@ let make_custom_rules
1299912999
Ext_buffer.add_string buf package_name;
1300013000
Ext_buffer.add_string buf (Bsb_package_specs.package_flag_of_package_specs package_specs "$in_d")
1300113001
end;
13002-
Ext_buffer.add_string buf " -o $out $i";
13002+
Ext_buffer.add_string buf " $i";
1300313003
begin match postbuild with
1300413004
| None -> ()
1300513005
| Some cmd ->

lib/4.06.1/whole_compiler.ml

Lines changed: 82 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -366101,6 +366101,70 @@ let write_file f content =
366101366101
end
366102366102

366103366103
end
366104+
module Ext_namespace_encode : sig
366105+
#1 "ext_namespace_encode.mli"
366106+
(* Copyright (C) 2020- Authors of BuckleScript
366107+
*
366108+
* This program is free software: you can redistribute it and/or modify
366109+
* it under the terms of the GNU Lesser General Public License as published by
366110+
* the Free Software Foundation, either version 3 of the License, or
366111+
* (at your option) any later version.
366112+
*
366113+
* In addition to the permissions granted to you by the LGPL, you may combine
366114+
* or link a "work that uses the Library" with a publicly distributed version
366115+
* of this file to produce a combined library or application, then distribute
366116+
* that combined work under the terms of your choosing, with no requirement
366117+
* to comply with the obligations normally placed on you by section 4 of the
366118+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
366119+
* should you choose to use a later version).
366120+
*
366121+
* This program is distributed in the hope that it will be useful,
366122+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
366123+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
366124+
* GNU Lesser General Public License for more details.
366125+
*
366126+
* You should have received a copy of the GNU Lesser General Public License
366127+
* along with this program; if not, write to the Free Software
366128+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
366129+
366130+
(** [make ~ns:"Ns" "a" ]
366131+
A typical example would return "a-Ns"
366132+
Note the namespace comes from the output of [namespace_of_package_name]
366133+
*)
366134+
val make :
366135+
?ns:string -> string -> string
366136+
366137+
end = struct
366138+
#1 "ext_namespace_encode.ml"
366139+
(* Copyright (C) 2020- Authors of BuckleScript
366140+
*
366141+
* This program is free software: you can redistribute it and/or modify
366142+
* it under the terms of the GNU Lesser General Public License as published by
366143+
* the Free Software Foundation, either version 3 of the License, or
366144+
* (at your option) any later version.
366145+
*
366146+
* In addition to the permissions granted to you by the LGPL, you may combine
366147+
* or link a "work that uses the Library" with a publicly distributed version
366148+
* of this file to produce a combined library or application, then distribute
366149+
* that combined work under the terms of your choosing, with no requirement
366150+
* to comply with the obligations normally placed on you by section 4 of the
366151+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
366152+
* should you choose to use a later version).
366153+
*
366154+
* This program is distributed in the hope that it will be useful,
366155+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
366156+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
366157+
* GNU Lesser General Public License for more details.
366158+
*
366159+
* You should have received a copy of the GNU Lesser General Public License
366160+
* along with this program; if not, write to the Free Software
366161+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
366162+
366163+
let make ?ns cunit =
366164+
match ns with
366165+
| None -> cunit
366166+
| Some ns -> cunit ^ Literals.ns_sep ^ ns
366167+
end
366104366168
module Depend : sig
366105366169
#1 "depend.mli"
366106366170
(**************************************************************************)
@@ -367330,70 +367394,6 @@ end = struct
367330367394

367331367395
let hex_length = 32
367332367396
end
367333-
module Ext_namespace_encode : sig
367334-
#1 "ext_namespace_encode.mli"
367335-
(* Copyright (C) 2020- Authors of BuckleScript
367336-
*
367337-
* This program is free software: you can redistribute it and/or modify
367338-
* it under the terms of the GNU Lesser General Public License as published by
367339-
* the Free Software Foundation, either version 3 of the License, or
367340-
* (at your option) any later version.
367341-
*
367342-
* In addition to the permissions granted to you by the LGPL, you may combine
367343-
* or link a "work that uses the Library" with a publicly distributed version
367344-
* of this file to produce a combined library or application, then distribute
367345-
* that combined work under the terms of your choosing, with no requirement
367346-
* to comply with the obligations normally placed on you by section 4 of the
367347-
* LGPL version 3 (or the corresponding section of a later version of the LGPL
367348-
* should you choose to use a later version).
367349-
*
367350-
* This program is distributed in the hope that it will be useful,
367351-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
367352-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
367353-
* GNU Lesser General Public License for more details.
367354-
*
367355-
* You should have received a copy of the GNU Lesser General Public License
367356-
* along with this program; if not, write to the Free Software
367357-
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
367358-
367359-
(** [make ~ns:"Ns" "a" ]
367360-
A typical example would return "a-Ns"
367361-
Note the namespace comes from the output of [namespace_of_package_name]
367362-
*)
367363-
val make :
367364-
?ns:string -> string -> string
367365-
367366-
end = struct
367367-
#1 "ext_namespace_encode.ml"
367368-
(* Copyright (C) 2020- Authors of BuckleScript
367369-
*
367370-
* This program is free software: you can redistribute it and/or modify
367371-
* it under the terms of the GNU Lesser General Public License as published by
367372-
* the Free Software Foundation, either version 3 of the License, or
367373-
* (at your option) any later version.
367374-
*
367375-
* In addition to the permissions granted to you by the LGPL, you may combine
367376-
* or link a "work that uses the Library" with a publicly distributed version
367377-
* of this file to produce a combined library or application, then distribute
367378-
* that combined work under the terms of your choosing, with no requirement
367379-
* to comply with the obligations normally placed on you by section 4 of the
367380-
* LGPL version 3 (or the corresponding section of a later version of the LGPL
367381-
* should you choose to use a later version).
367382-
*
367383-
* This program is distributed in the hope that it will be useful,
367384-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
367385-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
367386-
* GNU Lesser General Public License for more details.
367387-
*
367388-
* You should have received a copy of the GNU Lesser General Public License
367389-
* along with this program; if not, write to the Free Software
367390-
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
367391-
367392-
let make ?ns cunit =
367393-
match ns with
367394-
| None -> cunit
367395-
| Some ns -> cunit ^ Literals.ns_sep ^ ns
367396-
end
367397367397
module Ext_modulename : sig
367398367398
#1 "ext_modulename.mli"
367399367399
(* Copyright (C) 2017 Authors of BuckleScript
@@ -436137,21 +436137,15 @@ end = struct
436137436137
(***********************************************************************)
436138436138

436139436139
let output_prefix name =
436140-
let oname =
436141-
match !Clflags.output_name with
436142-
| None -> name
436143-
| Some n -> (Clflags.output_name := None; n) in
436144-
Filename.remove_extension oname
436140+
match !Clflags.output_name with
436141+
| None ->
436142+
Ext_namespace_encode.make
436143+
(Filename.remove_extension name)
436144+
?ns:!Clflags.dont_record_crc_unit
436145+
| Some oname ->
436146+
Filename.remove_extension oname
436145436147

436146436148

436147-
let process_interface_file ppf name =
436148-
Js_implementation.interface ppf name
436149-
~parser:Pparse_driver.parse_interface
436150-
(output_prefix name)
436151-
let process_implementation_file ppf name =
436152-
Js_implementation.implementation ppf name
436153-
~parser:Pparse_driver.parse_implementation
436154-
(output_prefix name)
436155436149

436156436150

436157436151
let setup_error_printer (syntax_kind : [ `ml | `reason | `rescript ])=
@@ -436193,20 +436187,19 @@ let handle_reason (type a) (kind : a Ml_binary.kind) sourcefile ppf opref =
436193436187

436194436188

436195436189

436196-
436197-
436198-
436199-
436200-
let process_file ppf sourcefile =
436190+
let process_file sourcefile
436191+
?(kind ) ppf =
436201436192
(* This is a better default then "", it will be changed later
436202436193
The {!Location.input_name} relies on that we write the binary ast
436203436194
properly
436204436195
*)
436205-
Location.set_input_name sourcefile;
436206-
let ext = Ext_filename.get_extension_maybe sourcefile in
436207-
let input = Ext_file_extensions.classify_input ext in
436196+
Location.set_input_name sourcefile;
436208436197
let opref = output_prefix sourcefile in
436209-
match input with
436198+
let kind =
436199+
match kind with
436200+
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
436201+
| Some kind -> kind in
436202+
match kind with
436210436203
| Re -> handle_reason Ml sourcefile ppf opref
436211436204
| Rei ->
436212436205
handle_reason Mli sourcefile ppf opref
@@ -436265,7 +436258,7 @@ let anonymous ~(rev_args : string list) =
436265436258
begin
436266436259
match rev_args with
436267436260
| [filename] ->
436268-
process_file ppf filename
436261+
process_file filename ppf
436269436262
| [] -> ()
436270436263
| _ ->
436271436264
Bsc_args.bad_arg "can not handle multiple files"
@@ -436274,10 +436267,10 @@ let anonymous ~(rev_args : string list) =
436274436267
(** used by -impl -intf *)
436275436268
let impl filename =
436276436269
Js_config.js_stdout := false;
436277-
process_implementation_file ppf filename;;
436270+
process_file filename ~kind:Ml ppf ;;
436278436271
let intf filename =
436279436272
Js_config.js_stdout := false ;
436280-
process_interface_file ppf filename;;
436273+
process_file filename ~kind:Mli ppf;;
436281436274

436282436275

436283436276
let format_file input =

0 commit comments

Comments
 (0)