Fix subscript hoisting; correct coercion/matrix lowering#94
Fix subscript hoisting; correct coercion/matrix lowering#94t-kalinowski merged 5 commits intomainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02082b16b1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| source <- glue("{src}") | ||
| Fortran( | ||
| glue( | ||
| "reshape({source}, [{bind_dim_int(rows)}, {bind_dim_int(cols)}], pad = {source})" | ||
| ), |
There was a problem hiding this comment.
Avoid double-evaluating matrix() data expression
The new matrix() lowering uses reshape(..., pad = {source}), which inserts the data expression twice. In Fortran, all actual arguments are evaluated before the intrinsic call, so a non-scalar data expression (e.g., runif(4) or any user-defined function with side effects) will be evaluated twice. That changes semantics versus R, which evaluates data once, and can produce different values or duplicated side effects. Consider hoisting data into a temporary and using that name in both reshape and pad, or only supplying pad when it’s needed and the source is already a plain symbol.
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #94 +/- ##
=======================================
Coverage 92.78% 92.78%
=======================================
Files 27 27
Lines 5749 5754 +5
=======================================
+ Hits 5334 5339 +5
Misses 415 415 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR fixes several lowering/translation issues hit by simplified lowering patterns:
[ ... ]so index expressions are compiled with the caller hoist context, avoiding invalid inlineblock ... end blockexpressions inside Fortran array designators (e.g.rev(seq_len(n))in a multi-d subscript).as.double(<array>)andas.integer(<array>)drop dimensions (return a vector) by reshaping rank>1 results, matching base R semantics and fixing slice assignments likeout[1:6] <- as.double(a).matrix(<non-scalar expr>, nrow=, ncol=)lowering by emitting an explicitreshape(...)so the generated Fortran ranks match.bad rankerror for rank-0 scalar declarations to point users atinteger(1)/double(1).Regression tests added:
tests/testthat/test-subscript-hoisted-temporaries.Rtests/testthat/test-as-double.Rtests/testthat/test-matrix.Rtests/testthat/test-c-wrapper-public-api-coverage.RTested:
devtools::test()