Skip to content

transpile: Refactor binary operand handling and handle pointers/complex numbers - #1835

Open
Rua wants to merge 3 commits into
immunant:masterfrom
Rua:expected_operand_types
Open

transpile: Refactor binary operand handling and handle pointers/complex numbers#1835
Rua wants to merge 3 commits into
immunant:masterfrom
Rua:expected_operand_types

Conversation

@Rua

@Rua Rua commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Both a refactor and a functional improvement. Complex numbers aren't supported yet, so I haven't included any tests for that, but this is needed to support them later.

@Rua
Rua force-pushed the expected_operand_types branch 3 times, most recently from b78f827 to d93cde7 Compare June 2, 2026 13:59
@Rua
Rua force-pushed the expected_operand_types branch 3 times, most recently from 854e317 to 7efb825 Compare June 13, 2026 15:43
@Rua Rua changed the title transpile: Split off CBinOp::expected_operand_types and handle pointers/complex numbers transpile: Refactor binary operand handling and handle pointers/complex numbers Jun 13, 2026
@Rua
Rua force-pushed the expected_operand_types branch 5 times, most recently from e62b79c to 85e05aa Compare June 19, 2026 10:32
@Rua
Rua force-pushed the expected_operand_types branch 3 times, most recently from d79be12 to fa2af73 Compare July 7, 2026 10:21

@ahomescu ahomescu 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.

Could you add a test or two for this (unit and/or snapshot)?

@Rua

Rua commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Not really sure what to test for, that isn't already tested?

@Rua
Rua force-pushed the expected_operand_types branch 4 times, most recently from 46b0ce9 to 31c8fbb Compare July 26, 2026 10:18
@Rua
Rua force-pushed the expected_operand_types branch from 31c8fbb to e5c1d4e Compare August 1, 2026 15:29
@ahomescu

ahomescu commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Okay we can land this as is since it's a pretty small change, but it would be nice in the future if changes were split between 1) refactorings (no tests needed), and 2) actual functional changes, that would need a test or two to handle those specific corner cases.

// See if a `Complex` version of the new result type exists.
if matches!(result_type_kind, CTypeKind::Complex(..)) {
let new_result_type_kind =
CTypeKind::Complex(result_type_id.ctype);

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.

What if result_type_id is already a Complex? Would something like double f(double _Complex a, double _Complex b) { ... a + b ... } panic here? That could be a new test.

}

// Add Rust fixed-size types.
for rust_type_kind in CTypeKind::PULLBACK_KINDS {

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.

All the pullback types are integers, do any of them make sense for complex?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They'd probably not be used much, but since C supports them, they probably ought to be here too.

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.

2 participants