-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
171: Use arbitrary self types so that we can use `self: Gc<Self>`. r=jacob-hughes a=ltratt VM objects are all allocated on the heap. The Val::recover function turns an object back into a `Val`, but is deeply unsafe: if you didn't allocate the object via `Val::from_obj` all sorts of bad, weird things will happen. Previously we entirely relied on the programmer doing The Right Thing in order that the bad case didn't occur. This commit makes it *much* clearer that objects are `Gc`d things by making their `self` types `self: Gc<Self>`. For example this means that String::concatenate function previously looked like this: ```rust pub fn concatenate(&self, ...) -> Result<Val, Box<VMError>> { ... Val::recover(self) ... } ``` But you could call that with a non-GCd `&self` and then things would explode. This function now looks like: ```rust pub fn concatenate(self: Gc<Self>, ...) -> Result<Val, Box<VMError>> { ... Val::recover(self) ... } ``` and `Val::recover` now looks like: ```rust pub fn recover<T: Obj + 'static>(obj: Gc<T>) -> Self { ``` so we can statically guarantee that you can't `recover` something that wasn't Gc'd.rs There is more to do to squeeze more static guarantees out of the codebase, but this is the minimal change which starts that process off. Co-authored-by: Laurence Tratt <[email protected]>
- Loading branch information
Showing
13 changed files
with
189 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.