diff --git a/compiler/bsc/rescript_compiler_main.ml b/compiler/bsc/rescript_compiler_main.ml index 8045973e6c..b3d51c1e98 100644 --- a/compiler/bsc/rescript_compiler_main.ml +++ b/compiler/bsc/rescript_compiler_main.ml @@ -425,6 +425,9 @@ let command_line_flags : (string * Bsc_args.spec * string) array = ("-dtypedtree", set Clflags.dump_typedtree, "*internal* debug typedtree"); ("-dparsetree", set Clflags.dump_parsetree, "*internal* debug parsetree"); ("-drawlambda", set Clflags.dump_rawlambda, "*internal* debug raw lambda"); + ( "-draw-coercions", + set Clflags.dump_coercions, + "*internal* debug module coercions with raw internal types" ); ("-dsource", set Clflags.dump_source, "*internal* print source"); ( "-reprint-source", string_call reprint_source_file, diff --git a/compiler/common/bs_loc.ml b/compiler/common/bs_loc.ml deleted file mode 100644 index ff7df2bf54..0000000000 --- a/compiler/common/bs_loc.ml +++ /dev/null @@ -1,41 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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 t = Location.t = { - loc_start: Lexing.position; - loc_end: Lexing.position; - loc_ghost: bool; -} - -let is_ghost x = x.loc_ghost - -let merge (l : t) (r : t) = - if is_ghost l then r - else if is_ghost r then l - else - match (l, r) with - | {loc_start; _}, {loc_end; _} (* TODO: improve*) -> - {loc_start; loc_end; loc_ghost = false} - -(* let none = Location.none *) diff --git a/compiler/common/bs_loc.mli b/compiler/common/bs_loc.mli deleted file mode 100644 index de22c2d980..0000000000 --- a/compiler/common/bs_loc.mli +++ /dev/null @@ -1,33 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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 t = Location.t = { - loc_start: Lexing.position; - loc_end: Lexing.position; - loc_ghost: bool; -} - -(* val is_ghost : t -> bool *) -val merge : t -> t -> t -(* val none : t *) diff --git a/compiler/common/ext_log.mli b/compiler/common/ext_log.mli index 8881c965b0..74985067f6 100644 --- a/compiler/common/ext_log.mli +++ b/compiler/common/ext_log.mli @@ -25,9 +25,10 @@ (** A Poor man's logging utility Example: - {[ - err __LOC__ "xx" + {[ + dwarn ~__POS__ "unexpected %s" name ]} + prints a warning to stderr when [-debug-ir] is set. *) type 'a logging = ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a diff --git a/compiler/common/js_config.ml b/compiler/common/js_config.ml index 93df8b3cde..501ca35405 100644 --- a/compiler/common/js_config.ml +++ b/compiler/common/js_config.ml @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(** Browser is not set via command line only for internal use *) - type jsx_version = Jsx_v4 type jsx_module = React | Generic of {module_name: string} type source_map = No_source_map | Linked | Inline | Hidden @@ -35,10 +33,6 @@ let cross_module_inline = ref false let debug_ir = ref false let check_lam = ref false -(* let (//) = Filename.concat *) - -(* let get_packages_info () = !packages_info *) - let no_builtin_ppx = ref false let tool_name = "ReScript" let check_div_by_zero = ref true diff --git a/compiler/common/js_config.mli b/compiler/common/js_config.mli index c4098918ca..6510961705 100644 --- a/compiler/common/js_config.mli +++ b/compiler/common/js_config.mli @@ -26,26 +26,12 @@ type jsx_version = Jsx_v4 type jsx_module = React | Generic of {module_name: string} type source_map = No_source_map | Linked | Inline | Hidden -(* val get_packages_info : - unit -> Js_packages_info.t *) - val no_version_header : bool ref (** set/get header *) val directives : string list ref (** directives printed verbatims just after the version header *) -(** return [package_name] and [path] - when in script mode: -*) - -(* val get_current_package_name_and_path : - Js_packages_info.module_system -> - Js_packages_info.info_query *) - -(* val set_package_name : string -> unit - val get_package_name : unit -> string option *) - val cross_module_inline : bool ref (** cross module inline option *) diff --git a/compiler/common/ml_binary.ml b/compiler/common/ml_binary.ml index 0d3832bb25..413fb3e47f 100644 --- a/compiler/common/ml_binary.ml +++ b/compiler/common/ml_binary.ml @@ -26,9 +26,13 @@ type _ kind = Ml : Parsetree.structure kind | Mli : Parsetree.signature kind type ast0 = Impl of Parsetree0.structure | Intf of Parsetree0.signature +let magic_of_kind : type a. a kind -> string = function + | Ml -> Config.ast0_impl_magic_number + | Mli -> Config.ast0_intf_magic_number + let magic_of_ast0 : ast0 -> string = function - | Impl _ -> Config.ast0_impl_magic_number - | Intf _ -> Config.ast0_intf_magic_number + | Impl _ -> magic_of_kind Ml + | Intf _ -> magic_of_kind Mli let to_ast0 : type a. a kind -> a -> ast0 = fun kind ast -> @@ -57,7 +61,3 @@ let ast0_roundtrip : type a. a kind -> a -> a = match kind with | Ml -> ast |> to_ast0 Ml |> ast0_to_structure | Mli -> ast |> to_ast0 Mli |> ast0_to_signature - -let magic_of_kind : type a. a kind -> string = function - | Ml -> Config.ast0_impl_magic_number - | Mli -> Config.ast0_intf_magic_number diff --git a/compiler/common/ml_binary.mli b/compiler/common/ml_binary.mli index 13ca35c930..01ee113092 100644 --- a/compiler/common/ml_binary.mli +++ b/compiler/common/ml_binary.mli @@ -22,9 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* This file was used to read reason ast - and part of parsing binary ast -*) +(* The kind (structure or signature) of an AST, and conversion between + Parsetree and the frozen Parsetree0 that PPX executables read and write *) type _ kind = Ml : Parsetree.structure kind | Mli : Parsetree.signature kind type ast0 = Impl of Parsetree0.structure | Intf of Parsetree0.signature diff --git a/compiler/depends/binary_ast.ml b/compiler/depends/binary_ast.ml index 73a9a0c7f9..26be9af9af 100644 --- a/compiler/depends/binary_ast.ml +++ b/compiler/depends/binary_ast.ml @@ -23,7 +23,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) module Set_string = Ast_extract.Set_string -(** Synced up with module {!Bsb_helper_depfile_gen} *) type 'a kind = 'a Ml_binary.kind = | Ml : Parsetree.structure kind diff --git a/compiler/depends/binary_ast.mli b/compiler/depends/binary_ast.mli index 97c98cb12b..90b6d4ad0b 100644 --- a/compiler/depends/binary_ast.mli +++ b/compiler/depends/binary_ast.mli @@ -26,21 +26,12 @@ type _ kind = Ml : Parsetree.structure kind | Mli : Parsetree.signature kind val read_ast_exn : fname:string -> 'a kind -> 'a -val magic_sep_char : char - val write_ast : sourcefile:string -> output:string -> 'a kind -> 'a -> unit -(** - Check out {!Bsb_depfile_gen} for set decoding - The [.ml] file can be recognized as an ast directly, the format - is - { - magic number; - filename; - ast - } - when [fname] is "-" it means the file is from an standard input or pipe. - An empty name would marshallized. - - Use case cat - | fan -printer -impl - - redirect the standard input to fan -*) +(** [write_ast ~sourcefile ~output kind ast] writes to [output]: + - the length in bytes of the dependency block ([output_binary_int]); + - the dependency block: a newline, then each module name [ast] refers to + (predefined names excluded), each followed by a newline; + - [sourcefile] and a newline; + - the marshalled [ast]. + [read_ast_exn] skips the dependency block; rewatch reads it in + [get_dep_modules] (rewatch/src/build/deps.rs). *) diff --git a/compiler/ext/config.mli b/compiler/ext/config.mli index e96ab299ff..46c246d4f0 100644 --- a/compiler/ext/config.mli +++ b/compiler/ext/config.mli @@ -38,4 +38,4 @@ val ast0_impl_magic_number : string tree, as used on the external-PPX wire *) val cmt_magic_number : string -(* Magic number for compiled interface files *) +(* Magic number for typed-tree files (.cmt, .cmti) *) diff --git a/compiler/ext/ext_array.ml b/compiler/ext/ext_array.ml index 2535addcb2..57eeb17a86 100644 --- a/compiler/ext/ext_array.ml +++ b/compiler/ext/ext_array.ml @@ -35,8 +35,6 @@ let reverse_range a i len = a.!(i + len - 1 - k) <- t done -let reverse_in_place a = reverse_range a 0 (Array.length a) - let reverse a = let b_len = Array.length a in if b_len = 0 then [||] @@ -60,49 +58,6 @@ let reverse_of_list = function in fill (len - 1) tl -let filter a f = - let arr_len = Array.length a in - let rec aux acc i = - if i = arr_len then reverse_of_list acc - else - let v = Array.unsafe_get a i in - if f v then aux (v :: acc) (i + 1) else aux acc (i + 1) - in - aux [] 0 - -let filter_map a (f : _ -> _ option) = - let arr_len = Array.length a in - let rec aux acc i = - if i = arr_len then reverse_of_list acc - else - let v = Array.unsafe_get a i in - match f v with - | Some v -> aux (v :: acc) (i + 1) - | None -> aux acc (i + 1) - in - aux [] 0 - -let filter_mapi a (f : _ -> _ -> _ option) = - let arr_len = Array.length a in - let rec aux acc i = - if i = arr_len then reverse_of_list acc - else - let v = Array.unsafe_get a i in - match f i v with - | Some v -> aux (v :: acc) (i + 1) - | None -> aux acc (i + 1) - in - aux [] 0 - -let range from to_ = - if from > to_ then invalid_arg "Ext_array.range" - else Array.init (to_ - from + 1) (fun i -> i + from) - -let map2i f a b = - let len = Array.length a in - if len <> Array.length b then invalid_arg "Ext_array.map2i" - else Array.mapi (fun i a -> f i a (Array.unsafe_get b i)) a - let rec tolist_f_aux a f i res = if i < 0 then res else @@ -197,8 +152,6 @@ let exists a p = in loop 0 -let is_empty arr = Array.length arr = 0 - let rec unsafe_loop index len p xs ys = if index >= len then true else diff --git a/compiler/ext/ext_array.mli b/compiler/ext/ext_array.mli index 0f0eb4dfa3..d1942e16c5 100644 --- a/compiler/ext/ext_array.mli +++ b/compiler/ext/ext_array.mli @@ -25,22 +25,10 @@ val reverse_range : 'a array -> int -> int -> unit (** Some utilities for {!Array} operations *) -val reverse_in_place : 'a array -> unit - val reverse : 'a array -> 'a array val reverse_of_list : 'a list -> 'a array -val filter : 'a array -> ('a -> bool) -> 'a array - -val filter_map : 'a array -> ('a -> 'b option) -> 'b array - -val filter_mapi : 'a array -> (int -> 'a -> 'b option) -> 'b array - -val range : int -> int -> int array - -val map2i : (int -> 'a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array - val to_list_f : 'a array -> ('a -> 'b) -> 'b list val to_list_map_acc : 'a array -> 'b list -> ('a -> 'b option) -> 'b list @@ -53,8 +41,6 @@ val find_and_split : 'a array -> ('a -> 'b -> bool) -> 'b -> 'a split val exists : 'a array -> ('a -> bool) -> bool -val is_empty : 'a array -> bool - val for_all2_no_exn : 'a array -> 'b array -> ('a -> 'b -> bool) -> bool val for_alli : 'a array -> (int -> 'a -> bool) -> bool diff --git a/compiler/ext/ext_buffer.ml b/compiler/ext/ext_buffer.ml index 88df4bbcde..1bf4f0dcbc 100644 --- a/compiler/ext/ext_buffer.ml +++ b/compiler/ext/ext_buffer.ml @@ -41,8 +41,6 @@ let length b = b.position let is_empty b = b.position = 0 -let clear b = b.position <- 0 - (* let reset b = b.position <- 0; b.buffer <- b.initial_buffer; b.length <- Bytes.length b.buffer *) diff --git a/compiler/ext/ext_buffer.mli b/compiler/ext/ext_buffer.mli index 0271495642..262b803cac 100644 --- a/compiler/ext/ext_buffer.mli +++ b/compiler/ext/ext_buffer.mli @@ -47,9 +47,6 @@ val length : t -> int val is_empty : t -> bool -val clear : t -> unit -(** Empty the buffer. *) - val add_char : t -> char -> unit (** [add_char b c] appends the character [c] at the end of the buffer [b]. *) diff --git a/compiler/ext/ext_char.ml b/compiler/ext/ext_char.ml index 3754665a69..bfb5def4d8 100644 --- a/compiler/ext/ext_char.ml +++ b/compiler/ext/ext_char.ml @@ -22,15 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(** {!Char.escaped} is locale sensitive in 4.02.3, fixed in the trunk, - backport it here -*) - -let valid_hex x = - match x with - | '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' -> true - | _ -> false - let is_lower_case c = (c >= 'a' && c <= 'z') || (c >= '\224' && c <= '\246') diff --git a/compiler/ext/ext_char.mli b/compiler/ext/ext_char.mli index bf150c840e..330dcee367 100644 --- a/compiler/ext/ext_char.mli +++ b/compiler/ext/ext_char.mli @@ -24,6 +24,4 @@ (** Extension to Standard char module, avoid locale sensitivity *) -val valid_hex : char -> bool - val is_lower_case : char -> bool diff --git a/compiler/ext/ext_fmt.ml b/compiler/ext/ext_fmt.ml index ea59637c49..7658c4dfd3 100644 --- a/compiler/ext/ext_fmt.ml +++ b/compiler/ext/ext_fmt.ml @@ -6,5 +6,3 @@ let with_file_as_pp filename f = v) let failwithf ~loc fmt = Format.ksprintf (fun s -> failwith (loc ^ s)) fmt - -let invalid_argf fmt = Format.ksprintf invalid_arg fmt diff --git a/compiler/ext/ext_ident.mli b/compiler/ext/ext_ident.mli index 970db72780..59edbe8e2a 100644 --- a/compiler/ext/ext_ident.mli +++ b/compiler/ext/ext_ident.mli @@ -37,8 +37,6 @@ val create_tmp : ?name:string -> unit -> Ident.t val is_uident : string -> bool -val is_uppercase_exotic : string -> bool - val unwrap_uppercase_exotic : string -> string val convert : string -> string diff --git a/compiler/ext/ext_list.ml b/compiler/ext/ext_list.ml index 0217ed5c52..be256b10b0 100644 --- a/compiler/ext/ext_list.ml +++ b/compiler/ext/ext_list.ml @@ -71,7 +71,7 @@ let rec arr_list_combine_unsafe arr l i j acc f = if i = j then acc else match l with - | [] -> invalid_arg "Ext_list.combine" + | [] -> invalid_arg "Ext_list.arr_list_combine_unsafe" | h :: tl -> (f arr.!(i), h) :: arr_list_combine_unsafe arr tl (i + 1) j acc f @@ -79,33 +79,19 @@ let combine_array arr l f = let len = Array.length arr in arr_list_combine_unsafe arr l 0 len [] f -let rec arr_list_filter_map_unasfe arr l i j acc f = +let rec arr_list_filter_map_unsafe arr l i j acc f = if i = j then acc else match l with | [] -> invalid_arg "Ext_list.arr_list_filter_map_unsafe" | h :: tl -> ( match f arr.!(i) h with - | None -> arr_list_filter_map_unasfe arr tl (i + 1) j acc f - | Some v -> v :: arr_list_filter_map_unasfe arr tl (i + 1) j acc f) + | None -> arr_list_filter_map_unsafe arr tl (i + 1) j acc f + | Some v -> v :: arr_list_filter_map_unsafe arr tl (i + 1) j acc f) let array_list_filter_map arr l f = let len = Array.length arr in - arr_list_filter_map_unasfe arr l 0 len [] f - -let rec map_split_opt (xs : 'a list) (f : 'a -> 'b option * 'c option) : - 'b list * 'c list = - match xs with - | [] -> ([], []) - | x :: xs -> ( - let c, d = f x in - let cs, ds = map_split_opt xs f in - ( (match c with - | Some c -> c :: cs - | None -> cs), - match d with - | Some d -> d :: ds - | None -> ds )) + arr_list_filter_map_unsafe arr l 0 len [] f let rec map_snd l f = match l with @@ -296,41 +282,6 @@ let rec fold_right3 l r last acc f = (f a3 b3 c3 (f a4 b4 c4 (fold_right3 arest brest crest acc f))))) | _, _, _ -> invalid_arg "Ext_list.fold_right2" -let rec map2i l r f = - match (l, r) with - | [], [] -> [] - | [a0], [b0] -> [f 0 a0 b0] - | [a0; a1], [b0; b1] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - [c0; c1] - | [a0; a1; a2], [b0; b1; b2] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - [c0; c1; c2] - | [a0; a1; a2; a3], [b0; b1; b2; b3] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - let c3 = f 3 a3 b3 in - [c0; c1; c2; c3] - | [a0; a1; a2; a3; a4], [b0; b1; b2; b3; b4] -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - let c3 = f 3 a3 b3 in - let c4 = f 4 a4 b4 in - [c0; c1; c2; c3; c4] - | a0 :: a1 :: a2 :: a3 :: a4 :: arest, b0 :: b1 :: b2 :: b3 :: b4 :: brest -> - let c0 = f 0 a0 b0 in - let c1 = f 1 a1 b1 in - let c2 = f 2 a2 b2 in - let c3 = f 3 a3 b3 in - let c4 = f 4 a4 b4 in - c0 :: c1 :: c2 :: c3 :: c4 :: map2i arest brest f - | _, _ -> invalid_arg "Ext_list.map2" - let rec map2 l r f = match (l, r) with | [], [] -> [] @@ -485,15 +436,6 @@ let filter_mapi xs f = in aux 0 xs -let rec filter_map2 xs ys (f : 'a -> 'b -> 'c option) = - match (xs, ys) with - | [], [] -> [] - | u :: us, v :: vs -> ( - match f u v with - | None -> filter_map2 us vs f (* idea: rec f us vs instead? *) - | Some z -> z :: filter_map2 us vs f) - | _ -> invalid_arg "Ext_list.filter_map2" - let rec rev_map_append l1 l2 f = match l1 with | [] -> l2 @@ -558,14 +500,6 @@ and aux eq (x : 'a) (xss : 'a list list) : 'a list list = let stable_group lst eq = group eq lst |> rev -let rec drop h n = - if n < 0 then invalid_arg "Ext_list.drop" - else if n = 0 then h - else - match h with - | [] -> invalid_arg "Ext_list.drop" - | _ :: tl -> drop tl (n - 1) - let rec find_first x p = match x with | [] -> None @@ -648,14 +582,6 @@ let rec find_opt xs p = | Some _ as v -> v | None -> find_opt l p) -let rec find_def xs p def = - match xs with - | [] -> def - | x :: l -> ( - match p x with - | Some v -> v - | None -> find_def l p def) - let rec split_map l f = match l with | [] -> ([], []) @@ -769,11 +695,6 @@ let singleton_exn xs = | [x] -> x | _ -> assert false -let rec mem_string (xs : string list) (x : string) = - match xs with - | [] -> false - | a :: l -> a = x || mem_string l x - let filter lst p = let rec find ~p accu lst = match lst with diff --git a/compiler/ext/ext_list.mli b/compiler/ext/ext_list.mli index 0fe22de37a..a1533d42f9 100644 --- a/compiler/ext/ext_list.mli +++ b/compiler/ext/ext_list.mli @@ -30,9 +30,6 @@ val combine_array : 'a array -> 'b list -> ('a -> 'c) -> ('c * 'b) list val has_string : string list -> string -> bool -val map_split_opt : - 'a list -> ('a -> 'b option * 'c option) -> 'b list * 'c list - val mapi : 'a list -> (int -> 'a -> 'b) -> 'b list val mapi_append : 'a list -> (int -> 'a -> 'b) -> 'b list -> 'b list @@ -74,17 +71,12 @@ val fold_right3 : val map2 : 'a list -> 'b list -> ('a -> 'b -> 'c) -> 'c list -val map2i : 'a list -> 'b list -> (int -> 'a -> 'b -> 'c) -> 'c list - val fold_left_with_offset : 'a list -> 'acc -> int -> ('a -> 'acc -> int -> 'acc) -> 'acc val filter_map : 'a list -> ('a -> 'b option) -> 'b list (** @unused *) -val exclude : 'a list -> ('a -> bool) -> 'a list -(** [exclude p l] is the opposite of [filter p l] *) - val exclude_with_val : 'a list -> ('a -> bool) -> 'a list option (** [excludes p l] return a tuple [excluded,newl] @@ -110,8 +102,6 @@ val split_at_last : 'a list -> 'a list * 'a val filter_mapi : 'a list -> ('a -> int -> 'b option) -> 'b list -val filter_map2 : 'a list -> 'b list -> ('a -> 'b -> 'c option) -> 'c list - val length_compare : 'a list -> int -> [`Gt | `Eq | `Lt] val length_ge : 'a list -> int -> bool @@ -153,12 +143,6 @@ val stable_group : 'a list -> ('a -> 'a -> bool) -> 'a list list which could be improved later *) -val drop : 'a list -> int -> 'a list -(** [drop n list] - raise when [n] is negative - raise when list's length is less than [n] -*) - val find_first : 'a list -> ('a -> bool) -> 'a option val find_first_not : 'a list -> ('a -> bool) -> 'a option @@ -174,8 +158,6 @@ val find_first_not : 'a list -> ('a -> bool) -> 'a option val find_opt : 'a list -> ('a -> 'b option) -> 'b option -val find_def : 'a list -> ('a -> 'b option) -> 'b -> 'b - val rev_iter : 'a list -> ('a -> unit) -> unit val iter : 'a list -> ('a -> unit) -> unit @@ -226,8 +208,6 @@ val fold_left : 'a list -> 'b -> ('b -> 'a -> 'b) -> 'b val singleton_exn : 'a list -> 'a -val mem_string : string list -> string -> bool - val filter : 'a list -> ('a -> bool) -> 'a list val array_list_filter_map : diff --git a/compiler/ext/ext_map.ml b/compiler/ext/ext_map.ml index 9bb91449a8..b513cc4045 100644 --- a/compiler/ext/ext_map.ml +++ b/compiler/ext/ext_map.ml @@ -118,16 +118,6 @@ module Make (Key : OrderedType) = struct let c = compare_key x k in c = 0 || mem (if c < 0 then l else r) x - let rec remove (tree : _ Map_gen.t as 'a) x : 'a = - match tree with - | Empty -> empty - | Leaf leaf -> if eq_key x leaf.k then empty else tree - | Node {l; k; v; r} -> - let c = compare_key x k in - if c = 0 then Map_gen.merge l r - else if c < 0 then bal (remove l x) k v r - else bal l k v (remove r x) - type 'a split = | Yes of {l: (key, 'a) Map_gen.t; r: (key, 'a) Map_gen.t; v: 'a} | No of {l: (key, 'a) Map_gen.t; r: (key, 'a) Map_gen.t} @@ -192,10 +182,7 @@ module Make (Key : OrderedType) = struct (disjoint_merge_exn r s2.r fail) | Yes {v = s1v} -> raise_notrace (fail k s1v s2.v))) - let add_list (xs : _ list) init = - Ext_list.fold_left xs init (fun acc (k, v) -> add acc k v) - - let of_list xs = add_list xs empty + let of_list xs = Ext_list.fold_left xs empty (fun acc (k, v) -> add acc k v) let of_array xs = Ext_array.fold_left xs empty (fun acc (k, v) -> add acc k v) end diff --git a/compiler/ext/ext_obj.ml b/compiler/ext/ext_obj.ml index ae11db924b..d085671c84 100644 --- a/compiler/ext/ext_obj.ml +++ b/compiler/ext/ext_obj.ml @@ -99,22 +99,3 @@ let rec dump r = | _ -> opaque (Printf.sprintf "unknown: tag %d size %d" t s) let dump v = dump (Obj.repr v) - -let bt () = - let raw_bt = Printexc.backtrace_slots (Printexc.get_raw_backtrace ()) in - match raw_bt with - | None -> () - | Some raw_bt -> - let acc = ref [] in - for i = Array.length raw_bt - 1 downto 0 do - let slot = raw_bt.(i) in - match Printexc.Slot.location slot with - | None -> () - | Some bt -> ( - match !acc with - | [] -> acc := [bt] - | hd :: _ -> if hd <> bt then acc := bt :: !acc) - done; - Ext_list.iter !acc (fun bt -> - Printf.eprintf "File \"%s\", line %d, characters %d-%d\n" bt.filename - bt.line_number bt.start_char bt.end_char) diff --git a/compiler/ext/ext_obj.mli b/compiler/ext/ext_obj.mli index 3dc59084e8..5ec3864c07 100644 --- a/compiler/ext/ext_obj.mli +++ b/compiler/ext/ext_obj.mli @@ -22,5 +22,3 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) val dump : 'a -> string - -val bt : unit -> unit diff --git a/compiler/ext/ext_option.ml b/compiler/ext/ext_option.ml index 7e7e133a5a..35c88b3ac6 100644 --- a/compiler/ext/ext_option.ml +++ b/compiler/ext/ext_option.ml @@ -22,10 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let map v f = - match v with - | None -> None - | Some x -> Some (f x) +let map v f = Stdlib.Option.map f v let map_sharing v f = match v with @@ -34,10 +31,7 @@ let map_sharing v f = let x' = f x in if x' == x then v else Some x' -let iter v f = - match v with - | None -> () - | Some x -> f x +let iter v f = Stdlib.Option.iter f v let exists v f = match v with diff --git a/compiler/ext/ext_pervasives.mli b/compiler/ext/ext_pervasives.mli index 970898dc89..6a9d02a015 100644 --- a/compiler/ext/ext_pervasives.mli +++ b/compiler/ext/ext_pervasives.mli @@ -25,8 +25,6 @@ (** Extension to standard library [Pervavives] module, safe to open *) -external reraise : exn -> 'a = "%raise" - val finally : 'a -> clean:('a -> unit) -> ('a -> 'b) -> 'b (* val try_it : (unit -> 'a) -> unit *) diff --git a/compiler/ext/ext_pp_scope.ml b/compiler/ext/ext_pp_scope.ml index f074a411f0..8e4d9c949e 100644 --- a/compiler/ext/ext_pp_scope.ml +++ b/compiler/ext/ext_pp_scope.ml @@ -29,15 +29,6 @@ type t = int Map_int.t Map_string.t *) let empty : t = Map_string.empty -let rec print fmt v = - Format.fprintf fmt "@[{"; - Map_string.iter v (fun k m -> - Format.fprintf fmt "%s: @[%a@],@ " k print_int_map m); - Format.fprintf fmt "}@]" - -and print_int_map fmt m = - Map_int.iter m (fun k v -> Format.fprintf fmt "%d - %d" k v) - let add_ident ~mangled:name (stamp : int) (cxt : t) : int * t = match Map_string.find_opt cxt name with | None -> (0, Map_string.add cxt name (Map_int.add Map_int.empty stamp 0)) @@ -49,7 +40,7 @@ let add_ident ~mangled:name (stamp : int) (cxt : t) : int * t = | Some i -> (i, cxt)) (** - same as {!Js_dump.ident} except it generates a string instead of doing the printing + same as {!ident} except it generates a string instead of doing the printing For fast/debug mode, we can generate the name as [Printf.sprintf "%s$%d" name id.stamp] which is not relevant to the context @@ -62,8 +53,6 @@ let add_ident ~mangled:name (stamp : int) (cxt : t) : int * t = However, this means we loose the ability of dynamic loading, is it a big deal? we can fix this by a scanning first, since we already know which modules are global - - check [test/test_global_print.ml] for regression - collision It is obvious that for the same identifier that they print the same name. diff --git a/compiler/ext/ext_pp_scope.mli b/compiler/ext/ext_pp_scope.mli index 460a0354d3..2eae91087f 100644 --- a/compiler/ext/ext_pp_scope.mli +++ b/compiler/ext/ext_pp_scope.mli @@ -33,8 +33,6 @@ type t val empty : t -val print : Format.formatter -> t -> unit - val sub_scope : t -> Set_ident.t -> t val merge : t -> Set_ident.t -> t diff --git a/compiler/ext/ext_set.ml b/compiler/ext/ext_set.ml index f1b70d62e9..04a811cb44 100644 --- a/compiler/ext/ext_set.ml +++ b/compiler/ext/ext_set.ml @@ -27,7 +27,6 @@ module type OrderedType = sig val compare : t -> t -> int val equal : t -> t -> bool - val print : Format.formatter -> t -> unit end module Make (Elt : OrderedType) = struct @@ -35,7 +34,6 @@ module Make (Elt : OrderedType) = struct let compare_elt = Elt.compare let eq_elt = Elt.equal - let print_elt = Elt.print type 'a t0 = 'a Set_gen.t @@ -179,8 +177,6 @@ module Make (Elt : OrderedType) = struct else if c < 0 then Set_gen.bal (remove l x) v r else Set_gen.bal l v (remove r x) - (* let compare s1 s2 = Set_gen.compare ~cmp:compare_elt s1 s2 *) - let of_list l = match l with | [] -> empty @@ -198,10 +194,4 @@ module Make (Elt : OrderedType) = struct let invariant t = Set_gen.check t; Set_gen.is_ordered ~cmp:compare_elt t - - let print fmt s = - Format.fprintf fmt "@[{%a}@]@." - (fun fmt s -> - iter s (fun e -> Format.fprintf fmt "@[%a@],@ " print_elt e)) - s end diff --git a/compiler/ext/ext_set.mli b/compiler/ext/ext_set.mli index eca44b0e70..fcb00c6d4f 100644 --- a/compiler/ext/ext_set.mli +++ b/compiler/ext/ext_set.mli @@ -27,7 +27,6 @@ module type OrderedType = sig val compare : t -> t -> int val equal : t -> t -> bool - val print : Format.formatter -> t -> unit end module Make (Elt : OrderedType) : Set_gen.S with type elt = Elt.t diff --git a/compiler/ext/ext_string.ml b/compiler/ext/ext_string.ml index 4c62d2e8bf..7bbb7a49c4 100644 --- a/compiler/ext/ext_string.ml +++ b/compiler/ext/ext_string.ml @@ -100,9 +100,6 @@ let ends_with_then_chop s beg = (* let check_suffix_case = ends_with *) (* let check_suffix_case_then_chop = ends_with_then_chop *) -(* let check_any_suffix_case s suffixes = - Ext_list.exists suffixes (fun x -> check_suffix_case s x) *) - (* let check_any_suffix_case_then_chop s suffixes = let rec aux suffixes = match suffixes with @@ -132,14 +129,6 @@ let for_all s (p : char -> bool) = let is_empty s = String.length s = 0 -let repeat n s = - let len = String.length s in - let res = Bytes.create (n * len) in - for i = 0 to pred n do - String.blit s 0 res (i * len) len - done; - Bytes.to_string res - let unsafe_is_sub ~sub i s j ~len = let rec check k = if k = len then true @@ -217,40 +206,13 @@ let index_count s i c count = (* let index_next s i c = index_count s i c 1 *) -(* let extract_until s cursor c = - let len = String.length s in - let start = !cursor in - if start < 0 || start >= len then ( - cursor := -1; - "" - ) - else - let i = index_rec s len start c in - let finish = - if i < 0 then ( - cursor := -1 ; - len - ) - else ( - cursor := i + 1; - i - ) in - String.sub s start (finish - start) *) - let rec rindex_rec s i c = if i < 0 then i else if String.unsafe_get s i = c then i else rindex_rec s (i - 1) c -let rec rindex_rec_opt s i c = - if i < 0 then None - else if String.unsafe_get s i = c then Some i - else rindex_rec_opt s (i - 1) c - let rindex_neg s c = rindex_rec s (String.length s - 1) c -let rindex_opt s c = rindex_rec_opt s (String.length s - 1) c - (** TODO: can be improved to return a positive integer instead *) let rec unsafe_no_char x ch i last_idx = i > last_idx @@ -408,15 +370,8 @@ let capitalize_sub (s : string) len : string = let uncapitalize_ascii = String.uncapitalize_ascii -let lowercase_ascii = String.lowercase_ascii - external ( .![] ) : string -> int -> int = "%string_unsafe_get" -let unsafe_sub x offs len = - let b = Bytes.create len in - Ext_bytes.unsafe_blit_string x offs b 0 len; - Bytes.unsafe_to_string b - let is_valid_hash_number (x : string) = let len = String.length x in len > 0 diff --git a/compiler/ext/ext_string.mli b/compiler/ext/ext_string.mli index 4c568ac100..8af96a243f 100644 --- a/compiler/ext/ext_string.mli +++ b/compiler/ext/ext_string.mli @@ -36,12 +36,6 @@ val split : ?keep_empty:bool -> string -> char -> string list val starts_with : string -> string -> bool -val ends_with_index : string -> string -> int -(** - return [-1] when not found, the returned index is useful - see [ends_with_then_chop] -*) - val ends_with : string -> string -> bool val ends_with_then_chop : string -> string -> string option @@ -66,24 +60,8 @@ val for_all : string -> (char -> bool) -> bool val is_empty : string -> bool -val repeat : int -> string -> string - val equal : string -> string -> bool -(** - [extract_until s cursor sep] - When [sep] not found, the cursor is updated to -1, - otherwise cursor is increased to 1 + [sep_position] - User can not determine whether it is found or not by - telling the return string is empty since - "\n\n" would result in an empty string too. -*) -(* val extract_until: - string -> - int ref -> (* cursor to be updated *) - char -> - string *) - val index_count : string -> int -> char -> int -> int (* val index_next : @@ -112,8 +90,6 @@ val tail_from : string -> int -> string val rindex_neg : string -> char -> int (** returns negative number if not found *) -val rindex_opt : string -> char -> int option - val no_slash : string -> bool val no_slash_idx : string -> int @@ -134,7 +110,6 @@ val single_space : string val concat3 : string -> string -> string -> string val concat4 : string -> string -> string -> string -> string -val concat5 : string -> string -> string -> string -> string -> string val inter2 : string -> string -> string val inter3 : string -> string -> string -> string val inter4 : string -> string -> string -> string -> string @@ -148,10 +123,6 @@ val capitalize_sub : string -> int -> string val uncapitalize_ascii : string -> string -val lowercase_ascii : string -> string - -val unsafe_sub : string -> int -> int -> string - val is_valid_hash_number : string -> bool val hash_number_as_i32_exn : string -> int32 diff --git a/compiler/ext/hash.ml b/compiler/ext/hash.ml index 76e13b292c..26372cc723 100644 --- a/compiler/ext/hash.ml +++ b/compiler/ext/hash.ml @@ -37,7 +37,6 @@ module Make (Key : Hashtbl.HashedType) = struct let to_list = Hash_gen.to_list let fold = Hash_gen.fold let length = Hash_gen.length - (* let stats = Hash_gen.stats *) let add (h : _ t) key data = let i = key_index h key in diff --git a/compiler/ext/hash_set.ml b/compiler/ext/hash_set.ml index 7702476d5e..6947f58ed2 100644 --- a/compiler/ext/hash_set.ml +++ b/compiler/ext/hash_set.ml @@ -33,12 +33,10 @@ struct let clear = Hash_set_gen.clear let reset = Hash_set_gen.reset - (* let copy = Hash_set_gen.copy *) let iter = Hash_set_gen.iter let fold = Hash_set_gen.fold let length = Hash_set_gen.length - (* let stats = Hash_set_gen.stats *) let to_list = Hash_set_gen.to_list let remove (h : _ Hash_set_gen.t) key = diff --git a/compiler/ext/hash_set_ident_mask.mli b/compiler/ext/hash_set_ident_mask.mli index 1c5bb8f481..e691f9dcdc 100644 --- a/compiler/ext/hash_set_ident_mask.mli +++ b/compiler/ext/hash_set_ident_mask.mli @@ -11,7 +11,7 @@ val create : int -> t val add_unmask : t -> ident -> unit val mask_and_check_all_hit : t -> ident -> bool -(** [check_mask h key] if [key] exists mask it otherwise nothing +(** [mask_and_check_all_hit h key] if [key] exists mask it otherwise nothing return true if all keys are masked otherwise false *) diff --git a/compiler/ext/hash_set_poly.ml b/compiler/ext/hash_set_poly.ml deleted file mode 100644 index 441cc88056..0000000000 --- a/compiler/ext/hash_set_poly.ml +++ /dev/null @@ -1,58 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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. *) -let key_index (h : _ Hash_set_gen.t) (key : 'a) = - Hashtbl.hash key land (Array.length h.data - 1) -let eq_key = ( = ) -type 'a t = 'a Hash_set_gen.t - -let create = Hash_set_gen.create -let clear = Hash_set_gen.clear -let reset = Hash_set_gen.reset - -(* let copy = Hash_set_gen.copy *) -let iter = Hash_set_gen.iter -let length = Hash_set_gen.length - -(* let stats = Hash_set_gen.stats *) -let to_list = Hash_set_gen.to_list - -let remove (h : _ Hash_set_gen.t) key = - let i = key_index h key in - let h_data = h.data in - Hash_set_gen.remove_bucket h i key ~prec:Empty - (Array.unsafe_get h_data i) - eq_key - -let add (h : _ Hash_set_gen.t) key = - let i = key_index h key in - let h_data = h.data in - let old_bucket = Array.unsafe_get h_data i in - if not (Hash_set_gen.small_bucket_mem eq_key key old_bucket) then ( - Array.unsafe_set h_data i (Cons {key; next = old_bucket}); - h.size <- h.size + 1; - if h.size > Array.length h_data lsl 1 then Hash_set_gen.resize key_index h) - -let mem (h : _ Hash_set_gen.t) key = - Hash_set_gen.small_bucket_mem eq_key key - (Array.unsafe_get h.data (key_index h key)) diff --git a/compiler/ext/hash_set_poly.mli b/compiler/ext/hash_set_poly.mli deleted file mode 100644 index 1539d3f7bf..0000000000 --- a/compiler/ext/hash_set_poly.mli +++ /dev/null @@ -1,47 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * 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 'a t - -val create : int -> 'a t - -val clear : 'a t -> unit - -val reset : 'a t -> unit - -(* val copy : 'a t -> 'a t *) - -val add : 'a t -> 'a -> unit - -val remove : 'a t -> 'a -> unit - -val mem : 'a t -> 'a -> bool - -val iter : 'a t -> ('a -> unit) -> unit - -val to_list : 'a t -> 'a list - -val length : 'a t -> int - -(* val stats: 'a t -> Hashtbl.statistics *) diff --git a/compiler/ext/ident.mli b/compiler/ext/ident.mli index d73cff6f6e..b766729519 100644 --- a/compiler/ext/ident.mli +++ b/compiler/ext/ident.mli @@ -29,7 +29,6 @@ val create_persistent : string -> t val create_predef_exn : string -> t val rename : t -> t val name : t -> string -val unique_name : t -> string val unique_toplevel_name : t -> string val persistent : t -> bool val same : t -> t -> bool diff --git a/compiler/ext/identifiable.ml b/compiler/ext/identifiable.ml index bd6133c87e..807519ccb8 100644 --- a/compiler/ext/identifiable.ml +++ b/compiler/ext/identifiable.ml @@ -42,25 +42,9 @@ module type Map = sig val filter_map : (key -> 'a -> 'b option) -> 'a t -> 'b t val of_list : (key * 'a) list -> 'a t - val disjoint_union : - ?eq:('a -> 'a -> bool) -> - ?print:(Format.formatter -> 'a -> unit) -> - 'a t -> - 'a t -> - 'a t - - val union_right : 'a t -> 'a t -> 'a t - - val union_left : 'a t -> 'a t -> 'a t - - val union_merge : ('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t val rename : key t -> key -> key - val map_keys : (key -> key) -> 'a t -> 'a t val keys : 'a t -> Set.Make(T).t val data : 'a t -> 'a list - val of_set : (key -> 'a) -> Set.Make(T).t -> 'a t - val transpose_keys_and_data : key t -> key t - val transpose_keys_and_data_set : key t -> Set.Make(T).t t val print : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit end @@ -78,23 +62,9 @@ module type Tbl = sig val to_map : 'a t -> 'a Map.Make(T).t val of_map : 'a Map.Make(T).t -> 'a t - val memoize : 'a t -> (key -> 'a) -> key -> 'a val map : 'a t -> ('a -> 'b) -> 'b t end -module Pair (A : Thing) (B : Thing) : Thing with type t = A.t * B.t = struct - type t = A.t * B.t - - let compare (a1, b1) (a2, b2) = - let c = A.compare a1 a2 in - if c <> 0 then c else B.compare b1 b2 - - let output oc (a, b) = Printf.fprintf oc " (%a, %a)" A.output a B.output b - let hash (a, b) = Hashtbl.hash (A.hash a, B.hash b) - let equal (a1, b1) (a2, b2) = A.equal a1 a2 && B.equal b1 b2 - let print ppf (a, b) = Format.fprintf ppf " (%a, @ %a)" A.print a B.print b -end - module Make_map (T : Thing) = struct include Map.Make (T) @@ -108,48 +78,8 @@ module Make_map (T : Thing) = struct let of_list l = List.fold_left (fun map (id, v) -> add id v map) empty l - let disjoint_union ?eq ?print m1 m2 = - union - (fun id v1 v2 -> - let ok = - match eq with - | None -> false - | Some eq -> eq v1 v2 - in - if not ok then - let err = - match print with - | None -> Format.asprintf "Map.disjoint_union %a" T.print id - | Some print -> - Format.asprintf "Map.disjoint_union %a => %a <> %a" T.print id - print v1 print v2 - in - Misc.fatal_error err - else Some v1) - m1 m2 - - let union_right m1 m2 = - merge - (fun _id x y -> - match (x, y) with - | None, None -> None - | None, Some v | Some v, None | Some _, Some v -> Some v) - m1 m2 - - let union_left m1 m2 = union_right m2 m1 - - let union_merge f m1 m2 = - let aux _ m1 m2 = - match (m1, m2) with - | None, m | m, None -> m - | Some m1, Some m2 -> Some (f m1 m2) - in - merge aux m1 m2 - let rename m v = try find v m with Not_found -> v - let map_keys f m = of_list (List.map (fun (k, v) -> (f k, v)) (bindings m)) - let print f ppf s = let elts ppf s = iter (fun id v -> Format.fprintf ppf "@ (@[%a@ %a@])" T.print id f v) s @@ -161,20 +91,6 @@ module Make_map (T : Thing) = struct let keys map = fold (fun k _ set -> T_set.add k set) map T_set.empty let data t = List.map snd (bindings t) - - let of_set f set = T_set.fold (fun e map -> add e (f e) map) set empty - - let transpose_keys_and_data map = fold (fun k v m -> add v k m) map empty - let transpose_keys_and_data_set map = - fold - (fun k v m -> - let set = - match find v m with - | exception Not_found -> T_set.singleton k - | set -> T_set.add k set - in - add v set m) - map empty end module Make_set (T : Thing) = struct @@ -219,13 +135,6 @@ module Make_tbl (T : Thing) = struct T_map.iter (fun k v -> add t k v) m; t - let memoize t f key = - try find t key - with Not_found -> - let r = f key in - add t key r; - r - let map t f = of_map (T_map.map f (to_map t)) end diff --git a/compiler/ext/identifiable.mli b/compiler/ext/identifiable.mli index 9dd8defd9e..55ccbc7b3e 100644 --- a/compiler/ext/identifiable.mli +++ b/compiler/ext/identifiable.mli @@ -26,8 +26,6 @@ module type Thing = sig val print : Format.formatter -> t -> unit end -module Pair : functor (A : Thing) (B : Thing) -> Thing with type t = A.t * B.t - module type Set = sig module T : Set.OrderedType include Set.S with type elt = T.t and type t = Set.Make(T).t @@ -46,31 +44,9 @@ module type Map = sig val filter_map : (key -> 'a -> 'b option) -> 'a t -> 'b t val of_list : (key * 'a) list -> 'a t - val disjoint_union : - ?eq:('a -> 'a -> bool) -> - ?print:(Format.formatter -> 'a -> unit) -> - 'a t -> - 'a t -> - 'a t - (** [disjoint_union m1 m2] contains all bindings from [m1] and - [m2]. If some binding is present in both and the associated - value is not equal, a Fatal_error is raised *) - - val union_right : 'a t -> 'a t -> 'a t - (** [union_right m1 m2] contains all bindings from [m1] and [m2]. If - some binding is present in both, the one from [m2] is taken *) - - val union_left : 'a t -> 'a t -> 'a t - (** [union_left m1 m2 = union_right m2 m1] *) - - val union_merge : ('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t val rename : key t -> key -> key - val map_keys : (key -> key) -> 'a t -> 'a t val keys : 'a t -> Set.Make(T).t val data : 'a t -> 'a list - val of_set : (key -> 'a) -> Set.Make(T).t -> 'a t - val transpose_keys_and_data : key t -> key t - val transpose_keys_and_data_set : key t -> Set.Make(T).t t val print : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit end @@ -88,7 +64,6 @@ module type Tbl = sig val to_map : 'a t -> 'a Map.Make(T).t val of_map : 'a Map.Make(T).t -> 'a t - val memoize : 'a t -> (key -> 'a) -> key -> 'a val map : 'a t -> ('a -> 'b) -> 'b t end diff --git a/compiler/ext/literals.ml b/compiler/ext/literals.ml index 9f6e9ce70e..d0863677e1 100644 --- a/compiler/ext/literals.ml +++ b/compiler/ext/literals.ml @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let js_array_ctor = "Array" - let js_type_number = "number" let js_type_string = "string" @@ -32,89 +30,26 @@ let js_type_object = "object" let js_type_boolean = "boolean" -let js_undefined = "undefined" - -let js_prop_length = "length" - -let prim = "prim" - -let param = "param" - -let partial_arg = "partial_arg" - let tmp = "tmp" -let create = "create" (* {!Caml_exceptions.create}*) - -let runtime = "runtime" (* runtime directory *) - -let stdlib = "stdlib" - -let debugger = "debugger" - -let fn_run = "fn_run" - -let method_run = "method_run" - -let fn_method = "fn_method" - -let fn_mk = "fn_mk" -(*let js_fn_runmethod = "js_fn_runmethod"*) - -(** nodejs *) -let node_modules = "node_modules" - -let node_modules_length = String.length "node_modules" - -let package_json = "package.json" - -(* Name of the library file created for each external dependency. *) -let library_file = "lib" - -let suffix_a = ".a" +let create = "create" (* {!Primitive_exceptions.create}*) let suffix_cmj = ".cmj" -let suffix_cmo = ".cmo" - -let suffix_cma = ".cma" - let suffix_cmi = ".cmi" -let suffix_cmx = ".cmx" - -let suffix_cmxa = ".cmxa" - -let suffix_mll = ".mll" - let suffix_res = ".res" let suffix_resi = ".resi" let suffix_mlmap = ".mlmap" -let suffix_cmt = ".cmt" - -let suffix_cmti = ".cmti" - let suffix_ast = ".ast" let suffix_iast = ".iast" -let suffix_d = ".d" - let suffix_js = ".js" -let suffix_gen_js = ".gen.js" - -let suffix_gen_tsx = ".gen.tsx" - -let esmodule = "esmodule" - -let commonjs = "commonjs" - -let unused_attribute = "Unused attribute " - (** Used when produce node compatible paths *) let node_sep = "/" @@ -125,8 +60,6 @@ let node_current = "." let gentype_import1 = "genType.import" let gentype_import2 = "gentype.import" -let sourcedirs_meta = ".sourcedirs.json" - (* Note the build system should check the validity of filenames espeically, it should not contain '-' *) diff --git a/compiler/ext/map_gen.ml b/compiler/ext/map_gen.ml index 8e4597a922..a8c73b7290 100644 --- a/compiler/ext/map_gen.ml +++ b/compiler/ext/map_gen.ml @@ -184,28 +184,6 @@ let[@inline] is_empty = function | Empty -> true | _ -> false -let rec min_binding_exn = function - | Empty -> raise Not_found - | Leaf {k; v} -> (k, v) - | Node {l; k; v} -> ( - match l with - | Empty -> (k, v) - | Leaf _ | Node _ -> min_binding_exn l) - -let rec remove_min_binding = function - | Empty -> invalid_arg "Map.remove_min_elt" - | Leaf _ -> empty - | Node {l = Empty; r} -> r - | Node {l; k; v; r} -> bal (remove_min_binding l) k v r - -let merge t1 t2 = - match (t1, t2) with - | Empty, t -> t - | t, Empty -> t - | _, _ -> - let x, d = min_binding_exn t2 in - bal t1 x d (remove_min_binding t2) - let rec iter x f = match x with | Empty -> () @@ -269,18 +247,6 @@ let rec join l v d r = else if rh > lh + 2 then bal (join l v d xr.l) xr.k xr.v xr.r else unsafe_node v d l r (calc_height lh rh)) -(* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. *) - -let concat t1 t2 = - match (t1, t2) with - | Empty, t -> t - | t, Empty -> t - | _, _ -> - let x, d = min_binding_exn t2 in - join t1 x d (remove_min_binding t2) - module type S = sig type key @@ -309,10 +275,6 @@ module type S = sig val singleton : key -> 'a -> 'a t - val remove : 'a t -> key -> 'a t - (** [remove x m] returns a map containing the same bindings as - [m], except for [x] which is unbound in the returned map. *) - (* val merge: 'a t -> 'b t -> (key -> 'a option -> 'b option -> 'c option) -> 'c t *) @@ -402,6 +364,4 @@ module type S = sig val of_list : (key * 'a) list -> 'a t val of_array : (key * 'a) array -> 'a t - - val add_list : (key * 'b) list -> 'b t -> 'b t end diff --git a/compiler/ext/map_gen.mli b/compiler/ext/map_gen.mli index dbed5417c0..ded8acb023 100644 --- a/compiler/ext/map_gen.mli +++ b/compiler/ext/map_gen.mli @@ -7,10 +7,6 @@ val cardinal : ('a, 'b) t -> int val bindings : ('a, 'b) t -> ('a * 'b) list -val fill_array_with_f : ('a, 'b) t -> int -> 'c array -> ('a -> 'b -> 'c) -> int - -val fill_array_aux : ('a, 'b) t -> int -> ('a * 'b) array -> int - val to_sorted_array : ('key, 'a) t -> ('key * 'a) array val to_sorted_array_with_f : ('a, 'b) t -> ('a -> 'b -> 'c) -> 'c array @@ -32,8 +28,6 @@ val empty : ('a, 'b) t val is_empty : ('a, 'b) t -> bool -val merge : ('a, 'b) t -> ('a, 'b) t -> ('a, 'b) t - val iter : ('a, 'b) t -> ('a -> 'b -> unit) -> unit val map : ('a, 'b) t -> ('b -> 'c) -> ('a, 'c) t @@ -48,8 +42,6 @@ val exists : ('a, 'b) t -> ('a -> 'b -> bool) -> bool val join : ('a, 'b) t -> 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t -val concat : ('a, 'b) t -> ('a, 'b) t -> ('a, 'b) t - module type S = sig type key @@ -73,8 +65,6 @@ module type S = sig val singleton : key -> 'a -> 'a t - val remove : 'a t -> key -> 'a t - (* val merge : 'a t -> 'b t -> (key -> 'a option -> 'b option -> 'c option) -> 'c t *) val disjoint_merge_exn : 'a t -> 'a t -> (key -> 'a -> 'a -> exn) -> 'a t @@ -109,6 +99,4 @@ module type S = sig val of_list : (key * 'a) list -> 'a t val of_array : (key * 'a) array -> 'a t - - val add_list : (key * 'b) list -> 'b t -> 'b t end diff --git a/compiler/ext/misc.ml b/compiler/ext/misc.ml index ce5dcc1207..572fd07899 100644 --- a/compiler/ext/misc.ml +++ b/compiler/ext/misc.ml @@ -54,32 +54,9 @@ let rec map_end f l1 l2 = | [] -> l2 | hd :: tl -> f hd :: map_end f tl l2 -let rec map_left_right f = function - | [] -> [] - | hd :: tl -> - let res = f hd in - res :: map_left_right f tl - -let rec for_all2 pred l1 l2 = - match (l1, l2) with - | [], [] -> true - | hd1 :: tl1, hd2 :: tl2 -> pred hd1 hd2 && for_all2 pred tl1 tl2 - | _, _ -> false - let rec replicate_list elem n = if n <= 0 then [] else elem :: replicate_list elem (n - 1) -let rec list_remove x = function - | [] -> [] - | hd :: tl -> if hd = x then tl else hd :: list_remove x tl - -let rec split_last = function - | [] -> assert false - | [x] -> ([], x) - | hd :: tl -> - let lst, last = split_last tl in - (hd :: lst, last) - let may = Stdlib.Option.iter let may_map = Stdlib.Option.map @@ -130,68 +107,31 @@ let output_to_bin_file_directly filename fn = close_out oc; raise e -let output_to_file_via_temporary ?(mode = [Open_text]) filename fn = - let temp_filename, oc = - Filename.open_temp_file ~mode ~perms:0o666 - ~temp_dir:(Filename.dirname filename) - (Filename.basename filename) - ".tmp" - in - (* The 0o666 permissions will be modified by the umask. It's just - like what [open_out] and [open_out_bin] do. - With temp_dir = dirname filename, we ensure that the returned - temp file is in the same directory as filename itself, making - it safe to rename temp_filename to filename later. - With prefix = basename filename, we are almost certain that - the first generated name will be unique. A fixed prefix - would work too but might generate more collisions if many - files are being produced simultaneously in the same directory. *) - match fn temp_filename oc with - | res -> ( - close_out oc; - try - Sys.rename temp_filename filename; - res - with exn -> - remove_file temp_filename; - raise exn) - | exception exn -> - close_out oc; - remove_file temp_filename; - raise exn - (* Integer operations *) -let rec log2 n = if n <= 1 then 0 else 1 + log2 (n asr 1) - module Int_literal_converter = struct (* To convert integer literals, allowing max_int + 1 (PR#4210) *) let cvt_int_aux str neg of_string = if String.length str = 0 || str.[0] = '-' then of_string str else neg (of_string ("-" ^ str)) let int s = cvt_int_aux s ( ~- ) int_of_string - let int32 s = cvt_int_aux s Int32.neg Int32.of_string - let int64 s = cvt_int_aux s Int64.neg Int64.of_string end -(* String operations *) - -let chop_extensions file = - let dirname = Filename.dirname file and basename = Filename.basename file in - try - let pos = String.index basename '.' in - let basename = String.sub basename 0 pos in - if Filename.is_implicit file && dirname = Filename.current_dir_name then - basename - else Filename.concat dirname basename - with Not_found -> file - let get_ref r = let v = !r in r := []; v -let fst3 (x, _, _) = x +(** [edit_distance a b cutoff] computes the edit distance between + strings [a] and [b]. To help efficiency, it uses a cutoff: if the + distance [d] is smaller than [cutoff], it returns [Some d], else + [None]. + + The distance algorithm currently used is Damerau-Levenshtein: it + computes the number of insertion, deletion, substitution of + letters, or swapping of adjacent letters to go from one word to the + other. The particular algorithm may change in the future. +*) let edit_distance a b cutoff = let la, lb = (String.length a, String.length b) in let cutoff = @@ -265,7 +205,7 @@ let did_you_mean ppf get_choices = match get_choices () with | [] -> () | choices -> - let rest, last = split_last choices in + let rest, last = Ext_list.split_at_last choices in Format.fprintf ppf "@\nHint: Did you mean %s%s%s?@?" (String.concat ", " rest) (if rest = [] then "" else " or ") diff --git a/compiler/ext/misc.mli b/compiler/ext/misc.mli index b054fb380d..b9da827cad 100644 --- a/compiler/ext/misc.mli +++ b/compiler/ext/misc.mli @@ -23,25 +23,10 @@ val try_finally : (unit -> 'a) -> (unit -> unit) -> 'a val map_end : ('a -> 'b) -> 'a list -> 'b list -> 'b list (* [map_end f l t] is [map f l @ t], just more efficient. *) -val map_left_right : ('a -> 'b) -> 'a list -> 'b list -(* Like [List.map], with guaranteed left-to-right evaluation order *) - -val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool -(* Same as [List.for_all] but for a binary predicate. - In addition, this [for_all2] never fails: given two lists - with different lengths, it returns false. *) - val replicate_list : 'a -> int -> 'a list (* [replicate_list elem n] is the list with [n] elements all identical to [elem]. *) -val list_remove : 'a -> 'a list -> 'a list -(* [list_remove x l] returns a copy of [l] with the first - element equal to [x] removed. *) - -val split_last : 'a list -> 'a list * 'a -(* Return the last element and the other elements of the given list. *) - val may : ('a -> unit) -> 'a option -> unit val may_map : ('a -> 'b) -> 'a option -> 'b option @@ -70,50 +55,14 @@ val create_hashtable : ('a * 'b) array -> ('a, 'b) Hashtbl.t val output_to_bin_file_directly : string -> (string -> out_channel -> 'a) -> 'a -val output_to_file_via_temporary : - ?mode:open_flag list -> string -> (string -> out_channel -> 'a) -> 'a -(* Produce output in temporary file, then rename it - (as atomically as possible) to the desired output file name. - [output_to_file_via_temporary filename fn] opens a temporary file - which is passed to [fn] (name + output channel). When [fn] returns, - the channel is closed and the temporary file is renamed to - [filename]. *) - -val log2 : int -> int -(* [log2 n] returns [s] such that [n = 1 lsl s] - if [n] is a power of 2*) - module Int_literal_converter : sig val int : string -> int - val int32 : string -> int32 - val int64 : string -> int64 end -val chop_extensions : string -> string -(* Return the given file name without its extensions. The extensions - is the longest suffix starting with a period and not including - a directory separator, [.xyz.uvw] for instance. - - Return the given name if it does not contain an extension. *) - val get_ref : 'a list ref -> 'a list (* [get_ref lr] returns the content of the list reference [lr] and reset its content to the empty list. *) -val fst3 : 'a * 'b * 'c -> 'a - -val edit_distance : string -> string -> int -> int option -(** [edit_distance a b cutoff] computes the edit distance between - strings [a] and [b]. To help efficiency, it uses a cutoff: if the - distance [d] is smaller than [cutoff], it returns [Some d], else - [None]. - - The distance algorithm currently used is Damerau-Levenshtein: it - computes the number of insertion, deletion, substitution of - letters, or swapping of adjacent letters to go from one word to the - other. The particular algorithm may change in the future. -*) - val spellcheck : string list -> string -> string list (** [spellcheck env name] takes a list of names [env] that exist in the current environment and an erroneous [name], and returns a diff --git a/compiler/ext/ordered_hash_map.ml b/compiler/ext/ordered_hash_map.ml index 9b7440447b..8a053ddb31 100644 --- a/compiler/ext/ordered_hash_map.ml +++ b/compiler/ext/ordered_hash_map.ml @@ -32,15 +32,10 @@ module Make (H : Hashtbl.HashedType) : open Ordered_hash_map_gen let create = create - let clear = clear - let reset = reset let iter = iter - let fold = fold let length = length - let elements = elements - let choose = choose let to_sorted_array = to_sorted_array let rec small_bucket_mem key lst = @@ -99,8 +94,6 @@ module Make (H : Hashtbl.HashedType) : h.size <- h.size + 1; if h.size > Array.length h.data lsl 1 then resize key_index h) - let mem h key = - small_bucket_mem key (Array.unsafe_get h.data (key_index h key)) let rank h key = small_bucket_rank key (Array.unsafe_get h.data (key_index h key)) diff --git a/compiler/ext/ordered_hash_map_gen.ml b/compiler/ext/ordered_hash_map_gen.ml index b85ce6e96b..4ae5d30506 100644 --- a/compiler/ext/ordered_hash_map_gen.ml +++ b/compiler/ext/ordered_hash_map_gen.ml @@ -33,28 +33,16 @@ module type S = sig val create : int -> 'value t - val clear : 'vaulue t -> unit - - val reset : 'value t -> unit - val add : 'value t -> key -> 'value -> unit - val mem : 'value t -> key -> bool - val rank : 'value t -> key -> int (* -1 if not found*) val find_value : 'value t -> key -> 'value (* raise if not found*) val iter : 'value t -> (key -> 'value -> int -> unit) -> unit - val fold : 'value t -> 'b -> (key -> 'value -> int -> 'b -> 'b) -> 'b - val length : 'value t -> int - val elements : 'value t -> key list - - val choose : 'value t -> key - val to_sorted_array : 'value t -> key array end @@ -67,25 +55,12 @@ type ('a, 'b) bucket = type ('a, 'b) t = { mutable size: int; (* number of entries *) - mutable data: ('a, 'b) bucket array; - (* the buckets *) - initial_size: int; (* initial array size *) + mutable data: ('a, 'b) bucket array; (* the buckets *) } let create initial_size = let s = Ext_util.power_2_above 16 initial_size in - {initial_size = s; size = 0; data = Array.make s Empty} - -let clear h = - h.size <- 0; - let len = Array.length h.data in - for i = 0 to len - 1 do - Array.unsafe_set h.data i Empty - done - -let reset h = - h.size <- 0; - h.data <- Array.make h.initial_size Empty + {size = 0; data = Array.make s Empty} let length h = h.size @@ -138,23 +113,3 @@ let to_sorted_array h = let arr = Array.make h.size v in iter h (fun k _ i -> Array.unsafe_set arr i k); arr - -let fold h init f = - let rec do_bucket b accu = - match b with - | Empty -> accu - | Cons {key; ord; data; next} -> do_bucket next (f key data ord accu) - in - let d = h.data in - let accu = ref init in - for i = 0 to Array.length d - 1 do - accu := do_bucket (Array.unsafe_get d i) !accu - done; - !accu - -let elements set = fold set [] (fun k _ _ acc -> k :: acc) - -let rec bucket_length acc (x : _ bucket) = - match x with - | Empty -> 0 - | Cons rhs -> bucket_length (acc + 1) rhs.next diff --git a/compiler/ext/set_gen.ml b/compiler/ext/set_gen.ml index 0fd5e66f41..74892686b6 100644 --- a/compiler/ext/set_gen.ml +++ b/compiler/ext/set_gen.ml @@ -250,20 +250,6 @@ let internal_concat t1 t2 = | t, Empty -> t | _, _ -> internal_join t1 (min_exn t2) (remove_min_elt t2) -let rec partition x p = - match x with - | Empty -> (empty, empty) - | Leaf v -> - let pv = p v in - if pv then (x, empty) else (empty, x) - | Node {l; v; r} -> - (* call [p] in the expected left-to-right order *) - let lt, lf = partition l p in - let pv = p v in - let rt, rf = partition r p in - if pv then (internal_join lt v rt, internal_concat lf rf) - else (internal_concat lt rt, internal_join lf v rf) - let of_sorted_array l = let rec sub start n l = if n = 0 then empty @@ -311,10 +297,6 @@ let is_ordered ~cmp tree = in is_ordered_min_max tree <> `No -let invariant ~cmp t = - check t; - is_ordered ~cmp t - module type S = sig type elt @@ -357,6 +339,4 @@ module type S = sig val of_sorted_array : elt array -> t val invariant : t -> bool - - val print : Format.formatter -> t -> unit end diff --git a/compiler/ext/set_gen.mli b/compiler/ext/set_gen.mli index f3f39f0191..cdd9247541 100644 --- a/compiler/ext/set_gen.mli +++ b/compiler/ext/set_gen.mli @@ -27,8 +27,6 @@ val check : 'a t -> unit val bal : 'a t -> 'a -> 'a t -> 'a t -val remove_min_elt : 'a t -> 'a t - val singleton : 'a -> 'a t val internal_merge : 'a t -> 'a t -> 'a t @@ -37,14 +35,10 @@ val internal_join : 'a t -> 'a -> 'a t -> 'a t val internal_concat : 'a t -> 'a t -> 'a t -val partition : 'a t -> ('a -> bool) -> 'a t * 'a t - val of_sorted_array : 'a array -> 'a t val is_ordered : cmp:('a -> 'a -> int) -> 'a t -> bool -val invariant : cmp:('a -> 'a -> int) -> 'a t -> bool - module type S = sig type elt @@ -87,6 +81,4 @@ module type S = sig val of_sorted_array : elt array -> t val invariant : t -> bool - - val print : Format.formatter -> t -> unit end diff --git a/compiler/ext/set_ident.ml b/compiler/ext/set_ident.ml index bf75cd3be4..483e0ab6bc 100644 --- a/compiler/ext/set_ident.ml +++ b/compiler/ext/set_ident.ml @@ -33,5 +33,4 @@ include Ext_set.Make (struct if name <> 0 then name else Stdlib.compare x.flags y.flags let equal = Ident.same - let print = Ident.print end) diff --git a/compiler/ext/set_int.ml b/compiler/ext/set_int.ml index bd10d7c6b8..91505b5c32 100644 --- a/compiler/ext/set_int.ml +++ b/compiler/ext/set_int.ml @@ -27,5 +27,4 @@ include Ext_set.Make (struct let compare = Ext_int.compare let equal = Ext_int.equal - let print = Format.pp_print_int end) diff --git a/compiler/ext/set_string.ml b/compiler/ext/set_string.ml index be1d2d1fb3..ef7f66fcbf 100644 --- a/compiler/ext/set_string.ml +++ b/compiler/ext/set_string.ml @@ -27,5 +27,4 @@ include Ext_set.Make (struct let compare = Ext_string.compare let equal = Ext_string.equal - let print = Format.pp_print_string end) diff --git a/compiler/ext/warnings.mli b/compiler/ext/warnings.mli index 7a34634e58..0d71b855b5 100644 --- a/compiler/ext/warnings.mli +++ b/compiler/ext/warnings.mli @@ -76,8 +76,6 @@ val without_warnings : (unit -> 'a) -> 'a val is_active : t -> bool -val is_error : t -> bool - type reporting_information = { number: int; message: string; @@ -103,8 +101,6 @@ val restore : state -> unit val has_warnings : bool ref -val nerrors : int ref - val message : t -> string val number : t -> int diff --git a/compiler/frontend/ast_external_process.ml b/compiler/frontend/ast_external_process.ml index 4c7ec8fc47..c7e04abbce 100644 --- a/compiler/frontend/ast_external_process.ml +++ b/compiler/frontend/ast_external_process.ml @@ -889,7 +889,7 @@ let external_decl_of_non_obj (loc : Location.t) (st : external_desc) Location.raise_errorf ~loc "Attribute found that conflicts with %@get" (** Note that the passed [type_annotation] is already processed by visitor pattern before*) -let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type) +let handle_attributes (loc : Location.t) (type_annotation : Parsetree.core_type) (prim_attributes : Ast_attributes.t) (prim_name : string) : Parsetree.core_type * External_ffi_types.t * Parsetree.attributes * bool = let prim_name_with_source = {name = prim_name; source = External} in diff --git a/compiler/frontend/ast_external_process.mli b/compiler/frontend/ast_external_process.mli index 33a1a5a5fd..7c564d4257 100644 --- a/compiler/frontend/ast_external_process.mli +++ b/compiler/frontend/ast_external_process.mli @@ -30,7 +30,7 @@ type response = { } val handle_attributes_as_prim : - Bs_loc.t -> Ast_core_type.t -> Ast_attributes.t -> string -> response + Location.t -> Ast_core_type.t -> Ast_attributes.t -> string -> response (** [handle_attributes_as_prim loc pval_name.txt pval_type pval_attributes pval_prim] diff --git a/compiler/ml/annot.ml b/compiler/ml/annot.ml deleted file mode 100644 index 13a586592e..0000000000 --- a/compiler/ml/annot.ml +++ /dev/null @@ -1,23 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Damien Doligez, projet Gallium, INRIA Rocquencourt *) -(* *) -(* Copyright 2007 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(* Data types for annotations (Stypes.ml) *) - -type call = Tail | Stack | Inline - -type ident = - | Iref_internal of Location.t (* defining occurrence *) - | Iref_external - | Idef of Location.t (* scope *) diff --git a/compiler/ml/ast_helper.ml b/compiler/ml/ast_helper.ml index 972fcb6da9..5aebf79cf2 100644 --- a/compiler/ml/ast_helper.ml +++ b/compiler/ml/ast_helper.ml @@ -23,25 +23,14 @@ type str = string loc type loc = Location.t type attrs = attribute list +(** Default value for all optional location arguments. *) let default_loc = ref Location.none -let with_default_loc l f = - let old = !default_loc in - default_loc := l; - try - let r = f () in - default_loc := old; - r - with exn -> - default_loc := old; - raise exn - module Const = struct let integer ?suffix i = Pconst_integer (i, suffix) let int ?suffix i = integer ?suffix (string_of_int i) let int32 ?(suffix = 'l') i = integer ~suffix (Int32.to_string i) let int64 ?(suffix = 'L') i = integer ~suffix (Int64.to_string i) - let nativeint ?(suffix = 'n') i = integer ~suffix (Nativeint.to_string i) let float ?suffix f = Pconst_float (f, suffix) let char c = let semantic = Char.code c in diff --git a/compiler/ml/ast_helper.mli b/compiler/ml/ast_helper.mli index 072f3d2863..f6cf03d3e7 100644 --- a/compiler/ml/ast_helper.mli +++ b/compiler/ml/ast_helper.mli @@ -25,13 +25,6 @@ type attrs = attribute list (** {1 Default locations} *) -val default_loc : loc ref -(** Default value for all optional location arguments. *) - -val with_default_loc : loc -> (unit -> 'a) -> 'a -(** Set the [default_loc] within the scope of the execution - of the provided function. *) - (** {1 Constants} *) module Const : sig @@ -41,7 +34,6 @@ module Const : sig val int : ?suffix:char -> int -> constant val int32 : ?suffix:char -> int32 -> constant val int64 : ?suffix:char -> int64 -> constant - val nativeint : ?suffix:char -> nativeint -> constant val float : ?suffix:char -> string -> constant end diff --git a/compiler/ml/ast_helper0.ml b/compiler/ml/ast_helper0.ml index cc008b3d51..5cdfcb5bc9 100644 --- a/compiler/ml/ast_helper0.ml +++ b/compiler/ml/ast_helper0.ml @@ -25,17 +25,6 @@ type attrs = attribute list let default_loc = ref Location.none -let with_default_loc l f = - let old = !default_loc in - default_loc := l; - try - let r = f () in - default_loc := old; - r - with exn -> - default_loc := old; - raise exn - module Const = struct let integer ?suffix i = Pconst_integer (i, suffix) let int ?suffix i = integer ?suffix (string_of_int i) diff --git a/compiler/ml/ast_mapper.ml b/compiler/ml/ast_mapper.ml index 5922b60fd7..a8b4da96b8 100644 --- a/compiler/ml/ast_mapper.ml +++ b/compiler/ml/ast_mapper.ml @@ -599,10 +599,6 @@ end) let cookies = ref String_map.empty -let tool_name_ref = ref "_none_" - -let tool_name () = !tool_name_ref - module Ppx_context = struct open Longident open Asttypes @@ -721,7 +717,6 @@ module Ppx_context = struct name in match name with - | "tool_name" -> tool_name_ref := get_string payload | "include_dirs" -> Clflags.include_dirs := get_list get_string payload | "load_path" -> Config.load_path := get_list get_string payload | "open_modules" -> Clflags.open_modules := get_list get_string payload @@ -739,99 +734,10 @@ module Ppx_context = struct | {lid = {txt = Lident name}; x} -> field name x | _ -> ()) fields - - let update_cookies fields = - let fields = - Ext_list.filter fields (function - | {lid = {txt = Lident "cookies"}} -> false - | _ -> true) - in - fields @ [get_cookies ()] end let ppx_context = Ppx_context.make -let extension_of_exn exn = - match error_of_exn exn with - | Some (`Ok error) -> extension_of_error error - | Some `Already_displayed -> - ({loc = Location.none; txt = "ocaml.error"}, PStr []) - | None -> raise exn - -let apply_lazy ~source ~target mapper = - let implem ast = - let fields, ast = - match ast with - | {pstr_desc = Pstr_attribute ({txt = "ocaml.ppx.context"}, x)} :: l -> - (Ppx_context.get_fields x, l) - | _ -> ([], ast) - in - Ppx_context.restore fields; - let ast = - try - let mapper = mapper () in - mapper.structure mapper ast - with exn -> - [ - { - pstr_desc = Pstr_extension (extension_of_exn exn, []); - pstr_loc = Location.none; - }; - ] - in - let fields = Ppx_context.update_cookies fields in - Str.attribute (Ppx_context.mk fields) :: ast - in - let iface ast = - let fields, ast = - match ast with - | {psig_desc = Psig_attribute ({txt = "ocaml.ppx.context"}, x)} :: l -> - (Ppx_context.get_fields x, l) - | _ -> ([], ast) - in - Ppx_context.restore fields; - let ast = - try - let mapper = mapper () in - mapper.signature mapper ast - with exn -> - [ - { - psig_desc = Psig_extension (extension_of_exn exn, []); - psig_loc = Location.none; - }; - ] - in - let fields = Ppx_context.update_cookies fields in - Sig.attribute (Ppx_context.mk fields) :: ast - in - - let ic = open_in_bin source in - let magic = - really_input_string ic (String.length Config.ast_impl_magic_number) - in - - let rewrite transform = - Location.set_input_name @@ input_value ic; - let ast = input_value ic in - close_in ic; - let ast = transform ast in - let oc = open_out_bin target in - output_string oc magic; - output_value oc !Location.input_name; - output_value oc ast; - close_out oc - and fail () = - close_in ic; - failwith "Ast_mapper: OCaml version mismatch or malformed input" - in - - if magic = Config.ast_impl_magic_number then - rewrite (implem : structure -> structure) - else if magic = Config.ast_intf_magic_number then - rewrite (iface : signature -> signature) - else fail () - let drop_ppx_context_str ~restore = function | {pstr_desc = Pstr_attribute ({Location.txt = "ocaml.ppx.context"}, a)} :: items -> @@ -851,29 +757,3 @@ let add_ppx_context_str ~tool_name ast = let add_ppx_context_sig ~tool_name ast = Ast_helper.Sig.attribute (ppx_context ~tool_name ()) :: ast - -let apply ~source ~target mapper = apply_lazy ~source ~target (fun () -> mapper) - -let run_main mapper = - try - let a = Sys.argv in - let n = Array.length a in - if n > 2 then - let mapper () = - try mapper (Array.to_list (Array.sub a 1 (n - 3))) - with exn -> - (* PR#6463 *) - let f _ _ = raise exn in - {default_mapper with structure = f; signature = f} - in - apply_lazy ~source:a.(n - 2) ~target:a.(n - 1) mapper - else ( - Printf.eprintf "Usage: %s [extra_args] \n%!" - Sys.executable_name; - exit 2) - with exn -> - prerr_endline (Printexc.to_string exn); - exit 2 - -let register_function = ref (fun _name f -> run_main f) -let register name f = !register_function name f diff --git a/compiler/ml/ast_mapper.mli b/compiler/ml/ast_mapper.mli index 49bdde1d7e..887c9b4049 100644 --- a/compiler/ml/ast_mapper.mli +++ b/compiler/ml/ast_mapper.mli @@ -13,39 +13,39 @@ (* *) (**************************************************************************) -(** The interface of a -ppx rewriter +(** Parsetree mappers - A -ppx rewriter is a program that accepts a serialized abstract syntax - tree and outputs another, possibly modified, abstract syntax tree. - This module encapsulates the interface between the compiler and - the -ppx rewriters, handling such details as the serialization format, - forwarding of command-line flags, and storing state. - - {!mapper} allows to implement AST rewriting using open recursion. - A typical mapper would be based on {!default_mapper}, a deep - identity mapper, and will fall back on it for handling the syntax it - does not modify. For example: + {!mapper} implements AST rewriting using open recursion. A typical + mapper is based on {!default_mapper}, a deep identity mapper, and + falls back on it for the syntax it does not modify. For example: {[ -open Asttypes open Parsetree open Ast_mapper -let test_mapper argv = +let test_mapper = { default_mapper with expr = fun mapper expr -> match expr with | { pexp_desc = Pexp_extension ({ txt = "test" }, PStr [])} -> - Ast_helper.Exp.constant (Const_int 42) + Ast_helper.Exp.constant (Ast_helper.Const.int 42) | other -> default_mapper.expr mapper other; } -let () = - register "ppx_test" test_mapper]} - - This -ppx rewriter, which replaces [[%test]] in expressions with - the constant [42], can be compiled using - [ocamlc -o ppx_test -I +compiler-libs ocamlcommon.cma ppx_test.ml]. - +let rewrite (str : structure) = test_mapper.structure test_mapper str]} + + This mapper replaces [[%test]] in expressions with the constant [42]. + The compiler's built-in rewriters ({!Bs_builtin_ppx}, {!Jsx_ppx}) are + mappers of this kind and run inside [bsc]. + + External rewriters passed to [bsc] with [-ppx] are separate + executables. {!Cmd_ppx_apply} prepends the [ocaml.ppx.context] + attribute ({!add_ppx_context_str}, {!add_ppx_context_sig}), writes the + AST to a temporary file as the magic number of {!Ml_binary}, the + source file name and the marshalled {!Parsetree0} structure or + signature, and runs [ppx input output]. The executable writes its + result to [output] in the same format; {!Cmd_ppx_apply} reads it back, + converts it to {!Parsetree}, and removes the context attribute + ({!drop_ppx_context_str}, {!drop_ppx_context_sig}). *) open Parsetree @@ -96,55 +96,8 @@ type mapper = { val default_mapper : mapper (** A default mapper, which implements a "deep identity" mapping. *) -(** {1 Apply mappers to compilation units} *) - -val tool_name : unit -> string -(** Can be used within a ppx preprocessor to know which tool is - calling it ["ocamlc"], ["ocamlopt"], ["ocamldoc"], ["ocamldep"], - ["ocaml"], ... Some global variables that reflect command-line - options are automatically synchronized between the calling tool - and the ppx preprocessor: {!Clflags.include_dirs}, - {!Config.load_path}, {!Clflags.open_modules}, {!Clflags.for_package}, - {!Clflags.debug}. *) - -val apply : source:string -> target:string -> mapper -> unit -(** Apply a mapper (parametrized by the unit name) to a dumped - parsetree found in the [source] file and put the result in the - [target] file. The [structure] or [signature] field of the mapper - is applied to the implementation or interface. *) - -val run_main : (string list -> mapper) -> unit -(** Entry point to call to implement a standalone -ppx rewriter from a - mapper, parametrized by the command line arguments. The current - unit name can be obtained from {!Location.input_name}. This - function implements proper error reporting for uncaught - exceptions. *) - -(** {1 Registration API} *) - -val register_function : (string -> (string list -> mapper) -> unit) ref - -val register : string -> (string list -> mapper) -> unit -(** Apply the [register_function]. The default behavior is to run the - mapper immediately, taking arguments from the process command - line. This is to support a scenario where a mapper is linked as a - stand-alone executable. - - It is possible to overwrite the [register_function] to define - "-ppx drivers", which combine several mappers in a single process. - Typically, a driver starts by defining [register_function] to a - custom implementation, then lets ppx rewriters (linked statically - or dynamically) register themselves, and then run all or some of - them. It is also possible to have -ppx drivers apply rewriters to - only specific parts of an AST. - - The first argument to [register] is a symbolic name to be used by - the ppx driver. *) - (** {1 Convenience functions to write mappers} *) -val map_opt : ('a -> 'b) -> 'a option -> 'b option - val extension_of_error : Location.error -> extension (** Encode an error into an 'ocaml.error' extension node which can be inserted in a generated Parsetree. The compiler will be @@ -170,9 +123,3 @@ val drop_ppx_context_str : val drop_ppx_context_sig : restore:bool -> Parsetree.signature -> Parsetree.signature (** Same as [drop_ppx_context_str], but for signatures. *) - -(** {1 Cookies} *) - -(** Cookies are used to pass information from a ppx processor to - a further invocation of itself, when called from the OCaml - toplevel (or other tools that support cookies). *) diff --git a/compiler/ml/ast_mapper_from0.ml b/compiler/ml/ast_mapper_from0.ml index 924f41e3eb..407f6eec90 100644 --- a/compiler/ml/ast_mapper_from0.ml +++ b/compiler/ml/ast_mapper_from0.ml @@ -85,7 +85,6 @@ type mapper = { } let map_fst f (x, y) = (f x, y) -let map_snd f (x, y) = (x, f y) let map_tuple f1 f2 (x, y) = (f1 x, f2 y) let map_tuple3 f1 f2 f3 (x, y, z) = (f1 x, f2 y, f3 z) let map_opt f = function diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index 78b78358fb..c1bf3b8855 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -70,7 +70,6 @@ type mapper = { } let map_fst f (x, y) = (f x, y) -let map_snd f (x, y) = (x, f y) let map_tuple f1 f2 (x, y) = (f1 x, f2 y) let map_tuple3 f1 f2 f3 (x, y, z) = (f1 x, f2 y, f3 z) let map_opt f = function diff --git a/compiler/ml/ast_payload.ml b/compiler/ml/ast_payload.ml index 9333928e9b..2a522a0907 100644 --- a/compiler/ml/ast_payload.ml +++ b/compiler/ml/ast_payload.ml @@ -264,6 +264,8 @@ type action = lid * Parsetree.expression option {[ { x = exp }]} *) +(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow + external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *) let unrecognized_config_record loc text = Location.prerr_warning loc (Warnings.Bs_derive_warning text) diff --git a/compiler/ml/ast_payload.mli b/compiler/ml/ast_payload.mli index df1cd08215..75a00cd8b9 100644 --- a/compiler/ml/ast_payload.mli +++ b/compiler/ml/ast_payload.mli @@ -105,7 +105,3 @@ val empty : t val table_dispatch : (Parsetree.expression option -> 'a) Map_string.t -> action -> 'a - -val unrecognized_config_record : Location.t -> string -> unit -(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow - external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *) diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index 871e99e42f..ffd6a8a6de 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -63,17 +63,6 @@ let report_error ppf = rename the field." constructor_name runtime_value field_name -let block_type_to_user_visible_string = function - | IntType -> "int" - | StringType -> "string" - | FloatType -> "float" - | BigintType -> "bigint" - | BooleanType -> "bool" - | InstanceType i -> Instance.to_string i - | FunctionType -> "function" - | ObjectType -> "object" - | UnknownType -> "unknown" - (* Type of the runtime representation of a tag. Can be a literal (case with no payload), or a block (case with payload). diff --git a/compiler/ml/asttypes.ml b/compiler/ml/asttypes.ml index 54d661dec3..ad3bd456f9 100644 --- a/compiler/ml/asttypes.ml +++ b/compiler/ml/asttypes.ml @@ -44,8 +44,6 @@ type private_flag = Private | Public type mutable_flag = Immutable | Mutable -type virtual_flag = Virtual | Concrete - type override_flag = Override | Fresh type closed_flag = Closed | Open diff --git a/compiler/ml/bigint_utils.mli b/compiler/ml/bigint_utils.mli index 14b09a9efc..c8fcf3b7dd 100644 --- a/compiler/ml/bigint_utils.mli +++ b/compiler/ml/bigint_utils.mli @@ -1,8 +1,4 @@ -val is_neg : string -> bool -val is_pos : string -> bool val to_string : bool -> string -> string -val remove_leading_sign : string -> bool * string -val remove_leading_zeros : string -> string val parse_bigint : string -> bool * string val is_valid : string -> bool val compare : bool * string -> bool * string -> int diff --git a/compiler/ml/btype.ml b/compiler/ml/btype.ml index b76ba8c001..3301f0c545 100644 --- a/compiler/ml/btype.ml +++ b/compiler/ml/btype.ml @@ -27,9 +27,6 @@ module Type_hash = Hashtbl.Make (Type_ops) (**** Forward declarations ****) -let print_raw = - ref (fun _ -> assert false : Format.formatter -> type_expr -> unit) - (**** Type level management ****) let generic_level = 100000000 @@ -85,8 +82,6 @@ type change = | Ctype of type_expr * type_desc | Ccompress of type_expr * type_desc * type_desc | Clevel of type_expr * int - | Cname of - (Path.t * type_expr list) option ref * (Path.t * type_expr list) option | Crow of row_field option ref * row_field option | Cmutability of field_mutability ref * field_mutability | Cuniv of type_expr option ref * type_expr option @@ -711,7 +706,6 @@ let undo_change = function | Ctype (ty, desc) -> ty.desc <- desc | Ccompress (ty, desc, _) -> ty.desc <- desc | Clevel (ty, level) -> ty.level <- level - | Cname (r, v) -> r := v | Crow (r, v) -> r := v | Cmutability (r, v) -> r := v | Cuniv (r, v) -> r := v @@ -750,9 +744,6 @@ let set_level ty level = let set_univar rty ty = log_change (Cuniv (rty, !rty)); rty := Some ty -let set_name nm v = - log_change (Cname (nm, !nm)); - nm := v let set_row_field e v = log_change (Crow (e, !e)); e := Some v diff --git a/compiler/ml/btype.mli b/compiler/ml/btype.mli index fbe452e2bc..d38d0a6f3f 100644 --- a/compiler/ml/btype.mli +++ b/compiler/ml/btype.mli @@ -220,10 +220,6 @@ val link_type : type_expr -> type_expr -> unit value if there is an active snapshot *) val set_level : type_expr -> int -> unit -val set_name : - (Path.t * type_expr list) option ref -> - (Path.t * type_expr list) option -> - unit val set_row_field : row_field option ref -> row_field -> unit val set_univar : type_expr option ref -> type_expr -> unit @@ -243,7 +239,6 @@ val log_type : type_expr -> unit (* Log the old value of a type, before modifying it by hand *) (**** Forward declarations ****) -val print_raw : (Format.formatter -> type_expr -> unit) ref val iter_type_expr_kind : (type_expr -> unit) -> type_kind -> unit diff --git a/compiler/ml/clflags.ml b/compiler/ml/clflags.ml index 1255d2974f..44ce28596e 100644 --- a/compiler/ml/clflags.ml +++ b/compiler/ml/clflags.ml @@ -13,8 +13,7 @@ and preprocessor = ref (None : string option) (* -pp *) and all_ppx = ref ([] : string list) (* -ppx *) -let annotations = ref false (* -annot *) -let binary_annotations = ref false (* -annot *) +let binary_annotations = ref false (* write .cmt/.cmti; -bs-no-bin-annot *) and noassert = ref false (* -noassert *) @@ -36,6 +35,8 @@ and dump_typedtree = ref false (* -dtypedtree *) and dump_rawlambda = ref false (* -drawlambda *) +and dump_coercions = ref false (* -draw-coercions *) + and only_parse = ref false (* -only-parse *) and editor_mode = ref false (* -editor-mode *) @@ -48,7 +49,8 @@ let reset_dump_state () = dump_source := false; dump_parsetree := false; dump_typedtree := false; - dump_rawlambda := false + dump_rawlambda := false; + dump_coercions := false let keep_locs = ref true (* -keep-locs *) diff --git a/compiler/ml/clflags.mli b/compiler/ml/clflags.mli index e532fd6f7d..79ecb6ecff 100644 --- a/compiler/ml/clflags.mli +++ b/compiler/ml/clflags.mli @@ -8,7 +8,6 @@ val nopervasives : bool ref val open_modules : string list ref val preprocessor : string option ref val all_ppx : string list ref -val annotations : bool ref val binary_annotations : bool ref val noassert : bool ref val verbose : bool ref @@ -20,6 +19,7 @@ val dump_source : bool ref val dump_parsetree : bool ref val dump_typedtree : bool ref val dump_rawlambda : bool ref +val dump_coercions : bool ref val dont_write_files : bool ref val keep_locs : bool ref val only_parse : bool ref diff --git a/compiler/ml/cmt_format.mli b/compiler/ml/cmt_format.mli index 9d37721f1b..b8f32c9cfe 100644 --- a/compiler/ml/cmt_format.mli +++ b/compiler/ml/cmt_format.mli @@ -70,16 +70,6 @@ type error = Not_a_typedtree of string exception Error of error -val read : string -> Cmi_format.cmi_infos option * cmt_infos option -(** [read filename] opens filename, and extract both the cmi_infos, if - it exists, and the cmt_infos, if it exists. Thus, it can be used - with .cmi, .cmt and .cmti files. - - .cmti files always contain a cmi_infos at the beginning. .cmt files - only contain a cmi_infos at the beginning if there is no associated - .cmti file. -*) - val read_cmt : string -> cmt_infos val read_cmi : string -> Cmi_format.cmi_infos @@ -101,8 +91,6 @@ val save_cmt : (* Miscellaneous functions *) -val read_magic_number : in_channel -> string - val clear : unit -> unit val add_saved_type : binary_part -> unit @@ -111,23 +99,3 @@ val set_saved_types : binary_part list -> unit val record_value_dependency : Types.value_description -> Types.value_description -> unit - -val record_deprecated_used : - ?deprecated_context:Cmt_utils.deprecated_used_context -> - ?migration_template:Parsetree.expression -> - ?migration_in_pipe_chain_template:Parsetree.expression -> - Location.t -> - string -> - unit - -(* - - val is_magic_number : string -> bool - val read : in_channel -> Env.cmi_infos option * t - val write_magic_number : out_channel -> unit - val write : out_channel -> t -> unit - - val find : string list -> string -> string - val read_signature : 'a -> string -> Types.signature * 'b list * 'c list - -*) diff --git a/compiler/ml/cmt_format_common.ml b/compiler/ml/cmt_format_common.ml index d3a151f944..6edbf1b114 100644 --- a/compiler/ml/cmt_format_common.ml +++ b/compiler/ml/cmt_format_common.ml @@ -13,9 +13,10 @@ (* *) (**************************************************************************) -(* Shared CMT reading and collection logic. Persistence is supplied by the - selected Cmt_format implementation so the playground does not retain the - native writer and its transitive dependencies. *) +(* Shared CMT reading and collection logic. Persistence is supplied by + Cmt_format_persistence, which compiler/ml/dune copies from platform/native + or platform/playground according to the profile, so the playground does + not retain the native writer and its transitive dependencies. *) open Typedtree @@ -106,6 +107,14 @@ exception Error of error let input_cmt ic = (input_value ic : cmt_infos) +(** [read filename] opens filename, and extract both the cmi_infos, if + it exists, and the cmt_infos, if it exists. Thus, it can be used + with .cmi, .cmt and .cmti files. + + .cmti files always contain a cmi_infos at the beginning. .cmt files + only contain a cmi_infos at the beginning if there is no associated + .cmti file. +*) let read filename = (* Printf.fprintf stderr "Cmt_format.read %s\n%!" filename; *) let ic = open_in_bin filename in diff --git a/compiler/ml/consistbl.ml b/compiler/ml/consistbl.ml index 02510bb650..16a7ed6435 100644 --- a/compiler/ml/consistbl.ml +++ b/compiler/ml/consistbl.ml @@ -31,8 +31,6 @@ let check tbl name crc source = let set tbl name crc source = Hashtbl.add tbl name (crc, source) -let source tbl name = snd (Hashtbl.find tbl name) - let extract l tbl = let l = List.sort_uniq String.compare l in List.fold_left @@ -42,15 +40,3 @@ let extract l tbl = (name, Some crc) :: assc with Not_found -> (name, None) :: assc) [] l - -let filter p tbl = - let to_remove = ref [] in - Hashtbl.iter - (fun name _ -> if not (p name) then to_remove := name :: !to_remove) - tbl; - List.iter - (fun name -> - while Hashtbl.mem tbl name do - Hashtbl.remove tbl name - done) - !to_remove diff --git a/compiler/ml/consistbl.mli b/compiler/ml/consistbl.mli index 29303b53c9..8b8f385ecc 100644 --- a/compiler/ml/consistbl.mli +++ b/compiler/ml/consistbl.mli @@ -34,17 +34,11 @@ val set : t -> string -> Digest.t -> string -> unit [crc] in [tbl], even if [name] already had a different CRC associated with [name] in [tbl]. *) -val source : t -> string -> string -(* [source tbl name] returns the file name associated with [name] - if the latter has an associated CRC in [tbl]. - Raise [Not_found] otherwise. *) - val extract : string list -> t -> (string * Digest.t option) list (* [extract tbl names] returns an associative list mapping each string in [names] to the CRC associated with it in [tbl]. If no CRC is associated with a name then it is mapped to [None]. *) -val filter : (string -> bool) -> t -> unit (* [filter pred tbl] removes from [tbl] table all (name, CRC) pairs such that [pred name] is [false]. *) diff --git a/compiler/ml/ctype.ml b/compiler/ml/ctype.ml index 883aa379bd..62672a4a04 100644 --- a/compiler/ml/ctype.ml +++ b/compiler/ml/ctype.ml @@ -1378,7 +1378,6 @@ let occur_in env ty0 t = (* This is a simplified version of occur, only for the rectypes case *) let rec local_non_recursive_abbrev strict visited env p ty = - (*Format.eprintf "@[Check %s =@ %a@]@." (Path.name p) !Btype.print_raw ty;*) let ty = repr ty in if not (List.memq ty visited) then match ty.desc with @@ -2073,7 +2072,7 @@ let rec unify (env : Env.t ref) t1 t2 = update_level !env t1.level t2; link_type t1 t2 | Tconstr (p1, [], a1), Tconstr (p2, [], a2) - when Path.same p1 p2 (* && actual_mode !env = Old *) + when Path.same p1 p2 (* This optimization assumes that t1 does not expand to t2 (and conversely), so we fall back to the general case when any of the types has a cached expansion. *) diff --git a/compiler/ml/ctype.mli b/compiler/ml/ctype.mli index a25d6d62e2..908dc348df 100644 --- a/compiler/ml/ctype.mli +++ b/compiler/ml/ctype.mli @@ -126,7 +126,6 @@ val object_row_is_structurally_open : type_expr -> bool val lid_of_path : ?hash:string -> Path.t -> Longident.t -val sort_row_fields : (label * row_field) list -> (label * row_field) list val merge_row_fields : (label * row_field) list -> (label * row_field) list -> @@ -212,7 +211,6 @@ val expand_head_opt : Env.t -> type_expr -> type_expr (** The compiler's own version of [expand_head] necessary for type-based optimisations. *) -val full_expand : Env.t -> type_expr -> type_expr val extract_concrete_typedecl : Env.t -> type_expr -> Path.t * Path.t * type_declaration (* Return the original path of the types, and the first concrete @@ -266,10 +264,8 @@ val deep_occur : type_expr -> type_expr -> bool val moregeneral : Env.t -> bool -> type_expr -> type_expr -> bool (* Check if the first type scheme is more general than the second. *) -val rigidify : type_expr -> type_expr list (* "Rigidify" a type and return its type variable *) -val all_distinct_vars : Env.t -> type_expr list -> bool (* Check those types are all distinct type variables *) val matches : Env.t -> type_expr -> type_expr -> bool @@ -307,9 +303,7 @@ val nondep_extension_constructor : Env.t -> Ident.t -> extension_constructor -> extension_constructor (* Same for extension constructor *) -(*val correct_abbrev: Env.t -> Path.t -> type_expr list -> type_expr -> unit*) val cyclic_abbrev : Env.t -> Ident.t -> type_expr -> bool -val is_contractive : Env.t -> Path.t -> bool val normalize_type : Env.t -> type_expr -> unit val closed_schema : Env.t -> type_expr -> bool diff --git a/compiler/ml/datarepr.ml b/compiler/ml/datarepr.ml index e5dc848838..e0e2090787 100644 --- a/compiler/ml/datarepr.ml +++ b/compiler/ml/datarepr.ml @@ -45,6 +45,11 @@ let free_vars ?(param = false) ty = let newgenconstr path tyl = newgenty (Tconstr (path, tyl, ref Mnil)) +(** Takes [cd_args] and [cd_res] from a [constructor_declaration] and + returns: + - the types of the constructor's arguments + - the existential variables introduced by the constructor + *) let constructor_existentials cd_args cd_res = let tyl = match cd_args with diff --git a/compiler/ml/datarepr.mli b/compiler/ml/datarepr.mli index 5996ebe278..94a838fc9f 100644 --- a/compiler/ml/datarepr.mli +++ b/compiler/ml/datarepr.mli @@ -34,13 +34,5 @@ val labels_of_type : val constructors_of_type : Path.t -> type_declaration -> (Ident.t * constructor_description) list -val constructor_existentials : - constructor_arguments -> type_expr option -> type_expr list * type_expr list -(** Takes [cd_args] and [cd_res] from a [constructor_declaration] and - returns: - - the types of the constructor's arguments - - the existential variables introduced by the constructor - *) - (* Set the polymorphic variant row_name field *) val set_row_name : type_declaration -> Path.t -> unit diff --git a/compiler/ml/depend.ml b/compiler/ml/depend.ml index d88b47558c..50a4b5aee2 100644 --- a/compiler/ml/depend.ml +++ b/compiler/ml/depend.ml @@ -34,8 +34,6 @@ let bound = Node (String_set.empty, String_map.empty) let get_map (Node (_s, m)) = m let make_leaf s = Node (String_set.singleton s, String_map.empty) let make_node m = Node (String_set.empty, m) -let rec weaken_map s (Node (s0, m0)) = - Node (String_set.union s s0, String_map.map (weaken_map s) m0) let rec collect_free (Node (s, m)) = String_map.fold (fun _ n -> String_set.union (collect_free n)) m s @@ -66,8 +64,6 @@ let rec add_path bv ?(p = []) = function let free = try lookup_free (s :: p) bv with Not_found -> String_set.singleton s in - (*StringSet.iter (fun s -> Printf.eprintf "%s " s) free; - prerr_endline "";*) add_names free | Ldot (l, s) -> add_path bv ~p:(s :: p) l diff --git a/compiler/ml/depend.mli b/compiler/ml/depend.mli index 5684d2a647..12f20d9e2f 100644 --- a/compiler/ml/depend.mli +++ b/compiler/ml/depend.mli @@ -20,9 +20,6 @@ module String_map : Map.S with type key = string type map_tree = Node of String_set.t * bound_map and bound_map = map_tree String_map.t -val make_leaf : string -> map_tree -val make_node : bound_map -> map_tree -val weaken_map : String_set.t -> map_tree -> map_tree val free_structure_names : String_set.t ref @@ -32,5 +29,3 @@ val open_module : bound_map -> Longident.t -> bound_map val add_signature : bound_map -> Parsetree.signature -> unit val add_implementation : bound_map -> Parsetree.structure -> unit - -val add_signature_binding : bound_map -> Parsetree.signature -> bound_map diff --git a/compiler/ml/env.ml b/compiler/ml/env.ml index 0a85e44278..2c28955846 100644 --- a/compiler/ml/env.ml +++ b/compiler/ml/env.ml @@ -226,22 +226,6 @@ module Tycomp_tbl = struct |> Tbl.fold (fun _name -> List.fold_right (fun desc -> f desc)) components |> fold_name f next | None -> acc - - let rec local_keys tbl acc = - let acc = Ident.fold_all (fun k _ accu -> k :: accu) tbl.current acc in - match tbl.opened with - | Some o -> local_keys o.next acc - | None -> acc - - let diff_keys is_local tbl1 tbl2 = - let keys2 = local_keys tbl2 [] in - Ext_list.filter keys2 (fun id -> - is_local (find_same id tbl2) - && - try - ignore (find_same id tbl1); - false - with Not_found -> true) end module Id_tbl = struct @@ -357,12 +341,6 @@ module Id_tbl = struct |> fold_name f next | None -> acc - let rec local_keys tbl acc = - let acc = Ident.fold_all (fun k _ accu -> k :: accu) tbl.current acc in - match tbl.opened with - | Some o -> local_keys o.next acc - | None -> acc - let rec iter f tbl = Ident.iter (fun id desc -> f id (Pident id, desc)) tbl.current; match tbl.opened with @@ -373,14 +351,6 @@ module Id_tbl = struct components; iter f next | None -> () - - let diff_keys tbl1 tbl2 = - let keys2 = local_keys tbl2 [] in - Ext_list.filter keys2 (fun id -> - try - ignore (find_same id tbl1); - false - with Not_found -> true) end type type_descriptions = constructor_description list * label_description list @@ -437,14 +407,6 @@ and functor_components = { fcomp_subst_cache: (Path.t, module_type) Hashtbl.t; } -let copy_local ~from env = - { - env with - local_constraints = from.local_constraints; - gadt_instances = from.gadt_instances; - flags = from.flags; - } - let same_constr = ref (fun _ _ _ -> assert false) (* Helper to decide whether to report an identifier shadowing @@ -505,19 +467,6 @@ let implicit_coercion env = let is_in_signature env = env.flags land in_signature_flag <> 0 let is_implicit_coercion env = env.flags land implicit_coercion_flag <> 0 -let is_ident = function - | Pident _ -> true - | Pdot _ | Papply _ -> false - -let is_local_ext = function - | {cstr_kind = Extension_constructor p} -> is_ident p - | _ -> false - -let diff env1 env2 = - Id_tbl.diff_keys env1.values env2.values - @ Tycomp_tbl.diff_keys is_local_ext env1.constrs env2.constrs - @ Id_tbl.diff_keys env1.modules env2.modules - type can_load_cmis = Can_load_cmis | Cannot_load_cmis of Env_lazy.log let can_load_cmis = ref Can_load_cmis @@ -1368,9 +1317,6 @@ let add_gadt_instances env lv tl = let r = try List.assoc lv env.gadt_instances with Not_found -> assert false in - (* Format.eprintf "Added"; - List.iter (fun ty -> Format.eprintf "@ %a" !Btype.print_raw ty) tl; - Format.eprintf "@."; *) set_typeset r (List.fold_right Type_set.add tl !r) (* Only use this after expand_head! *) @@ -1381,7 +1327,6 @@ let add_gadt_instance_chain env lv t = let rec add_instance t = let t = repr t in if not (Type_set.mem t !r) then ( - (* Format.eprintf "@ %a" !Btype.print_raw t; *) set_typeset r (Type_set.add t !r); match t.desc with | Tconstr (p, _, memo) -> may add_instance (find_expans Private p !memo) @@ -1900,7 +1845,7 @@ let save_signature_with_imports ?check_exists ~deprecated sg modname filename {cmi_name = modname; cmi_sign = sg; cmi_crcs = imports; cmi_flags = flags} in let crc = create_cmi ?check_exists filename cmi in - (* Enter signature in persistent table so that imported_unit() + (* Enter signature in persistent table so that imports () will also return its crc *) let comps = components_of_module ~deprecated ~loc:Location.none empty Subst.identity @@ -2009,12 +1954,6 @@ let initial_safe_string = (add_extension ~check:false) empty -(* Return the environment summary *) - -let summary env = - if Path_map.is_empty env.local_constraints then env.summary - else Env_constraints (env.summary, env.local_constraints) - let last_env = ref empty let last_reduced_env = ref empty diff --git a/compiler/ml/env.mli b/compiler/ml/env.mli index 584a6e05c3..b46fa784a4 100644 --- a/compiler/ml/env.mli +++ b/compiler/ml/env.mli @@ -37,9 +37,6 @@ type t val empty : t val initial_safe_string : t -val diff : t -> t -> Ident.t list -val copy_local : from:t -> t -> t - type type_descriptions = constructor_description list * label_description list (* For short-paths *) @@ -71,7 +68,6 @@ val find_type_expansion_opt : (* Find the manifest type information associated to a type for the sake of the compiler's type-based optimisations. *) val find_modtype_expansion : Path.t -> t -> module_type -val add_functor_arg : Ident.t -> t -> t val is_functor_arg : Path.t -> t -> bool val normalize_path : Location.t option -> t -> Path.t -> Path.t @@ -192,14 +188,6 @@ val save_signature : Cmi_format.cmi_infos (* Arguments: signature, module name, file name. *) -val save_signature_with_imports : - ?check_exists:unit -> - deprecated:string option -> - signature -> - string -> - string -> - (string * Digest.t option) list -> - Cmi_format.cmi_infos (* Arguments: signature, module name, file name, imported units with their CRCs. *) @@ -209,14 +197,9 @@ val imports : unit -> (string * Digest.t option) list (* Direct access to the table of imported compilation units with their CRC *) -val crc_units : Consistbl.t -val add_import : string -> unit - (* Summaries -- compact representation of an environment, to be exported in debugging information. *) -val summary : t -> summary - (* Return an equivalent environment where all fields have been reset, except the summary. *) @@ -229,10 +212,6 @@ type error = exception Error of error -open Format - -val report_error : formatter -> error -> unit - val mark_value_used : t -> string -> value_description -> unit val mark_module_used : t -> string -> Location.t -> unit val mark_type_used : t -> string -> type_declaration -> unit diff --git a/compiler/ml/error_message_utils.ml b/compiler/ml/error_message_utils.ml index cafb45f8e1..9e63805ecb 100644 --- a/compiler/ml/error_message_utils.ml +++ b/compiler/ml/error_message_utils.ml @@ -91,7 +91,6 @@ type type_clash_context = } | ArrayValue | TaggedTemplateValue - | MaybeUnwrapOption | IfCondition | AssertCondition | IfReturn @@ -189,8 +188,7 @@ let error_expected_type_text ppf type_clash_context = fprintf ppf "But you're using @{await@} on this expression, so it is expected \ to be of type:" - | Some MaybeUnwrapOption | Some BracedIdent | None -> - fprintf ppf "But it's expected to have type:" + | Some BracedIdent | None -> fprintf ppf "But it's expected to have type:" let is_record_type ~(extract_concrete_typedecl : extract_concrete_typedecl) ~env ty = @@ -442,12 +440,6 @@ let print_extra_type_clash_help ~extract_concrete_typedecl ~env loc ppf "\n\n\ \ Ternaries (@{?@} and @{:@}) must return the same type in \ both branches." - | Some MaybeUnwrapOption, _ -> - fprintf ppf - "\n\n\ - \ Possible solutions:\n\ - \ - Unwrap the option to its underlying value using \ - `yourValue->Option.getOr(someDefaultValue)`" | Some ComparisonOperator, _ -> fprintf ppf "\n\n You can only compare things of the same type." | Some ArrayValue, Some ({desc = Tobject _}, ({Types.desc = Tconstr _} as t1)) @@ -856,15 +848,6 @@ let type_clash_context_for_function_argument ~label type_clash_context sarg0 = }) | type_clash_context -> type_clash_context -let type_clash_context_maybe_option ty_expected ty_res = - match (ty_expected, ty_res) with - | ( {Types.desc = Tconstr (expected_path, _, _)}, - {Types.desc = Tconstr (type_path, _, _)} ) - when Path.same Predef.path_option type_path - && Path.same expected_path Predef.path_option = false -> - Some MaybeUnwrapOption - | _ -> None - let type_clash_context_in_statement sexp = match sexp.Parsetree.pexp_desc with | Pexp_apply {transformed_jsx = false} -> Some (Statement FunctionCall) diff --git a/compiler/ml/external_arg_spec.mli b/compiler/ml/external_arg_spec.mli index 058be3c7f5..c23336fa23 100644 --- a/compiler/ml/external_arg_spec.mli +++ b/compiler/ml/external_arg_spec.mli @@ -59,9 +59,6 @@ val cst_int : int -> cst val cst_string : string -> cst val cst_json : string -> cst -val empty_label : label - -(* val empty_lit : cst -> label *) val obj_label : string -> label val optional : bool -> string -> label diff --git a/compiler/ml/includemod.ml b/compiler/ml/includemod.ml index b71af86d67..eee8c8bda9 100644 --- a/compiler/ml/includemod.ml +++ b/compiler/ml/includemod.ml @@ -15,7 +15,6 @@ (* Inclusion checks for the module language *) -open Misc open Path open Typedtree open Types @@ -167,7 +166,7 @@ and print_coercion2 ppf (n, c) = Format.fprintf ppf "@[%d,@ %a@]" n print_coercion c and print_coercion3 ppf (i, n, c) = - Format.fprintf ppf "@[%s, %d,@ %a@]" (Ident.unique_name i) n print_coercion c + Format.fprintf ppf "@[%s, %d,@ %a@]" (Ident.name i) n print_coercion c (* Simplify a structure coercion *) @@ -648,7 +647,7 @@ let is_big obj = let report_error ppf errs = if errs = [] then () else - let errs, err = split_last errs in + let errs, err = Ext_list.split_at_last errs in let pe = ref true in let include_err' ppf ((_, _, obj) as err) = if not (is_big obj) then fprintf ppf "%a@ " include_err err diff --git a/compiler/ml/lambda.ml b/compiler/ml/lambda.ml index 5bed56fa7b..b3ad9f18cc 100644 --- a/compiler/ml/lambda.ml +++ b/compiler/ml/lambda.ml @@ -86,8 +86,6 @@ let fld_record name = Fld_record {name} let fld_record_extension name = Fld_record_extension {name} -let ref_field_info : field_dbg_info = Fld_record {name = "contents"} - type set_field_dbg_info = | Fld_record_set of string | Fld_record_inline_set of string diff --git a/compiler/ml/lambda.mli b/compiler/ml/lambda.mli index 38ffead4b9..9914628559 100644 --- a/compiler/ml/lambda.mli +++ b/compiler/ml/lambda.mli @@ -88,8 +88,6 @@ val fld_record_inline : string -> field_dbg_info val fld_record_extension : string -> field_dbg_info -val ref_field_info : field_dbg_info - type set_field_dbg_info = | Fld_record_set of string | Fld_record_inline_set of string @@ -411,18 +409,6 @@ and 'a switch = { and lambda_switch = t switch -(* Lambda code for the middle-end. - * In the closure case the code is a sequence of assignments to a - preallocated block of size [main_module_block_size] using - (Setfield(Getglobal(module_ident))). The size is used to preallocate - the block. - * In the flambda case the code is an expression returning a block - value of size [main_module_block_size]. The size is used to build - the module root as an initialize_symbol - Initialize_symbol(module_name, 0, - [getfield 0; ...; getfield (main_module_block_size - 1)]) -*) - (* Sharing key *) val const_int : int -> structured_constant @@ -526,10 +512,6 @@ val sequor : t -> t -> t val sequand : t -> t -> t -val lambda_true : t - -val lambda_false : t - val eq_approx : t -> t -> bool val mk_builtin : builtin -> t list -> Location.t -> t diff --git a/compiler/ml/lambda_traverse.ml b/compiler/ml/lambda_traverse.ml index f4e6cd4fe2..74f1308c68 100644 --- a/compiler/ml/lambda_traverse.ml +++ b/compiler/ml/lambda_traverse.ml @@ -94,7 +94,7 @@ let shallow_map_sharing (f : t -> t) (lam : t) : t = if b' == b then lam else assign id b' (* - Those keys are later compared with Pervasives.compare. + Those keys are later compared with Stdlib.compare. For that reason, they should not include cycles. *) diff --git a/compiler/ml/location.ml b/compiler/ml/location.ml index 80d9da0d6d..c328ddc378 100644 --- a/compiler/ml/location.ml +++ b/compiler/ml/location.ml @@ -199,7 +199,7 @@ let pp_ksprintf ?before k fmt = is always added by the compiler after the message has been formatted *) let print_phanton_error_prefix ppf = (* modified from the original. We use only 2 indentations for error report - (see super_error_reporter above) *) + (see default_error_reporter below) *) Format.pp_print_as ppf 2 "" let errorf ?(loc = none) ?(sub = []) ?(if_highlight = "") fmt = diff --git a/compiler/ml/location.mli b/compiler/ml/location.mli index 76f4db2bd8..2e29b16a67 100644 --- a/compiler/ml/location.mli +++ b/compiler/ml/location.mli @@ -110,15 +110,6 @@ val report_error : error -> unit -val error_reporter : - (?custom_intro:string option -> - ?src:string option -> - formatter -> - error -> - unit) - ref -(** Hook for intercepting error reports. *) - val default_error_reporter : ?custom_intro:string option -> ?src:string option -> diff --git a/compiler/ml/longident.mli b/compiler/ml/longident.mli index 51ddc2746c..1534d84db6 100644 --- a/compiler/ml/longident.mli +++ b/compiler/ml/longident.mli @@ -19,6 +19,5 @@ type t = Lident of string | Ldot of t * string val cmp : t -> t -> int val flatten : t -> string list -val unflatten : string list -> t option val last : t -> string val parse : string -> t diff --git a/compiler/ml/matching.ml b/compiler/ml/matching.ml index e1bdf871d1..9e908a3fbc 100644 --- a/compiler/ml/matching.ml +++ b/compiler/ml/matching.ml @@ -176,7 +176,7 @@ let ctx_matcher p = fun q rem -> match q.pat_desc with | Tpat_construct (_, cstr', args) - (* NB: may_constr_equal considers (potential) constructor rebinding *) + (* NB: may_equal_constr considers (potential) constructor rebinding *) when Types.may_equal_constr cstr cstr' -> (p, args @ rem) | Tpat_any -> (p, omegas @ rem) @@ -2803,7 +2803,7 @@ let flatten_cases size cases = (fun (ps, action) -> match ps with | [p] -> (flatten_pattern size p, action) - | _ -> fatal_error "Matching.flatten_case") + | _ -> fatal_error "Matching.flatten_cases") cases let flatten_matrix size pss = @@ -2840,7 +2840,7 @@ let flatten_precompiled size args pmh = | PmVar _ -> assert false (* - compiled_flattened is a ``comp_fun'' argument to comp_match_handlers. + compile_flattened is a ``comp_fun'' argument to comp_match_handlers. Hence it needs a fourth argument, which it ignores *) diff --git a/compiler/ml/matching.mli b/compiler/ml/matching.mli index 3d09413bc5..9f00480dd7 100644 --- a/compiler/ml/matching.mli +++ b/compiler/ml/matching.mli @@ -56,5 +56,3 @@ val for_multiple_match : Location.t -> Lambda.t list -> (pattern * action) list -> partial -> Lambda.t exception Cannot_flatten - -val flatten_pattern : int -> pattern -> pattern list diff --git a/compiler/ml/mtype.ml b/compiler/ml/mtype.ml index 0f284fdaf7..8fb04fdc84 100644 --- a/compiler/ml/mtype.ml +++ b/compiler/ml/mtype.ml @@ -225,29 +225,6 @@ and type_paths_sig env p pos sg = type_paths_sig (Env.add_modtype id decl env) p pos rem | Sig_typext _ :: rem -> type_paths_sig env p (pos + 1) rem -let rec no_code_needed env mty = - match scrape env mty with - | Mty_ident _ -> false - | Mty_signature sg -> no_code_needed_sig env sg - | Mty_functor (_, _, _) -> false - | Mty_alias (Mta_absent, _) -> true - | Mty_alias (Mta_present, _) -> false - -and no_code_needed_sig env sg = - match sg with - | [] -> true - | Sig_value (_id, decl) :: rem -> ( - match decl.val_kind with - | Val_prim _ -> no_code_needed_sig env rem - | _ -> false) - | Sig_module (id, md, _) :: rem -> - no_code_needed env md.md_type - && no_code_needed_sig - (Env.add_module_declaration ~check:false id md env) - rem - | (Sig_type _ | Sig_modtype _) :: rem -> no_code_needed_sig env rem - | Sig_typext _ :: _ -> false - (* Check whether a module type may return types *) let rec contains_type env = function @@ -379,8 +356,6 @@ and remove_aliases_sig env excl sg = let remove_aliases env sg = let excl = collect_arg_paths sg in - (* PathSet.iter (fun p -> Format.eprintf "%a@ " Printtyp.path p) excl; - Format.eprintf "@."; *) remove_aliases env excl sg (* Lower non-generalizable type variables *) diff --git a/compiler/ml/mtype.mli b/compiler/ml/mtype.mli index 64198df4bd..589363db77 100644 --- a/compiler/ml/mtype.mli +++ b/compiler/ml/mtype.mli @@ -37,8 +37,6 @@ val nondep_supertype : Env.t -> Ident.t -> module_type -> module_type in which the given ident does not appear. Raise [Not_found] if no such type exists. *) -val no_code_needed : Env.t -> module_type -> bool -val no_code_needed_sig : Env.t -> signature -> bool (* Determine whether a module needs no implementation code, i.e. consists only of type definitions. *) diff --git a/compiler/ml/oprint.mli b/compiler/ml/oprint.mli index d37d206c7d..b24c7faecd 100644 --- a/compiler/ml/oprint.mli +++ b/compiler/ml/oprint.mli @@ -25,5 +25,3 @@ val out_sig_item : (formatter -> out_sig_item -> unit) ref val out_signature : (formatter -> out_sig_item list -> unit) ref val out_type_extension : (formatter -> out_type_extension -> unit) ref val out_phrase : (formatter -> out_phrase -> unit) ref - -val parenthesized_ident : string -> bool diff --git a/compiler/ml/outcometree.ml b/compiler/ml/outcometree.ml index 351e07dde6..eb36a5b8f9 100644 --- a/compiler/ml/outcometree.ml +++ b/compiler/ml/outcometree.ml @@ -13,14 +13,13 @@ (* *) (**************************************************************************) -(* Module [Outcometree]: results displayed by the toplevel *) +(* Module [Outcometree]: printable representation of types, values and + signature items *) -(* These types represent messages that the toplevel displays as normal - results or errors. The real displaying is customisable using the hooks: - [Toploop.print_out_value] - [Toploop.print_out_type] - [Toploop.print_out_sig_item] - [Toploop.print_out_phrase] *) +(* [Printtyp] builds these trees. They are printed through the hooks + [Oprint.out_type], [Oprint.out_value], [Oprint.out_sig_item], + [Oprint.out_signature] and related refs, which bsc sets to the ReScript + printer through [Res_outcome_printer.setup]. *) type out_ident = | Oide_apply of out_ident * out_ident diff --git a/compiler/ml/parmatch.ml b/compiler/ml/parmatch.ml index 4d98de826c..b9e67b0679 100644 --- a/compiler/ml/parmatch.ml +++ b/compiler/ml/parmatch.ml @@ -273,7 +273,7 @@ let const_compare x y = | _, _ -> compare x y let records_args l1 l2 = - (* Invariant: fields are already sorted by Typecore.type_label_a_list *) + (* Invariant: fields are already sorted by Typecore.type_record_elem_list *) let rec combine r1 r2 l1 l2 = match (l1, l2) with | [], [] -> (List.rev r1, List.rev r2) @@ -512,7 +512,7 @@ let record_arg p = match p.pat_desc with | Tpat_any -> [] | Tpat_record (args, _, _rest) -> args - | _ -> fatal_error "Parmatch.as_record" + | _ -> fatal_error "Parmatch.record_arg" (* Raise Not_found when pos is not present in arg *) let get_field pos arg = @@ -1239,15 +1239,6 @@ type 'a result = | Rnone (* No matching value *) | Rsome of 'a (* This matching value *) -(* -let rec try_many f = function - | [] -> Rnone - | (p,pss)::rest -> - match f (p,pss) with - | Rnone -> try_many f rest - | r -> r -*) - let rappend r1 r2 = match (r1, r2) with | Rnone, _ -> r2 @@ -1258,68 +1249,6 @@ let rec try_many_gadt f = function | [] -> Rnone | (p, pss) :: rest -> rappend (f (p, pss)) (try_many_gadt f rest) -(* -let rec exhaust ext pss n = match pss with -| [] -> Rsome (omegas n) -| []::_ -> Rnone -| pss -> - let q0 = discr_pat omega pss in - begin match filter_all q0 pss with - (* first column of pss is made of variables only *) - | [] -> - begin match exhaust ext (filter_extra pss) (n-1) with - | Rsome r -> Rsome (q0::r) - | r -> r - end - | constrs -> - let try_non_omega (p,pss) = - if is_absent_pat p then - Rnone - else - match - exhaust - ext pss (List.length (simple_match_args p omega) + n - 1) - with - | Rsome r -> Rsome (set_args p r) - | r -> r in - if - full_match true false constrs && not (should_extend ext constrs) - then - try_many try_non_omega constrs - else - (* - D = filter_extra pss is the default matrix - as it is included in pss, one can avoid - recursive calls on specialized matrices, - Essentially : - * D exhaustive => pss exhaustive - * D non-exhaustive => we have a non-filtered value - *) - let r = exhaust ext (filter_extra pss) (n-1) in - match r with - | Rnone -> Rnone - | Rsome r -> - try - Rsome (build_other ext constrs::r) - with - (* cannot occur, since constructors don't make a full signature *) - | Empty -> fatal_error "Parmatch.exhaust" - end - -let combinations f lst lst' = - let rec iter2 x = - function - [] -> [] - | y :: ys -> - f x y :: iter2 x ys - in - let rec iter = - function - [] -> [] - | x :: xs -> iter2 x lst' @ iter xs - in - iter lst -*) (* let print_pat pat = let rec string_of_pat pat = @@ -1486,7 +1415,7 @@ let rec pressure_variants tdefs = function (* Yet another satisfiable function *) (* - This time every_satisfiable pss qs checks the + This time every_satisfiables pss qs checks the utility of every expansion of qs. Expansion means expansion of or-patterns inside qs *) @@ -1702,7 +1631,7 @@ let rec every_satisfiables pss qs = (* This function ``every_both'' performs the usefulness check of or-pat q1|q2. - The trick is to call every_satisfied twice with + The trick is to call every_satisfiables twice with current active columns restricted to q1 and q2, That way, - others orpats in qs.ors will not get expanded. @@ -2083,11 +2012,6 @@ let do_check_partial ?partial_match_warning_hint ?pred exhaust loc casel pss = Partial) | _ -> fatal_error "Parmatch.check_partial") -(* -let do_check_partial_normal loc casel pss = - do_check_partial exhaust loc casel pss - *) - let do_check_partial_gadt ?partial_match_warning_hint pred loc casel pss = do_check_partial ?partial_match_warning_hint ~pred exhaust_gadt loc casel pss @@ -2153,7 +2077,6 @@ let do_check_fragile_param exhaust loc casel pss = | Rsome _ -> ()) exts) -(*let do_check_fragile_normal = do_check_fragile_param exhaust*) let do_check_fragile_gadt = do_check_fragile_param exhaust_gadt (********************************) @@ -2235,29 +2158,6 @@ let check_unused pred casel = let irrefutable pat = le_pat pat omega -let inactive ~partial pat = - match partial with - | Partial -> false - | Total -> - let rec loop pat = - match pat.pat_desc with - | Tpat_array _ -> false - | Tpat_any | Tpat_var _ | Tpat_variant (_, None, _) -> true - | Tpat_constant c -> ( - match c with - | Const_string _ -> true (*Config.safe_string*) - | Const_int _ | Const_char _ | Const_float _ | Const_bigint _ -> true) - | Tpat_tuple ps | Tpat_construct (_, _, ps) -> - List.for_all (fun p -> loop p) ps - | Tpat_alias (p, _, _) | Tpat_variant (_, Some p, _) -> loop p - | Tpat_record (ldps, _, _rest) -> - List.for_all - (fun (_, lbl, p, _) -> lbl.lbl_mut = Immutable && loop p) - ldps - | Tpat_or (p, q, _) -> loop p && loop q - in - loop pat - (*********************************) (* Exported exhaustiveness check *) (*********************************) @@ -2275,11 +2175,6 @@ let check_partial_param do_check_partial do_check_fragile loc casel = do_check_fragile loc casel pss; total -(*let check_partial = - check_partial_param - do_check_partial_normal - do_check_fragile_normal*) - let check_partial_gadt ?partial_match_warning_hint pred loc casel = check_partial_param (do_check_partial_gadt ?partial_match_warning_hint pred) diff --git a/compiler/ml/parmatch.mli b/compiler/ml/parmatch.mli index 125b0022a5..5856327d1a 100644 --- a/compiler/ml/parmatch.mli +++ b/compiler/ml/parmatch.mli @@ -88,11 +88,6 @@ val check_unused : (* Irrefutability tests *) val irrefutable : pattern -> bool -val inactive : partial:partial -> pattern -> bool -(** An inactive pattern is a pattern, matching against which can be duplicated, erased or - delayed without change in observable behavior of the program. Patterns containing - (lazy _) subpatterns or reads of mutable fields are active. *) - (* Ambiguous bindings *) val check_ambiguous_bindings : case list -> unit diff --git a/compiler/ml/pprintast.ml b/compiler/ml/pprintast.ml index b76ca9d710..358bd50a88 100644 --- a/compiler/ml/pprintast.ml +++ b/compiler/ml/pprintast.ml @@ -1450,15 +1450,6 @@ and label_x_expression_param ctxt f (l, e) = if Some lbl = simple_name then pp f "~%s" lbl else pp f "~%s:%a" lbl (simple_expr ctxt) e -let expression f x = pp f "@[%a@]" (expression reset_ctxt) x - -let string_of_expression x = - ignore (flush_str_formatter ()); - let f = str_formatter in - expression f x; - flush_str_formatter () - -let core_type = core_type reset_ctxt let pattern = pattern reset_ctxt let signature = signature reset_ctxt let structure = structure reset_ctxt diff --git a/compiler/ml/pprintast.mli b/compiler/ml/pprintast.mli index bbb8dd7a9e..c82be33c3e 100644 --- a/compiler/ml/pprintast.mli +++ b/compiler/ml/pprintast.mli @@ -15,10 +15,6 @@ type space_formatter = (unit, Format.formatter, unit) format -val expression : Format.formatter -> Parsetree.expression -> unit -val string_of_expression : Parsetree.expression -> string - -val core_type : Format.formatter -> Parsetree.core_type -> unit val pattern : Format.formatter -> Parsetree.pattern -> unit val signature : Format.formatter -> Parsetree.signature -> unit val structure : Format.formatter -> Parsetree.structure -> unit diff --git a/compiler/ml/predef.ml b/compiler/ml/predef.ml index 2de67f84da..f71c5c083a 100644 --- a/compiler/ml/predef.ml +++ b/compiler/ml/predef.ml @@ -137,8 +137,6 @@ and type_async_iterable t = and type_list t = newgenty (Tconstr (path_list, [t], ref Mnil)) -and type_option t = newgenty (Tconstr (path_option, [t], ref Mnil)) - and type_bigint = newgenty (Tconstr (path_bigint, [], ref Mnil)) and type_string = newgenty (Tconstr (path_string, [], ref Mnil)) diff --git a/compiler/ml/predef.mli b/compiler/ml/predef.mli index 1c8a8df941..408ba7ba0f 100644 --- a/compiler/ml/predef.mli +++ b/compiler/ml/predef.mli @@ -27,8 +27,6 @@ val type_exn : type_expr val type_array : type_expr -> type_expr val type_iterable : type_expr -> type_expr val type_async_iterable : type_expr -> type_expr -val type_list : type_expr -> type_expr -val type_option : type_expr -> type_expr val type_bigint : type_expr val type_extension_constructor : type_expr @@ -40,15 +38,12 @@ val path_bool : Path.t val path_unit : Path.t val path_exn : Path.t val path_array : Path.t -val path_iterable : Path.t -val path_async_iterable : Path.t val path_list : Path.t val path_option : Path.t val path_result : Path.t val path_dict : Path.t val path_bigint : Path.t -val path_extension_constructor : Path.t val path_promise : Path.t val path_tagged_template : Path.t @@ -68,12 +63,6 @@ val build_initial_env : val builtin_idents : (string * Ident.t) list -val ident_division_by_zero : Ident.t -(** All predefined exceptions, exposed as [Ident.t] for flambda (for - building value approximations). - The [Ident.t] for division by zero is also exported explicitly - so flambda can generate code to raise it. *) - type test = For_sure_yes | For_sure_no | NA val type_is_builtin_path_but_option : Path.t -> test diff --git a/compiler/ml/printast.mli b/compiler/ml/printast.mli index 87da25385c..6471a9509c 100644 --- a/compiler/ml/printast.mli +++ b/compiler/ml/printast.mli @@ -19,6 +19,4 @@ open Format val interface : formatter -> signature_item list -> unit val implementation : formatter -> structure_item list -> unit -val expression : int -> formatter -> expression -> unit -val structure : int -> formatter -> structure -> unit val payload : int -> formatter -> payload -> unit diff --git a/compiler/ml/printlambda.ml b/compiler/ml/printlambda.ml index e006d602aa..95499f5c20 100644 --- a/compiler/ml/printlambda.ml +++ b/compiler/ml/printlambda.ml @@ -43,12 +43,6 @@ let rec struct_const ppf = function | Const_js_false -> fprintf ppf "false" | Const_js_true -> fprintf ppf "true" -(* let field_kind = function - | Pgenval -> "*" - | Pintval -> "int" - | Pfloatval -> "float" - | Pboxedintval bi -> boxed_integer_name bi *) - (* let block_shape ppf shape = match shape with | None | Some [] -> () | Some l when List.for_all ((=) Pgenval) l -> () @@ -378,8 +372,6 @@ and sequence ppf = function | Lsequence (l1, l2) -> fprintf ppf "%a@ %a" sequence l1 sequence l2 | l -> lam ppf l -let structured_constant = struct_const - let lambda = lam let serialize (filename : string) (l : Lambda.t) : unit = diff --git a/compiler/ml/printlambda.mli b/compiler/ml/printlambda.mli index d4e1dfbd09..720a78d122 100644 --- a/compiler/ml/printlambda.mli +++ b/compiler/ml/printlambda.mli @@ -13,15 +13,10 @@ (* *) (**************************************************************************) -open Lambda - open Format -val structured_constant : formatter -> structured_constant -> unit val lambda : formatter -> Lambda.t -> unit -val primitive : formatter -> Lambda.primitive -> unit - val serialize : string -> Lambda.t -> unit (** Print a term to a file, unwrapped: used for the -debug-ir dumps. *) diff --git a/compiler/ml/printtyp.ml b/compiler/ml/printtyp.ml index 40a0a826dc..a367004ce3 100644 --- a/compiler/ml/printtyp.ml +++ b/compiler/ml/printtyp.ml @@ -102,6 +102,11 @@ let tree_of_rec = function | Trec_first -> Orec_first | Trec_next -> Orec_next +let string_of_label = function + | Nolabel -> "" + | Labelled {txt} -> txt + | Optional {txt} -> "?" ^ txt + (* Print a raw type expression, with sharing *) let raw_list pr ppf = function @@ -123,11 +128,6 @@ let print_name ppf = function | None -> fprintf ppf "None" | Some name -> fprintf ppf "\"%s\"" name -let string_of_label = function - | Nolabel -> "" - | Labelled {txt} -> txt - | Optional {txt} -> "?" ^ txt - let visited = ref [] let rec raw_type ppf ty = let ty = safe_repr [] ty in @@ -194,8 +194,6 @@ let raw_type_expr ppf t = raw_type ppf t; visited := [] -let () = Btype.print_raw := raw_type_expr - (* Normalize paths *) type param_subst = Id | Nth of int | Map of int list @@ -932,8 +930,6 @@ let typexp ?printing_context sch ppf ty = let type_expr ppf ty = typexp false ppf ty -and type_sch ppf ty = typexp true ppf ty - and type_scheme ppf ty = reset_and_mark_loops ty; typexp true ppf ty @@ -1010,7 +1006,6 @@ let extension_constructor id ppf ext = (* Print a value declaration *) let tree_of_value_description id decl = - (* Format.eprintf "@[%a@]@." raw_type_expr decl.val_type; *) let id = Ident.name id in let ty = tree_of_type_scheme decl.val_type in let vd = @@ -1138,33 +1133,6 @@ let modtype ppf mty = !Oprint.out_module_type ppf (tree_of_modtype mty) let modtype_declaration id ppf decl = !Oprint.out_sig_item ppf (tree_of_modtype_declaration id decl) -(* For the toplevel: merge with tree_of_signature? *) - -(* Refresh weak variable map in the toplevel *) -let refresh_weak () = - let refresh t name (m, s) = - if is_non_gen true (repr t) then - (Type_map.add t name m, String_set.add name s) - else (m, s) - in - let m, s = - Type_map.fold refresh !weak_var_map (Type_map.empty, String_set.empty) - in - named_weak_vars := s; - weak_var_map := m - -let print_items showval env x = - refresh_weak (); - let rec print showval env = function - | [] -> [] - | item :: rem as items -> - let _sg, rem = filter_rem_sig item rem in - hide_rec_items items; - let trees = trees_of_sigitem item in - List.map (fun d -> (d, showval env item)) trees @ print showval env rem - in - print showval env x - (* Print a signature body (used by -i when compiling a .ml) *) let print_signature ppf tree = diff --git a/compiler/ml/printtyp.mli b/compiler/ml/printtyp.mli index cc7af05150..685df56b19 100644 --- a/compiler/ml/printtyp.mli +++ b/compiler/ml/printtyp.mli @@ -35,14 +35,11 @@ val wrap_printing_env : Env.t -> (unit -> 'a) -> 'a (* Call the function using the environment for type path shortening *) (* This affects all the printing functions below *) -val reset : unit -> unit val mark_loops : type_expr -> unit val reset_and_mark_loops : type_expr -> unit val reset_and_mark_loops_list : type_expr list -> unit val type_expr : formatter -> type_expr -> unit val constructor_arguments : formatter -> constructor_arguments -> unit -val tree_of_type_scheme : type_expr -> out_type -val type_sch : formatter -> type_expr -> unit val type_scheme : formatter -> type_expr -> unit (* Maxence *) @@ -56,19 +53,12 @@ val tree_of_extension_constructor : Ident.t -> extension_constructor -> ext_status -> out_sig_item val extension_constructor : Ident.t -> formatter -> extension_constructor -> unit -val tree_of_module : - Ident.t -> ?ellipsis:bool -> module_type -> rec_status -> out_sig_item val modtype : formatter -> module_type -> unit val signature : formatter -> signature -> unit -val tree_of_modtype_declaration : Ident.t -> modtype_declaration -> out_sig_item val tree_of_signature : Types.signature -> out_sig_item list val tree_of_typexp : ?printing_context:printing_context -> bool -> type_expr -> out_type val modtype_declaration : Ident.t -> formatter -> modtype_declaration -> unit -val type_expansion : type_expr -> Format.formatter -> type_expr -> unit -val prepare_expansion : type_expr * type_expr -> type_expr * type_expr -val trace : - bool -> bool -> string -> formatter -> (type_expr * type_expr) list -> unit val report_unification_error : formatter -> Env.t -> @@ -105,10 +95,3 @@ val report_ambiguous_type_error : (formatter -> unit) -> (formatter -> unit) -> unit - -(* for toploop *) -val print_items : - (Env.t -> signature_item -> 'a option) -> - Env.t -> - signature_item list -> - (out_sig_item * 'a option) list diff --git a/compiler/ml/printtyped.mli b/compiler/ml/printtyped.mli index 11837f15e3..385c916977 100644 --- a/compiler/ml/printtyped.mli +++ b/compiler/ml/printtyped.mli @@ -17,7 +17,6 @@ open Typedtree open Format val interface : formatter -> signature -> unit -val implementation : formatter -> structure -> unit val implementation_with_coercion : formatter -> structure * module_coercion -> unit diff --git a/compiler/ml/record_type_spread.ml b/compiler/ml/record_type_spread.ml index 7e254d0351..2592ea8563 100644 --- a/compiler/ml/record_type_spread.ml +++ b/compiler/ml/record_type_spread.ml @@ -1,7 +1,5 @@ module String_map = Map.Make (String) -let t_equals t1 t2 = t1.Types.level = t2.Types.level && t1.id = t2.id - let substitute_types ~type_map (t : Types.type_expr) = if String_map.is_empty type_map then t else diff --git a/compiler/ml/string_literal.ml b/compiler/ml/string_literal.ml index 24dd0c8afa..88579e1a3c 100644 --- a/compiler/ml/string_literal.ml +++ b/compiler/ml/string_literal.ml @@ -283,6 +283,8 @@ let encode_js mode s = let encode_js_string = encode_js String +(** Encode a semantic UTF-8 string as a canonical JavaScript template-segment + body. *) let encode_js_template = encode_js Template let string_from_source source : string_literal option = diff --git a/compiler/ml/string_literal.mli b/compiler/ml/string_literal.mli index 46477407b5..f3dda64277 100644 --- a/compiler/ml/string_literal.mli +++ b/compiler/ml/string_literal.mli @@ -65,10 +65,6 @@ val encode_js_string : string -> string (** Encode a semantic UTF-8 string as a canonical JavaScript string-literal body. *) -val encode_js_template : string -> string -(** Encode a semantic UTF-8 string as a canonical JavaScript template-segment - body. *) - val string_from_source : string -> string_literal option (** Validate and decode an ordinary string-literal body. *) diff --git a/compiler/ml/stypes.ml b/compiler/ml/stypes.ml deleted file mode 100644 index 0584b16938..0000000000 --- a/compiler/ml/stypes.ml +++ /dev/null @@ -1,188 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) -(* *) -(* Copyright 2003 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(* Recording and dumping (partial) type information *) - -(* - We record all types in a list as they are created. - This means we can dump type information even if type inference fails, - which is extremely important, since type information is most - interesting in case of errors. -*) - -open Annot -open Lexing -open Location -open Typedtree - -let output_int oc i = output_string oc (string_of_int i) - -type annotation = - | Ti_pat of pattern - | Ti_expr of expression - | Ti_class of unit - | Ti_mod of module_expr - | An_call of Location.t * Annot.call - | An_ident of Location.t * string * Annot.ident - -let get_location ti = - match ti with - | Ti_pat p -> p.pat_loc - | Ti_expr e -> e.exp_loc - | Ti_class () -> assert false - | Ti_mod m -> m.mod_loc - | An_call (l, _k) -> l - | An_ident (l, _s, _k) -> l - -let annotations = ref ([] : annotation list) -let phrases = ref ([] : Location.t list) - -let record ti = - if !Clflags.annotations && not (get_location ti).Location.loc_ghost then - annotations := ti :: !annotations - -let record_phrase loc = if !Clflags.annotations then phrases := loc :: !phrases - -(* comparison order: - the intervals are sorted by order of increasing upper bound - same upper bound -> sorted by decreasing lower bound -*) -let cmp_loc_inner_first loc1 loc2 = - match compare loc1.loc_end.pos_cnum loc2.loc_end.pos_cnum with - | 0 -> compare loc2.loc_start.pos_cnum loc1.loc_start.pos_cnum - | x -> x -let cmp_ti_inner_first ti1 ti2 = - cmp_loc_inner_first (get_location ti1) (get_location ti2) - -let print_position pp pos = - if pos = dummy_pos then output_string pp "--" - else ( - output_char pp '\"'; - output_string pp (String.escaped pos.pos_fname); - output_string pp "\" "; - output_int pp pos.pos_lnum; - output_char pp ' '; - output_int pp pos.pos_bol; - output_char pp ' '; - output_int pp pos.pos_cnum) - -let print_location pp loc = - print_position pp loc.loc_start; - output_char pp ' '; - print_position pp loc.loc_end - -let sort_filter_phrases () = - let ph = List.sort (fun x y -> cmp_loc_inner_first y x) !phrases in - let rec loop accu cur l = - match l with - | [] -> accu - | loc :: t -> - if - cur.loc_start.pos_cnum <= loc.loc_start.pos_cnum - && cur.loc_end.pos_cnum >= loc.loc_end.pos_cnum - then loop accu cur t - else loop (loc :: accu) loc t - in - phrases := loop [] Location.none ph - -let rec printtyp_reset_maybe loc = - match !phrases with - | cur :: t when cur.loc_start.pos_cnum <= loc.loc_start.pos_cnum -> - Printtyp.reset (); - phrases := t; - printtyp_reset_maybe loc - | _ -> () - -let call_kind_string k = - match k with - | Tail -> "tail" - | Stack -> "stack" - | Inline -> "inline" - -let print_ident_annot pp str k = - match k with - | Idef l -> - output_string pp "def "; - output_string pp str; - output_char pp ' '; - print_location pp l; - output_char pp '\n' - | Iref_internal l -> - output_string pp "int_ref "; - output_string pp str; - output_char pp ' '; - print_location pp l; - output_char pp '\n' - | Iref_external -> - output_string pp "ext_ref "; - output_string pp str; - output_char pp '\n' - -(* The format of the annotation file is documented in emacs/caml-types.el. *) - -let print_info pp prev_loc ti = - match ti with - | Ti_class _ | Ti_mod _ -> prev_loc - | Ti_pat {pat_loc = loc; pat_type = typ; pat_env = env} - | Ti_expr {exp_loc = loc; exp_type = typ; exp_env = env} -> - if loc <> prev_loc then ( - print_location pp loc; - output_char pp '\n'); - output_string pp "type(\n"; - printtyp_reset_maybe loc; - Printtyp.mark_loops typ; - Format.pp_print_string Format.str_formatter " "; - Printtyp.wrap_printing_env env (fun () -> - Printtyp.type_sch Format.str_formatter typ); - Format.pp_print_newline Format.str_formatter (); - let s = Format.flush_str_formatter () in - output_string pp s; - output_string pp ")\n"; - loc - | An_call (loc, k) -> - if loc <> prev_loc then ( - print_location pp loc; - output_char pp '\n'); - output_string pp "call(\n "; - output_string pp (call_kind_string k); - output_string pp "\n)\n"; - loc - | An_ident (loc, str, k) -> - if loc <> prev_loc then ( - print_location pp loc; - output_char pp '\n'); - output_string pp "ident(\n "; - print_ident_annot pp str k; - output_string pp ")\n"; - loc - -let get_info () = - let info = List.fast_sort cmp_ti_inner_first !annotations in - annotations := []; - info - -let dump filename = - if !Clflags.annotations then ( - let do_dump _temp_filename pp = - let info = get_info () in - sort_filter_phrases (); - ignore (List.fold_left (print_info pp) Location.none info) - in - (match filename with - | None -> do_dump "" stdout - | Some filename -> - Misc.output_to_file_via_temporary ~mode:[Open_text] filename do_dump); - phrases := []) - else annotations := [] diff --git a/compiler/ml/stypes.mli b/compiler/ml/stypes.mli deleted file mode 100644 index 3182f7eb9a..0000000000 --- a/compiler/ml/stypes.mli +++ /dev/null @@ -1,35 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Damien Doligez, projet Moscova, INRIA Rocquencourt *) -(* *) -(* Copyright 2003 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(* Recording and dumping (partial) type information *) - -(* Clflags.save_types must be true *) - -open Typedtree - -type annotation = - | Ti_pat of pattern - | Ti_expr of expression - | Ti_class of unit - | Ti_mod of module_expr - | An_call of Location.t * Annot.call - | An_ident of Location.t * string * Annot.ident - -val record : annotation -> unit -val record_phrase : Location.t -> unit -val dump : string option -> unit - -val get_location : annotation -> Location.t -val get_info : unit -> annotation list diff --git a/compiler/ml/subst.ml b/compiler/ml/subst.ml index c4d2215d2a..ac93e40702 100644 --- a/compiler/ml/subst.ml +++ b/compiler/ml/subst.ml @@ -232,8 +232,6 @@ let rec typexp_rec s ty = *) let type_expr s ty = with_copy_session (fun () -> typexp_rec s ty) -let typexp = type_expr - let label_declaration s l = { ld_id = l.ld_id; diff --git a/compiler/ml/subst.mli b/compiler/ml/subst.mli index 3ab7386521..e04842364a 100644 --- a/compiler/ml/subst.mli +++ b/compiler/ml/subst.mli @@ -60,8 +60,6 @@ val extension_constructor : t -> extension_constructor -> extension_constructor val modtype : t -> module_type -> module_type val signature : t -> signature -> signature val modtype_declaration : t -> modtype_declaration -> modtype_declaration -val module_declaration : t -> module_declaration -> module_declaration -val typexp : t -> Types.type_expr -> Types.type_expr (* A forward reference to be filled in ctype.ml. *) val ctype_apply_env_empty : diff --git a/compiler/ml/tbl.ml b/compiler/ml/tbl.ml index d37ba50e77..54fa8c9c09 100644 --- a/compiler/ml/tbl.ml +++ b/compiler/ml/tbl.ml @@ -63,27 +63,6 @@ let rec find_str (x : string) = function let c = compare x v in if c = 0 then d else find_str x (if c < 0 then l else r) -let rec mem x = function - | Empty -> false - | Node (l, v, _d, r, _) -> - let c = compare x v in - c = 0 || mem x (if c < 0 then l else r) - -let rec merge t1 t2 = - match (t1, t2) with - | Empty, t -> t - | t, Empty -> t - | Node (l1, v1, d1, r1, _h1), Node (l2, v2, d2, r2, _h2) -> - bal l1 v1 d1 (bal (merge r1 l2) v2 d2 r2) - -let rec remove x = function - | Empty -> Empty - | Node (l, v, d, r, _h) -> - let c = compare x v in - if c = 0 then merge l r - else if c < 0 then bal (remove x l) v d r - else bal l v d (remove x r) - let rec iter f = function | Empty -> () | Node (l, v, d, r, _) -> @@ -91,21 +70,7 @@ let rec iter f = function f v d; iter f r -let rec map f = function - | Empty -> Empty - | Node (l, v, d, r, h) -> Node (map f l, v, f v d, map f r, h) - let rec fold f m accu = match m with | Empty -> accu | Node (l, v, d, r, _) -> fold f r (f v d (fold f l accu)) - -open Format - -let print print_key print_data ppf tbl = - let print_tbl ppf tbl = - iter - (fun k d -> fprintf ppf "@[<2>%a ->@ %a;@]@ " print_key k print_data d) - tbl - in - fprintf ppf "@[[[%a]]@]" print_tbl tbl diff --git a/compiler/ml/tbl.mli b/compiler/ml/tbl.mli index 7d9296eb25..9b67830715 100644 --- a/compiler/ml/tbl.mli +++ b/compiler/ml/tbl.mli @@ -22,17 +22,5 @@ val empty : ('k, 'v) t val add : 'k -> 'v -> ('k, 'v) t -> ('k, 'v) t val find : 'k -> ('k, 'v) t -> 'v val find_str : string -> (string, 'v) t -> 'v -val mem : 'k -> ('k, 'v) t -> bool -val remove : 'k -> ('k, 'v) t -> ('k, 'v) t val iter : ('k -> 'v -> unit) -> ('k, 'v) t -> unit -val map : ('k -> 'v1 -> 'v2) -> ('k, 'v1) t -> ('k, 'v2) t val fold : ('k -> 'v -> 'acc -> 'acc) -> ('k, 'v) t -> 'acc -> 'acc - -open Format - -val print : - (formatter -> 'k -> unit) -> - (formatter -> 'v -> unit) -> - formatter -> - ('k, 'v) t -> - unit diff --git a/compiler/ml/translmod.ml b/compiler/ml/translmod.ml index 6e9d02b88e..064d9723c1 100644 --- a/compiler/ml/translmod.ml +++ b/compiler/ml/translmod.ml @@ -71,6 +71,8 @@ let transl_type_extension env rootpath (tyext : Typedtree.type_extension) body : (* Compile a coercion *) let rec apply_coercion loc strict (restr : Typedtree.module_coercion) arg = + if !Clflags.dump_coercions then + Format.eprintf "@[<2>apply_coercion@ %a@]@." Includemod.print_coercion restr; match restr with | Tcoerce_none -> arg | Tcoerce_structure (pos_cc_list, id_pos_list, runtime_fields) -> @@ -115,9 +117,6 @@ and apply_coercion_result loc strict funct param arg cc_res = and wrap_id_pos_list loc id_pos_list get_field lam = let fv = Lambda_traverse.free_variables lam in - (*Format.eprintf "%a@." Printlambda.lambda lam; - IdentSet.iter (fun id -> Format.eprintf "%a " Ident.print id) fv; - Format.eprintf "@.";*) let lam, s = List.fold_left (fun (lam, s) (id', pos, c) -> @@ -166,19 +165,6 @@ let rec compose_coercions c1 c2 = | c1, Tcoerce_alias (path, c2) -> Tcoerce_alias (path, compose_coercions c1 c2) | _, _ -> Misc.fatal_error "Translmod.compose_coercions" -(* -let apply_coercion a b c = - Format.eprintf "@[<2>apply_coercion@ %a@]@." Includemod.print_coercion b; - apply_coercion a b c - -let compose_coercions c1 c2 = - let c3 = compose_coercions c1 c2 in - let open Includemod in - Format.eprintf "@[<2>compose_coercions@ (%a)@ (%a) =@ %a@]@." - print_coercion c1 print_coercion c2 print_coercion c3; - c3 -*) - (* Record the primitive declarations occurring in the module compiled *) let rec pure_module m : Lambda.let_kind = diff --git a/compiler/ml/translmod.mli b/compiler/ml/translmod.mli index efd18ad9c8..471a46f4ca 100644 --- a/compiler/ml/translmod.mli +++ b/compiler/ml/translmod.mli @@ -27,5 +27,3 @@ val transl_implementation : type error (* exception Error of Location.t * error *) - -val report_error : Format.formatter -> error -> unit diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index 54d4833f68..0292c362d5 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -136,11 +136,9 @@ let type_package = ref (fun _ -> assert false) *) let re node = Cmt_format.add_saved_type (Cmt_format.Partial_expression node); - Stypes.record (Stypes.Ti_expr node); node let rp node = Cmt_format.add_saved_type (Cmt_format.Partial_pattern node); - Stypes.record (Stypes.Ti_pat node); node type recarg = Allowed | Required | Rejected @@ -314,7 +312,7 @@ let check_polyvar_name env loc name = | Some _ -> () | None -> raise (Error (loc, env, Polyvar_literal_overflow)) -(* Specific version of type_option, using newty rather than newgenty *) +(* The type [ty option], created at the current level *) let type_option ty = newty (Tconstr (Predef.path_option, [ty], ref Mnil)) @@ -421,12 +419,7 @@ let finalize_variant pat = | Some pat -> List.iter (unify_pat pat.pat_env pat) (ty :: tl)) | Reither (c, _l, true, e) when not (row_fixed row) -> set_row_field e (Reither (c, [], false, ref None)) - | _ -> () - (* Force check of well-formedness WHY? *) - (* unify_pat pat.pat_env pat - (newty(Tvariant{row_fields=[]; row_more=newvar(); row_closed=false; - row_bound=(); row_fixed=false; row_name=None})); *) - ) + | _ -> ()) | _ -> () let rec iter_pattern f p = @@ -450,13 +443,11 @@ let pattern_variables = : (Ident.t * type_expr * string loc * Location.t * bool (* as-variable *)) list) let pattern_force = ref ([] : (unit -> unit) list) -let pattern_scope = ref (None : Annot.ident option) let allow_modules = ref false let module_variables = ref ([] : (string loc * Location.t) list) -let reset_pattern scope allow = +let reset_pattern allow = pattern_variables := []; pattern_force := []; - pattern_scope := scope; allow_modules := allow; module_variables := [] @@ -472,12 +463,7 @@ let enter_variable ?(is_module = false) ?(is_as_variable = false) loc name ty = (* Note: unpack patterns enter a variable of the same name *) if not !allow_modules then raise (Error (loc, Env.empty, Modules_not_allowed)); - module_variables := (name, loc) :: !module_variables) - else - (* moved to genannot *) - may - (fun s -> Stypes.record (Stypes.An_ident (name.loc, name.txt, s))) - !pattern_scope; + module_variables := (name, loc) :: !module_variables); id let sort_pattern_variables vs = @@ -1733,9 +1719,6 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env sp in unify_pat_types loc !env ty expected_ty; type_pat sp expected_ty' (fun p -> - (*Format.printf "%a@.%a@." - Printtyp.raw_type_expr ty - Printtyp.raw_type_expr p.pat_type;*) pattern_force := force :: !pattern_force; let extra = (Tpat_constraint cty, loc, sp.ppat_attributes) in let p = @@ -1783,13 +1766,13 @@ let type_pat ?(allow_existentials = false) ?constrs ?labels ?(mode = Normal) newtype_level := None; raise e -(* this function is passed to Partial.parmatch - to type check gadt nonexhaustiveness *) +(* this function is passed to Parmatch.check_partial_gadt and + Parmatch.check_unused to type check gadt nonexhaustiveness *) let partial_pred ~lev ?mode ?explode env expected_ty constrs labels p = let env = ref env in let state = save_state env in try - reset_pattern None true; + reset_pattern true; let typed_p = Ctype.with_passive_variants (type_pat ~allow_existentials:true ~lev ~constrs ~labels ?mode ?explode @@ -1837,8 +1820,8 @@ let add_pattern_variables ?check ?check_as env = pv env, get_ref module_variables ) -let type_pattern ~lev env spat scope expected_ty = - reset_pattern scope true; +let type_pattern ~lev env spat expected_ty = + reset_pattern true; let new_env = ref env in let pat = type_pat ~allow_existentials:true ~lev new_env spat expected_ty in let new_env, unpacks = @@ -1848,8 +1831,8 @@ let type_pattern ~lev env spat scope expected_ty = in (pat, new_env, get_ref pattern_force, unpacks) -let type_pattern_list env spatl scope expected_tys allow = - reset_pattern scope allow; +let type_pattern_list env spatl expected_tys allow = + reset_pattern allow; let new_env = ref env in let type_pat (attrs, pat) ty = Builtin_attributes.warning_scope ~ppwarning:false attrs (fun () -> @@ -2238,7 +2221,6 @@ let check_absent_variant env = (fun (s', fi) -> s = s' && row_field_repr fi <> Rabsent) row.row_fields || ((not row.row_fixed) && not (static_row row)) - (* same as Ctype.poly *) then () else let ty_arg = @@ -2270,9 +2252,9 @@ let duplicate_ident_types caselist env = in Env.copy_types (all_idents_cases caselist) env -(* type_label_a_list returns a list of labels sorted by lbl_pos *) +(* type_record_elem_list returns a list of labels sorted by lbl_pos *) (* note: check_duplicates would better be implemented in - type_label_a_list directly *) + type_record_elem_list directly *) let rec check_duplicates ~get_jsx_component_error_info loc env = function | (_, lbl1, _, _) :: ((l : Longident.t loc), lbl2, _, _) :: _ when lbl1.lbl_pos = lbl2.lbl_pos -> @@ -2461,14 +2443,6 @@ and type_expect_ ?deprecated_context ~context ?(recarg = Rejected) env sexp | v -> v) env lid.loc lid.txt in - (if !Clflags.annotations then - let dloc = desc.Types.val_loc in - let annot = - if dloc.Location.loc_ghost then Annot.Iref_external - else Annot.Iref_internal dloc - in - let name = Path.name ~paren:Oprint.parenthesized_ident path in - Stypes.record (Stypes.An_ident (loc, name, annot))); let is_recarg = match (repr desc.val_type).desc with | Tconstr (p, _, _) -> Path.is_constructor_typath p @@ -2513,13 +2487,8 @@ and type_expect_ ?deprecated_context ~context ?(recarg = Rejected) env sexp } ty_expected | Pexp_let (rec_flag, spat_sexp_list, sbody) -> - let scp = - match rec_flag with - | Recursive -> Some (Annot.Idef loc) - | Nonrecursive -> Some (Annot.Idef sbody.pexp_loc) - in let pat_exp_list, new_env, unpacks = - type_let ~context:None env rec_flag spat_sexp_list scp true + type_let ~context:None env rec_flag spat_sexp_list true in let body = type_expect ~context:None new_env (wrap_unpacks sbody unpacks) ty_expected @@ -3245,7 +3214,7 @@ and type_expect_ ?deprecated_context ~context ?(recarg = Rejected) env sexp } env ~check:(fun s -> Warnings.Unused_for_index s) | _ -> (* unreachable: the parser's normalize_for_of_pattern - (compiler/syntax/src/res_core.ml:3841) catches every non-var, + (compiler/syntax/src/res_core.ml) catches every non-var, non-`_` pattern, emits a syntax error, and replaces the pattern with Ppat_any before the typer runs *) assert false @@ -3282,7 +3251,7 @@ and type_expect_ ?deprecated_context ~context ?(recarg = Rejected) env sexp } env ~check:(fun s -> Warnings.Unused_for_index s) | _ -> (* unreachable: the parser's normalize_for_of_pattern - (compiler/syntax/src/res_core.ml:3841) catches every non-var, + (compiler/syntax/src/res_core.ml) catches every non-var, non-`_` pattern, emits a syntax error, and replaces the pattern with Ppat_any before the typer runs *) assert false @@ -3822,7 +3791,6 @@ and type_function ~async loc attrs env ty_expected_ let lev, env = if has_gadts then init_env () else (get_current_level (), env) in - let scope = Some (Annot.Idef sbody.pexp_loc) in let rec type_params typed_acc env unpacks_acc defaults_acc (params : (Parsetree.fun_param * Parsetree.value_binding option) list) tys = @@ -3844,7 +3812,7 @@ and type_function ~async loc attrs env ty_expected_ let pat, ext_env, force, unpacks = let partial = if erase_either then Some false else None in let ty_arg_i = instance ?partial env ty_arg_c in - type_pattern ~lev env spat scope ty_arg_i + type_pattern ~lev env spat ty_arg_i in pattern_force := force @ !pattern_force; let ty_arg' = newvar () in @@ -3869,7 +3837,7 @@ and type_function ~async loc attrs env ty_expected_ | Some vb -> let let_env = ext_env in let pat_exp_list, ext_env, let_unpacks = - type_let ~context:None ext_env Nonrecursive [vb] None true + type_let ~context:None ext_env Nonrecursive [vb] true in (* The pattern binds the option carrier under an unspellable name ([*opt_