feat(slang): cast function call arguments to match parameter types#352
feat(slang): cast function call arguments to match parameter types#352hedgar2017 wants to merge 1 commit intomainfrom
Conversation
24b943a to
ef8407c
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates Sol dialect lowering to record full function parameter types in the MLIR context and uses those declared types at call sites to cast arguments so sol.call operand types match the callee signature (aligning more closely with solc’s “target type” rvalue emission behavior). It also simplifies several melior:: fully-qualified references by adding local use imports.
Changes:
- Store declared parameter types (not just arity) in
solx-mlir::Contextfunction signatures and return them fromresolve_function. - In call lowering, cast each argument to the callee’s declared parameter type before emitting
sol.call. - Clean up
melior::path usage by importingContext,BlockRef,Value,Block, andRegionwhere needed.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| solx-slang/src/ast/contract/mod.rs | Pre-registers parameter MLIR types (not just counts) for later call-site casting. |
| solx-slang/src/ast/contract/function/statement/control_flow.rs | Uses Block/Region imports to reduce fully-qualified references. |
| solx-slang/src/ast/contract/function/mod.rs | Uses imported BlockRef/Value types for clarity; no behavioral change here. |
| solx-slang/src/ast/contract/function/expression/operator.rs | Uses imported melior::Context in operator emission signature. |
| solx-slang/src/ast/contract/function/expression/call/type_conversion.rs | Uses imported Context/BlockRef/Value; keeps conversion logic centralized. |
| solx-slang/src/ast/contract/function/expression/call/mod.rs | Adds argument casting prior to emitting sol.call. |
| solx-mlir/src/context/mod.rs | Stores parameter types in signatures and returns them from resolve_function. |
| solx-mlir/src/context/function.rs | Updates Function metadata to store parameter_types: Vec<Type>. |
304913e to
ab59f37
Compare
9d62e0f to
4ab5e3a
Compare
|
It looks like If it does, we should map the resolved AST definition to its MLIR op, keyed by something unique to the definition node (like its node ID), rather than doing string-based lookup. |
|
@abinavpp that makes total sense, and I want to do this migration. But this PR's job is only emitting the casts. Happy to fold it in here or do it as a follow-up. What do you prefer? |
Register declared parameter types in function signatures and resolve overloads by exact type match instead of arity. Cast arguments using TypeConversion to correctly handle bool (cmp != 0) and address (truncate to ui160 + address_cast). Extract resolve_function_types to deduplicate Slang-to-MLIR type resolution.
4ab5e3a to
03a1782
Compare
Store declared parameter types in function signatures and emit
sol.castfor each argument whose type differs from the callee's declared parameter type. This matches the C++ reference behavior wheregenRValExprreceives a target type and casts accordingly.Also cleans up inline
melior::fully-qualified paths across solx-slang by adding properuseimports forContext,BlockRef,Value,Block,Region, andIntegerType.