Skip to content

Commit db65b76

Browse files
committed
library: make the error formatter a parameter
1 parent 3ecc3ab commit db65b76

29 files changed

+135
-109
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Support 5.2
44
* Support 5.3
5+
* Expose LGPL library
6+
* Make the error formatter a parameter
57

68
## Bug fixes
79

core/analysis.ml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type param = {
55
epsilon_dependencies:bool;
66
transparent_aliases: bool;
77
transparent_extension_nodes: bool;
8-
policy: Fault.Policy.t;
8+
fault_handler: Fault.handler;
99
precomputed_libs: Name.set;
1010
closed_world: bool;
1111
sig_only:bool;
@@ -59,38 +59,38 @@ let pair_split l =
5959
List.fold_left folder {ml=[];mli=[]} l
6060

6161
(** organisation **)
62-
let signature_error policy = function
62+
let signature_error fault_handler = function
6363
| Ok x, _ -> Some x
6464
| Error e, filename ->
65-
Standard_faults.schematic_errors policy (filename,"sig",e);
65+
Standard_faults.schematic_errors fault_handler (filename,"sig",e);
6666
None
6767

68-
let pre_organize policy io files =
68+
let pre_organize fault_handler io files =
6969
let units, signatures = split (info_split io) files in
7070
let signatures =
7171
Module.Namespace.merge_all @@ Option.List'.filter
72-
@@ List.map (signature_error policy) signatures in
72+
@@ List.map (signature_error fault_handler) signatures in
7373
units, signatures
7474

75-
let load_file (io:Io.reader) policy sig_only opens (info,file,n) =
75+
let load_file (io:Io.reader) fault_handler sig_only opens (info,file,n) =
7676
let filter_m2l (u: Unit.s) = if sig_only then
7777
{ u with Unit.code = M2l.Sig_only.filter u.code }
7878
else
7979
u in
80-
io.m2l policy info file n
80+
io.m2l fault_handler info file n
8181
|> filter_m2l
8282
|> open_within opens
8383

8484

85-
let log_conflict policy proj (path, units) =
86-
Fault.raise policy Standard_faults.local_module_conflict
85+
let log_conflict fault_handler proj (path, units) =
86+
Fault.raise fault_handler Standard_faults.local_module_conflict
8787
(path, List.map proj units)
8888

89-
let organize io policy sig_only opens files =
90-
let units, signatures = pre_organize policy io files in
91-
let units = List.map (load_file io policy sig_only opens) units in
89+
let organize io fault_handler sig_only opens files =
90+
let units, signatures = pre_organize fault_handler io files in
91+
let units = List.map (load_file io fault_handler sig_only opens) units in
9292
let units, errs = Unit.Group.(split % group) @@ pair_split units in
93-
List.iter (log_conflict policy @@ fun (u:Unit.s) -> u.src ) errs;
93+
List.iter (log_conflict fault_handler @@ fun (u:Unit.s) -> u.src ) errs;
9494
units, signatures
9595

9696

@@ -140,7 +140,7 @@ let start_env io param libs signatures fileset =
140140

141141
let lift p =
142142
(module struct
143-
let policy = p.policy
143+
let fault_handler = p.fault_handler
144144
let epsilon_dependencies = p.epsilon_dependencies
145145
let transparent_extension_nodes = p.transparent_extension_nodes
146146
let transparent_aliases = p.transparent_aliases
@@ -206,9 +206,9 @@ module Collisions = struct
206206
) m units
207207

208208
(** Print error message for a given collision map *)
209-
let handle policy fault collisions =
209+
let handle fault_handler fault collisions =
210210
let err name paths () =
211-
Fault.raise policy fault (name,Pkg.Set.elements paths) in
211+
Fault.raise fault_handler fault (name,Pkg.Set.elements paths) in
212212
Nms.Map.fold err collisions ()
213213

214214
(** Compute local/local collisions *)
@@ -229,16 +229,17 @@ end
229229
(** Analysis step *)
230230
let main_std io param (task:Common.task) =
231231
let module F = Standard_faults in
232+
let is_silent f = Fault.is_silent param.fault_handler.policy f in
232233
let units, signatures =
233-
organize io param.policy param.sig_only task.opens task.files in
234-
if not @@ Fault.is_silent param.policy F.module_conflict then
234+
organize io param.fault_handler param.sig_only task.opens task.files in
235+
if not (is_silent F.module_conflict) then
235236
Collisions.libs task units.mli
236-
|> Collisions.handle param.policy F.module_conflict;
237+
|> Collisions.handle param.fault_handler F.module_conflict;
237238
let collisions = Collisions.local units.mli in
238239
let namespace = List.map (fun (u:Unit.s) -> u.path) units.mli in
239240
let () =
240-
if not @@ Fault.is_silent param.policy F.local_module_conflict then
241-
Collisions.handle param.policy F.local_module_conflict collisions in
241+
if not (is_silent F.local_module_conflict) then
242+
Collisions.handle param.fault_handler F.local_module_conflict collisions in
242243
let e = start_env io param task.libs signatures namespace in
243244
let {Unit.ml; mli} = solve param e units in
244245
let ml = remove_units task.invisibles ml in
@@ -248,9 +249,9 @@ let main_std io param (task:Common.task) =
248249
(** Analysis step *)
249250
let main_seed io param (task:Common.task) =
250251
let units, signatures =
251-
pre_organize param.policy io task.files in
252+
pre_organize param.fault_handler io task.files in
252253
let file_list = List.map (fun (_k,_x,p) -> p) units in
253-
let load_file = load_file io param.policy param.sig_only task.opens in
254+
let load_file = load_file io param.fault_handler param.sig_only task.opens in
254255
let e = start_env io param task.libs signatures file_list in
255256
let units = solve_from_seeds task.seeds load_file units param e in
256257
let units = remove_units task.invisibles units in
@@ -261,7 +262,7 @@ let main_seed io param (task:Common.task) =
261262
) { ml=[]; mli=[]} units in
262263
let g, errs = Unit.Group.(split % group) units in
263264
List.iter
264-
(log_conflict param.policy @@ fun (u:Unit.r) -> u.src) errs;
265+
(log_conflict param.fault_handler @@ fun (u:Unit.r) -> u.src) errs;
265266
g
266267

267268
let main io param (task:Common.task) =

core/analysis.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type param = {
44
epsilon_dependencies: bool;
55
transparent_aliases: bool;
66
transparent_extension_nodes: bool;
7-
policy: Fault.Policy.t;
7+
fault_handler: Fault.handler;
88
precomputed_libs: Name.set ;
99
closed_world: bool;
1010
sig_only:bool;

core/args.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ let param0 = {
4444
precomputed_libs = Name.Set.singleton "stdlib";
4545
closed_world = false;
4646
sig_only = false;
47-
policy = Codept_policies.policy;
47+
fault_handler = {
48+
Fault.policy = Codept_policies.policy;
49+
err_formatter = Format.err_formatter
50+
}
4851
};
4952

5053
no_include = false;
@@ -80,7 +83,7 @@ let with_output out s f=
8083

8184
let iter_makefile out param interm s =
8285
with_output out s (fun ppf ->
83-
Makefile.main L.(param#.policy) ppf param.synonyms param.makefile interm
86+
Makefile.main L.(param#.fault_handler) ppf param.synonyms param.makefile interm
8487
)
8588

8689
(** {2 Option implementations } *)

core/common.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ let is_stdlib_pkg = function
5050
| _ -> false
5151

5252

53-
let classify policy synonyms f =
53+
let classify fault_handler synonyms f =
5454
let ext = Support.extension f in
5555
match Name.Map.find ext synonyms with
5656
| x -> Some x
5757
| exception Not_found ->
58-
Fault.raise policy Codept_policies.unknown_extension ext; None
58+
Fault.raise fault_handler Codept_policies.unknown_extension ext; None

core/common.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ val is_stdlib_pkg: Name.t -> bool
3838

3939
(** [classify policy synonyms filename] classifies file type
4040
according to the dictionary [synonyms] *)
41-
val classify: Fault.Policy.t -> info Name.map -> string -> info option
41+
val classify: Fault.handler -> info Name.map -> string -> info option

core/io.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
type reader = {
33
sign: string -> (Module.Namespace.t, Schematic.Ext.error) result;
4-
m2l: Fault.Policy.t -> Read.kind -> string
4+
m2l: Fault.handler -> Read.kind -> string
55
-> Namespaced.t -> Unit.s;
66
findlib: Common.task -> Findlib.query -> Common.task ;
77
env: Module.dict

core/io.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
type reader = {
55
sign: string -> (Module.Namespace.t, Schematic.Ext.error) result ;
6-
m2l: Fault.Policy.t -> Read.kind -> string -> Namespaced.t
6+
m2l: Fault.handler -> Read.kind -> string -> Namespaced.t
77
-> Unit.s;
88
findlib: Common.task -> Findlib.query -> Common.task ;
99
env: Module.dict

core/makefile.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let implicit_dep synonyms path =
4242

4343

4444

45-
let expand_includes policy synonyms includes =
45+
let expand_includes fault_handler synonyms includes =
4646
let read_dir expanded dir =
4747
let dir = Common.expand_dir dir in
4848
if Sys.file_exists dir && Sys.is_directory dir then
@@ -52,8 +52,9 @@ let expand_includes policy synonyms includes =
5252
let policy =
5353
let open Fault in
5454
Policy.register ~lvl:Level.info
55-
Codept_policies.unknown_extension policy in
56-
match Common.classify policy synonyms x with
55+
Codept_policies.unknown_extension fault_handler.Fault.policy in
56+
let fault_handler = Fault.{ fault_handler with policy } in
57+
match Common.classify fault_handler synonyms x with
5758
| None | Some { Common.kind = Signature; _ } -> m
5859
| Some { Common.kind = Interface | Implementation ; _ } ->
5960
Modname.Map.add (Unitname.modname (Read.name x))
@@ -121,19 +122,19 @@ let cmo_or_cmi synonyms path =
121122
| { Unit.mli = true; ml = _ } -> Pkg.cmi path
122123
| _ -> Pkg.cmo path
123124

124-
let collision_error policy = function
125+
let collision_error fault_handler = function
125126
| a :: _ as l ->
126-
Fault.raise policy Standard_faults.local_module_conflict
127+
Fault.raise fault_handler Standard_faults.local_module_conflict
127128
(a.Unit.path, List.map (fun u -> u.Unit.src) l)
128129
| [] -> ()
129130

130-
let unit_main policy param synonyms printer g =
131+
let unit_main fault_handler param synonyms printer g =
131132
let cmo_or_cmi = cmo_or_cmi synonyms and cmi_or = cmi_or synonyms in
132133
let open Unit in
133134
let all = param.all in
134135
let if_all l = if all then l else [] in
135136
let g, err = Unit.Group.flatten g in
136-
List.iter (collision_error policy) [err.ml; err.mli];
137+
List.iter (collision_error fault_handler) [err.ml; err.mli];
137138
match g with
138139
| { ml= Some impl ; mli = Some intf } ->
139140
let cmi = Pkg.cmi impl.src in
@@ -167,8 +168,8 @@ let unit_main policy param synonyms printer g =
167168
| { ml = None; mli = None } -> ()
168169

169170

170-
let main policy ppf synonyms param units =
171-
let includes = expand_includes policy synonyms param.includes in
171+
let main fault_handler ppf synonyms param units =
172+
let includes = expand_includes fault_handler synonyms param.includes in
172173
let print_deps x y = print_deps includes param x y ppf in
173174
let m =regroup units in
174-
Unit.Group.Map.iter (unit_main policy param synonyms print_deps) m
175+
Unit.Group.Map.iter (unit_main fault_handler param synonyms print_deps) m

core/makefile.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ type param =
1414
}
1515

1616
val main:
17-
Fault.Policy.t -> Format.formatter -> Common.synonyms -> param ->
17+
Fault.handler -> Format.formatter -> Common.synonyms -> param ->
1818
Unit.r list Unit.pair -> unit

0 commit comments

Comments
 (0)