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

Fixed bug in textinput::adjust_vertical concerning selection_origin #22458

Merged
merged 1 commit into from Dec 23, 2018

Conversation

Projects
None yet
6 participants
@denismerigoux
Copy link
Contributor

denismerigoux commented Dec 14, 2018

The adjust_vertical function of the TextInput module was forgetting to update the selection_origin.

I discovered the bug and figured out how it fix it using formal verification. More precisely, I manually translated the Rust code in a F* program that was functionally equivalent. Then I used the assert_ok_selection as a post-condition on the following functions :

  • select_all
  • clear_selection
  • adjust_selection_for_horizontal_change
  • clear_selection_to_limit
  • adjust_vertical
  • perform_horizontal_adjustment
  • adjust_horizontal
  • adjust_horizontal_to_line_end

I managed to prove automatically (using the Z3 backend of F*) that the post-condition held for all the functions except for adjust_vertical. I used the error messages from F* to infer the missing code so that the postcondition could hold and manually translated it to this PR diff.

I also added a simple unit test that would fail without this patch, and observed that the assertion failures noted in #22457 disappeared with this patch.

This verification work also allows me to say that the code of all the functions is now functionally correct in the sense that they all yield a valid selection in the sense of asssert_ok_selection, in all cases.


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

This change is Reviewable

@highfive

This comment has been minimized.

Copy link

highfive commented Dec 14, 2018

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @jdm (or someone else) soon.

@highfive

This comment has been minimized.

Copy link

highfive commented Dec 14, 2018

Heads up! This PR modifies the following files:

@KiChjang
Copy link
Member

KiChjang left a comment

Nice work! I only have some code syntax comments below.

Show resolved Hide resolved components/script/textinput.rs Outdated
Show resolved Hide resolved components/script/textinput.rs Outdated
Show resolved Hide resolved components/script/textinput.rs Outdated

@denismerigoux denismerigoux force-pushed the denismerigoux:master branch from 25efd7b to 0662dc6 Dec 17, 2018

Show resolved Hide resolved components/script/textinput.rs Outdated
Show resolved Hide resolved components/script/textinput.rs Outdated
@jdm

jdm approved these changes Dec 21, 2018

@jdm

This comment has been minimized.

Copy link
Member

jdm commented Dec 21, 2018

Neat that you used formal methods to prove properties about the code! Thanks for fixing this!

@jdm jdm removed the S-awaiting-review label Dec 21, 2018

@jdm

This comment has been minimized.

Copy link
Member

jdm commented Dec 22, 2018

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 22, 2018

📌 Commit d95d850 has been approved by jdm

@KiChjang

This comment has been minimized.

Copy link
Member

KiChjang commented Dec 22, 2018

@bors-servo r-

Sorry, do you mind squashing your commits into one?

Fixed bug in textinput::adjust_vertical concerning selection_origin u…
…pdate

This bug was discovered using the F* formal verification framework.

Style changes (match -> if let)

Replace if let Some(_) by .is_some()

@denismerigoux denismerigoux force-pushed the denismerigoux:master branch from d95d850 to e1ea8fb Dec 22, 2018

@denismerigoux

This comment has been minimized.

Copy link
Contributor

denismerigoux commented Dec 22, 2018

The commits are squashed :)

@jdm

This comment has been minimized.

Copy link
Member

jdm commented Dec 22, 2018

@bors-servo r+
Thanks!

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 22, 2018

📌 Commit e1ea8fb has been approved by jdm

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 22, 2018

⌛️ Testing commit e1ea8fb with merge a42f4a0...

bors-servo added a commit that referenced this pull request Dec 22, 2018

Auto merge of #22458 - denismerigoux:master, r=jdm
Fixed bug in textinput::adjust_vertical concerning selection_origin

<!-- Please describe your changes on the following line: -->
The `adjust_vertical` function of the `TextInput` module was forgetting to update the `selection_origin`.

I discovered the bug and figured out how it fix it using formal verification. More precisely, I manually translated the Rust code in a [F*](https://www.fstar-lang.org/) program that was functionally equivalent. Then I used the `assert_ok_selection` as a post-condition on the following functions :

* `select_all`
* `clear_selection`
* `adjust_selection_for_horizontal_change`
* `clear_selection_to_limit`
* `adjust_vertical`
* `perform_horizontal_adjustment`
* `adjust_horizontal`
* `adjust_horizontal_to_line_end`

I managed to prove automatically (using the Z3 backend of F*) that the post-condition held for all the functions except for `adjust_vertical`. I used the error messages from F* to infer the missing code so that the postcondition could hold and manually translated it to this PR diff.

I also added a simple unit test that would fail without this patch, and observed that the assertion failures noted in #22457 disappeared with this patch.

This verification work also allows me to say that the code of all the functions is now functionally correct in the sense that they all yield a valid selection in the sense of `asssert_ok_selection`, in all cases.

---
<!-- 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 #22457 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22458)
<!-- Reviewable:end -->
@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 22, 2018

💔 Test failed - mac-rel-wpt4

@jdm

This comment has been minimized.

Copy link
Member

jdm commented Dec 22, 2018

@bors-servo retry

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 23, 2018

⌛️ Testing commit e1ea8fb with merge e40922e...

bors-servo added a commit that referenced this pull request Dec 23, 2018

Auto merge of #22458 - denismerigoux:master, r=jdm
Fixed bug in textinput::adjust_vertical concerning selection_origin

<!-- Please describe your changes on the following line: -->
The `adjust_vertical` function of the `TextInput` module was forgetting to update the `selection_origin`.

I discovered the bug and figured out how it fix it using formal verification. More precisely, I manually translated the Rust code in a [F*](https://www.fstar-lang.org/) program that was functionally equivalent. Then I used the `assert_ok_selection` as a post-condition on the following functions :

* `select_all`
* `clear_selection`
* `adjust_selection_for_horizontal_change`
* `clear_selection_to_limit`
* `adjust_vertical`
* `perform_horizontal_adjustment`
* `adjust_horizontal`
* `adjust_horizontal_to_line_end`

I managed to prove automatically (using the Z3 backend of F*) that the post-condition held for all the functions except for `adjust_vertical`. I used the error messages from F* to infer the missing code so that the postcondition could hold and manually translated it to this PR diff.

I also added a simple unit test that would fail without this patch, and observed that the assertion failures noted in #22457 disappeared with this patch.

This verification work also allows me to say that the code of all the functions is now functionally correct in the sense that they all yield a valid selection in the sense of `asssert_ok_selection`, in all cases.

---
<!-- 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 #22457 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22458)
<!-- Reviewable:end -->
@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 23, 2018

💔 Test failed - linux-rel-css

@jdm

This comment has been minimized.

Copy link
Member

jdm commented Dec 23, 2018

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 23, 2018

⌛️ Testing commit e1ea8fb with merge 31c6188...

bors-servo added a commit that referenced this pull request Dec 23, 2018

Auto merge of #22458 - denismerigoux:master, r=jdm
Fixed bug in textinput::adjust_vertical concerning selection_origin

<!-- Please describe your changes on the following line: -->
The `adjust_vertical` function of the `TextInput` module was forgetting to update the `selection_origin`.

I discovered the bug and figured out how it fix it using formal verification. More precisely, I manually translated the Rust code in a [F*](https://www.fstar-lang.org/) program that was functionally equivalent. Then I used the `assert_ok_selection` as a post-condition on the following functions :

* `select_all`
* `clear_selection`
* `adjust_selection_for_horizontal_change`
* `clear_selection_to_limit`
* `adjust_vertical`
* `perform_horizontal_adjustment`
* `adjust_horizontal`
* `adjust_horizontal_to_line_end`

I managed to prove automatically (using the Z3 backend of F*) that the post-condition held for all the functions except for `adjust_vertical`. I used the error messages from F* to infer the missing code so that the postcondition could hold and manually translated it to this PR diff.

I also added a simple unit test that would fail without this patch, and observed that the assertion failures noted in #22457 disappeared with this patch.

This verification work also allows me to say that the code of all the functions is now functionally correct in the sense that they all yield a valid selection in the sense of `asssert_ok_selection`, in all cases.

---
<!-- 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 #22457 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22458)
<!-- Reviewable:end -->
@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Dec 23, 2018

@bors-servo bors-servo merged commit e1ea8fb into servo:master Dec 23, 2018

2 of 3 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment