Skip to content

Comparisons: Enable safe mixed integer shortcut helpers#2

Open
KRRT7 wants to merge 3 commits into
developfrom
tests-mixed-comparison-shortcut-edges
Open

Comparisons: Enable safe mixed integer shortcut helpers#2
KRRT7 wants to merge 3 commits into
developfrom
tests-mixed-comparison-shortcut-edges

Conversation

@KRRT7

@KRRT7 KRRT7 commented May 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • add runtime NaN ordered comparison coverage for object and condition result contexts
  • document NaN non-complement behavior for inverted comparisons
  • add Python 2-only mixed int/long comparison coverage without Python 3-incompatible syntax

Property-based exploration

I used crosshair-tool and hypothesis in tests/scratch/ to check which comparison inversions are unsafe.

CrossHair found NaN counterexamples for scalar float and tuple comparisons:

uv run crosshair diffbehavior --per_condition_timeout=10 tests.scratch.crosshair_compare.gt_original tests.scratch.crosshair_compare.gt_inverted
uv run crosshair diffbehavior --per_condition_timeout=10 tests.scratch.crosshair_compare.ge_original tests.scratch.crosshair_compare.ge_inverted
uv run crosshair diffbehavior --per_condition_timeout=10 tests.scratch.crosshair_compare.tuple_gt_original tests.scratch.crosshair_compare.tuple_gt_inverted

Examples found:

gt_original(-1.0, nan) -> False
gt_inverted(-1.0, nan) -> True

ge_original(7.4050824148778e-304, nan) -> False
ge_inverted(7.4050824148778e-304, nan) -> True

tuple_gt_original((1.184418094435452e-308,), (nan,)) -> False
tuple_gt_inverted((1.184418094435452e-308,), (nan,)) -> True

Hypothesis found minimized counterexamples, including the list case:

uv run python tests/scratch/hypothesis_compare.py

Minimized examples:

float gt: (0.0, nan)
float ge: (0.0, nan)
tuple gt: ((0.0,), (nan,))
list gt: ([0.0], [nan])

These support keeping inversion restricted to comparison families where complement inversion is valid.

Testing

  • ./bin/autoformat-nuitka-source --un-pushed
  • ./.venv/bin/python ./tests/basics/run_all.py only BuiltinsTest.py
  • ./bin/check-nuitka-with-pylint --un-pushed
  • git diff --check
  • NUITKA_CACHE_DIR=tests/scratch/nuitka-cache python3 tests/basics/run_all.py only BuiltinsTest
  • NUITKA_CACHE_DIR=tests/scratch/nuitka-cache PYTHON=python NUITKA_EXTRA_OPTIONS="--lto=no --disable-cache=ccache" python tests/basics/run_all.py only BuiltinsTest

Python 2.7.18 validation passed after disabling local LTO/ccache because the default macOS toolchain had an unrelated LLVM bitcode linker mismatch.

@KRRT7 KRRT7 force-pushed the tests-mixed-comparison-shortcut-edges branch from f4f292b to 28ca634 Compare May 12, 2026 22:15
@KRRT7 KRRT7 changed the title Tests: Cover mixed comparison shortcut edge cases Comparisons: Enable safe mixed integer shortcut helpers May 13, 2026
KRRT7 added 3 commits May 23, 2026 22:29
Limit mixed-type result inversion to helper families where the inverse comparison is semantically safe and generated accordingly. This keeps float comparisons on their direct helpers because NaN makes ordered comparisons non-complementary.

Keep the Python2 LONG_INT GT/GE/NE generated helpers because dual NILONG helpers still depend on their internal LONG_CLONG implementations, while enabling shortcut generation for INT_CLONG helpers.
Restricts the PyObject*/CTypeCLong inversion path to tshape_int and
tshape_long, making the allowed inversion domain explicit and preventing
any future non-integer shape routed through CTypeCLong from bypassing
the NaN/complement protections.
@kayhayen kayhayen force-pushed the tests-mixed-comparison-shortcut-edges branch from 440502b to f8bf3b7 Compare May 23, 2026 20:31
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.

1 participant