-
Notifications
You must be signed in to change notification settings - Fork 440
Enable a mode in the parser in which it inspects alternative token choices to mutate test cases #1340
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
Conversation
@swift-ci Please test |
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.
Cool idea!
Sources/SwiftParser/TokenSpec.swift
Outdated
/// matches this `TokenSpec`. | ||
/// | ||
/// IMPORTANT: Should only be used when generating tokens during the | ||
/// modifiation of test cases. This should never be used in the parser itself. |
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.
/// modifiation of test cases. This should never be used in the parser itself. | |
/// modification of test cases. This should never be used in the parser itself. |
// FIXME: Currently, tests are failing when we enable test case mutation. | ||
// Once all of those issues are fixed, this should become | ||
// let enableTestCaseMutation = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"] != "1" |
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.
Out of interest, how much longer does this take to run?
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.
Oh, it’s quite significant. It increases test time from 39s to 250s if you are not skipping long tests (SKIP_LONG_TESTS=1
)
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.
How many mutations happen? Given it's mutating one at a time (concurrently, but each one just has the one change), That's maybe not as bad as I thought it would be 😅. Wonder if it's worth batching some together.
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.
How many mutations happen?
I didn’t measure but I imagine there are on average 3 to 5 different choices for each token. I thought about batching them together, but you really need to be clever so one doesn’t shadow the other. And trying to be clever is usually a bad idea in my experience.
78fe006
to
cf26631
Compare
These parser failures were found by swiftlang#1340. - There was one round-trip failure introduced by swiftlang#1464 - A few cases were just consume tokens as the wrong child - The list of expected token kinds of `DeclModifierSynax` didn’t contain one modifier that was actually parsed
cf26631
to
f3e13ef
Compare
These parser failures were found by swiftlang#1340. - There was one round-trip failure introduced by swiftlang#1464 - A few cases were just consume tokens as the wrong child - The list of expected token kinds of `DeclModifierSynax` didn’t contain one modifier that was actually parsed
…oices to mutate test cases The basic idea is that the parser records which `TokenSpec`s it checked for at individual offsets in the source. We can then use that information to generate new, interesting test cases by replacing a token by the one of the `TokenSpec` we checked for. This technique has found 11 bugs in the parser and I’m expecting it to find quite a few more once we assert that tokens have one of the expected kinds. Gathering of that information is hidden behind a conditional compilation flag because just performing the check of whether we want to record alternative token choices inflicts a 6% performance regression, which doesn’t provide any value except when we are running SwiftParserTest.
f3e13ef
to
b32317c
Compare
@swift-ci Please test |
Enable a mode in the parser in which it inspects alternative token choices to mutate test cases
Enable a mode in the parser in which it inspects alternative token choices to mutate test cases
The basic idea is that the parser records which
TokenSpec
s it checked for at individual offsets in the source. We can then use that information to generate new, interesting test cases by replacing a token by the one of theTokenSpec
we checked for. This technique has found 7 bugs in the parser and I’m expecting it to find quite a few more once we assert that tokens have one of the expected kinds. I’m fixing the bugs this technique found in #1341.Gathering of that information is hidden behind a conditional compilation flag because just performing the check of whether we want to record alternative token choices inflicts a 6% performance regression, which doesn’t provide any value except when we are running SwiftParserTest.