stanc3 icon indicating copy to clipboard operation
stanc3 copied to clipboard

Simplify some common patterns in Cpp DSL

Open WardBrian opened this issue 11 months ago • 1 comments

This introduces a couple helpers to make some things we do in the Cpp IR less verbose, similar to the existing helper syntax we've had previously.

A good example is this snippet from Lower_program:

  Expression
    (Assign
       ( Var "vars"
       , Constructor
           (Types.std_vector Double, [Var "num_to_write"; Exprs.quiet_NaN]) ))

Becomes

  "vars" := (Types.std_vector Double).:(Var "num_to_write"; Exprs.quiet_NaN)

Both of these pieces of OCaml encode the following C++:

  vars = std::vector<double>(num_to_write,
            std::numeric_limits<double>::quiet_NaN());

Submission Checklist

  • [x] Run unit tests
  • Documentation
    • [x] OR, no user-facing changes were made

Release notes

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)

WardBrian avatar Mar 26 '25 20:03 WardBrian

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.56%. Comparing base (e511e97) to head (4a7b1d0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1507      +/-   ##
==========================================
+ Coverage   89.55%   89.56%   +0.01%     
==========================================
  Files          66       66              
  Lines        9695     9706      +11     
==========================================
+ Hits         8682     8693      +11     
  Misses       1013     1013              
Files with missing lines Coverage Δ
src/stan_math_backend/Cpp.ml 89.00% <100.00%> (+0.19%) :arrow_up:
src/stan_math_backend/Lower_expr.ml 93.65% <100.00%> (ø)
src/stan_math_backend/Lower_functions.ml 96.90% <ø> (+0.01%) :arrow_up:
src/stan_math_backend/Lower_program.ml 99.19% <100.00%> (+<0.01%) :arrow_up:
src/stan_math_backend/Lower_stmt.ml 95.65% <100.00%> (ø)
src/stan_math_backend/Numbering.ml 100.00% <100.00%> (ø)
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Mar 26 '25 21:03 codecov[bot]

@SteveBronder I agree with your major comments. I've removed the indexing shorthand and swiched to {} for construction and I agree it reads better than before.

WardBrian avatar Apr 10 '25 17:04 WardBrian