Skip to content

feat(slang): complete operator emission#552

Open
hedgar2017 wants to merge 1 commit into
mainfrom
az-slang-operator-completion
Open

feat(slang): complete operator emission#552
hedgar2017 wants to merge 1 commit into
mainfrom
az-slang-operator-completion

Conversation

@hedgar2017

@hedgar2017 hedgar2017 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Completes operator emission on the Slang frontend:

  • Comparison reconciles mixed operand types to the wider integer operand, or the widest fixed-bytes width.
  • Shift and exponentiation keep their right operand at its own type.
  • Bitwise, shift, and negation operators apply directly to fixed-bytes values.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR completes several operator-emission behaviors in the Slang frontend by refining operand coercion rules (notably for comparisons, shifts, exponentiation, and fixed-bytes bitwise ops) and extending the MLIR layer to properly detect and reconcile fixed-bytes types during coercion and comparisons.

Changes:

  • Introduces FunctionScope::coerced() and applies it broadly to simplify/standardize “emit then coerce” call sites.
  • Updates shift/exponentiation and compound-assignment lowering to keep the RHS operand at its original type (instead of coercing both operands to the result type).
  • Extends MLIR type/value utilities with fixed-bytes inspection and comparison reconciliation logic, and adds/updates lit tests covering fixed-bytes bitwise/shift and mixed-width integer comparisons.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
solx-slang/src/contract/function/statement/variable_declaration.rs Uses the new coerced() helper for initializer coercion.
solx-slang/src/contract/function/expression/unary.rs Refactors unary operator lowering to use coerced() consistently.
solx-slang/src/contract/function/expression/mod.rs Adds FunctionScope::coerced() and refactors coerced_operands() to use it.
solx-slang/src/contract/function/expression/call/mod.rs Switches call argument coercions to coerced() for consistency.
solx-slang/src/contract/function/expression/call/arguments.rs Uses coerced() for parameter/argument coercion.
solx-slang/src/contract/function/expression/bitwise.rs Adjusts shift lowering so shift amounts keep their own type.
solx-slang/src/contract/function/expression/assignment.rs Keeps RHS type for shift compound assignments; coerces RHS for other compound ops.
solx-slang/src/contract/function/expression/array.rs Uses coerced() for array literal element coercion.
solx-slang/src/contract/function/expression/arithmetic.rs Adjusts exponentiation lowering so exponent keeps its own type.
solx-mlir/tests/lit/fixed_bytes_shift.sol Adds lit coverage for fixed-bytes shift with typed shift amounts.
solx-mlir/tests/lit/fixed_bytes_bitwise.sol Adds lit coverage for fixed-bytes bitwise ops (~, ^).
solx-mlir/tests/lit/comparison.sol Expands lit coverage for mixed-width integer comparisons.
solx-mlir/tests/lit/bitwise.sol Expands lit coverage for shifts with “wide” RHS shift amounts and signed shift-right.
solx-mlir/tests/lit/arithmetic.sol Updates arithmetic lit coverage to reflect revised operator emission (notably exp/neg cases).
solx-mlir/src/ir/value.rs Extends coercion to route fixed-bytes coercions through bytes_cast; updates comparison reconciliation logic.
solx-mlir/src/ir/type/mod.rs Adds fixed-bytes type predicates/accessors used by coercion and comparisons.
solx-mlir/src/ffi.rs Exposes new fixed-bytes inspection functions via Rust FFI.
solx-mlir/sol_attr_stubs.cpp Implements the fixed-bytes type predicate and size accessor for the Rust FFI.

Comment thread solx-mlir/src/ir/value.rs Outdated
@hedgar2017
hedgar2017 marked this pull request as ready for review July 15, 2026 20:43
@hedgar2017
hedgar2017 requested review from a team July 15, 2026 20:43
@hedgar2017 hedgar2017 added the ci:slang Trigger slang unit tests on PR label Jul 16, 2026
@hedgar2017
hedgar2017 force-pushed the az-slang-operator-completion branch 3 times, most recently from bd8421f to 4bb4143 Compare July 16, 2026 18:36
@hedgar2017
hedgar2017 force-pushed the az-slang-scope-poc branch from 65746b1 to ef62b4a Compare July 16, 2026 21:51
@hedgar2017
hedgar2017 force-pushed the az-slang-operator-completion branch from 4bb4143 to 273c366 Compare July 16, 2026 22:16
@hedgar2017
hedgar2017 force-pushed the az-slang-scope-poc branch from 21973e4 to 75139ef Compare July 17, 2026 14:56
@hedgar2017
hedgar2017 force-pushed the az-slang-operator-completion branch from 273c366 to 994ba87 Compare July 17, 2026 15:24
Base automatically changed from az-slang-scope-poc to main July 17, 2026 16:26
@hedgar2017
hedgar2017 force-pushed the az-slang-operator-completion branch from 994ba87 to 83eed32 Compare July 17, 2026 17:30
@hedgar2017
hedgar2017 force-pushed the az-slang-operator-completion branch 4 times, most recently from 97bd564 to e6bb2b8 Compare July 19, 2026 03:43
Comparison coerces its operands to the common type the slang binder
reconciles them to, read back through the binder rather than recomputed
here. The right operand of a shift or exponentiation keeps its own type
rather than a cast to the result type, which also removes a spurious cast
on signed right shifts. Bitwise, shift, and negation operators apply
directly to fixed-bytes values, whose coercion left-aligns through a
dedicated bytes cast, backed by fixed-bytes type queries added to the
dialect C API shim.

LIT: extends the arithmetic, bitwise, and comparison oracles and adds
fixed-bytes bitwise and shift fixtures.
@hedgar2017
hedgar2017 force-pushed the az-slang-operator-completion branch from e6bb2b8 to ff267ad Compare July 19, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:slang Trigger slang unit tests on PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants