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

Move away from Promise.all way and check if we need to finish manually #26395

Merged
merged 1 commit into from Jun 13, 2020

Conversation

@CYBAI
Copy link
Collaborator

CYBAI commented May 3, 2020

In the previous Promise.all way, we registered a promise for every
module script which means we will need to do many complex checkings like
"is this top level?" and it will make us much more difficult to understand
how the module script algorithm works.

In the new manual checking way, we will only register promises for top
level modules to notify its owner (e.g. the script element) to finish
the load. So, we can understand it much more easily and would be more
spec-aligned.

Also, I think the Ready and FetchFailed status are quite confusing
and we actually don't need them so they're removed in this patch. Then,
we will always go to Finished instead.

It would basically be following steps:

                                          +-----------------+
                                          | Failed to fetch | ----------+
+--------------+       +----------+     / +-----------------+           |
| Fetch module | ----> | Fetching | ---+                                v
+--------------+       +----------+     \ +---------+        +---------------------+
                                          | Fetched |        | Advance to Finished |
                                          +---------+        +---------------------+
                                               |                        ^
                                               v                        |
                                      +-------------------+             |
                                      | Fetch descendants | ----- if no descendants
                                      +-------------------+
                                               |
                                               V
                                     +----------------------+
                                     | Fetching Descendants |
                                     +----------------------+

In Advance to Finished, it means that module script is about to finished so it will

  1. Notify all of its ready and not finished parents to finish
  2. Link (instantiate) the module
  3. Resolve its promise to notify owner(s) to finish

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #25442
  • These changes do not require tests because it basically refactors the script module and should not break anything.
@highfive
Copy link

highfive commented May 3, 2020

Heads up! This PR modifies the following files:

@highfive
Copy link

highfive commented May 3, 2020

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@CYBAI
Copy link
Collaborator Author

CYBAI commented May 3, 2020

also cc @Manishearth

@CYBAI
Copy link
Collaborator Author

CYBAI commented May 3, 2020

@bors-servo try=wpt

@bors-servo
Copy link
Contributor

bors-servo commented May 3, 2020

Trying commit ca52155 with merge d64265e...

bors-servo added a commit that referenced this pull request May 3, 2020
Move away from Promise.all way and check if we need to finish manually

In the previous Promise.all way, we registered a promise for every
module script which means we will need to do many complex checkings like
"is this top level?" and it will make us much more difficult to understand
how the module script algorithm works.

In the new manual checking way, we will only register promises for top
level modules to notify its owner (e.g. the script element) to finish
the load. So, we can understand it much more easily and would be more
spec-aligned.

Also, I think the `Ready` and `FetchFailed` status are quite confusing
and we actually don't need them so they're removed in this patch. Then,
we will always go to `Finished` instead.

It would basically be following steps:

```
                                          +-----------------+
                                          | Failed to fetch | ----------+
+--------------+       +----------+     / +-----------------+           |
| Fetch module | ----> | Fetching | ---+                                v
+--------------+       +----------+     \ +---------+        +---------------------+
                                          | Fetched |        | Advance to Finished |
                                          +---------+        +---------------------+
                                               |                        ^
                                               v                        |
                                      +-------------------+             |
                                      | Fetch descendants | ----- if no descendants
                                      +-------------------+
                                               |
                                               V
                                     +----------------------+
                                     | Fetching Descendants |
                                     +----------------------+
```

In `Advance to Finished`, it means that module script is about to finished so it will

1. Notify all of its `ready` and `not finished` parents to finish
2. Link (instantiate) the module
3. Resolve its promise to notify owner(s) to finish

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #25442
- [x] These changes do not require tests because it basically refactors the script module and should not break anything.

<!-- 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
Copy link
Contributor

bors-servo commented May 3, 2020

💔 Test failed - status-taskcluster

@CYBAI CYBAI force-pushed the CYBAI:refactor-module-script branch from ca52155 to 2e8381d May 3, 2020
@highfive highfive removed the S-tests-failed label May 3, 2020
@CYBAI
Copy link
Collaborator Author

CYBAI commented May 3, 2020

@bors-servo try=wpt

I also refactored errors for module script in 2e8381d. Does that make sense to have that commit in this PR? or I can send another one which will depend on this one.

Also, I can't reproduce the failure in previous try locally... I suspect there will be some intermittent failures 😕 so, just try again.

@bors-servo
Copy link
Contributor

bors-servo commented May 3, 2020

Trying commit 2e8381d with merge 9424a0a...

bors-servo added a commit that referenced this pull request May 3, 2020
Move away from Promise.all way and check if we need to finish manually

In the previous Promise.all way, we registered a promise for every
module script which means we will need to do many complex checkings like
"is this top level?" and it will make us much more difficult to understand
how the module script algorithm works.

In the new manual checking way, we will only register promises for top
level modules to notify its owner (e.g. the script element) to finish
the load. So, we can understand it much more easily and would be more
spec-aligned.

Also, I think the `Ready` and `FetchFailed` status are quite confusing
and we actually don't need them so they're removed in this patch. Then,
we will always go to `Finished` instead.

It would basically be following steps:

```
                                          +-----------------+
                                          | Failed to fetch | ----------+
+--------------+       +----------+     / +-----------------+           |
| Fetch module | ----> | Fetching | ---+                                v
+--------------+       +----------+     \ +---------+        +---------------------+
                                          | Fetched |        | Advance to Finished |
                                          +---------+        +---------------------+
                                               |                        ^
                                               v                        |
                                      +-------------------+             |
                                      | Fetch descendants | ----- if no descendants
                                      +-------------------+
                                               |
                                               V
                                     +----------------------+
                                     | Fetching Descendants |
                                     +----------------------+
```

In `Advance to Finished`, it means that module script is about to finished so it will

1. Notify all of its `ready` and `not finished` parents to finish
2. Link (instantiate) the module
3. Resolve its promise to notify owner(s) to finish

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #25442
- [x] These changes do not require tests because it basically refactors the script module and should not break anything.

<!-- 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. -->
@CYBAI CYBAI force-pushed the CYBAI:refactor-module-script branch from 53dfd18 to bcd101c May 3, 2020
@CYBAI
Copy link
Collaborator Author

CYBAI commented May 3, 2020

@bors-servo try=wpt

  • Added some more steps to avoid intermittent failures. Let's see if it works well!
@bors-servo
Copy link
Contributor

bors-servo commented May 3, 2020

Trying commit bcd101c with merge 686c87a...

bors-servo added a commit that referenced this pull request May 3, 2020
Move away from Promise.all way and check if we need to finish manually

In the previous Promise.all way, we registered a promise for every
module script which means we will need to do many complex checkings like
"is this top level?" and it will make us much more difficult to understand
how the module script algorithm works.

In the new manual checking way, we will only register promises for top
level modules to notify its owner (e.g. the script element) to finish
the load. So, we can understand it much more easily and would be more
spec-aligned.

Also, I think the `Ready` and `FetchFailed` status are quite confusing
and we actually don't need them so they're removed in this patch. Then,
we will always go to `Finished` instead.

It would basically be following steps:

```
                                          +-----------------+
                                          | Failed to fetch | ----------+
+--------------+       +----------+     / +-----------------+           |
| Fetch module | ----> | Fetching | ---+                                v
+--------------+       +----------+     \ +---------+        +---------------------+
                                          | Fetched |        | Advance to Finished |
                                          +---------+        +---------------------+
                                               |                        ^
                                               v                        |
                                      +-------------------+             |
                                      | Fetch descendants | ----- if no descendants
                                      +-------------------+
                                               |
                                               V
                                     +----------------------+
                                     | Fetching Descendants |
                                     +----------------------+
```

In `Advance to Finished`, it means that module script is about to finished so it will

1. Notify all of its `ready` and `not finished` parents to finish
2. Link (instantiate) the module
3. Resolve its promise to notify owner(s) to finish

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #25442
- [x] These changes do not require tests because it basically refactors the script module and should not break anything.

<!-- 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
Copy link
Contributor

bors-servo commented May 3, 2020

☀️ Test successful - status-taskcluster
State: approved= try=True

@CYBAI
Copy link
Collaborator Author

CYBAI commented May 6, 2020

btw, is it worth writing the ASCII graph in PR description into script_module file as documentation comments 👀?

@jdm
Copy link
Member

jdm commented May 11, 2020

@highfive highfive assigned Manishearth and unassigned jdm May 11, 2020
Copy link
Member

Manishearth left a comment

Seems overall okay, but i'm having a hard time understanding how the resolution works: could you add more comments to the fetch modules and advance_finished_and_link functions?

also it seems like the advance_finished_and_link function, which contains a bunch of loops, is called a lot, but i'm unsure how necessary that is since it's unclear to me what the function is doing

components/script/script_module.rs Outdated Show resolved Hide resolved
components/script/script_module.rs Outdated Show resolved Hide resolved
components/script/script_module.rs Outdated Show resolved Hide resolved
components/script/script_module.rs Outdated Show resolved Hide resolved
components/script/script_module.rs Show resolved Hide resolved
components/script/script_module.rs Outdated Show resolved Hide resolved
@CYBAI CYBAI force-pushed the CYBAI:refactor-module-script branch from bcd101c to 9651097 May 27, 2020
@CYBAI
Copy link
Collaborator Author

CYBAI commented May 27, 2020

@bors-servo try=wpt

@bors-servo
Copy link
Contributor

bors-servo commented May 27, 2020

Trying commit 9651097 with merge a260b24...

bors-servo added a commit that referenced this pull request May 27, 2020
Move away from Promise.all way and check if we need to finish manually

In the previous Promise.all way, we registered a promise for every
module script which means we will need to do many complex checkings like
"is this top level?" and it will make us much more difficult to understand
how the module script algorithm works.

In the new manual checking way, we will only register promises for top
level modules to notify its owner (e.g. the script element) to finish
the load. So, we can understand it much more easily and would be more
spec-aligned.

Also, I think the `Ready` and `FetchFailed` status are quite confusing
and we actually don't need them so they're removed in this patch. Then,
we will always go to `Finished` instead.

It would basically be following steps:

```
                                          +-----------------+
                                          | Failed to fetch | ----------+
+--------------+       +----------+     / +-----------------+           |
| Fetch module | ----> | Fetching | ---+                                v
+--------------+       +----------+     \ +---------+        +---------------------+
                                          | Fetched |        | Advance to Finished |
                                          +---------+        +---------------------+
                                               |                        ^
                                               v                        |
                                      +-------------------+             |
                                      | Fetch descendants | ----- if no descendants
                                      +-------------------+
                                               |
                                               V
                                     +----------------------+
                                     | Fetching Descendants |
                                     +----------------------+
```

In `Advance to Finished`, it means that module script is about to finished so it will

1. Notify all of its `ready` and `not finished` parents to finish
2. Link (instantiate) the module
3. Resolve its promise to notify owner(s) to finish

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #25442
- [x] These changes do not require tests because it basically refactors the script module and should not break anything.

<!-- 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
Copy link
Contributor

bors-servo commented May 27, 2020

💔 Test failed - status-taskcluster

@CYBAI
Copy link
Collaborator Author

CYBAI commented Jun 13, 2020

@bors-servo retry

  • intermittently webrender build failure on layout-2020 machine
@bors-servo
Copy link
Contributor

bors-servo commented Jun 13, 2020

Testing commit dc2c2c8 with merge e99a00d...

bors-servo added a commit that referenced this pull request Jun 13, 2020
Move away from Promise.all way and check if we need to finish manually

In the previous Promise.all way, we registered a promise for every
module script which means we will need to do many complex checkings like
"is this top level?" and it will make us much more difficult to understand
how the module script algorithm works.

In the new manual checking way, we will only register promises for top
level modules to notify its owner (e.g. the script element) to finish
the load. So, we can understand it much more easily and would be more
spec-aligned.

Also, I think the `Ready` and `FetchFailed` status are quite confusing
and we actually don't need them so they're removed in this patch. Then,
we will always go to `Finished` instead.

It would basically be following steps:

```
                                          +-----------------+
                                          | Failed to fetch | ----------+
+--------------+       +----------+     / +-----------------+           |
| Fetch module | ----> | Fetching | ---+                                v
+--------------+       +----------+     \ +---------+        +---------------------+
                                          | Fetched |        | Advance to Finished |
                                          +---------+        +---------------------+
                                               |                        ^
                                               v                        |
                                      +-------------------+             |
                                      | Fetch descendants | ----- if no descendants
                                      +-------------------+
                                               |
                                               V
                                     +----------------------+
                                     | Fetching Descendants |
                                     +----------------------+
```

In `Advance to Finished`, it means that module script is about to finished so it will

1. Notify all of its `ready` and `not finished` parents to finish
2. Link (instantiate) the module
3. Resolve its promise to notify owner(s) to finish

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #25442
- [x] These changes do not require tests because it basically refactors the script module and should not break anything.

<!-- 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
Copy link
Contributor

bors-servo commented Jun 13, 2020

💔 Test failed - status-taskcluster

@CYBAI
Copy link
Collaborator Author

CYBAI commented Jun 13, 2020

@bors-servo retry

  ▶ Unexpected subtest result in /_webgl/conformance/textures/misc/copy-tex-image-2d-formats.html:
  │ FAIL [expected PASS] WebGL test #47: should be 64,255,191,255\nat (0, 0) expected: 64,255,191,255 was 0,0,0,255
  │   → assert_true: should be 64,255,191,255
  │   → at (0, 0) expected: 64,255,191,255 was 0,0,0,255 expected true got false
  │ 
  │ reportTestResultsToHarness/<@http://web-platform.test:8000/_webgl/js/js-test-pre.js:123:24
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1977:25
  │ test@http://web-platform.test:8000/resources/testharness.js:535:30
  │ reportTestResultsToHarness@http://web-platform.test:8000/_webgl/js/js-test-pre.js:122:15
  │ testFailed@http://web-platform.test:8000/_webgl/js/js-test-pre.js:249:31
  │ checkCanvasRect/<@http://web-platform.test:8000/_webgl/js/webgl-test-utils.js:1269:19
  │ checkCanvasRectColor@http://web-platform.test:8000/_webgl/js/webgl-test-utils.js:1225:20
  │ checkCanvasRect@http://web-platform.test:8000/_webgl/js/webgl-test-utils.js:1257:23
  │ checkCanvas@http://web-platform.test:8000/_webgl/js/webgl-test-utils.js:1287:18
  │ testCopyTexImage2D@http://web-platform.test:8000/_webgl/conformance/textures/misc/copy-tex-image-2d-formats.html:188:7
  │ testFormats@http://web-platform.test:8000/_webgl/conformance/textures/misc/copy-tex-image-2d-formats.html:133:23
  └ @http://web-platform.test:8000/_webgl/conformance/textures/misc/copy-tex-image-2d-formats.html:99:12

is this same as #26862?

@bors-servo
Copy link
Contributor

bors-servo commented Jun 13, 2020

Testing commit dc2c2c8 with merge 679f02b...

bors-servo added a commit that referenced this pull request Jun 13, 2020
Move away from Promise.all way and check if we need to finish manually

In the previous Promise.all way, we registered a promise for every
module script which means we will need to do many complex checkings like
"is this top level?" and it will make us much more difficult to understand
how the module script algorithm works.

In the new manual checking way, we will only register promises for top
level modules to notify its owner (e.g. the script element) to finish
the load. So, we can understand it much more easily and would be more
spec-aligned.

Also, I think the `Ready` and `FetchFailed` status are quite confusing
and we actually don't need them so they're removed in this patch. Then,
we will always go to `Finished` instead.

It would basically be following steps:

```
                                          +-----------------+
                                          | Failed to fetch | ----------+
+--------------+       +----------+     / +-----------------+           |
| Fetch module | ----> | Fetching | ---+                                v
+--------------+       +----------+     \ +---------+        +---------------------+
                                          | Fetched |        | Advance to Finished |
                                          +---------+        +---------------------+
                                               |                        ^
                                               v                        |
                                      +-------------------+             |
                                      | Fetch descendants | ----- if no descendants
                                      +-------------------+
                                               |
                                               V
                                     +----------------------+
                                     | Fetching Descendants |
                                     +----------------------+
```

In `Advance to Finished`, it means that module script is about to finished so it will

1. Notify all of its `ready` and `not finished` parents to finish
2. Link (instantiate) the module
3. Resolve its promise to notify owner(s) to finish

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #25442
- [x] These changes do not require tests because it basically refactors the script module and should not break anything.

<!-- 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
Copy link
Contributor

bors-servo commented Jun 13, 2020

💔 Test failed - status-taskcluster

@CYBAI
Copy link
Collaborator Author

CYBAI commented Jun 13, 2020

@bors-servo
Copy link
Contributor

bors-servo commented Jun 13, 2020

Testing commit dc2c2c8 with merge 2ce4bc5...

@bors-servo
Copy link
Contributor

bors-servo commented Jun 13, 2020

☀️ Test successful - status-taskcluster
Approved by: Manishearth
Pushing 2ce4bc5 to master...

@bors-servo bors-servo merged commit 2ce4bc5 into servo:master Jun 13, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
@CYBAI CYBAI deleted the CYBAI:refactor-module-script branch Jun 13, 2020
CYBAI added a commit to CYBAI/servo that referenced this pull request Jun 22, 2020
In servo#26395, we moved from `recursive checking` of dependency status to
check only the _current module_'s dependency status and its descendant
dependency status and also circular dependency status.

However, it will cause an issue.

For example, if the module dependency is like following

```
a -> b -> c -> d -> e
f -> g -> h -> c -> d -> e
```

In this example, if the d module is still under fetching but g is trying
to advance to finish. Then, it will cause a panic because module d is
g's grand-grand-grand-descendant which means it's still under fetching
and we can't instantiate module g.

Ideally, we should get rid of the checking in servo#26903 so, before servo#26903
fixed, we can just move back to the recursive checking way which will
ensure all descendants are not fetching.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

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