Skip to content

Add missing function conversion for member access to preconcurrency vardecl. #60521

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 3 commits into from
Aug 30, 2022

Conversation

kavon
Copy link
Member

@kavon kavon commented Aug 12, 2022

In something like:

#import <Foundation/Foundation.h>

NS_SWIFT_SENDABLE
@interface NSTouchGrass : NSObject
@property (nullable, copy) void (NS_SWIFT_SENDABLE ^cancellationHandler)(void);
@end
func testit(_ grass: NSTouchGrass) {
  grass.cancellationHandler?()
}

We'd strip the @Sendable off the @preconcurrency var NSTouchGrass.cancellationHandler in the AST without using a function conversion. This resulted in an AST like the following, which confuses SILGen and causes a crash:

(member_ref_expr type='@lvalue (() -> Void)?' ...)

So this patch makes sure that the member reference does result in something that is @Sendable, but the reference is followed by an appropriate conversion.

Resolves rdar://98018067

@kavon
Copy link
Member Author

kavon commented Aug 12, 2022

@swift-ci please smoke test

@kavon kavon force-pushed the preconcurrency-var-access branch from 8d73be0 to d60835e Compare August 18, 2022 04:22
@kavon
Copy link
Member Author

kavon commented Aug 18, 2022

@swift-ci please test

kavon added 3 commits August 29, 2022 20:58
…rences

We intended to introduce AST conversions that strip concurrency
attributes off of types associated with `@preconcurrency` decls.
But for VarDecl references, we stripped it too early, leading to
things like a MemberVarDecl that doesn't have `@Sendable` in its
result type, but the VarDecl it refers to does have it.

That caused crashes in SIL where types didn't match up. This patch
fixes things by delaying the stripping until the right point.

resolves rdar://98018067
We needed a way to describe an ABI-safe cast of an address
representing an LValue to implement `@preconcurrency` and
its injection of casts during accesses of members.

This new AST node, `ABISafeConversionExpr` models what is
essentially an `unchecked_addr_cast` in SIL when accessing
the LVAlue.

As of now I simply implemented it and the verification of
the node for the concurrency needs to ensure that it's not
misused by accident. If it finds use outside of that,
feel free to update the verifier.
@kavon kavon force-pushed the preconcurrency-var-access branch from 6e0a8be to a4d661d Compare August 30, 2022 04:03
@kavon kavon changed the title Add missing function conversion for access to preconcurrency vardecl. Add missing function conversion for member access to preconcurrency vardecl. Aug 30, 2022
@kavon kavon marked this pull request as ready for review August 30, 2022 04:29
@kavon
Copy link
Member Author

kavon commented Aug 30, 2022

@swift-ci please test and merge

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