Skip to content

Commit

Permalink
[mojo][repl] Fix erroneous destructor call emission in generated REPL…
Browse files Browse the repository at this point in the history
… source (#35595)

The REPL is doing dirty tricks with variables, turning them into heap
allocations and tracking them in indirect structs. However,
CheckLifetimes
is onto its tricks, which causes it to reject these as incorrect values.

The right solution is to make more invasive changes to the REPL, but
that isn't in the short term plans.  Workaround this by introducing a
horrible hack (tm) op `RefFromPointerUntrackedOp` that creates a
reference that isn't tracked by CheckLifetimes.

This pokes a hole in our nice reference system which makes me very
sad.  A comment saying "don't use this" will prevent other people from
using this for other things ... right???

---------

Co-authored-by: Chris Lattner <clattner@nondot.org>

modular-orig-commit: 7a6b7339522d2657f72d7e8a3a5b51e4d299167f
  • Loading branch information
Mogball authored and mzaks committed Apr 2, 2024
1 parent 55c27f3 commit 400acec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ and tools. Please add any significant user-visible changes here.
changed slightly: `mojo build ./test-dir/program.mojo` now outputs an
executable to the path `./program`, whereas before it would output to the path
`./test-dir/program`.
- The REPL no longer allows type level variable declarations to be
uninitialized, e.g. it will reject `var s: String`. This is because it does
not do proper lifetime tracking (yet!) across cells, and so such code would
lead to a crash. You can work around this by initializing to a dummy value
and overwriting later. This limitation only applies to top level variables,
variables in functions work as they always have.

### ❌ Removed

Expand Down
3 changes: 2 additions & 1 deletion examples/notebooks/BoolMLIR.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
"metadata": {},
"outputs": [],
"source": [
"var a: OurBool"
"fn uninitialized_our_bool():\n",
" var a: OurBool\n"
]
},
{
Expand Down
1 change: 0 additions & 1 deletion examples/notebooks/HelloMojo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
}
],
"source": [
"#| XFAIL: *\n",
"#| CHECK: Hello Mojo!\n",
"print(\"Hello Mojo!\")"
]
Expand Down

0 comments on commit 400acec

Please sign in to comment.