FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix missing value propagation in `as_integers/doubles()` by DavisVaughan · Pull Request #265 · r-lib/cpp11 · GitHub

/ cpp11 Public

Fix missing value propagation in as_integers/doubles() - #265

Merged
romainfrancois merged 8 commits into
r-lib:mainfrom
DavisVaughan:fix/as-missing-value-propagation
May 17, 2023
Merged

romainfrancois merged 8 commits into
r-lib:mainfrom
DavisVaughan:fix/as-missing-value-propagation

Conversation

DavisVaughan commented Mar 3, 2022 •
edited
Loading

Copy link
Copy Markdown
Member

This PR set out with the small goal of fixing as_integers() and as_doubles() to ensure that they propagate missing values from their inputs correctly when performing coercion.

It got a little more complicated along the way, as some forward declarations were needed and some functions had to be shifted around to get things to compile right. I think this is all for the better though, as it revealed a few subtle bugs which I will discuss inline below.

Also:
- Switch to `R_xlen_t` over `size_t` since this is what `size()` returns and is what our constructors prefer
- Initialize return value with `ret(len)` since that seems cleaner
- Forward declare required bits from `doubles.hpp`. Use of `is_na(<dbl>)` is new, so it makes sense that we need to forward declare it. Even before this PR, we used the `[]` double operator, so you might be wondering why we need the forward declaration. Well, it only previously worked by luck because we had a hidden dependency on `cpp11/doubles.hpp` in `test-integers.cpp` by including `cpp11/doubles.hpp` before `cpp11/integers.hpp`. I swapped them around in the test file and it indeed failed without this forward declaration.
Also:
- Switch to `R_xlen_t` over `size_t` since this is what `size()` returns and is what our constructors prefer
- Initialize sized return value, rather than using `push_back()`, which should be faster
- Forward declare required bits from `integers.hpp`. There is no `is_na(<int>)` specialization to forward declare, but there is a `na<int>()` forward declaration that is required, because that is used by the default `is_na()` implementation
- Move double specializations of `na()` and `is_na()` before the implementation of `as_doubles()`. Since `as_doubles()` now calls the `na<double>()` specialization, it has to be implemented (or forward declared) ahead of time.
DavisVaughan marked this pull request as ready for review March 3, 2022 21:31

DavisVaughan commented Mar 3, 2022 •
edited
Loading

Copy link
Copy Markdown
Member Author

The format_check build seems to be failing because I switched the include order of cpp11/integers.hpp and cpp11/doubles.hpp in test-integers.cpp. It seems to want to retain them in alphabetical order?

I disagree somewhat strongly with this, because including integers.hpp first in the integers test file should reduce the chances of having hidden dependency bugs, like the one introduced by #265 (comment)

I can change it back if we really want to get the formatter build to pass, but it seems like an anti pattern.


The 3.4 build is failing for some unrelated pandoc reasons

Copy link
Copy Markdown
Contributor

LGTM!

Comment thread inst/include/cpp11/integers.hpp Outdated

DavisVaughan commented Mar 8, 2022 •
edited
Loading

Copy link
Copy Markdown
Member Author

I have learned that because we set:

IncludeBlocks: Preserve

we can separate the includes into "blocks" and they will be sorted within their block. So I added a space between cpp11/integers.hpp and the other includes to block it off.

It we wanted to be more extreme, we could set SortIncludes: Never in the configuration file, but this at least gets us passing again (see https://clang.llvm.org/docs/ClangFormatStyleOptions.html)

vspinu commented Nov 2, 2022

Copy link
Copy Markdown
Contributor

Would be nice to add conversion from logicals as well. Primarly for the sake of all NA vectors.

romainfrancois left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

romainfrancois left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Copy link
Copy Markdown
Collaborator

I'll merge this now and follow up.

romainfrancois merged commit 3c87798 into r-lib:main May 17, 2023
romainfrancois added a commit that referenced this pull request May 24, 2023
romainfrancois added a commit that referenced this pull request May 25, 2023
* Revert "Fix missing value propagation in `as_integers/doubles()` (#265)"

This reverts commit 3c87798.

* is_convertible_without_loss_to_integer

* is_na using sfinae to differentiate double and !double

* install local cpp11 before cpp11test

* make format

* propage na

* integers test too

* new bullet

* as_doubles(SEXP)

* test for NA_REAL first
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL