stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

Add `fatal_error()` to the language #1402

Closed WardBrian closed 7 months ago

WardBrian commented 7 months ago

Closes #1393 .

Note that there is no way to parse this and also allow variables named exit, so this would immediately reserve the keyword. Based on a github search, I found only one package which uses exit as a variable name. If this is a serious concern we could consider different names like stop or something like fatal_error which is almost certainly unused.

Submission Checklist

Release notes

Added fatal_error(), which is similar to reject() but rather than signaling an error which is recoverable, signals an error which should terminate execution immediately. fatal_error is now a reserved word.

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)

codecov[bot] commented 7 months ago

Codecov Report

Attention: Patch coverage is 31.42857% with 24 lines in your changes are missing coverage. Please review.

Project coverage is 89.87%. Comparing base (fa03ea2) to head (d567dfb).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1402 +/- ## ========================================== - Coverage 89.88% 89.87% -0.02% ========================================== Files 63 63 Lines 10513 10525 +12 ========================================== + Hits 9450 9459 +9 - Misses 1063 1066 +3 ``` | [Files](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev) | Coverage Δ | | |---|---|---| | [src/analysis\_and\_optimization/Mir\_utils.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2FuYWx5c2lzX2FuZF9vcHRpbWl6YXRpb24vTWlyX3V0aWxzLm1s) | `77.30% <ø> (ø)` | | | [src/analysis\_and\_optimization/Optimize.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2FuYWx5c2lzX2FuZF9vcHRpbWl6YXRpb24vT3B0aW1pemUubWw=) | `93.23% <ø> (ø)` | | | [src/analysis\_and\_optimization/Pedantic\_analysis.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2FuYWx5c2lzX2FuZF9vcHRpbWl6YXRpb24vUGVkYW50aWNfYW5hbHlzaXMubWw=) | `93.30% <ø> (ø)` | | | [src/common/ICE.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2NvbW1vbi9JQ0UubWw=) | `0.00% <ø> (ø)` | | | [src/frontend/Ast.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2Zyb250ZW5kL0FzdC5tbA==) | `68.90% <100.00%> (+0.13%)` | :arrow_up: | | [src/frontend/Info.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL2Zyb250ZW5kL0luZm8ubWw=) | `93.65% <100.00%> (+0.10%)` | :arrow_up: | | [src/middle/SizedType.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL21pZGRsZS9TaXplZFR5cGUubWw=) | `88.31% <ø> (ø)` | | | [src/middle/Stan\_math\_signatures.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL21pZGRsZS9TdGFuX21hdGhfc2lnbmF0dXJlcy5tbA==) | `98.01% <ø> (ø)` | | | [src/middle/Stmt.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL21pZGRsZS9TdG10Lm1s) | `79.36% <ø> (ø)` | | | [src/middle/UnsizedType.ml](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev#diff-c3JjL21pZGRsZS9VbnNpemVkVHlwZS5tbA==) | `80.20% <ø> (ø)` | | | ... and [17 more](https://app.codecov.io/gh/stan-dev/stanc3/pull/1402?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=stan-dev) | |
nhuurre commented 7 months ago

I prefer fatal_error over exit. Note that in C++, std::exit(0) indicates a successful program completion.

bob-carpenter commented 7 months ago

Good point. fatal_error sounds more descriptive and will match the logging statement that comes out as an error.