Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@gmorenz
Copy link
Contributor

@gmorenz gmorenz commented Mar 29, 2025

  • Instead of storing MaybeUninit<T> in Rooted<T>, and initializing RootedGuard from a &mut Rooted<T>, store T in Rooted<T> and initialize RootedGuard from an &mut MaybeUninit<Rooted<T>>.

    Currently every time we touch the data through RootedGuard<T>, we need to re-assert to the compiler that it is initialized. Adding one more thing to think about in an already complicated safety dance. By instead getting rid of the half initialized state, and passing the entire place in as uninitialized memory, this part of initialization can happen through entirely safe functions, and access never needs to worry about it.

  • Correctly mark ValueArray::get_ptr as safe - it's doing things with the pointer that might be unsafe.

    This lets us drop the unsafe block in fn from(array: &Rooted<ValueArray<N>>) -> JS::HandleValueArray

  • Rename Rooted::ptr to Rooted::data, whenever working with this type via RootedGuard, we currently have a pointer to a field name ptr which is in fact not (necessarily) a pointer. This is... confusing. Let's change the name to something else.

None of these changes are necessary for correctness or anything, they would just make me happier when reading the code.

Servo still builds with this change, we're technically changing public APIs, but not ones that are actually directly used.

gmorenz added 2 commits March 28, 2025 22:04
Signed-off-by: Greg Morenz <[email protected]>
Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever! I appreciate how this makes a bunch of code easier to read, too.

@jdm jdm enabled auto-merge March 29, 2025 02:28
@jdm jdm added this pull request to the merge queue Mar 29, 2025
Merged via the queue into servo:main with commit 861c091 Mar 29, 2025
27 checks passed
@sagudev
Copy link
Member

sagudev commented Mar 29, 2025

Rename Rooted::ptr to Rooted::data, whenever working with this type via RootedGuard, we currently have a pointer to a field name ptr which is in fact not (necessarily) a pointer. This is... confusing. Let's change the name to something else.

This is actually from mozilla: https://searchfox.org/mozilla-central/source/js/public/RootingAPI.h#1250, but I agree the naming is not really clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants