Support internal array return registers#1868
Conversation
| throw s!"Compilation error: function '{fnName}' uses Stmt.returnArray to return parameter '{name}' of type {repr ty}, but declared returns are {repr expectedReturns}" | ||
| | none => | ||
| throw s!"Compilation error: function '{fnName}' returnArray references unknown parameter '{name}'" | ||
| match findParamType params name with |
There was a problem hiding this comment.
Validation allows Stmt.return for array-returning internal functions
Medium Severity
After this PR, freshInternalRetNames generates two Yul return registers for array return types, but validateReturnShapesInStmt still accepts Stmt.return for internal functions with any single return type (matching [_]), including ParamType.array _. The compileStmt path for Stmt.return only assigns the first register via retName :: _, leaving the second (length) register at Yul's default of 0. This produces silently incorrect code where the array length is always zero.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 31e725f. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fd1e4bd. Configure here.
| throw s!"Compilation error: function '{fnName}' uses Stmt.returnArray to return parameter '{name}' of type {repr ty}, but declared returns are {repr expectedReturns}" | ||
| | none => | ||
| throw s!"Compilation error: function '{fnName}' returnArray references unknown parameter '{name}'" | ||
| match findParamType params name with |
There was a problem hiding this comment.
Validation/compilation mismatch for internal array returnValues
Low Severity
Stmt.returnValues validation checks values.length against the logical return count (expectedReturns.length), but the compilation path checks it against internalRetNames.length (the Yul-level count, which is 2 for array returns). For an internal function returning a single array type, validation passes with one value expression, but compilation throws an arity mismatch because internalRetNames has two entries after the array expansion introduced by freshInternalRetNames.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit fd1e4bd. Configure here.


Summary
(data_offset, length)bindingsVerification
Note
Medium Risk
Changes internal function return lowering and validation to treat array returns as two Yul values (offset/length), which can affect codegen and call-shape checking across the compiler pipeline.
Overview
Internal
Stmt.returnArrayis now supported by lowering dynamic array returns to two internal return registers (offset + length) andleave, instead of ABI-encoding andreturn.The internal dispatch/validation pipeline is updated to account for array returns expanding to two Yul values:
freshInternalRetNamesgenerates extra return registers, andValidationCallsenforces Yul-level arity forExpr.internalCall/Stmt.internalCallAssign.Adds
Expr.memoryArrayLength/Expr.memoryArrayElementfor reading memory-backed array bindings (e.g. from internal helper returns) and threads these constructors through scope validation, purity/usage analyses, trust-surface checks, and proof scaffolding. Includes new feature tests asserting internaladdress[]round-trips and callers read via the memory array helper.Reviewed by Cursor Bugbot for commit b517341. Bugbot is set up for automated code reviews on this repo. Configure here.