Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stan 2.32] Delay expiring syntax deprecations one version #1303

Merged
merged 3 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/frontend/Deprecation_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ open Middle

let deprecated_functions =
String.Map.of_alist_exn
[ ("multiply_log", ("lmultiply", "2.32.0"))
; ("binomial_coefficient_log", ("lchoose", "2.32.0"))
; ("cov_exp_quad", ("gp_exp_quad_cov", "2.32.0"))
[ ("multiply_log", ("lmultiply", "2.33.0"))
; ("binomial_coefficient_log", ("lchoose", "2.33.0"))
; ("cov_exp_quad", ("gp_exp_quad_cov", "2.33.0"))
; ("fabs", ("abs", "2.33.0")) ]

let deprecated_odes =
Expand All @@ -19,7 +19,7 @@ let deprecated_odes =
let deprecated_distributions =
String.Map.of_alist_exn
(List.map
~f:(fun (x, y) -> (x, (y, "2.32.0")))
~f:(fun (x, y) -> (x, (y, "2.33.0")))
(List.concat_map Middle.Stan_math_signatures.distributions
~f:(fun (fnkinds, name, _, _) ->
List.filter_map fnkinds ~f:(function
Expand Down Expand Up @@ -112,7 +112,7 @@ let rec collect_deprecated_expr (acc : (Location_span.t * string) list)
acc
@ [ ( emeta.loc
, "The function `if_else` is deprecated and will be removed in Stan \
2.32.0. Use the conditional operator (x ? y : z) instead; this \
2.33.0. Use the conditional operator (x ? y : z) instead; this \
can be automatically changed using the canonicalize flag for \
stanc" ) ]
@ List.concat_map l ~f:(fun e -> collect_deprecated_expr [] e)
Expand All @@ -129,7 +129,7 @@ let rec collect_deprecated_expr (acc : (Location_span.t * string) list)
[ ( emeta.loc
, "Use of " ^ name
^ " without a vertical bar (|) between the first two arguments \
of a CDF is deprecated and will be removed in Stan 2.32.0. \
of a CDF is deprecated and will be removed in Stan 2.33.0. \
This can be automatically changed using the canonicalize \
flag for stanc" ) ]
| _ -> (
Expand Down Expand Up @@ -190,7 +190,7 @@ let rec collect_deprecated_stmt fundefs (acc : (Location_span.t * string) list)
acc
@ [ ( id_loc
, "Use of the _log suffix in user defined probability functions is \
deprecated and will be removed in Stan 2.32.0, use name '"
deprecated and will be removed in Stan 2.33.0, use name '"
^ update_suffix name type_
^ "' instead if you intend on using this function in ~ \
statements or calling unnormalized probability functions \
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/Input_warnings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ let array_syntax ?(unsized = false) (pos1, pos2) =
(Option.value ~default:Middle.Location_span.empty
(Middle.Location_span.of_positions_opt pos1 pos2) )
( "Declaration of arrays by placing brackets after " ^ placement
^ " is deprecated and will be removed in Stan 2.32.0. Instead use the \
^ " is deprecated and will be removed in Stan 2.33.0. Instead use the \
array keyword before the type. This can be changed automatically using \
the auto-format flag to stanc" )

let drop_array_future () =
match !warnings with
| ( _
, "Variable name 'array' will be a reserved word starting in Stan 2.32.0. \
, "Variable name 'array' will be a reserved word starting in Stan 2.33.0. \
Please rename it!" )
:: tl ->
warnings := tl
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/Typechecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ let check_lvalue cf tenv = function
add_warning loc
"Nested multi-indexing on the left hand side of assignment does not \
behave the same as nested indexing in expressions. This is \
considered a bug and will be disallowed in Stan 2.32.0. The \
considered a bug and will be disallowed in Stan 2.33.0. The \
indexing can be automatically fixed using the canonicalize flag for \
stanc." ;
let lvalue_rvalue_types_differ =
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ rule token = parse
(lexbuf.lex_curr_p, "Comments beginning with \
# are deprecated and this \
syntax will be removed in \
Stan 2.32.0. Use // to begin \
Stan 2.33.0. Use // to begin \
line comments; this can be \
done automatically using the \
auto-format flag to stanc") ;
Expand Down Expand Up @@ -193,7 +193,7 @@ rule token = parse
(lexbuf.lex_curr_p, "assignment operator <- \
is deprecated in the \
Stan language and will \
be removed in Stan 2.32.0; \
be removed in Stan 2.33.0; \
use = instead. This \
can be done automatically \
with the canonicalize flag \
Expand All @@ -204,7 +204,7 @@ rule token = parse
(lexbuf.lex_curr_p, "increment_log_prob(...)\
; is deprecated and \
will be removed in Stan \
2.32.0. Use target \
2.33.0. Use target \
+= ...; instead. This \
can be done automatically \
with the canonicalize flag \
Expand All @@ -226,7 +226,7 @@ rule token = parse
Input_warnings.deprecated "get_lp"
(lexbuf.lex_curr_p, "get_lp() function is \
deprecated. It will be \
removed in Stan 2.32.0. \
removed in Stan 2.33.0. \
Use target() instead. \
This can be done automatically \
with the canonicalize flag for \
Expand Down
10 changes: 5 additions & 5 deletions src/frontend/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ identifier:
}

future_keyword:
| OFFSET { build_id "offset" $loc, "2.32.0" }
| MULTIPLIER { build_id "multiplier" $loc, "2.32.0" }
| LOWER { build_id "lower" $loc, "2.32.0" }
| UPPER { build_id "upper" $loc, "2.32.0" }
| OFFSET { build_id "offset" $loc, "2.33.0" }
| MULTIPLIER { build_id "multiplier" $loc, "2.33.0" }
| LOWER { build_id "lower" $loc, "2.33.0" }
| UPPER { build_id "upper" $loc, "2.33.0" }
| ARRAY
{ build_id "array" $loc, "2.32.0" }
{ build_id "array" $loc, "2.33.0" }

decl_identifier:
| id=identifier { id }
Expand Down
6 changes: 2 additions & 4 deletions src/middle/Stan_math_signatures.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ let distributions =
; ([Lpdf; Log], "inv_wishart", [DMatrix; DReal; DMatrix], SoA)
; ([Lpdf; Log], "lkj_corr", [DMatrix; DReal], AoS)
; ([Lpdf; Log], "lkj_corr_cholesky", [DMatrix; DReal], AoS)
; ([Lpdf; Log], "lkj_cov", [DMatrix; DVector; DVector; DReal], AoS)
; (full_lpdf_depr, "logistic", [DVReal; DVReal; DVReal], SoA)
; ([Lpdf; Rng; Cdf; Log], "loglogistic", [DVReal; DVReal; DVReal], SoA)
; (full_lpdf_depr, "lognormal", [DVReal; DVReal; DVReal], SoA)
Expand Down Expand Up @@ -1606,8 +1607,6 @@ let () =
add_unqualified
("lkj_corr_cholesky_rng", ReturnType UMatrix, [UInt; UReal], AoS) ;
add_unqualified ("lkj_corr_rng", ReturnType UMatrix, [UInt; UReal], AoS) ;
add_unqualified
("lkj_cov_log", ReturnType UReal, [UMatrix; UVector; UVector; UReal], AoS) ;
add_binary_vec_int_real "lmgamma" AoS ;
add_binary_vec "lmultiply" SoA ;
add_unqualified ("log", ReturnType UComplex, [UComplex], AoS) ;
Expand Down Expand Up @@ -2718,5 +2717,4 @@ let%expect_test "declarative distributions" =
|> print_endline ;
[%expect {|
binomial_coefficient_log
multiply_log
lkj_cov_log |}]
multiply_log |}]
32 changes: 11 additions & 21 deletions src/stanc/stanc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,12 @@ let options =
; ( "--allow-undefined"
, Arg.Clear Typechecker.check_that_all_functions_have_definition
, " Do not fail if a function is declared but not defined" )
; ( "--allow_undefined"
, Arg.Clear Typechecker.check_that_all_functions_have_definition
, " Deprecated. Same as --allow-undefined. Will be removed in Stan 2.32.0"
)
; ( "--include-paths"
, Arg.String
(fun str ->
Preprocessor.include_paths := String.split_on_chars ~on:[','] str )
, " Takes a comma-separated list of directories that may contain a file \
in an #include directive (default = \"\")" )
; ( "--include_paths"
, Arg.String
(fun str ->
Preprocessor.include_paths :=
!Preprocessor.include_paths @ String.split_on_chars ~on:[','] str
)
, " Deprecated. Same as --include-paths. Will be removed in Stan 2.32.0"
)
; ( "--use-opencl"
, Arg.Set Transform_Mir.use_opencl
, " If set, try to use matrix_cl signatures." )
Expand All @@ -223,19 +211,21 @@ let options =
, Arg.Set print_info_json
, " If set, print information about the model." ) ]

let print_deprecated_arg_warning =
(* To be removed in Stan 2.33 *)
let removed_arg_errors =
(* is_prefix is used to also cover the --include-paths=... *)
let arg_is_used arg =
Array.mem ~equal:(fun x y -> String.is_prefix ~prefix:x y) Sys.argv arg
in
if arg_is_used "--allow_undefined" then
if arg_is_used "--allow_undefined" then (
eprintf
"--allow_undefined is deprecated and will be removed in Stan 2.32.0. \
Please use --allow-undefined.\n" ;
if arg_is_used "--include_paths" then
"--allow_undefined was removed in Stan 2.32.0. Please use \
--allow-undefined.\n" ;
exit 65 (* EX_DATAERR in sysexits.h*) ) ;
if arg_is_used "--include_paths" then (
eprintf
"--include_paths is deprecated and Will be removed in Stan 2.32.0. \
Please use --include-paths.\n"
"--include_paths was removed in Stan 2.32.0. Please use --include-paths.\n" ;
exit 65 (* EX_DATAERR in sysexits.h*) )

let model_file_err () =
Arg.usage options ("Please specify a model_file.\n" ^ usage) ;
Expand Down Expand Up @@ -312,7 +302,8 @@ let use_file filename =
(Deprecation_analysis.collect_warnings typed_ast) ;
if !generate_data then
print_endline
(Debug_data_generation.print_data_prog (Ast_to_Mir.gather_data typed_ast)) ;
(Debug_data_generation.print_data_prog
(Ast_to_Mir.gather_data typed_ast) ) ;
Debugging.typed_ast_logger typed_ast ;
if not !pretty_print_program then (
let mir = Ast_to_Mir.trans_prog filename typed_ast in
Expand Down Expand Up @@ -359,7 +350,6 @@ let mangle =
let main () =
(* Parse the arguments. *)
Arg.parse options add_file usage ;
print_deprecated_arg_warning ;
(* Deal with multiple modalities *)
if !dump_stan_math_sigs then (
Stan_math_signatures.pretty_print_all_math_sigs Format.std_formatter () ;
Expand Down
4 changes: 4 additions & 0 deletions src/stancjs/stancjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ let stan2cpp model_name model_string is_flag_set flag_val =
flag_val "max-line-length"
|> Option.map ~f:int_of_string
|> Option.value ~default:78 in
let deprecation_warnings =
if canonicalizer_settings.deprecations then []
else Deprecation_analysis.collect_warnings typed_ast in
let warnings = warnings @ deprecation_warnings in
let mir = Ast_to_Mir.trans_prog model_name typed_ast in
let tx_mir = Transform_Mir.trans_prog mir in
if is_flag_set "auto-format" || is_flag_set "print-canonical" then
Expand Down
20 changes: 10 additions & 10 deletions test/integration/bad/new/stanc.expected
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Expect a statement or top-level variable declaration.
$ ../../../../../install/default/bin/stanc compound-assign-decl-bad1.stan
Warning in 'compound-assign-decl-bad1.stan', line 1, column 18: assignment
operator <- is deprecated in the Stan language and will be removed in
Stan 2.32.0; use = instead. This can be done automatically with the
Stan 2.33.0; use = instead. This can be done automatically with the
canonicalize flag for stanc
Syntax error in 'compound-assign-decl-bad1.stan', line 1, column 18 to column 20, parsing error:
-------------------------------------------------
Expand All @@ -119,7 +119,7 @@ Expected ";" or assignment.
$ ../../../../../install/default/bin/stanc compound-assign-decl-bad2.stan
Warning in 'compound-assign-decl-bad2.stan', line 1, column 29: assignment
operator <- is deprecated in the Stan language and will be removed in
Stan 2.32.0; use = instead. This can be done automatically with the
Stan 2.33.0; use = instead. This can be done automatically with the
canonicalize flag for stanc
Syntax error in 'compound-assign-decl-bad2.stan', line 1, column 29 to column 31, parsing error:
-------------------------------------------------
Expand Down Expand Up @@ -1169,7 +1169,7 @@ Syntax error in 'ill-formed-statement20.stan', line 1, column 23 to column 28, p
Expected "(" after "for".
$ ../../../../../install/default/bin/stanc ill-formed-statement21.stan
Warning in 'ill-formed-statement21.stan', line 1, column 19: get_lp()
function is deprecated. It will be removed in Stan 2.32.0. Use target()
function is deprecated. It will be removed in Stan 2.33.0. Use target()
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement21.stan', line 1, column 28 to column 33, parsing error:
Expand All @@ -1181,7 +1181,7 @@ Syntax error in 'ill-formed-statement21.stan', line 1, column 28 to column 33, p
Expected ")" after "get_lp(".
$ ../../../../../install/default/bin/stanc ill-formed-statement22.stan
Warning in 'ill-formed-statement22.stan', line 1, column 19: get_lp()
function is deprecated. It will be removed in Stan 2.32.0. Use target()
function is deprecated. It will be removed in Stan 2.33.0. Use target()
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement22.stan', line 1, column 26 to column 31, parsing error:
Expand Down Expand Up @@ -1241,7 +1241,7 @@ Syntax error in 'ill-formed-statement28.stan', line 1, column 25 to column 26, p
Ill-formed expression. Expression expected after "(", for test of conditional control flow construct.
$ ../../../../../install/default/bin/stanc ill-formed-statement29.stan
Warning in 'ill-formed-statement29.stan', line 1, column 19: increment_log_prob(...);
is deprecated and will be removed in Stan 2.32.0. Use target += ...;
is deprecated and will be removed in Stan 2.33.0. Use target += ...;
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement29.stan', line 1, column 43 to column 48, parsing error:
Expand All @@ -1261,7 +1261,7 @@ Syntax error in 'ill-formed-statement3.stan', line 1, column 36 to column 40, pa
Ill-formed statement. Expected statement after ")" for the loop body of the for loop..
$ ../../../../../install/default/bin/stanc ill-formed-statement30.stan
Warning in 'ill-formed-statement30.stan', line 1, column 19: increment_log_prob(...);
is deprecated and will be removed in Stan 2.32.0. Use target += ...;
is deprecated and will be removed in Stan 2.33.0. Use target += ...;
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement30.stan', line 1, column 42 to column 47, parsing error:
Expand All @@ -1273,7 +1273,7 @@ Syntax error in 'ill-formed-statement30.stan', line 1, column 42 to column 47, p
Ill-formed statement. Expected expression followed by ");" after "(".
$ ../../../../../install/default/bin/stanc ill-formed-statement31.stan
Warning in 'ill-formed-statement31.stan', line 1, column 19: increment_log_prob(...);
is deprecated and will be removed in Stan 2.32.0. Use target += ...;
is deprecated and will be removed in Stan 2.33.0. Use target += ...;
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement31.stan', line 1, column 44 to column 49, parsing error:
Expand All @@ -1285,7 +1285,7 @@ Syntax error in 'ill-formed-statement31.stan', line 1, column 44 to column 49, p
Ill-formed statement. Expected ";" after ")".
$ ../../../../../install/default/bin/stanc ill-formed-statement32.stan
Warning in 'ill-formed-statement32.stan', line 1, column 19: increment_log_prob(...);
is deprecated and will be removed in Stan 2.32.0. Use target += ...;
is deprecated and will be removed in Stan 2.33.0. Use target += ...;
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement32.stan', line 1, column 42 to column 43, parsing error:
Expand All @@ -1297,7 +1297,7 @@ Syntax error in 'ill-formed-statement32.stan', line 1, column 42 to column 43, p
Ill-formed statement. Expected expression followed by ");" after "(".
$ ../../../../../install/default/bin/stanc ill-formed-statement33.stan
Warning in 'ill-formed-statement33.stan', line 1, column 19: increment_log_prob(...);
is deprecated and will be removed in Stan 2.32.0. Use target += ...;
is deprecated and will be removed in Stan 2.33.0. Use target += ...;
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement33.stan', line 1, column 40 to column 45, parsing error:
Expand All @@ -1309,7 +1309,7 @@ Syntax error in 'ill-formed-statement33.stan', line 1, column 40 to column 45, p
Ill-formed statement. Expected expression followed by ");" after "(".
$ ../../../../../install/default/bin/stanc ill-formed-statement34.stan
Warning in 'ill-formed-statement34.stan', line 1, column 19: increment_log_prob(...);
is deprecated and will be removed in Stan 2.32.0. Use target += ...;
is deprecated and will be removed in Stan 2.33.0. Use target += ...;
instead. This can be done automatically with the canonicalize flag for
stanc
Syntax error in 'ill-formed-statement34.stan', line 1, column 39 to column 44, parsing error:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/cli-args/canonicalize/canonical.expected
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ generated quantities {
Warning in 'deprecated.stan', line 37, column 2: Nested multi-indexing on the
left hand side of assignment does not behave the same as nested indexing
in expressions. This is considered a bug and will be disallowed in Stan
2.32.0. The indexing can be automatically fixed using the canonicalize
2.33.0. The indexing can be automatically fixed using the canonicalize
flag for stanc.
$ ../../../../../install/default/bin/stanc --print-canonical deprecated_tilde.stan
functions {
Expand Down
Loading