Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-9402: [C++] Rework portable wrappers for checked integer arithmetic #7784

Closed
wants to merge 2 commits into from

Conversation

pitrou
Copy link
Member

@pitrou pitrou commented Jul 16, 2020

Vendor relevant code from the portable-snippets library (~ public domain):
https://github.com/nemequ/portable-snippets/tree/master/safe-math

Also fix some bugs in checked arithmetic (null values had their value slots checked).
Add compute scaffolding for stateful binary scalar functions.

@pitrou pitrou force-pushed the ARROW-9402-overflow-arith branch from 8e57e8c to 478f663 Compare July 16, 2020 12:03
@github-actions
Copy link

@pitrou pitrou force-pushed the ARROW-9402-overflow-arith branch from 4b145a6 to 1b646ee Compare July 16, 2020 13:49
@pitrou pitrou marked this pull request as ready for review July 16, 2020 15:53
@pitrou
Copy link
Member Author

pitrou commented Jul 16, 2020

I think I finally squashed the horrid Windows preprocessor macro issues (Windows headers define OPTIONAL, but you can't undef it blindly because other subsequent includes may require it...).
AppVeyor build: https://ci.appveyor.com/project/pitrou/arrow/builds/34135787

@pitrou
Copy link
Member Author

pitrou commented Jul 16, 2020

@wesm You'll probably want to take a look at the codegen changes when you have some time.

@pitrou
Copy link
Member Author

pitrou commented Aug 5, 2020

Rebased. @wesm could you perhaps review this?

@pitrou
Copy link
Member Author

pitrou commented Aug 5, 2020

Or perhaps @bkietz .

@bkietz bkietz self-requested a review August 5, 2020 17:24
Copy link
Member

@bkietz bkietz left a comment

Choose a reason for hiding this comment

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

Some minor comments, this mostly looks good to me

Comment on lines +90 to +92
template <typename T, typename Arg0, typename Arg1>
enable_if_floating_point<T> Call(KernelContext*, Arg0 left, Arg1 right) {
static_assert(std::is_same<T, Arg0>::value && std::is_same<T, Arg1>::value, "");
Copy link
Member

Choose a reason for hiding this comment

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

What happens if we remove those template arguments?

Suggested change
template <typename T, typename Arg0, typename Arg1>
enable_if_floating_point<T> Call(KernelContext*, Arg0 left, Arg1 right) {
static_assert(std::is_same<T, Arg0>::value && std::is_same<T, Arg1>::value, "");
template <typename T>
enable_if_floating_point<T> Call(KernelContext*, T left, T right) {

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't compile, because Call is invoked with explicit template arguments by the kernel execution machinery.

cpp/src/arrow/compute/kernels/test_util.cc Outdated Show resolved Hide resolved
cpp/src/arrow/compute/kernels/test_util.cc Outdated Show resolved Hide resolved
@@ -103,6 +103,16 @@ void CheckScalarUnary(std::string func_name, std::shared_ptr<Scalar> input,
std::shared_ptr<Scalar> expected,
const FunctionOptions* options = nullptr);

void CheckScalarBinary(std::string func_name, std::shared_ptr<Scalar> left_input,
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -55,6 +55,8 @@
#include "parquet/schema.h"
#include "parquet/statistics.h"
#include "parquet/types.h"
// Required after "arrow/util/int_util_internal.h" (for OPTIONAL)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Required after "arrow/util/int_util_internal.h" (for OPTIONAL)
// Required after "arrow/util/int_util_internal.h" (for OPTIONAL)

I'm not sure if clang-format will always recognize this comment as breaking this #include out of the above block. I suppose it's alphabetically always going to be lower in the sort, though

cpp/src/arrow/compute/kernels/scalar_arithmetic_test.cc Outdated Show resolved Hide resolved
…etic

Vendor relevant code from the portable-snippets library (~ public domain):
https://github.com/nemequ/portable-snippets/tree/master/safe-math

Also fix some bugs in checked arithmetic (null values had their value slots checked as well),
add compute scaffolding for stateful binary scalar functions.
@pitrou
Copy link
Member Author

pitrou commented Aug 10, 2020

I believe I addressed your comments @bkietz , so I'm going to merge now.

@pitrou pitrou closed this in 811d8f6 Aug 10, 2020
@pitrou pitrou deleted the ARROW-9402-overflow-arith branch August 10, 2020 13:34
kszucs pushed a commit to kszucs/arrow that referenced this pull request Aug 11, 2020
…etic

Vendor relevant code from the portable-snippets library (~ public domain):
https://github.com/nemequ/portable-snippets/tree/master/safe-math

Also fix some bugs in checked arithmetic (null values had their value slots checked).
Add compute scaffolding for stateful binary scalar functions.

Closes apache#7784 from pitrou/ARROW-9402-overflow-arith

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
kszucs pushed a commit to kszucs/arrow that referenced this pull request Aug 11, 2020
…etic

Vendor relevant code from the portable-snippets library (~ public domain):
https://github.com/nemequ/portable-snippets/tree/master/safe-math

Also fix some bugs in checked arithmetic (null values had their value slots checked).
Add compute scaffolding for stateful binary scalar functions.

Closes apache#7784 from pitrou/ARROW-9402-overflow-arith

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
kszucs pushed a commit to kszucs/arrow that referenced this pull request Aug 17, 2020
…etic

Vendor relevant code from the portable-snippets library (~ public domain):
https://github.com/nemequ/portable-snippets/tree/master/safe-math

Also fix some bugs in checked arithmetic (null values had their value slots checked).
Add compute scaffolding for stateful binary scalar functions.

Closes apache#7784 from pitrou/ARROW-9402-overflow-arith

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
GeorgeAp pushed a commit to sirensolutions/arrow that referenced this pull request Jun 7, 2021
…etic

Vendor relevant code from the portable-snippets library (~ public domain):
https://github.com/nemequ/portable-snippets/tree/master/safe-math

Also fix some bugs in checked arithmetic (null values had their value slots checked).
Add compute scaffolding for stateful binary scalar functions.

Closes apache#7784 from pitrou/ARROW-9402-overflow-arith

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
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.

None yet

2 participants