Skip to content

Provide an opt-out conditional for lazy attachment encoding. #811

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Nov 6, 2024

This PR provides a compile-time conditional, SWT_NO_LAZY_ATTACHMENTS, which when set causes Swift Testing's new experimental attachments feature to always eagerly encode/serialize/whatever attachments even if they're copyable and sendable.

We anticipate using this functionality in Embedded Swift in the future. Note that support for Embedded Swift is not (yet!) a planned feature.

"Why not make Attachment generic?"

I've got a separate branch that tries to do this. It has a significantly more complex implementation and is brittle because we need to type-erase the attachable value in order to pass it into the event-handling machinery (which entails having a bunch of special-casing since any Test.Attachable does not conform to Test.Attachable.) Attachment is already meant to represent a type-erased Attachable value.

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 provides a compile-time conditional, `SWT_NO_LAZY_ATTACHMENTS`, which
when set causes Swift Testing's new experimental attachments feature to always
eagerly encode/serialize/whatever attachments even if they're copyable and
sendable.

We anticipate using this functionality in Embedded Swift in the future. Note
that support for Embedded Swift is not (yet!) a planned feature.
@grynspan grynspan added enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later) embedded-swift 📟 Embedded Swift issues attachments/activities 🖇️ Work related to attachments and/or activities labels Nov 6, 2024
@grynspan grynspan self-assigned this Nov 6, 2024
@grynspan
Copy link
Contributor Author

grynspan commented Nov 6, 2024

@swift-ci test

Comment on lines 163 to 164
// BUG: the borrow checker thinks that withErrorRecording() is consuming
// attachableValue, so get around it with an additional do/catch clause.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we ought to propagate caught Errors in this initializer? Unlike the other one, where encoding the attachment is deferred, and it does make sense to catch it and record an Issue, this one might be better to propagate and let the test author decide how to handle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but my reasoning was that:

  1. Errors adding attachments are probably going to be pretty rare;
  2. You'd have to try for non-sendable or move-only attachments, but not if the attachment is sendable and copyable, which is inconsistent and potentially confusing; and
  3. An error that occurs when creating an attachment is probably not a test failure, but an infrastructure failure, so it should not cause a test to halt execution—which it would unless you wrote try?, in which case we lose the error.

Copy link
Contributor

@stmontgomery stmontgomery left a comment

Choose a reason for hiding this comment

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

Had one tangential comment, but this PR looks good

@grynspan grynspan merged commit e2528b9 into main Nov 6, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/opt-out-for-lazy-attachments branch November 6, 2024 20:12
@grynspan grynspan added this to the Swift 6.1 milestone Nov 6, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
attachments/activities 🖇️ Work related to attachments and/or activities embedded-swift 📟 Embedded Swift issues enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants