Skip to content
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

clippy: Fix various clippy problems in components/scripts/dom #31910

Merged
merged 8 commits into from
Mar 31, 2024

Conversation

six-shot
Copy link
Contributor

@six-shot six-shot commented Mar 27, 2024


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes are part of Fix as many clippy problems as possible #31500.
  • These changes do not require tests because they do not modify functionality.

@@ -294,15 +294,15 @@ pub struct GlobalScope {
///
/// <https://html.spec.whatwg.org/multipage/#about-to-be-notified-rejected-promises-list>
#[ignore_malloc_size_of = "mozjs"]
uncaught_rejections: DomRefCell<Vec<Box<Heap<*mut JSObject>>>>,
Copy link
Member

Choose a reason for hiding this comment

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

What was the error that led you to removing the Box here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I think for now you should just allow the warning for uncaught_rejections and consumed_rejections below. It seems that Heap always comes boxed and it's tricky to undo that. Instead put a comment like:

/// TODO: `Vec` already stores members in a `Box` so this extra box is an unnecessary layer of
/// indirection. Can it be removed?

cc @sagudev

Copy link
Member

Choose a reason for hiding this comment

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

Objects using heap need to be on the heap and they need to be immovable. While vector content is on heap, immovability can only be assured with box. It is also planed to wrap this in pinned box: servo/mozjs#376 and then we could also pack it all in more high level wrapper that would hide all type nesting.

TL;DR: we should definitely keep the box here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeahhhh i get it now

}

pub fn remove_uncaught_rejection(&self, rejection: HandleObject) {
let mut uncaught_rejections = self.uncaught_rejections.borrow_mut();

if let Some(index) = uncaught_rejections
.iter()
.position(|promise| *promise == Heap::boxed(rejection.get()))
.position(|promise| *promise == *Heap::boxed(rejection.get()))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this comparison now. Heap::boxed is making a Box<> and then you immediately dereference it. We are boxing the heap unnecessarily now.

@@ -2179,42 +2179,42 @@ impl GlobalScope {
pub fn add_uncaught_rejection(&self, rejection: HandleObject) {
self.uncaught_rejections
.borrow_mut()
.push(Heap::boxed(rejection.get()));
.push(*Heap::boxed(rejection.get()));
Copy link
Member

Choose a reason for hiding this comment

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

This is creating a Box<Heap<>> and then immediately pulling it apart. I would either keep using Box<...> in the vector or figure out a way to create this Heap without putting it in a Box<...>.

@@ -294,15 +294,15 @@ pub struct GlobalScope {
///
/// <https://html.spec.whatwg.org/multipage/#about-to-be-notified-rejected-promises-list>
#[ignore_malloc_size_of = "mozjs"]
uncaught_rejections: DomRefCell<Vec<Box<Heap<*mut JSObject>>>>,
Copy link
Member

Choose a reason for hiding this comment

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

I think for now you should just allow the warning for uncaught_rejections and consumed_rejections below. It seems that Heap always comes boxed and it's tricky to undo that. Instead put a comment like:

/// TODO: `Vec` already stores members in a `Box` so this extra box is an unnecessary layer of
/// indirection. Can it be removed?

cc @sagudev

@six-shot six-shot requested a review from mrobinson March 31, 2024 17:03
@mrobinson mrobinson changed the title clippy:Fix various clippy problems in components/scripts/dom clippy: Fix various clippy problems in components/scripts/dom Mar 31, 2024
@mrobinson mrobinson added this pull request to the merge queue Mar 31, 2024
Merged via the queue into servo:main with commit 673eaa5 Mar 31, 2024
11 checks passed
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