Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Memory Safety's Hardest Problem (matklad.github.io)
6 points by surprisetalk 22 days ago | hide | past | favorite | 2 comments


This is fixed in Mojo btw, using the latest nightly:

``` $ cat test.mojo from std.utils import Variant

def main(): var x : Variant[Int, Pointer[Int, ImmStaticOrigin]] # set it to int x = 12345 # get a reference to the int (dynamically checked). ref elt_ref = x[Int]

    # Set it to the pointer.
    x = "hello".unsafe_ptr()

    # try to use the old reference to the int.
    print(elt_ref)

 $ mojo build x.mojo
 test.mojo:8:11: error: use of invalidated interior reference 'x["value"]'
     print(elt_ref)
          ^
 test.mojo:5:27: note: origin was invalidated here
     x = "hello".unsafe_ptr()
                           ^
 mojo: error: failed to run the pass manager
```


This sounds pretty similar to Java's array-of-templates problem. Is it really more of a problem than parent pointers?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: