[BUG] Compiler optimizations can prevent bounds checks
WardBrian opened this issue · 3 comments
WardBrian commented
Current Behavior:
Enabling compiler optimizations currently stops emitting a default assignment for a variable if it is immediately assigned to (#1029). However, this changes the behavior of those very assign
functions when it comes to bounds checks:
This means the same model:
parameters {
vector[3] y;
}
model {
vector[2] x;
x = y;
y ~ std_normal();
print(x); // prevent dead-code-elimination on x
}
Will throw an error at --O0:
Unrecoverable error evaluating the log probability at the initial value.
Exception: vector assign rows: assigning variable x (2) and right hand side rows (3) must match in size (in '../../ml/stanc3/bounds.stan', line 12, column 4 to column 10)
Exception: vector assign rows: assigning variable x (2) and right hand side rows (3) must match in size (in '../../ml/stanc3/bounds.stan', line 12, column 4 to column 10)
But will sample to completion at --O1
.
Expected Behavior:
Bounds checks are applied uniformly.