Repository navigation
Handle parentheses inside strings in lit check updater #9372
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
Open
Blue1977
wants to merge
1
commit into
WebAssembly:main
Choose a base branch
from
Blue1977:fix-parentheses-strings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than a Python unit test, let's just have a small .wast lit test that contains parens inside strings and make sure that the auto-update script can properly generate output for it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
| from scripts.test import shared | ||
|
|
||
| from . import utils | ||
|
|
||
|
|
||
| class UpdateLitChecksStringsTest(utils.BinaryenTestCase): | ||
| def test_parentheses_in_strings(self): | ||
| # The updater must not treat data bytes as WAT delimiters. Include | ||
| # escaped quotes and backslashes so the following function stays separate. | ||
| strings = ['hello', 'hello(', 'hello)', 'hello(()', r'hello\"(', r'hello\\('] | ||
| with tempfile.TemporaryDirectory() as temp: | ||
| for string in strings: | ||
| with self.subTest(string=string): | ||
| test = Path(temp) / 'input.wat' | ||
| test.write_text(';; RUN: wasm-opt %s -S -o - | filecheck %s\n' | ||
| '(module\n' | ||
| ' (memory $mem 1)\n' | ||
| f' (data $data (i32.const 0) "{string}")\n' | ||
| ' (func $after (result i32) (i32.const 42))\n' | ||
| ')\n') | ||
| command = [sys.executable, | ||
| os.path.join(shared.options.binaryen_root, 'scripts', 'update_lit_checks.py'), | ||
| '--binaryen-bin', shared.options.binaryen_bin, | ||
| '--force', '--all-items', '--dry-run', str(test)] | ||
| result = subprocess.run(command, capture_output=True, text=True) | ||
| self.assertEqual(result.returncode, 0, result.stderr) | ||
| lines = result.stdout.splitlines() | ||
| # Both items get their own CHECK block, rather than the | ||
| # function being absorbed into data's CHECK-NEXT block. | ||
| self.assertEqual(sum(';; CHECK:' in line and '(func $after' in line | ||
| for line in lines), 1, result.stdout) | ||
| self.assertFalse(any(';; CHECK-NEXT:' in line and '(func $after' in line | ||
| for line in lines), result.stdout) | ||
| self.assertTrue(any(';; CHECK:' in line and '(data $data' in line | ||
| and line.rstrip().endswith('")') for line in lines), result.stdout) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an off-by-one bug in the loop termination logic. If the matching closing parenthesis is the very last character of the
modulestring, the loop terminates naturally without executing the next iteration wheredepth == 0is checked. As a result,endis returned aslen(module) - 1instead oflen(module), which incorrectly truncates the closing parenthesis when slicing.We can fix this and simplify the logic by checking if
depth == 0immediately after decrementing it, and returningend + 1directly from within the loop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like it's worth fixing this at the same time.