Skip to content

Commit

Permalink
Merge pull request #1072 from WardBrian/test-reorg-warnings
Browse files Browse the repository at this point in the history
Reorganize tests and remove deprecated syntax when it isn't the thing being tested
  • Loading branch information
WardBrian authored Dec 10, 2021
2 parents a51dbaf + 5a0851e commit 6fa471d
Show file tree
Hide file tree
Showing 933 changed files with 212,717 additions and 216,419 deletions.
10 changes: 10 additions & 0 deletions src/frontend/Input_warnings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ let deprecated token (pos, message) =
|> Option.value ~default:Middle.Location_span.empty in
add_warning span message

let array_syntax ?(unsized = false) (pos1, pos2) =
let placement = if unsized then "a type" else "a variable name" in
add_warning
(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 \
array keyword before the type. This can be changed automatically using \
stanc --auto-format" )

let drop_array_future () =
match !warnings with
| ( _
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/Input_warnings.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ val deprecated : string -> Lexing.position * string -> unit
(** Register that a deprecated language construct has been found. *)

val empty : string -> unit
(** Register that an empty file is being lexxed *)
(** Register that an empty file is being parsed *)

val array_syntax : ?unsized:bool -> Lexing.position * Lexing.position -> unit
(** Warn on the old [real x\[3\]] syntax and suggest the [array] keyword*)

val future_keyword :
string -> string -> Lexing.position * Lexing.position -> unit
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/Semantic_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ module StatementError = struct
| InvalidSamplingCDForCCDF name ->
Fmt.pf ppf
"CDF and CCDF functions may not be used with sampling notation. Use \
increment_log_prob(%s_log(...)) instead."
target += %s_log(...) instead."
name
| InvalidSamplingNoSuchDistribution name ->
Fmt.pf ppf
Expand Down
16 changes: 9 additions & 7 deletions src/frontend/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,15 @@ arg_decl:
{ grammar_logger "arg_decl" ;
match od with None -> (UnsizedType.AutoDiffable, ut, id) | _ -> (DataOnly, ut, id) }

always(x):
| x=x
{ Some(x) }

unsized_type:
| ARRAY n_opt=always(unsized_dims) bt=basic_type
| ARRAY n=unsized_dims bt=basic_type
{ grammar_logger "unsized_type";
nest_unsized_array bt n
}
| bt=basic_type n_opt=option(unsized_dims)
{ grammar_logger "unsized_type";
if Option.is_some n_opt then
Input_warnings.array_syntax ~unsized:true $loc;
nest_unsized_array bt (Option.value n_opt ~default:0)
}

Expand Down Expand Up @@ -317,11 +318,12 @@ decl(type_rule, rhs):
We need to match it separately because we won't support multiple inline
declarations using this form.
This form is likely TO BE DEPRECIATED in Stan 3
This form is deprecated.
*)
| ty=type_rule id=decl_identifier dims=dims rhs_opt=optional_assignment(rhs)
SEMICOLON
{ (fun ~is_global ->
{ Input_warnings.array_syntax $loc;
(fun ~is_global ->
[{ stmt=
VarDecl {
decl_type= Sized (reducearray (fst ty, dims))
Expand Down
10 changes: 5 additions & 5 deletions test/integration/bad/algebra_solver/bad_fun_type.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (real[] y,
vector algebra_system (array[] real y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
int x_i[0];
array[0] real x_r;
array[0] int x_i;
}

parameters {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/bad/algebra_solver/bad_fun_type_control.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (real[] y,
vector algebra_system (array[] real y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
int x_i[0];
array[0] real x_r;
array[0] int x_i;
}

parameters {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (real[] y,
vector algebra_system (array[] real y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
int x_i[0];
array[0] real x_r;
array[0] int x_i;
}

parameters {
Expand Down
8 changes: 4 additions & 4 deletions test/integration/bad/algebra_solver/bad_newton_x_i_type.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (vector y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
real x_i[0];
array[0] real x_r;
array[0] real x_i;
}

parameters {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (vector y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
real x_i[0];
array[0] real x_r;
array[0] real x_i;
}

parameters {
Expand Down
8 changes: 4 additions & 4 deletions test/integration/bad/algebra_solver/bad_newton_x_r_type.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (vector y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
int x_r[0];
int x_i[0];
array[0] int x_r;
array[0] int x_i;
}

parameters {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (vector y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
int x_r[0];
int x_i[0];
array[0] int x_r;
array[0] int x_i;
}

parameters {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/bad/algebra_solver/bad_newton_x_r_var_type.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (vector y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -16,12 +16,12 @@ data {

transformed data {
vector[2] y;
// real x_r[0];
int x_i[0];
// array[0] real x_r;
array[0] int x_i;
}

parameters {
real x_r_p[0];
array[0] real x_r_p;
vector[2] theta_p;
real dummy_parameter;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (vector y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -16,12 +16,12 @@ data {

transformed data {
vector[2] y;
// real x_r[0];
int x_i[0];
// array[0] real x_r;
array[0] int x_i;
}

parameters {
real x_r_p[0];
array[0] real x_r_p;
vector[2] theta_p;
real dummy_parameter;
}
Expand Down
10 changes: 5 additions & 5 deletions test/integration/bad/algebra_solver/bad_newton_y_type.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (real[] y,
vector algebra_system (array[] real y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
real y;
real x_r[0];
int x_i[0];
array[0] real x_r;
array[0] int x_i;
}

parameters {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (real[] y,
vector algebra_system (array[] real y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
real y;
real x_r[0];
int x_i[0];
array[0] real x_r;
array[0] int x_i;
}

parameters {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/bad/algebra_solver/bad_theta_type.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (real[] y,
vector algebra_system (array[] real y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
int x_i[0];
array[0] real x_r;
array[0] int x_i;
}

parameters {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/bad/algebra_solver/bad_theta_type_control.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (real[] y,
vector algebra_system (array[] real y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
int x_i[0];
array[0] real x_r;
array[0] int x_i;
}

parameters {
Expand Down
8 changes: 4 additions & 4 deletions test/integration/bad/algebra_solver/bad_x_i_type.stan
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
functions {
vector algebra_system (vector y,
vector theta,
real[] x_r,
int[] x_i) {
array[] real x_r,
array[] int x_i) {
vector[2] f_y;
f_y[1] = y[1] - theta[1];
f_y[2] = y[2] - theta[2];
Expand All @@ -17,8 +17,8 @@ data {

transformed data {
vector[2] y;
real x_r[0];
real x_i[0];
array[0] real x_r;
array[0] real x_i;
}

parameters {
Expand Down
Loading

0 comments on commit 6fa471d

Please sign in to comment.