Skip to content

Start implementing stream internal slots and algos#32730

Merged
gterzian merged 29 commits intoservo:readablestream-re-implementationfrom
gterzian:rs-internal-slots-starts
Jul 19, 2024
Merged

Start implementing stream internal slots and algos#32730
gterzian merged 29 commits intoservo:readablestream-re-implementationfrom
gterzian:rs-internal-slots-starts

Conversation

@gterzian
Copy link
Copy Markdown
Member

@gterzian gterzian commented Jul 8, 2024


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #___ (GitHub issue number if applicable)
  • There are tests for these changes OR
  • These changes do not require tests because ___

@gterzian gterzian marked this pull request as draft July 8, 2024 15:10
@gterzian gterzian force-pushed the rs-internal-slots-starts branch 7 times, most recently from a5afb8f to 2fa3292 Compare July 9, 2024 12:32
@gterzian gterzian force-pushed the rs-internal-slots-starts branch 3 times, most recently from 6906fa1 to c50f7f3 Compare July 10, 2024 12:29
Copy link
Copy Markdown
Member

@wusyong wusyong left a comment

Choose a reason for hiding this comment

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

LGTM now, but I still don't have the permissions. Could I get some access to review and add labels?

@gterzian gterzian force-pushed the rs-internal-slots-starts branch 10 times, most recently from 585110e to 1daab8d Compare July 11, 2024 10:08
@servo-wpt-sync
Copy link
Copy Markdown
Collaborator

🛠 These changes could not be applied onto the latest upstream WPT. Servo's copy of the Web Platform Tests may be out of sync.

@gterzian gterzian force-pushed the rs-internal-slots-starts branch from 1daab8d to 9d7f4aa Compare July 11, 2024 10:17
@gterzian gterzian marked this pull request as ready for review July 12, 2024 04:24
@gterzian
Copy link
Copy Markdown
Member Author

gterzian commented Jul 12, 2024

Ok, I also turned-off the old streams, fixed some things, and as a kind of milestone, https://github.com/servo/servo/blob/496ce717c5343984e0f3da00d223604eff03893c/tests/wpt/tests/fetch/api/basic/stream-response.any.js is now passing again(which covers part of the "native" streaming I handled in this PR).

So I'd say let review and merge this one, so that work can resume in parallel on:

  • The BYOB controller/reader part(note we were not running tests for that part in the previous implementation, even though SM seems the implement it)
  • Various TODOs in the default controller/reader.
  • other stuff?

@jdm
Copy link
Copy Markdown
Member

jdm commented Jul 12, 2024

I'll try to take a look at this tonight!

@sagudev
Copy link
Copy Markdown
Member

sagudev commented Jul 12, 2024

note we were not running tests for that part in the previous implementation, even though SM seems the implement it

Doesn't that mean that readable-streams test's are run (not skipped)?


pub fn enqueue_chunk(&self, mut chunk: Vec<u8>) {
let mut buffer = self.buffer.borrow_mut();
chunk.append(&mut buffer);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't this push the existing buffer onto the end of the newest chunk?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes that seems to be the case.

On this and the comment below: I looked into this and actually we should re-structure this queue concept to allow to any JS value being a chunk, a first step of which I have done in the last commit. There is still a "native" chunk variant, which I guess we could optimize.

/// <https://streams.spec.whatwg.org/#readablestreamgenericreader-stream>
stream: Dom<ReadableStream>,

#[ignore_malloc_size_of = "Rc is hard"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: There are no Rc values involved in this field.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The read request contains a Rc<Promise>.

let cx = GlobalScope::get_cx();
rooted!(in(*cx) let mut underlying_source_dict = UndefinedValue());
if let UnderlyingSourceType::Js(ref js_source) = underlying_source_type {
#[allow(unsafe_code)]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: it makes more sense to have this annotation at the method level.

impl ReadRequest {
/// <https://streams.spec.whatwg.org/#read-request-chunk-steps>
#[allow(unsafe_code)]
#[allow(crown::unrooted_must_root)]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this annotation required?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was able to remove it by avoiding to assign the read result to a temporary variable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was able to remove it by avoiding to assign the read result to a temporary variable.

rooted!(in(*cx) let mut rval = UndefinedValue());
let result = RootedTraceableBox::new(Heap::default());
result.set(*rval);
let result = ReadableStreamReadResult {

This comment was marked as outdated.

@gterzian
Copy link
Copy Markdown
Member Author

gterzian commented Jul 15, 2024

Doesn't that mean that readable-streams test's are run (not skipped)?

@sagudev

yes but the byte stream stuff is in a separate folder, at https://github.com/servo/servo/tree/main/tests/wpt/tests/streams/readable-byte-streams, so we were never running them.

#[allow(crown::unrooted_must_root)]
struct PullAlgorithmFulfillmentHandler {
controller: DomRoot<ReadableStreamDefaultController>,
controller: Dom<ReadableStreamDefaultController>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is safe, since these structs aren't visible to the GC. That's why I recommend Trusted here.

Copy link
Copy Markdown
Member Author

@gterzian gterzian Jul 15, 2024

Choose a reason for hiding this comment

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

That's why I recommend Trusted here.

I just tried it and it breaks Callback: JSTraceable + MallocSizeOf .

these structs aren't visible to the GC

But they end-up on the PromiseNativeHandler, which is a dom_struct.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've strengthened this by keeping the controller rooted while the native promise handler is setup.

@jdm
Copy link
Copy Markdown
Member

jdm commented Jul 15, 2024

b65ba8d is how I would support dictionary callback values.

@gterzian gterzian force-pushed the rs-internal-slots-starts branch 2 times, most recently from 78e562b to d02783b Compare July 15, 2024 15:25
@gterzian
Copy link
Copy Markdown
Member Author

gterzian commented Jul 15, 2024

@jdm thank you!

@wusyong @Taym95 I will address the remaining points from the review, and then I think we need to merge and work in parallel, because I am starting to run into some complicated "how to do this in JS" stuff that warrant PRs in and of themselves...

@wusyong
Copy link
Copy Markdown
Member

wusyong commented Jul 16, 2024

@wusyong @Taym95 I will address the remaining points from the review, and then I think we need to merge and work in parallel, because I am starting to run into some complicated "how to do this in JS" stuff that warrant PRs in and of themselves...

I thought this PR would be merged earlier so I was waiting for it. Byte controller and reader is pretty similar to default one. So I believe once we have done the default ones, the byte part will be faster. I'll review the PR again pretty soon.

@wusyong wusyong self-requested a review July 16, 2024 03:55
Copy link
Copy Markdown
Member

@wusyong wusyong left a comment

Choose a reason for hiding this comment

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

@jdm @gterzian Could we merge this today? I believe @gterzian mentioned we could do more aggressive mergine since this is targeted to the feature branch.
There are some trivial improvements like EnqueuedValue and maybe QueueWithSize should share with byob controller. But I think it could wait for there's PR for such controller implementation.

Edit: I also hope we can update the feature branch to catch up main branch since there are some more commit over weeks.

@gterzian
Copy link
Copy Markdown
Member Author

Ok let's do it! @jdm I have addressed all of your comments, although I still had a few questions(about the rooting), but this had been noted in a TODO as needed to revisit...

@gterzian gterzian merged commit 4459d7e into servo:readablestream-re-implementation Jul 19, 2024
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.

5 participants