-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Sema: Fix some issues with overrides of materializeForSet #12614
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
Sema: Fix some issues with overrides of materializeForSet #12614
Conversation
@swift-ci Please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix looks good, tests need a bit of work.
baseASD->getMaterializeForSetFunc() && | ||
"Storage override but materializeForSet does not"); | ||
baseASD->isSetterAccessibleFrom(ASD->getDeclContext())) { | ||
if (baseASD->getMaterializeForSetFunc()->hasForcedStaticDispatch()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For later: should this just be final
?
var generatesDecimalNumbers: Bool { get set } | ||
} | ||
|
||
extension NumberFormatter : GeneratesDecimalNumbers {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the mock SDK or a handwritten class rather than the system Foundation.
@@ -0,0 +1,13 @@ | |||
// RUN: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use an Inputs/ subdirectory rather than a dummy RUN line.
// RUN: %target-build-swift %S/main.swift -I %t/onone/ -emit-ir > /dev/null | ||
|
||
// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -wmo %S/library.swift | ||
// RUN: %target-build-swift %S/main.swift -I %t/wmo/ -emit-ir > /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little antsy about none of the output being checked here. Seems like this would work better as an IRGen test. There are also no calls to the variable's materializeForSet shown, either through the protocol or with a member of the class hierarchy as a static type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The crash was while deserializing the base class's materializeForSet, which happens when you define the override. But I can think of a way to make this more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, instead of subclassing the subclass, the 'client' can just do an inout access on the property I guess.
- Put input files in directories named Inputs/ to eliminate bogus 'RUN: true' lines - Remove executable_test requirement since they're not executable
4cc60b0
to
e719109
Compare
@jrose-apple I couldn't get the mock SDK working. Ran into -enable-source-import issues, and the %clang-importer-sdk-nosource variant only works with %target-swift-frontend, not %target-build-swift. |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
Okay, but even if you have to use the real Foundation, please make your own class rather than reusing NumberFormatter. |
@jrose-apple What's the downside of using NumberFormatter (or some other Foundation class)? Are you suggesting using -import-objc-header with my own header, or something else? I actually want to build and link the result and there are multiple Swift modules in play so I'm not sure -import-objc-header makes sense either. |
When overriding storage with a forced static dispatch materializeForSet, the override's materializeForSet should not override the base materializeForSet. This is the case where a dynamic property witnesses a protocol requirement, and Sema synthesizes a materializeForSet for it. In this case, the synthesized materializeForSet dynamically dispatches to the dynamic property's getter and setter, and the protocol witness thunk directly calls the synthesized materializeForSet. The subclass only needs to override the getter and setter in this case, since the base class's materializeForSet will already do the right thing. In fact, marking it as an override exposes a problem where we cannot serialize an xref to an imported property's materializeForSet, since it was not created by the importer.
e719109
to
0f2da21
Compare
@jrose-apple I updated the tests to define a new Clang module with a custom type. |
@swift-ci Please test |
@shahmishal CI is broken again? |
@swift-ci Please test |
For fuck's sake |
@swift-ci Please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. It's much better when the tests don't depend on how the SDK declares its APIs.
Build failed |
Build failed |
@swift-ci Please test Linux |
@swift-ci Please test linux |
Build failed |
|
@swift-ci Please test Linux |
Build failed |
|
@swift-ci Please test Linux |
Build failed |
@swift-ci Please test Linux |
1 similar comment
@swift-ci Please test Linux |
When overriding storage with a forced static dispatch materializeForSet,
the override's materializeForSet should not override the base
materializeForSet.
This is the case where a dynamic property witnesses a protocol
requirement, and Sema synthesizes a materializeForSet for it.
In this case, the synthesized materializeForSet dynamically dispatches
to the dynamic property's getter and setter, and the protocol witness
thunk directly calls the synthesized materializeForSet.
The subclass only needs to override the getter and setter in this case,
since the base class's materializeForSet will already do the right
thing.
In fact, marking it as an override exposes a problem where we cannot
serialize an xref to an imported property's materializeForSet, since
it was not created by the importer.
Radar: rdar://problem/35138127