-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve safety of atom tables and RawBlock #2727
base: rebis-dev
Are you sure you want to change the base?
Conversation
Thank you so much for working on this! One question I have regarding these changes: Would it be better to apply them directly to the upcoming Please see the announcement and discussion at: #2569 |
The rebase to |
43046f8
to
e3c6a80
Compare
@bakaq: I would greatly appreciate if you could take a look at these impressive changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Not much to point out that you haven't already acknowledged in TODO comments.
I'm not sure why I would like to suggest in a subsequent PR a way to make the API of |
@adri326: This looks awesome, thank you so much for all these impressive contributions! |
Looks like there are some module access restrictions preventing the CI tests from passing. |
Those were fixed by #2735 iirc |
@adri326 is there a way to rerun the CI tests for this PR? One easy way may be to amend the topmost commit with |
963ca37
to
e74b60e
Compare
Did a rebase, the one failing test case is fixed in #2759, but you can run the tests locally with I should probably squash those commits down, too. |
…lloc properly aligns to it
This notably tightens assertions in RawBlock::get to require indices to be less than head. A special case for Machine::get_clause_p, as it needs to read a dangling stack frame. Switch `RawBlock.head` to be a Cell to reduce the number of invariants and be closer to being thread-safe.
- Fix miri warning about pointer->integer->pointer cast in stack.rs - Panic if Stack::truncate is called with an unaligned value - Add assertions in stack.rs and TODOs for leftover unsafe operations
e74b60e
to
166e4fd
Compare
@triska that's what I also understood. What I meant earlier was that the CI passing depends on #2759 (as of now, the same error in the CI occurs in In the meantime, I've reorganised/squashed the commits for them to not be a mess anymore :) As proof, you can see that the tests pass if you locally cherry-pick the fix from #2759: git cherry-pick 2546976
cargo test
# All tests pass |
The safety of the operations defined for
Atom
andRawBlock
relied until now on undocumented and unasserted properties of the inputs and the environment.For instance, the following (dubious) library prolog code triggers undefined behavior:
This PR aims to lessen the chance of someone inadvertently causing undefined behavior from an incorrect usage of
Atom
orRawBlock
, by making the following changes:RawBlockTraits::align()
into a constant, to enforce the invariant that it must be constant. This should also slightly improve performance.RawBlock::alloc
not actually aligning thesize
toT::align()
, causing potential UB (all call sites were already aligning the size themselves).AtomData
before the right metadata for its fat pointer is obtained.AtomData
has the expected representation.RawBlock
, to reduce the amount of code that needs to uphold its invariants. The raw accesses are replaced with functions with both checked and unchecked variants.UnsafeCell
withCell
inRawBlock
, as the previous code did not need to hand out mutable borrows toptr
.RawBlock
is still notSync
.ptr
tohead
and store it as an offset frombase
, to reduce the number of pointer operations to keep track of.AtomData
andRawBlock
.AtomData
andRawBlock
.I'm well aware that these are a lot of changes. I split them into multiple commits to make it possible to pull out changes into a future PR if needs be :)