Skip to content

Refactor test content discovery to produce a sequence. #914

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

Merged
merged 7 commits into from
Jan 16, 2025

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Jan 16, 2025

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

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

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.)
@grynspan grynspan added the enhancement New feature or request label Jan 16, 2025
@grynspan grynspan added this to the Swift 6.x milestone Jan 16, 2025
@grynspan grynspan self-assigned this Jan 16, 2025
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

Note the rendering of the diff is terrible. Might help to just look at one side or the other.

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") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes it easier to disable this code in #880.

@@ -615,43 +615,45 @@ struct MiscellaneousTests {
0xABCD1234,
0,
{ outValue, hint in
if let hint, hint.loadUnaligned(as: TestContentAccessorHint.self) != expectedHint {
if let hint, hint.load(as: TestContentAccessorHint.self) != expectedHint {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hint is always well-aligned.

@grynspan
Copy link
Contributor Author

@swift-ci test

1 similar comment
@grynspan
Copy link
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>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan requested a review from stmontgomery January 16, 2025 22:47
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit dfa0d24 into main Jan 16, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/test-content-discovery-as-sequence branch January 16, 2025 23:19
@grynspan grynspan added the discovery 🔎 test content discovery label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discovery 🔎 test content discovery enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants