Skip to content

[TypeChecker/SILGen] Dynamic enforcement of witness/objc isolation with @preconcurrency attribute #70867

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

xedin
Copy link
Contributor

@xedin xedin commented Jan 12, 2024

Initial implementation of @preconcurrency conformances and dynamic actor isolation enforcement that comes with them.

The PR:

  • Makes @preconcurrency attribute available in inheritance clauses of types and extensions
  • Suppresses witness actor isolation diagnostics when synchronous isolated member witnesses a synchronous requirement.
  • Emits intrinsic preconditions to witness thunks and @objc thunks to make sure that calls happens on expected executor.
  • Diagnoses @preconcurrency attributes on conformances as having no effect when no diagnostics were suppressed by them.

Resolves: rdar://102342433
Resolves: rdar://80972126

@xedin xedin force-pushed the dynamic-enforcement-of-witness-isolation-with-preconcurrency branch from f2c5e44 to ae4662d Compare January 16, 2024 18:32
@xedin
Copy link
Contributor Author

xedin commented Jan 16, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jan 16, 2024

@swift-ci please test source compatibility

@@ -1604,11 +1604,15 @@ struct InheritedEntry : public TypeLoc {
/// Whether there was an @retroactive attribute.
bool isRetroactive = false;

/// Whether there was an @preconcurrency attribute.
bool isPreconcurrency = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be bitfields?

/// conformances" bits.
llvm::PointerIntPair<DeclContext *, 3, unsigned> ContextAndBits;

/// Indicates whether the conformance is invalid.
bool Invalid : 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can combine the bits from ContextAndBits and SourceKindAndImplyingConformance with 'Invalid' into a single bitfield

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We discussed this offline with Slava and I'm going to follow-up with bitfield changes in a separate PR.

xedin added 6 commits January 16, 2024 11:51
…mances

Suppress warnings/errors when actor isolated synchroneous witness
is matched against `@preconcurrency` conformance requirement.

Witness thunk assumes isolation of the witness but instead of a
hop to its executor it would emit a runtime check to make sure
that its always called from the expected context.
…d @preconcurrency witness thunks

For `@preconcurrency` conformance witness thunks replace hop to
executor with a precondition to make sure that the thunk is always
called in the expected context.
…objc thunks

When `PreconcurrencyConformances` feature is enabled, emit a
precondition into every synchronous isolated @objc thunk to
make sure that it's always called on the right executor.
…at adopted concurrency

Don't treat isolated or explicitly `nonisolated` requirements as
preconcurrency because in that case we consider protocol as
concurrency adopter.
@xedin xedin force-pushed the dynamic-enforcement-of-witness-isolation-with-preconcurrency branch from ae4662d to 1caafee Compare January 16, 2024 19:51
@xedin
Copy link
Contributor Author

xedin commented Jan 16, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jan 16, 2024

@swift-ci please test source compatibility

@xedin
Copy link
Contributor Author

xedin commented Jan 16, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jan 16, 2024

@swift-ci please test source compatibility

@xedin
Copy link
Contributor Author

xedin commented Jan 17, 2024

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jan 17, 2024

@swift-ci please test Linux platform

@xedin xedin merged commit 6cdab78 into swiftlang:main Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants