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

Optional pipeline in WorkerScriptLoadOrigin should not be optional #24772

Closed
jdm opened this issue Nov 18, 2019 · 10 comments
Closed

Optional pipeline in WorkerScriptLoadOrigin should not be optional #24772

jdm opened this issue Nov 18, 2019 · 10 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Nov 18, 2019

All code that creates a WorkerScriptLoadOrigin passes a Some value for the pipeline, so we should remove the Option from the struct member field.

Code:

  • components/script_traits/lib.rs
  • components/script/dom/serviceworkerregistration.rs
  • components/script/dom/worker.rs

No need to run tests - if it builds, it's good enough for a pull request.

@highfive
Copy link

@highfive highfive commented Nov 18, 2019

Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

@jdm jdm mentioned this issue Nov 18, 2019
3 of 3 tasks complete
@ghost
Copy link

@ghost ghost commented Nov 19, 2019

@highfive: assign me

This looks like something I could do.

@highfive highfive added the C-assigned label Nov 19, 2019
@highfive
Copy link

@highfive highfive commented Nov 19, 2019

Hey @phil3112! Thanks for your interest in working on this issue. It's now assigned to you!

@LittleSouken
Copy link

@LittleSouken LittleSouken commented Nov 29, 2019

i help but dont give back

@warren-fisher
Copy link
Contributor

@warren-fisher warren-fisher commented Dec 19, 2019

@highfive : assign me

It seems like no work has been completed on this so I would like to give it a try.

@highfive
Copy link

@highfive highfive commented Dec 19, 2019

It looks like this has already been assigned to someone. I'll leave the decision to a core contributor.

@warren-fisher
Copy link
Contributor

@warren-fisher warren-fisher commented Dec 19, 2019

I have looked into this and this is my understanding:
components/script/dom/serviceworkerregistration.rs and components/script/dom/worker.rs create new instances of the WorkerScriptLoadOrigin struct with pipeline_id as a Some(pipeline_id). Therefore the Option type of the WorkerScriptLoadOrigin is not necessary since we can always expect a Some(pipeline_id) and never a None. So I tried changing it so that the WorkerScriptLoadOrigin pipeline_id field accepts a PipelineId type, as well as changing it so that in components/script/dom/serviceworkerregistration.rs and components/script/dom/worker.rs when creating this struct it gives it a PipelineId instead of a Some.

My problem with this is that both components/script/dom/serviceworkerglobalscope.rs and components/script/dom/dedicatedworkerglobalscope.rs expect an Option type in a few places so the compiler fails with mismatched types. Perhaps I am completely off on my ideas about this (very new to Rust) or perhaps these other files need updating as well. I will not proceed any further for the moment.

@jdm
Copy link
Member Author

@jdm jdm commented Dec 19, 2019

@warren-fisher I'm not sure I understand the issue - I believe any code in those files that expects an Option can be passed Some(pipline_id) and satisfy the compiler.

@warren-fisher
Copy link
Contributor

@warren-fisher warren-fisher commented Dec 19, 2019

@jdm My bad, I definitely explained it poorly. If I change the WorkerScriptLoadOrigin struct to have a PipelineId and not an Option<PipelineId> then that means I have to change the instances where Some(pipeline_id) occurs to pipeline_id or else there is a type mismatch with the Rust compiler. Perhaps I misunderstood this issue and it is not correct to change Option<PipelineId> into PipelineId in the WorkerScriptLoadOrigin struct in components/script/dom/serviceworkerregistration.rs.

This then has cascading affects in a few of the other files I mentioned where they were expecting an Optional but not are being passed a PipelineId struct instead. It is very possible that I misunderstood the goal of this issue.

I looked a little deeper and found this example of an unsafe block testing to make sure that Some(pipeline_id) = pipeline_id. I am not sure if this is necessary for making this block safe, I have not had the chance to look that far. If I were to guess I would say that this check is not necessary if the only places where the WorkerScriptLoadOrigin is initialized are in components/script/dom/worker.rs and components/script/dom/serviceworkerregistraction.rs. I am not sure of the larger picture here so I could be far off.

@jdm
Copy link
Member Author

@jdm jdm commented Dec 19, 2019

It certainly sounds like you're on the right track. We want to change the Option<PipelineId> to a PipelineId in WorkerScriptLoadOrigin; this means that any code that handles a None case when reading that value can be removed entirely. I think it might help if you linked to particular lines of code that are giving errors that you aren't sure how to address.

@warren-fisher warren-fisher mentioned this issue Dec 19, 2019
4 of 5 tasks complete
bors-servo added a commit that referenced this issue Dec 19, 2019
Remove Optional pipeline_id

<!-- Please describe your changes on the following line: -->
All code that creates a WorkerScriptLoadOrigin passes a Some value for the pipeline, so we should remove the Option from the struct member field.

I changed the `WorkerScriptLoadOrigin` struct in `components/script_traits/lib.rs` to have a PipelineId and not an Option<PipelineId>. In `components/script/dom/worker.rs` and `components/script/dom/serviceworkerregistration.rs` it was changed so that `WorkerScriptLoadOrigin` was instantiated with a non-Optional. In `components/script/dom/dedicatedworkerglobalscope.rs` testing for if pipeline_id is an Optional is removed.

In `components/script/dom/serviceworkerglobalscope.rs` and `components/script/dom/dedicatedworkerglobalscope.rs` a `PipelineId` was provided as an Optional to a `RequestBuilder` and I changed it to provide a `Some(pipeline_id)` instead. I am not sure changing the [RequestBuilder struct](https://github.com/warren-fisher/servo/blob/5c3bda025144118fc8dd67a3f975d8f91fd25e78/components/net_traits/request.rs#L118-L159) at line 147 to accept a non-optional was within this issue so I left it as is.

I was able to successfully build it so I assume these changes worked, however I am not sure about the implications of the changes made in the unsafe block in `components/script/dom/dedicatedworkerglobalscope.rs`.

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24772 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because the issue says so

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo added a commit that referenced this issue Dec 19, 2019
Remove Optional pipeline_id

<!-- Please describe your changes on the following line: -->
All code that creates a WorkerScriptLoadOrigin passes a Some value for the pipeline, so we should remove the Option from the struct member field.

I changed the `WorkerScriptLoadOrigin` struct in `components/script_traits/lib.rs` to have a PipelineId and not an Option<PipelineId>. In `components/script/dom/worker.rs` and `components/script/dom/serviceworkerregistration.rs` it was changed so that `WorkerScriptLoadOrigin` was instantiated with a non-Optional. In `components/script/dom/dedicatedworkerglobalscope.rs` testing for if pipeline_id is an Optional is removed.

In `components/script/dom/serviceworkerglobalscope.rs` and `components/script/dom/dedicatedworkerglobalscope.rs` a `PipelineId` was provided as an Optional to a `RequestBuilder` and I changed it to provide a `Some(pipeline_id)` instead. I am not sure changing the [RequestBuilder struct](https://github.com/warren-fisher/servo/blob/5c3bda025144118fc8dd67a3f975d8f91fd25e78/components/net_traits/request.rs#L118-L159) at line 147 to accept a non-optional was within this issue so I left it as is.

I was able to successfully build it so I assume these changes worked, however I am not sure about the implications of the changes made in the unsafe block in `components/script/dom/dedicatedworkerglobalscope.rs`.

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24772 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because the issue says so

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.