Skip to content
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

[SR-13032] Invalid .swiftinterface when textually including C struct in different modules #55477

Closed
swift-ci opened this issue Jun 17, 2020 · 2 comments · Fixed by #32465
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c interop Feature: Interoperability with C compiler The Swift compiler in itself swift 5.3 textual interfaces unexpected error Bug: Unexpected error

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13032
Radar rdar://problem/64517049
Original Reporter martinboehme (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ParseableInterfaces
Assignee None
Priority Medium

md5: 13b4c87976347810d07df29fa015e2a2

Issue Description:

The following commit contains a failing test demonstrating the problem:

martinboehme@f431f1b

It generates a .swiftinterface for module MainModule, but this .swiftinterface then fails to compile with the error message:

MainModule.swiftinterface:6:46: error: cannot find type 'ForeignA' in scope
public func funcTakingForeignStruct(_ param: ForeignA.ForeignStruct)
                                             ^~~~~~~~

To summarize the situation:

  • The Swift module SubModule imports Clang modules ForeignA and ForeignB. Both ForeignA and ForeignB include a textual header containing the struct ForeignStruct.
  • SubModule re-exports ForeignB but not ForeignA. ForeignStruct is therefore available to clients of SubModule; those clients can use it either using the unqualified name ForeignStruct or the qualified name ForeignB.ForeignStruct, but not ForeignA.ForeignStruct (because SubModule doesn't re-export ForeignA).
  • The Swift module MainModule imports SubModule and uses ForeignStruct in the signature of funcTakingForeignStruct. When MainModule is compiled to a .swiftinterface file, that signature erroneously refers to ForeignStruct as ForeignA.ForeignStruct instead of ForeignB.ForeignStruct. Because of this, the resulting .swiftinterface file does not compile.

I discovered this issue in the course of investigating a CI failure on #32404. The repro above corresponds to the situation in the failing test as follows:

  • SubModule is Glibc

  • ForeignA is SwiftOverlayShims

  • ForeignB is SwiftGlibc

  • The textual header is sys/time.h, and ForeignStruct is struct timeval

I believe this needs to be fixed in TypePrinter::printModuleContext(), but I'm not sure exactly how.

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Martin Böhme (JIRA)

Fix in review at

#32465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c interop Feature: Interoperability with C compiler The Swift compiler in itself swift 5.3 textual interfaces unexpected error Bug: Unexpected error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants