From 2d26b1320670374f5525d439bbddd4dfdd973ee9 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 11 Jul 2025 17:31:01 +0200 Subject: [PATCH 1/3] Remove Rescript_cpp module, -bs-D and -bs-list-conditionals --- compiler/bsc/rescript_compiler_main.ml | 20 +---- compiler/core/bs_conditional_initial.ml | 5 +- compiler/ml/rescript_cpp.ml | 109 ------------------------ compiler/ml/rescript_cpp.mli | 35 -------- 4 files changed, 2 insertions(+), 167 deletions(-) delete mode 100644 compiler/ml/rescript_cpp.ml delete mode 100644 compiler/ml/rescript_cpp.mli diff --git a/compiler/bsc/rescript_compiler_main.ml b/compiler/bsc/rescript_compiler_main.ml index 8fd209796d..79835ba60f 100644 --- a/compiler/bsc/rescript_compiler_main.ml +++ b/compiler/bsc/rescript_compiler_main.ml @@ -205,14 +205,6 @@ let eval (s : string) ~suffix = (* let (//) = Filename.concat *) -module Pp = Rescript_cpp -let define_variable s = - match Ext_string.split ~keep_empty:true s '=' with - | [key; v] -> - if not (Pp.define_key_value key v) then - Bsc_args.bad_arg ("illegal definition: " ^ s) - | _ -> Bsc_args.bad_arg ("illegal definition: " ^ s) - let print_standard_library () = let standard_library = Config.standard_library in print_string standard_library; @@ -297,11 +289,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = ( "-bs-syntax-only", set Js_config.syntax_only, "*internal* Only check syntax" ); - ( "-bs-g", - unit_call (fun _ -> - Js_config.debug := true; - Pp.replace_directive_bool "DEBUG" true), - "Debug mode" ); + ("-bs-g", unit_call (fun _ -> Js_config.debug := true), "Debug mode"); ( "-bs-package-name", string_call Js_packages_state.set_package_name, "*internal* Set package name, useful when you want to produce npm \ @@ -323,9 +311,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-D", - string_call define_variable, - "Define conditional variable e.g, -D DEBUG=true" ); ( "-bs-unsafe-empty-array", set Config.unsafe_empty_array, "*internal* Allow [||] to be polymorphic" ); @@ -341,9 +326,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = The current heuristic for 'auto'\n\ checks that the TERM environment variable exists and is\n\ not empty or \"dumb\", and that isatty(stderr) holds." ); - ( "-bs-list-conditionals", - unit_call (fun () -> Pp.list_variables Format.err_formatter), - "*internal* List existing conditional variables" ); ( "-e", string_call (fun s -> eval s ~suffix:Literals.suffix_res), "(experimental) set the string to be evaluated in ReScript syntax" ); diff --git a/compiler/core/bs_conditional_initial.ml b/compiler/core/bs_conditional_initial.ml index 56c981532d..6c384407cb 100644 --- a/compiler/core/bs_conditional_initial.ml +++ b/compiler/core/bs_conditional_initial.ml @@ -47,10 +47,7 @@ let setup_env () = Matching.names_from_construct_pattern := Matching_polyfill.names_from_construct_pattern; - Rescript_cpp.replace_directive_bool "BS" true; - Rescript_cpp.replace_directive_bool "JS" true; - Printtyp.print_res_poly_identifier := Res_printer.polyvar_ident_to_string; - Rescript_cpp.replace_directive_string "BS_VERSION" Bs_version.version + Printtyp.print_res_poly_identifier := Res_printer.polyvar_ident_to_string (*; Switch.cut := 100*) (* tweakable but not very useful *) diff --git a/compiler/ml/rescript_cpp.ml b/compiler/ml/rescript_cpp.ml deleted file mode 100644 index 2db504a4dd..0000000000 --- a/compiler/ml/rescript_cpp.ml +++ /dev/null @@ -1,109 +0,0 @@ -(* Copyright (C) 2021- Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type directive_value = - | Dir_bool of bool - | Dir_float of float - | Dir_int of int - | Dir_string of string - | Dir_null - -let directive_built_in_values = Hashtbl.create 51 - -let replace_directive_built_in_value k v = - Hashtbl.replace directive_built_in_values k v - -let remove_directive_built_in_value k = - Hashtbl.replace directive_built_in_values k Dir_null - -let replace_directive_bool k v = - Hashtbl.replace directive_built_in_values k (Dir_bool v) - -let replace_directive_string k v = - Hashtbl.replace directive_built_in_values k (Dir_string v) - -let () = - (* Note we use {!Config} instead of {!Sys} becasue - we want to overwrite in some cases with the - same stdlib - *) - let version = - Config.version - (* so that it can be overridden*) - in - replace_directive_built_in_value "OCAML_VERSION" (Dir_string version); - replace_directive_built_in_value "OS_TYPE" (Dir_string Sys.os_type) - -let iter_directive_built_in_value f = Hashtbl.iter f directive_built_in_values -(* let iter_directive_built_in_value f = Hashtbl.iter f directive_built_in_values *) - -(* - {[ - # semver 0 "12";; - - : int * int * int * string = (12, 0, 0, "");; - # semver 0 "12.3";; - - : int * int * int * string = (12, 3, 0, "");; - semver 0 "12.3.10";; - - : int * int * int * string = (12, 3, 10, "");; - # semver 0 "12.3.10+x";; - - : int * int * int * string = (12, 3, 10, "+x") - ]} - *) - -(** - {[ - semver Location.none "1.2.3" "~1.3.0" = false;; - semver Location.none "1.2.3" "^1.3.0" = true ;; - semver Location.none "1.2.3" ">1.3.0" = false ;; - semver Location.none "1.2.3" ">=1.3.0" = false ;; - semver Location.none "1.2.3" "<1.3.0" = true ;; - semver Location.none "1.2.3" "<=1.3.0" = true ;; - ]} - *) - -let pp_directive_value fmt (x : directive_value) = - match x with - | Dir_bool b -> Format.pp_print_bool fmt b - | Dir_int b -> Format.pp_print_int fmt b - | Dir_float b -> Format.pp_print_float fmt b - | Dir_string s -> Format.fprintf fmt "%S" s - | Dir_null -> Format.pp_print_string fmt "null" - -let list_variables fmt = - iter_directive_built_in_value (fun s dir_value -> - Format.fprintf fmt "@[%s@ %a@]@." s pp_directive_value dir_value) - -let define_key_value key v = - if String.length key > 0 && Char.uppercase_ascii key.[0] = key.[0] then ( - replace_directive_built_in_value key - (* NEED Sync up across {!lexer.mll} {!bspp.ml} and here, - TODO: put it in {!lexer.mll} - *) - (try Dir_bool (bool_of_string v) - with _ -> ( - try Dir_int (int_of_string v) - with _ -> ( - try Dir_float (float_of_string v) with _ -> Dir_string v))); - true) - else false diff --git a/compiler/ml/rescript_cpp.mli b/compiler/ml/rescript_cpp.mli deleted file mode 100644 index d0b1652d94..0000000000 --- a/compiler/ml/rescript_cpp.mli +++ /dev/null @@ -1,35 +0,0 @@ -(* Copyright (C) 2021- Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(* Methods below are used for cpp, they are not needed by the compiler patches*) -val remove_directive_built_in_value : string -> unit - -val replace_directive_string : string -> string -> unit - -val replace_directive_bool : string -> bool -> unit - -val define_key_value : string -> string -> bool -(** @return false means failed to define *) - -val list_variables : Format.formatter -> unit From 2630432f3f3ded9c84434f000b0984b6822006f1 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 11 Jul 2025 17:42:04 +0200 Subject: [PATCH 2/3] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34b4bfb252..adf1501b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ #### :house: Internal - Remove internal/unused `-bs-v` flag. https://github.com/rescript-lang/rescript/pull/7627 +- Remove unused `-bs-D` and `-bs-list-conditionals` flags. https://github.com/rescript-lang/rescript/pull/7631 # 12.0.0-beta.1 From afb419bbc7fda4ec5e7559a55f01c3c8de437c9e Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 11 Jul 2025 17:46:31 +0200 Subject: [PATCH 3/3] simplify --- compiler/bsc/rescript_compiler_main.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/bsc/rescript_compiler_main.ml b/compiler/bsc/rescript_compiler_main.ml index 79835ba60f..ab569d4083 100644 --- a/compiler/bsc/rescript_compiler_main.ml +++ b/compiler/bsc/rescript_compiler_main.ml @@ -289,7 +289,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = ( "-bs-syntax-only", set Js_config.syntax_only, "*internal* Only check syntax" ); - ("-bs-g", unit_call (fun _ -> Js_config.debug := true), "Debug mode"); + ("-bs-g", set Js_config.debug, "Debug mode"); ( "-bs-package-name", string_call Js_packages_state.set_package_name, "*internal* Set package name, useful when you want to produce npm \