-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Work around the materialization bug present in #2825 #2826
Open
gabrieldemarmiesse
wants to merge
110
commits into
modularml:nightly
Choose a base branch
from
gabrieldemarmiesse:fix_materializing
base: nightly
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[stdlib] Work around the materialization bug present in #2825 #2826
gabrieldemarmiesse
wants to merge
110
commits into
modularml:nightly
from
gabrieldemarmiesse:fix_materializing
+765
−377
Conversation
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
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
!sync |
modularbot
added
the
imported-internally
Signals that a given pull request has been imported internally.
label
May 26, 2024
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
…nstructor Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
…_branch Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
!sync |
… remove_copyable_from_collectionelement Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
…lectionelementnew
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
Signed-off-by: gabrieldemarmiesse <gabrieldemarmiesse@gmail.com>
!sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
blocked
Blocked by another issue that must be resolved first
imported-internally
Signals that a given pull request has been imported internally.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR solves part of #2467
This PR is part of three PRs to read and merge in the following order
List
, take 2 #2825The important diff is the one between this branch and the branch of the PR #2825 .
You can take a look at this diff here: gabrieldemarmiesse/mojo@sbo_take_2...gabrieldemarmiesse:mojo:fix_materializing
As you can see it's fairly small.
The bug
To understand the workaround, one must understand the bug.
This PR is here to work around the issue #2637
Long story short, when materializing a struct, if the struct holds a pointer to one of its elements, the compiler is a bit lost and will call
__del__
on a struct with the pointer value not updated. (I think it moves the data but doesn't change the pointer value accordingly).This causes us to call
free()
on a pointer that points to stack allocated data, because we check if SBO is in use by usingself.data == self._small_buffer.unsafe_ptr()
. Thus crashing the program. And it's really common to materilize things, especially with Strings that have default values in signatures.The workaround
We don't trust the compiler to copy pointers to some elements of
self
, but we trust the compiler to copy correctly a bool. As such, we add a flag to know if sbo is in use or not, and we use it. This flag can be removed when the compiler bug is fixed.Consequences on the default
List
Because of this flag,
List
has one more byte. I wanted to add this flag only when using asmall_buffer_size > 0
(you pay for what you use and all that), so I wanted to store this flag inside anInlineArray[Bool, Int(Self.sbo_enabled)]
, so that it doesn't take space whensmall_buffer_size = 0
. At first, this worked. Then another compiler bug was introduced the 25/05/2024 which @JoeLoser managed to biscect down to some given commit. (feel free to link it here @JoeLoser ). Thus theInlineArray
wasn't an option anymore and a simple permanantBool
must be used. Users will seeList
take one more byte until one of those two bugs are fixed.Storing the flag inside the
capacity
orsize
at the most significant bitThis is an option to save one byte. But since the workaround is supposed to be temporary, I chose to avoid adding complexity (and possibly bugs) to the codebase for something like that. Furthermore, it doesn't impact performance much (see the next benchmarks), it only increases the size of the
List
.