fix(slang): convert operands to the types their dialect ops admit - #676
fix(slang): convert operands to the types their dialect ops admit#676PavelKopyl wants to merge 1 commit into
Conversation
973f2eb to
22c1544
Compare
There was a problem hiding this comment.
Pull request overview
This PR tightens Slang→Sol dialect lowering by ensuring operands are converted to the exact MLIR types required by the Sol dialect ops, with particular focus on bridging sol.byte vs bytes1 at the right boundaries and fixing built-in/member-call argument typing.
Changes:
- Convert
ecrecoveroperands (hash,r,s) to!sol.fixedbytes<32>at the call boundary; convertsend/transferamounts toui256. - Adjust compound-assignment lowering to operate at the semantic element type while writing back through
Place::assign(fixingsol.byteelement cases). - Extend
Value::convertto correctly convert dynamic bytes/string values into!sol.bytevia!sol.fixedbytes<1>, and expand lit coverage for these conversion paths.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
solx-slang/src/contract/function/expression/call/mod.rs |
Ensures built-ins/member calls (ecrecover, send, transfer) convert operands to the types their dialect ops admit. |
solx-slang/src/contract/function/expression/assignment.rs |
Fixes compound assignment to load/operate in the semantic type and write back via Place::assign (important for byte element cases). |
solx-mlir/src/ir/value.rs |
Adds a dedicated string/bytes → !sol.byte conversion bridge through !sol.fixedbytes<1>. |
solx-mlir/tests/lit/value_transfer.sol |
Adds coverage for literal send/transfer amounts folding narrow then casting to ui256 before the op. |
solx-mlir/tests/lit/ecrecover.sol |
Adds coverage for folded constants and verifies byte-cast behavior for ecrecover operands. |
solx-mlir/tests/lit/compound_assignment_bytes_element.sol |
New test validating correct conversion/storing behavior for compound ops on bytes elements. |
solx-mlir/tests/lit/array_string_ops.sol |
Splits FileCheck expectations for solx vs solc output and adds coverage for pushing byte-sized string/hex literals. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
hedgar2017
left a comment
There was a problem hiding this comment.
Thanks!
You may also ask AI to add tests that got green if any!
Yes, those tests exist. I am actually adding them right now in the MLIR test migration PR: #674" |
22c1544 to
16b9db7
Compare
My apologies, I meant adding the |
9fdb02d to
4b4ba04
Compare
16b9db7 to
73476e7
Compare
Sure, rebased onto |
Coverage Summary
|
e6b2bb7 to
a92fa3b
Compare
Yeah, I added the tests that started passing to the description. I also updated the folding of constant identifiers, as the initial implementation had a bug, and added a new runtime test. |
This includes: - aligning 'sol.byte' with 'bytes1' at conversion boundaries; - converting arguments for 'sol.ecrecover', 'sol.send', and 'sol.transfer'; - folding constant identifiers at their declared type
a92fa3b to
3de543d
Compare
| let values = scope.positional_arguments(arguments); | ||
| vec![Value::send(address, values[0], scope)] | ||
| let amount = scope.converted( | ||
| arguments |
There was a problem hiding this comment.
nit: can be just arguments[0]
| Value::transfer(address, values[0], scope); | ||
| let amount = scope.converted( | ||
| arguments | ||
| .iter() |
There was a problem hiding this comment.
nit: can be just arguments[0]
| // CHECK: %[[FD:.*]] = sol.bytes_cast %[[FDC]] : ui128 to !sol.fixedbytes<16> | ||
| // CHECK: sol.fixed_bytes_index %[[FD]][%{{.*}}] : !sol.fixedbytes<16>, ui256 -> !sol.fixedbytes<1> | ||
|
|
||
| bytes16 constant FILE_DIGITS = "EDCBA98765432100"; |
There was a problem hiding this comment.
Please include the Solidity code by following the evaluation_order examples to avoid duplication.
|
|
||
| /// The type a constant folds at: its declared type, except that a `string`/`bytes` constant | ||
| /// folds in memory. | ||
| fn constant_folding_type( |
There was a problem hiding this comment.
- Is string the only such exception?
- Can it be moved to MlirType as a method?
This includes:
Fixed semantic tests: