Skip to content

Preserve lexical blocks - #557

Open
Y-Nak wants to merge 3 commits into
argotorg:mainfrom
Y-Nak:preserve-lexical-blocks
Open

Preserve lexical blocks#557
Y-Nak wants to merge 3 commits into
argotorg:mainfrom
Y-Nak:preserve-lexical-blocks

Conversation

@Y-Nak

@Y-Nak Y-Nak commented Aug 5, 2026

Copy link
Copy Markdown
Member

Depends on #555

Retain block boundaries and local lifetimes during backend lowering.
Fixes flattened blocks that allowed locals to escape their scope or changed nested and compound assignment behavior.

Y-Nak added 3 commits August 4, 2026 15:20
(cherry picked from commit 2b2eeebb09dfbc12bf7c4b513b0bba9c81142ef5)
(cherry picked from commit 51305f258dbc60ca351086933baaeb276f4c311e)
(cherry picked from commit f5cb0ebe30411ddccd84fa4d99737aa464a3e078)

@mbenke mbenke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sadly this (still) leads to incorrect Yul:

$ ./runsol.sh test/examples/cases/block-shadowing.solc
Processing: test/examples/cases/block-shadowing.solc
Compiling to hull...
Emitting hull for contract BlockShadowing
Writing to /home/ben/work/review/build/output1.hull
Generating Yul...
writing output to /home/ben/work/review/build/block-shadowing.yul
Compiling to bytecode...
Error: Variable name x already taken in this scope.
  --> build/block-shadowing.yul:25:9:
   |
25 |         let x
   |         ^^^^^

Error: solc compilation failed
ben@trawa:~/work/review$ cat /home/ben/work/review/build/block-shadowing.yul
object "BlockShadowingDeploy" {
  code {
    function usr$$$N126$36_36_83_55_48_36_36_36_81_81_51_55_36_78_57_36_49_48_53_95_49_49_48_95_49_49_56_95_49_49_49_95_49_48_55_95_57_55_95_57_56_95_49_48_56_95_49_48_49_95_54_36_49_48_53_95_49_49_48_95_49_49_56_95_49_49_49_95_49_48_55_95_49_48_49_95_49_36_52_53_36_84_51_57_36_78_49_48_36_49_49_54_95_57_53_95_49_48_53_95_49_49_48_95_49_48_53_95_49_49_54_95_57_53_95_53_50_95_53_55_95_53_50_95_48_36_ () {
      usr$init_()
      leave
    }
    function usr$_start () {
      mstore(64, memoryguard(128))
      if lt(codesize(), datasize("BlockShadowingDeploy")) {revert(0, 0)}
      if callvalue() {mstore(0, 3046674083)
                      revert(28, 4)}
      usr$$$N126$36_36_83_55_48_36_36_36_81_81_51_55_36_78_57_36_49_48_53_95_49_49_48_95_49_49_56_95_49_49_49_95_49_48_55_95_57_55_95_57_56_95_49_48_56_95_49_48_49_95_54_36_49_48_53_95_49_49_48_95_49_49_56_95_49_49_49_95_49_48_55_95_49_48_49_95_49_36_52_53_36_84_51_57_36_78_49_48_36_49_49_54_95_57_53_95_49_48_53_95_49_49_48_95_49_48_53_95_49_49_54_95_57_53_95_53_50_95_53_55_95_53_50_95_48_36_()
      let size := datasize("BlockShadowing")
      codecopy(0, dataoffset("BlockShadowing"), datasize("BlockShadowing"))
      return(0, size)
    }
    function usr$init_ () { }
    usr$_start()
  }
  object "BlockShadowing" {
    code {
      function usr$main () -> _result {
        let x
        x := 1
        let x
        x := 2
        let directShadow
        directShadow := 1
        let inlineShadow
        inlineShadow := 1
        let inlineUpdate
        inlineUpdate := 3
        let updateBeforeShadow
        updateBeforeShadow := 2
        x := 3
        _result := 3
        leave
      }
      let _mainresult := usr$main()
      mstore(0, _mainresult)
      return(0, 32)
    }
  }
}

@mbenke

mbenke commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Proposed fix is on the yul-nesting-fix branch (commit 0b7fb9e)

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