@@ -17,17 +17,23 @@ type warning_span = Location_span.t * string [@@deriving compare]
1717 ********************)
1818
1919let list_unused_params (factor_graph : factor_graph ) (mir : Program.Typed.t ) :
20- string Set.Poly. t =
20+ ( string * Location_span. t ) Set.Poly. t =
2121 (* Build a factor graph of the program, check for missing parameters *)
22- let params = parameter_names_set ~include_transformed: false mir in
22+ let param_info = parameter_set ~include_transformed: false mir in
23+ let params = Set.Poly. map ~f: fst3 param_info in
2324 let used_params =
2425 Set.Poly. map
2526 ~f: (fun (VVar v ) -> v)
2627 (Set.Poly. of_list (Map.Poly. keys factor_graph.var_map)) in
27- Set. diff params used_params
28+ let unused = Set. diff params used_params in
29+ Set.Poly. filter_map
30+ ~f: (fun (pname , _ , loc ) ->
31+ if Set. mem unused pname then Some (pname, loc) else None )
32+ param_info
2833
2934let list_hard_constrained (mir : Program.Typed.t ) :
30- (string * [`HardConstraint | `NonsenseConstraint]) Set.Poly. t =
35+ (string * [`HardConstraint | `NonsenseConstraint] * Location_span. t )
36+ Set.Poly. t =
3137 (* Iterate through all parameters' transformations for hard constraints *)
3238 let constrained (e : bound_values ) =
3339 match e with
@@ -37,9 +43,9 @@ let list_hard_constrained (mir : Program.Typed.t) :
3743 | {lower = `Lit _ ; upper = `Lit _ } -> Some `HardConstraint
3844 | _ -> None in
3945 Set.Poly. filter_map
40- ~f: (fun (name , trans ) ->
46+ ~f: (fun (name , trans , loc ) ->
4147 Option. map
42- ~f: (fun c -> (name, c))
48+ ~f: (fun c -> (name, c, loc ))
4349 (constrained (trans_bounds_values trans)))
4450 (parameter_set mir)
4551
@@ -261,30 +267,31 @@ let list_param_dependant_fundefs_cf (mir : Program.Typed.t) :
261267 (fun_def.fdname, cf_loc, deps, arg_name, arg_loc)))
262268
263269let list_non_one_priors (fg : factor_graph ) (mir : Program.Typed.t ) :
264- (string * int ) Set.Poly. t =
270+ (string * int * Location_span. t ) Set.Poly. t =
265271 (* Use the factor graph definition of priors, which treats a neighboring
266272 factor as a prior for parameter P if it has no connection to the data
267273 except through P *)
268274 let priors = list_priors ~factor_graph: (Some fg) mir in
269275 let prior_set =
270276 Map.Poly. fold priors ~init: Set.Poly. empty
271- ~f: (fun ~key :(VVar v ) ~data :factors_opt s ->
277+ ~f: (fun ~key :(VVar v ) ~data :( factors_opt , loc ) s ->
272278 Option. value_map factors_opt ~default: s ~f: (fun factors ->
273- Set. add s (v, Set. length factors))) in
279+ Set. add s (v, Set. length factors, loc ))) in
274280 (* Return only multi-prior parameters *)
275- Set. filter prior_set ~f: (fun (_ , n ) -> n <> 1 )
281+ Set. filter prior_set ~f: (fun (_ , n , _ ) -> n <> 1 )
276282
277283(* Collect useful information about an expression that's available at
278284 compile-time into a convenient form. *)
279285let compiletime_value_of_expr
280- (params : (string * Expr.Typed.t Transformation.t) Set.Poly.t )
286+ (params :
287+ (string * Expr.Typed.t Transformation.t * Location_span.t) Set.Poly.t )
281288 (data : string Set.Poly.t ) (expr : Expr.Typed.t ) :
282289 compiletime_val * Expr.Typed.Meta. t =
283290 let v =
284291 match expr with
285292 | {pattern = Var pname ; _} -> (
286- match Set. find params ~f: (fun (name , _ ) -> name = pname) with
287- | Some (name , trans ) -> Param (name, trans)
293+ match Set. find params ~f: (fun (name , _ , _ ) -> name = pname) with
294+ | Some (name , trans , _ ) -> Param (name, trans)
288295 | None -> (
289296 match Set. find data ~f: (fun name -> name = pname) with
290297 | Some name -> Data name
@@ -372,11 +379,10 @@ let hard_constrained_message (pname : string) : string =
372379let hard_constrained_warnings (mir : Program.Typed.t ) =
373380 let pnames = list_hard_constrained mir in
374381 Set.Poly. map
375- ~f: (fun (pname , c ) ->
382+ ~f: (fun (pname , c , loc ) ->
376383 match c with
377- | `HardConstraint -> (Location_span. empty, hard_constrained_message pname)
378- | `NonsenseConstraint ->
379- (Location_span. empty, nonsense_constrained_message pname))
384+ | `HardConstraint -> (loc, hard_constrained_message pname)
385+ | `NonsenseConstraint -> (loc, nonsense_constrained_message pname))
380386 pnames
381387
382388let maybe_jacobian_adjustment_warnings (mir : Program.Typed.t ) =
@@ -440,7 +446,7 @@ let unused_params_message (pname : string) : string =
440446let unused_params_warnings (factor_graph : factor_graph ) (mir : Program.Typed.t )
441447 =
442448 Set.Poly. map
443- ~f: (fun pname -> (Location_span. empty , unused_params_message pname))
449+ ~f: (fun ( pname , loc ) -> (loc , unused_params_message pname))
444450 (list_unused_params factor_graph mir)
445451
446452let non_one_priors_message (pname : string ) (n : int ) : string =
@@ -455,7 +461,7 @@ let non_one_priors_message (pname : string) (n : int) : string =
455461let non_one_priors_warnings (factor_graph : factor_graph )
456462 (mir : Program.Typed.t ) =
457463 Set.Poly. map
458- ~f: (fun (pname , n ) -> (Location_span. empty , non_one_priors_message pname n))
464+ ~f: (fun (pname , n , loc ) -> (loc , non_one_priors_message pname n))
459465 (list_non_one_priors factor_graph mir)
460466
461467let uninitialized_message (vname : string ) : string =
@@ -500,4 +506,4 @@ let warn_pedantic (mir_unopt : Program.Typed.t) =
500506 ; param_dependant_cf_warnings mir; param_dependant_fundef_cf_warnings mir
501507 ; non_one_priors_warnings factor_graph mir
502508 ; distribution_warnings distributions_info ]
503- |> to_list
509+ |> to_list |> List. rev
0 commit comments