@@ -2,34 +2,47 @@ open Core_kernel
22open Ast
33open Middle
44
5- type t = Location_span .t * string
6-
75let deprecated_functions =
86 String.Map. of_alist_exn
9- [ (" multiply_log" , " lmultiply" ); (" binomial_coefficient_log" , " lchoose" )
10- ; (" cov_exp_quad" , " gp_exp_quad_cov" ) ]
7+ [ (" multiply_log" , (" lmultiply" , " 2.32.0" ))
8+ ; (" binomial_coefficient_log" , (" lchoose" , " 2.32.0" ))
9+ ; (" cov_exp_quad" , (" gp_exp_quad_cov" , " 2.32.0" )) ]
1110
1211let deprecated_odes =
1312 String.Map. of_alist_exn
14- [ (" integrate_ode" , " ode_rk45" ); (" integrate_ode_rk45" , " ode_rk45" )
15- ; (" integrate_ode_bdf" , " ode_bdf" ); (" integrate_ode_adams" , " ode_adams" ) ]
13+ [ (" integrate_ode" , (" ode_rk45" , " 3.0" ))
14+ ; (" integrate_ode_rk45" , (" ode_rk45" , " 3.0" ))
15+ ; (" integrate_ode_bdf" , (" ode_bdf" , " 3.0" ))
16+ ; (" integrate_ode_adams" , (" ode_adams" , " 3.0" )) ]
1617
1718let deprecated_distributions =
1819 String.Map. of_alist_exn
19- (List. concat_map Middle.Stan_math_signatures. distributions
20- ~f: (fun (fnkinds , name , _ , _ ) ->
21- List. filter_map fnkinds ~f: (function
22- | Lpdf -> Some (name ^ " _log" , name ^ " _lpdf" )
23- | Lpmf -> Some (name ^ " _log" , name ^ " _lpmf" )
24- | Cdf -> Some (name ^ " _cdf_log" , name ^ " _lcdf" )
25- | Ccdf -> Some (name ^ " _ccdf_log" , name ^ " _lccdf" )
26- | Rng | UnaryVectorized -> None ) ) )
20+ (List. map
21+ ~f: (fun (x , y ) -> (x, (y, " 2.32.0" )))
22+ (List. concat_map Middle.Stan_math_signatures. distributions
23+ ~f: (fun (fnkinds , name , _ , _ ) ->
24+ List. filter_map fnkinds ~f: (function
25+ | Lpdf -> Some (name ^ " _log" , name ^ " _lpdf" )
26+ | Lpmf -> Some (name ^ " _log" , name ^ " _lpmf" )
27+ | Cdf -> Some (name ^ " _cdf_log" , name ^ " _lcdf" )
28+ | Ccdf -> Some (name ^ " _ccdf_log" , name ^ " _lccdf" )
29+ | Rng | UnaryVectorized -> None ) ) ) )
30+
31+ let stan_lib_deprecations =
32+ Map. merge_skewed deprecated_distributions deprecated_functions
33+ ~combine: (fun ~key x y ->
34+ Common.FatalError. fatal_error_msg
35+ [% message
36+ " Common key in deprecation map"
37+ (key : string )
38+ (x : string * string )
39+ (y : string * string )] )
2740
2841let is_deprecated_distribution name =
29- Option. is_some (String. Map. find deprecated_distributions name)
42+ Option. is_some (Map. find deprecated_distributions name)
3043
3144let rename_deprecated map name =
32- Option. value ~default: name ( String.Map. find map name)
45+ Map. find map name |> Option. map ~f: fst |> Option. value ~default: name
3346
3447let distribution_suffix name =
3548 let open String in
@@ -74,114 +87,91 @@ let update_suffix name type_ =
7487 else drop_suffix name 4 ^ " _lpmf"
7588
7689let find_udf_log_suffix = function
77- | { stmt= FunDef {funname= {name; _}; arguments= (_, type_, _) :: _; _}
90+ | { stmt=
91+ FunDef
92+ { funname= {name; _}
93+ ; arguments= (_, ((UReal | UInt ) as type_), _) :: _
94+ ; _ }
7895 ; smeta= _ }
7996 when String. is_suffix ~suffix: " _log" name ->
8097 Some (name, type_)
8198 | _ -> None
8299
83- let rec collect_deprecated_expr deprecated_userdefined
84- (acc : (Location_span.t * string) list )
100+ let rec collect_deprecated_expr (acc : (Location_span.t * string) list )
85101 ({expr; emeta} : (typed_expr_meta, fun_kind) expr_with ) :
86102 (Location_span. t * string ) list =
87103 match expr with
88- | GetLP ->
89- acc
90- @ [ ( emeta.loc
91- , " The no-argument function `get_lp()` is deprecated. Use the \
92- no-argument function `target()` instead." ) ]
93104 | FunApp (StanLib FnPlain , {name= " abs" ; _}, [e])
94105 when Middle.UnsizedType. is_real_type e.emeta.type_ ->
95- collect_deprecated_expr deprecated_userdefined
106+ collect_deprecated_expr
96107 ( acc
97108 @ [ ( emeta.loc
98109 , " Use of the `abs` function with real-valued arguments is \
99- deprecated; use functions `fabs` instead." ) ] )
110+ deprecated; use function `fabs` instead." ) ] )
100111 e
101112 | FunApp (StanLib FnPlain, {name = "if_else" ; _} , l ) ->
102113 acc
103114 @ [ ( emeta.loc
104- , " The function `if_else` is deprecated. Use the conditional \
105- operator (x ? y : z) instead." ) ]
106- @ List. concat
107- (List. map l ~f: (fun e ->
108- collect_deprecated_expr deprecated_userdefined [] e ) )
109- | FunApp (StanLib _ , {name; _} , l ) ->
115+ , " The function `if_else` is deprecated and will be removed in Stan \
116+ 2.32.0. Use the conditional operator (x ? y : z) instead; this \
117+ can be automatically changed using stanc --print-canonical" ) ]
118+ @ List. concat_map l ~f: (fun e -> collect_deprecated_expr [] e)
119+ | FunApp ((StanLib _ | UserDefined _ ), {name; _} , l ) ->
110120 let w =
111- if Option. is_some (String.Map. find deprecated_distributions name) then
112- [ ( emeta.loc
113- , name ^ " is deprecated and will be removed in the future. Use "
114- ^ rename_deprecated deprecated_distributions name
115- ^ " instead." ) ]
116- else if String. is_suffix name ~suffix: " _cdf" then
117- [ ( emeta.loc
118- , " Use of " ^ name
119- ^ " without a vertical bar (|) between the first two arguments \
120- is deprecated." ) ]
121- else if Option. is_some (String.Map. find deprecated_functions name) then
122- [ ( emeta.loc
123- , name ^ " is deprecated and will be removed in the future. Use "
124- ^ rename_deprecated deprecated_functions name
125- ^ " instead." ) ]
126- else if Option. is_some (String.Map. find deprecated_odes name) then
127- [ ( emeta.loc
128- , name ^ " is deprecated and will be removed in the future. Use "
129- ^ rename_deprecated deprecated_odes name
130- ^ " instead. \n \
131- The new interface is slightly different, see: \n \
132- https://mc-stan.org/users/documentation/case-studies/convert_odes.html"
133- ) ]
134- else [] in
135- acc @ w
136- @ List. concat
137- (List. map l ~f: (fun e ->
138- collect_deprecated_expr deprecated_userdefined [] e ) )
139- | FunApp (UserDefined _ , {name; _} , l ) ->
140- let w =
141- let type_ = String.Map. find deprecated_userdefined name in
142- if Option. is_some type_ then
143- [ ( emeta.loc
144- , " Use of the _log suffix in user defined function " ^ name
145- ^ " is deprecated, use "
146- ^ update_suffix name (Option. value_exn type_)
147- ^ " instead." ) ]
148- else if String. is_suffix name ~suffix: " _cdf" then
149- [ ( emeta.loc
150- , " Use of " ^ name
151- ^ " without a vertical bar (|) between the first two arguments \
152- is deprecated." ) ]
153- else [] in
154- acc @ w
155- @ List. concat
156- (List. map l ~f: (fun e ->
157- collect_deprecated_expr deprecated_userdefined [] e ) )
158- | _ ->
159- fold_expression
160- (collect_deprecated_expr deprecated_userdefined)
161- (fun l _ -> l)
162- acc expr
163-
164- let collect_deprecated_lval deprecated_userdefined acc l =
165- fold_lval_with
166- (collect_deprecated_expr deprecated_userdefined)
167- (fun x _ -> x)
168- acc l
169-
170- let rec collect_deprecated_stmt deprecated_userdefined
171- (acc : (Location_span.t * string) list ) {stmt; _} :
172- (Location_span. t * string ) list =
121+ match Map. find stan_lib_deprecations name with
122+ | Some (rename , version ) ->
123+ [ ( emeta.loc
124+ , name ^ " is deprecated and will be removed in Stan " ^ version
125+ ^ " . Use " ^ rename
126+ ^ " instead. This can be automatically changed using stanc \
127+ --print-canonical" ) ]
128+ | _ when String. is_suffix name ~suffix: " _cdf" ->
129+ [ ( emeta.loc
130+ , " Use of " ^ name
131+ ^ " without a vertical bar (|) between the first two arguments \
132+ of a CDF is deprecated and will be removed in Stan 2.32.0. \
133+ This can be automatically changed using stanc \
134+ --print-canonical" ) ]
135+ | _ -> (
136+ match Map. find deprecated_odes name with
137+ | Some (rename , version ) ->
138+ [ ( emeta.loc
139+ , name ^ " is deprecated and will be removed in Stan " ^ version
140+ ^ " . Use " ^ rename
141+ ^ " instead. \n \
142+ The new interface is slightly different, see: \
143+ https://mc-stan.org/users/documentation/case-studies/convert_odes.html"
144+ ) ]
145+ | _ -> [] ) in
146+ acc @ w @ List. concat_map l ~f: (fun e -> collect_deprecated_expr [] e)
147+ | _ -> fold_expression collect_deprecated_expr (fun l _ -> l) acc expr
148+
149+ let collect_deprecated_lval acc l =
150+ fold_lval_with collect_deprecated_expr (fun x _ -> x) acc l
151+
152+ let rec collect_deprecated_stmt (acc : (Location_span.t * string) list ) {stmt; _}
153+ : (Location_span.t * string) list =
173154 match stmt with
174- | IncrementLogProb e -> collect_deprecated_expr deprecated_userdefined acc e
175- | Assignment {assign_lhs = l ; assign_op = ArrowAssign ; assign_rhs = e } ->
176- acc
177- @ collect_deprecated_lval deprecated_userdefined [] l
178- @ collect_deprecated_expr deprecated_userdefined [] e
179- | FunDef {body; _} -> collect_deprecated_stmt deprecated_userdefined acc body
155+ | FunDef
156+ { body
157+ ; funname= {name; id_loc}
158+ ; arguments= (_, ((UReal | UInt ) as type_), _) :: _
159+ ; _ }
160+ when String. is_suffix ~suffix: " _log" name ->
161+ let acc =
162+ acc
163+ @ [ ( id_loc
164+ , " Use of the _log suffix in user defined probability functions is \
165+ deprecated and will be removed in Stan 2.32.0, use name '"
166+ ^ update_suffix name type_
167+ ^ " ' instead if you intend on using this function in ~ \
168+ statements or calling unnormalized probability functions \
169+ inside of it." ) ] in
170+ collect_deprecated_stmt acc body
171+ | FunDef {body; _} -> collect_deprecated_stmt acc body
180172 | _ ->
181- fold_statement
182- (collect_deprecated_expr deprecated_userdefined)
183- (collect_deprecated_stmt deprecated_userdefined)
184- (collect_deprecated_lval deprecated_userdefined)
173+ fold_statement collect_deprecated_expr collect_deprecated_stmt
174+ collect_deprecated_lval
185175 (fun l _ -> l)
186176 acc stmt
187177
@@ -192,6 +182,4 @@ let collect_userdef_distributions program =
192182 |> String.Map. of_alist_exn
193183
194184let collect_warnings (program : typed_program ) =
195- fold_program
196- (collect_deprecated_stmt (collect_userdef_distributions program))
197- [] program
185+ fold_program collect_deprecated_stmt [] program
0 commit comments