Skip to content

Bridge types during import only if we are in a fully-bridgeable context. #10832

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

Conversation

rjmccall
Copy link
Contributor

@rjmccall rjmccall commented Jul 9, 2017

Somehow the logic had slipped so that we were basing this decision purely
on the ImportTypeKind and not on whether the broader context is bridgeable.
This was allowing us to use bridged types when e.g. importing the results and
parameters of C function pointer types, which is really bad.

Also, when importing a reference to a typedef of block type, do not use
the typedef in a non-bridgeable context. We import typedefs of block type
as fully-bridged types, but this means that it is invalid to import a type
using the typedef in a context where the original C type must be used.
Similarly, make sure we use a properly-imported underlying type of the
typedef when the typedef itself is unavailable.

Also, extend the special behavior of block typedefs to abstract-function
typedefs, which seems to be consistent with the expected behavior of the
tests.

Finally, I changed importType to take a new Bridgeability enum instead of
a raw canFullyBridgeTypes bool. At the time, I was doing that because I
was going to make it tri-valued; that turned out to be unnecessary, but I
think it's an improvement anyway.

@rjmccall
Copy link
Contributor Author

rjmccall commented Jul 9, 2017

@swift-ci Please test.

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - db4cef25a0f2f2fe443aa6792bba92afe573c853
Test requested by - @rjmccall

@rjmccall rjmccall force-pushed the fix-function-component-bridging-import branch from db4cef2 to 37e7c7b Compare July 9, 2017 17:47
@rjmccall
Copy link
Contributor Author

rjmccall commented Jul 9, 2017

@swift-ci Please test.

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - db4cef25a0f2f2fe443aa6792bba92afe573c853
Test requested by - @rjmccall

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - db4cef25a0f2f2fe443aa6792bba92afe573c853
Test requested by - @rjmccall

Somehow the logic had slipped so that we were basing this decision purely
on the ImportTypeKind and not on whether the broader context is bridgeable.
This was allowing us to use bridged types when e.g. importing the results
and parameters of C function pointer types, which is really bad.

Also, when importing a reference to a typedef of block type, do not use
the typedef in a non-bridgeable context.  We import typedefs of block type
as fully-bridged types, but this means that it is invalid to import a type
using the typedef in a context where the original C type must be used.
Similarly, make sure we use a properly-imported underlying type of the
typedef when the typedef itself is unavailable.

Also, extend the special behavior of block typedefs to abstract-function
typedefs, which seems to be consistent with the expected behavior of the
tests.

Finally, I changed importType to take a new Bridgeability enum instead of
a raw canFullyBridgeTypes bool.  At the time, I was doing that because I
was going to make it tri-valued; that turned out to be unnecessary, but I
think it's an improvement anyway.
@rjmccall rjmccall force-pushed the fix-function-component-bridging-import branch from 37e7c7b to 0e89efa Compare July 9, 2017 17:53
@rjmccall
Copy link
Contributor Author

rjmccall commented Jul 9, 2017

@swift-ci Please test.

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2017

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 37e7c7b1cefdd266828406a3002bf45f43e744a0
Test requested by - @rjmccall

@swift-ci
Copy link
Contributor

swift-ci commented Jul 9, 2017

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 37e7c7b1cefdd266828406a3002bf45f43e744a0
Test requested by - @rjmccall

@rjmccall rjmccall merged commit f4f8349 into swiftlang:master Jul 9, 2017
@rjmccall rjmccall deleted the fix-function-component-bridging-import branch July 9, 2017 20:47
@jrose-apple
Copy link
Contributor

Hm, I wonder if this fixed rdar://problem/33027057.

@jrose-apple
Copy link
Contributor

So it looks like this caused rdar://problem/34913634, because block-typed globals aren't bridged anymore. I tried to just re-enable that by checking for blocks in VisitVarDecl and allowing bridging in that case (something we already do for NSString globals), but we're not set up to bridge a function in SILGen in that position. Am I on the right path here?

cc @slavapestov

@rjmccall
Copy link
Contributor Author

I think the original change might have gone the wrong way entirely, actually. We implicitly un-bridge all the component types of C/block function types in SILGen, which I didn't realize, so arguably we ought to bridge all the component types of function types during import regardless of the context.

@jrose-apple
Copy link
Contributor

I ran into trouble with that too. I'll check it again tomorrow.

@DougGregor
Copy link
Member

I suspect that I fixed rdar://problem/34913634 with #12680, because it reinstated bridging for typedefs.

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