Refactor test content discovery to produce a sequence.#914
Merged
Conversation
This PR does away with `enumerateTestContent {}` and replaces it with
`discover()`, a function that returns a sequence of `TestContentRecord`
instances that the caller can then inspect. This simplifies the logic in callers
by letting them use sequence operations/monads like `map()`, and simplifies the
logic in the implementation by doing away with intermediate tuples and allowing
it to just map section bounds to sequences of `TestContentRecord` values.
Evaluation of the accessor functions for test content records is now lazier,
allowing us to potentially leverage the `context` field of a test content record
to avoid calling accessors for records we know won't match due to the content of
that field. (This functionality isn't currently needed, but could be useful for
future test content types.)
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
Note the rendering of the diff is terrible. Might help to just look at one side or the other. |
grynspan
commented
Jan 16, 2025
| case legacyOnly | ||
| } | ||
| let discoveryMode: DiscoveryMode = switch Environment.flag(named: "SWT_USE_LEGACY_TEST_DISCOVERY") { | ||
| let (useNewMode, useLegacyMode) = switch Environment.flag(named: "SWT_USE_LEGACY_TEST_DISCOVERY") { |
Contributor
Author
There was a problem hiding this comment.
This change makes it easier to disable this code in #880.
grynspan
commented
Jan 16, 2025
| 0, | ||
| { outValue, hint in | ||
| if let hint, hint.loadUnaligned(as: TestContentAccessorHint.self) != expectedHint { | ||
| if let hint, hint.load(as: TestContentAccessorHint.self) != expectedHint { |
Contributor
Author
There was a problem hiding this comment.
The hint is always well-aligned.
Contributor
Author
|
@swift-ci test |
1 similar comment
Contributor
Author
|
@swift-ci test |
| /// - Returns: A sequence of instances of ``TestContentRecord``. Only test | ||
| /// content records matching this ``TestContent`` type's requirements are | ||
| /// included in the sequence. | ||
| static func discover() -> some Sequence<TestContentRecord<Self>> { |
Contributor
There was a problem hiding this comment.
Can you talk about the choice of name? I might suggest a property instead of a function and naming it something like allRecords or allTestContentRecords. At the call site, discover() feels more like an imperative instruction rather than a call which returns a value to me.
Contributor
Author
|
@swift-ci test |
stmontgomery
approved these changes
Jan 16, 2025
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
@swift-ci test |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR does away with
enumerateTestContent {}and replaces it withdiscover(), a function that returns a sequence ofTestContentRecordinstances that the caller can then inspect. This simplifies the logic in callers by letting them use sequence operations/monads likemap(), and simplifies the logic in the implementation by doing away with intermediate tuples and allowing it to just map section bounds to sequences ofTestContentRecordvalues.Evaluation of the accessor functions for test content records is now lazier, allowing us to potentially leverage the
contextfield of a test content record to avoid calling accessors for records we know won't match due to the content of that field. (This functionality isn't currently needed, but could be useful for future test content types.)Checklist: