Skip to content

Conversation

@jerryjrchen
Copy link
Contributor

WIP, needs some additional work to get build working locally. Although the _swift_testing_getFallbackEventHandler is forward declared, I don't think it will be present at link time since we're not linking against _TestingInterop.

…n not present

WIP, needs some additional work to get build working locally. Although
the `_swift_testing_getFallbackEventHandler` is forward declared, I
don't think it will be present at link time since we're not linking
against _TestingInterop.
@jerryjrchen jerryjrchen added this to the Swift 6.3.0 milestone Dec 5, 2025
@jerryjrchen jerryjrchen self-assigned this Dec 5, 2025
@jerryjrchen jerryjrchen added enhancement New feature or request issue-handling Related to Issue handling within the testing library labels Dec 5, 2025

#if !SWT_NO_INTEROP

typedef void (*FallbackEventHandler)(const char *recordJSONSchemaVersionNumber,
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR's still a draft, but if you stick with this approach, please plan to add some documentation for these (even if it's a cursory explanation of how they shadow functions elsewhere).

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
typedef void (*FallbackEventHandler)(const char *recordJSONSchemaVersionNumber,
typedef void (* FallbackEventHandler)(const char *recordJSONSchemaVersionNumber,

The smallest possible nitpick. :)

/// currently-installed handler belongs to the testing library, returns
/// `false`.
borrowing func postToFallbackHandler(in context: borrowing Context) -> Bool {
#if canImport(_TestingInterop)
Copy link
Contributor

Choose a reason for hiding this comment

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

Style-wise, we usually outdent #if guards to column 0

}
#endif

#if !SWT_NO_INTEROP
Copy link
Contributor

Choose a reason for hiding this comment

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

Anywhere you're doing this, I suggest changing it to:

Suggested change
#if !SWT_NO_INTEROP
#if compiler(>=6.3) && !SWT_NO_INTEROP

So that when we build against the 6.2 toolchain, we don't even try to link this function.

long recordJSONByteCount,
const void *_Nullable reserved);

FallbackEventHandler _Nullable _swift_testing_getFallbackEventHandler();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
FallbackEventHandler _Nullable _swift_testing_getFallbackEventHandler();
SWT_EXTERN FallbackEventHandler _Nullable _swift_testing_getFallbackEventHandler(void);

The argument lists () and (void) don't mean the same thing in C. 😱

}

// Encode the event as JSON and pass it to the handler.
let encodeAndInvoke = ABI.CurrentVersion.eventHandler(encodeAsJSONLines: false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to cache this event handler somewhere as there's a bit of runtime overhead to generating it. Remember the fallback event handler can't change after its initial assignment, and will be set by the time an event is generated, so we don't need to worry about it having changed on later calls (i.e. the closure we generate here can permanently capture it.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request issue-handling Related to Issue handling within the testing library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants