Skip to content

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Oct 25, 2017

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

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@jrose-apple jrose-apple left a 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()) {
Copy link
Contributor

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 {}
Copy link
Contributor

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
Copy link
Contributor

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
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 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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
@slavapestov slavapestov force-pushed the imported-materialize-for-set-override-bugs branch from 4cc60b0 to e719109 Compare October 26, 2017 22:46
@slavapestov
Copy link
Contributor Author

@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.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor

Okay, but even if you have to use the real Foundation, please make your own class rather than reusing NumberFormatter.

@slavapestov
Copy link
Contributor Author

@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.
@slavapestov slavapestov force-pushed the imported-materialize-for-set-override-bugs branch from e719109 to 0f2da21 Compare October 27, 2017 00:13
@slavapestov
Copy link
Contributor Author

@jrose-apple I updated the tests to define a new Clang module with a custom type.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

2 similar comments
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@shahmishal CI is broken again?

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

For fuck's sake

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@jrose-apple jrose-apple left a 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.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e719109268a29da2d19e0e13004dfb2dc20f652b

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0f2da21

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

@shahmishal
Copy link
Member

@swift-ci Please test linux

@shahmishal
Copy link
Member

Its due to number of systems we have available. graph

https://ci.swift.org/label/mac-pro/load-statistics

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0f2da21

@slavapestov
Copy link
Contributor Author

@shahmishal

<unknown>:0: error: module map file '/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/swift-corelibs-libdispatch/dispatch/module.modulemap' not found
<unknown>:0: error: module map file '/home/buildnode/jenkins/workspace/swift-PR-Linux/branch-master/swift-corelibs-libdispatch/dispatch/module.modulemap' not found

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0f2da21

@slavapestov
Copy link
Contributor Author

Building remotely on ubuntu-16.04-04 (Ubuntu-16.04 linux-pr executors-4) in workspace /home/buildnode/jenkins/workspace/swift-PR-Linux
java.util.concurrent.TimeoutException: Ping started at 1509064218500 hasn't completed by 1509064458500
Caused: java.io.IOException

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0f2da21

@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test Linux

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.

4 participants