Skip to content

compiler: Avoid CSE capture of opaque DefFunction calls - #3004

Merged
FabioLuporini merged 2 commits into
mainfrom
fix-cse-deffunction
Aug 14, 2026
Merged

compiler: Avoid CSE capture of opaque DefFunction calls#3004
FabioLuporini merged 2 commits into
mainfrom
fix-cse-deffunction

Conversation

@mloubout

Copy link
Copy Markdown
Contributor

CSE registers sympy.Function applications as candidates, so an opaque C-level call (DefFunction) appearing verbatim on several right-hand sides gets captured into a CTemp. The temporary's dtype comes from extract_dtype, which only sees the call's free symbols — for a call like make_float4(r1, r1, r1, r1) (emitted downstream when vector types are in play) that is float32, so the generated code declares

float r0 = make_float4(r1, r1, r1, r1);

which nvcc rejects (no operator "=" matches these operands: float4 = float; observed as codepy.CompileError on staggered/TTI elastic adjoint operators on GPU with vector types enabled).

This adds a _catch handler that leaves DefFunctions uncaptured: their return dtype is invisible to the type inference, and, being opaque calls, they are not guaranteed to be pure either.

@mloubout mloubout added compiler bug-C bug in the generated code labels Aug 13, 2026
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.63%. Comparing base (60def5f) to head (eed99bb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3004   +/-   ##
=======================================
  Coverage   83.63%   83.63%           
=======================================
  Files         257      257           
  Lines       54221    54235   +14     
  Branches     4629     4629           
=======================================
+ Hits        45349    45361   +12     
- Misses       8074     8076    +2     
  Partials      798      798           
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.52% <75.00%> (-0.02%) ⬇️
pytest-gpu-gcc- 78.29% <100.00%> (-0.01%) ⬇️
pytest-gpu-icx- 78.20% <100.00%> (+<0.01%) ⬆️
pytest-gpu-nvc-nvidiaX 69.20% <75.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FabioLuporini FabioLuporini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Uncontroversial

@FabioLuporini
FabioLuporini merged commit 3df12db into main Aug 14, 2026
42 checks passed
@FabioLuporini
FabioLuporini deleted the fix-cse-deffunction branch August 14, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-C bug in the generated code compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants