Skip to content

Use AbstractStorageDecl::isSettableInSwift to prohibit direct writes to optional requirements #42455

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 1 commit into from
Apr 20, 2022

Conversation

AnthonyLatsis
Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis commented Apr 19, 2022

Stop pretending that an optional requirement is immutable via the StorageImplInfo request. This approach has lead astray the conformance checker and may have had a negative impact on other code paths that expect isSettable or supportsMutation to mean "has a setter", and it doesn't work for imported declarations because they bypass the request. Instead, use a forwarding AbstractStorageDecl::isSettableInSwift method that special-cases optional requirements.

@AnthonyLatsis AnthonyLatsis requested a review from jckarter April 19, 2022 21:14
@AnthonyLatsis
Copy link
Collaborator Author

#42363 (comment)

@AnthonyLatsis AnthonyLatsis force-pushed the objc-optional-keypath-fixes branch from a32a8d4 to ecf865d Compare April 19, 2022 21:38
@jckarter
Copy link
Contributor

@swift-ci Please test

@porglezomp
Copy link
Contributor

Hi Anthony! I'm the one who's been making the minimized cases Joe's been sharing—happy to report this seems to fix the actual crashes in the project I've been minimizing cases from.

@AnthonyLatsis
Copy link
Collaborator Author

Glad to hear. Sorry for the trouble!

@AnthonyLatsis AnthonyLatsis force-pushed the objc-optional-keypath-fixes branch from ecf865d to a5077e4 Compare April 20, 2022 08:21
@AnthonyLatsis
Copy link
Collaborator Author

AnthonyLatsis commented Apr 20, 2022

Switched to -import-objc-header. Also, added a separate non-iOS test for ObjCBoolBool bridging in a key path accessor. <\s>

@@ -0,0 +1,12 @@
// RUN: %target-swift-emit-silgen -import-objc-header %swift_src_root/test/Inputs/ObjCOptionalRequirements.h %s | %FileCheck %s

// REQUIRES: objc_interop
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What are the criteria for REQUIRES: objc_interop? Could tests like these simply -enable-objc-interop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently linux is not happy with -enable-objc-interop when importing a header, even though the test passed when an Objective-C module was being imported instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

REQUIRES: objc_interop is enabled when the target runtime is built with ObjC interop, which is practically only on Apple platforms. -enable-objc-interop's behavior is only maintained on those platforms, so I don't think it makes sense to try to test it when running tests for target platforms that don't have ObjC interop.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test

@AnthonyLatsis AnthonyLatsis force-pushed the objc-optional-keypath-fixes branch from a5077e4 to f27b316 Compare April 20, 2022 09:21
…s to `optional` requirements

Stop pretending that an optional requirement is immutable via the `StorageImplInfo` request.
This approach has lead astray the conformance checker and may have had a negative impact
on other code paths, and it doesn't work for imported declarations because they bypass the
request. Instead, use a forwarding `AbstractStorageDecl::isSettableInSwift` method
that special-cases optional requirements.
@AnthonyLatsis AnthonyLatsis force-pushed the objc-optional-keypath-fixes branch from f27b316 to 934964d Compare April 20, 2022 11:28
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test

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.

3 participants