-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Sema: Pick the most relevant import for diagnostics about the source of a decl #76358
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9eaa0e5
Sema: getImportAccessLevel returns an authoritative import
xymus 839f99e
Sema: Register clang's export_as in ModuleDecl::getExportAsModule
xymus 9751be9
Diagnostics: Ignore public-module-name for warnings about unused imports
xymus 9ce34ab
Tests: Add a comment where warnings would be desired
xymus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/// Point to the most relevant import relative to the target decl. | ||
// RUN: %empty-directory(%t) | ||
// RUN: split-file --leading-lines %s %t | ||
|
||
/// Build the Swift libraries. | ||
// RUN: %target-swift-frontend -emit-module %t/SwiftPublicNameCore.swift -o %t \ | ||
// RUN: -public-module-name SwiftPublicName | ||
// RUN: %target-swift-frontend -emit-module %t/SwiftPublicName.swift -o %t -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/MixedDep.swift -o %t -I %t | ||
|
||
/// Client testing order between indirect imports of the same priority. | ||
// RUN: %target-swift-frontend -typecheck -I %t \ | ||
// RUN: %t/OrderClient_FileA.swift %t/OrderClient_FileB.swift \ | ||
// RUN: -enable-upcoming-feature InternalImportsByDefault \ | ||
// RUN: -Rmodule-api-import -verify | ||
|
||
/// Client testing order of preference for more levels of imports. | ||
// RUN: %target-swift-frontend -typecheck -I %t \ | ||
// RUN: %t/ExportedClient_FileExported.swift %t/ExportedClient_FileA.swift \ | ||
// RUN: %t/ExportedClient_FileB.swift %t/ExportedClient_FileC.swift %t/ExportedClient_FileD.swift \ | ||
// RUN: -import-underlying-module -module-name ExportedClient \ | ||
// RUN: -enable-upcoming-feature InternalImportsByDefault \ | ||
// RUN: -Rmodule-api-import -verify | ||
|
||
/// Client testing -public-module-name ordering. | ||
// RUN: %target-swift-frontend -typecheck -I %t \ | ||
// RUN: %t/SwiftLibClient_FileA.swift %t/SwiftLibClient_FileB.swift \ | ||
// RUN: -enable-upcoming-feature InternalImportsByDefault \ | ||
// RUN: -Rmodule-api-import -verify | ||
|
||
/// Client testing import of the overlay vs an unrelated module. | ||
// RUN: %target-swift-frontend -typecheck -I %t \ | ||
// RUN: %t/OverlayClient_FileA.swift %t/OverlayClient_FileB.swift \ | ||
// RUN: -enable-upcoming-feature InternalImportsByDefault \ | ||
// RUN: -Rmodule-api-import -verify | ||
|
||
//--- module.modulemap | ||
module FarClangDep { | ||
header "FarClangDep.h" | ||
} | ||
|
||
module MixedDep { | ||
export * | ||
header "MixedDep.h" | ||
} | ||
|
||
module IndirectClangDepA { | ||
export * | ||
header "IndirectClangDepA.h" | ||
} | ||
|
||
module IndirectClangDepB { | ||
export * | ||
header "IndirectClangDepB.h" | ||
} | ||
|
||
module LibCore { | ||
export * | ||
export_as Lib | ||
header "LibCore.h" | ||
} | ||
|
||
module Lib { | ||
export * | ||
header "Lib.h" | ||
} | ||
|
||
module NotLib { | ||
export * | ||
header "NotLib.h" | ||
} | ||
|
||
module ExportedClient { | ||
export * | ||
header "ExportedClient.h" | ||
} | ||
|
||
//--- FarClangDep.h | ||
struct FarClangType{}; | ||
|
||
//--- MixedDep.h | ||
struct UnderlyingType{}; | ||
|
||
//--- IndirectClangDepA.h | ||
#include <FarClangDep.h> | ||
#include <MixedDep.h> | ||
|
||
//--- IndirectClangDepB.h | ||
#include <FarClangDep.h> | ||
#include <MixedDep.h> | ||
|
||
//--- LibCore.h | ||
struct ExportedType {}; | ||
|
||
//--- Lib.h | ||
#include <LibCore.h> | ||
|
||
//--- NotLib.h | ||
#include <LibCore.h> | ||
|
||
//--- ExportedClient.h | ||
#include <LibCore.h> | ||
|
||
//--- SwiftPublicNameCore.swift | ||
public struct SwiftStruct {} | ||
|
||
//--- SwiftPublicName.swift | ||
@_exported import SwiftPublicNameCore | ||
|
||
//--- MixedDep.swift | ||
@_exported import MixedDep | ||
|
||
//--- OrderClient_FileA.swift | ||
/// Between indirect imports, prefer the first one. | ||
public import IndirectClangDepA | ||
public import IndirectClangDepB // expected-warning {{public import of 'IndirectClangDepB' was not used in public declarations or inlinable code}} | ||
|
||
public func useTypesB(a: FarClangType) {} | ||
// expected-remark @-1 {{struct 'FarClangType' is imported via 'IndirectClangDepA', which reexports definition from 'FarClangDep'}} | ||
|
||
//--- OrderClient_FileB.swift | ||
/// Still prefer the first one after changing the order. | ||
public import IndirectClangDepB | ||
public import IndirectClangDepA // expected-warning {{public import of 'IndirectClangDepA' was not used in public declarations or inlinable code}} | ||
|
||
public func useTypesC(a: FarClangType) {} | ||
// expected-remark @-1 {{struct 'FarClangType' is imported via 'IndirectClangDepB', which reexports definition from 'FarClangDep'}} | ||
|
||
|
||
//--- ExportedClient_FileExported.swift | ||
@_exported public import ExportedClient | ||
|
||
//--- ExportedClient_FileA.swift | ||
/// Prefer the defining module. | ||
public import NotLib // expected-warning {{public import of 'NotLib' was not used in public declarations or inlinable code}} | ||
public import LibCore // We should warn here. | ||
public import Lib | ||
|
||
public func useTypesA(a: ExportedType) {} | ||
// expected-remark @-1 {{struct 'ExportedType' is imported via 'Lib', which reexports definition from 'LibCore'}} | ||
|
||
//--- ExportedClient_FileB.swift | ||
/// Then prefer the export_as module. | ||
public import NotLib // expected-warning {{public import of 'NotLib' was not used in public declarations or inlinable code}} | ||
public import Lib | ||
|
||
public func useTypesB(a: ExportedType) {} | ||
// expected-remark @-1 {{struct 'ExportedType' is imported via 'Lib'}} | ||
|
||
//--- ExportedClient_FileC.swift | ||
/// Then prefer any local import. | ||
public import NotLib | ||
|
||
public func useTypesC(a: ExportedType) {} | ||
// expected-remark @-1 {{struct 'ExportedType' is imported via 'NotLib', which reexports definition from 'LibCore'}} | ||
|
||
//--- ExportedClient_FileD.swift | ||
/// Last used the module-wide @_exported import. | ||
public func useTypesD(a: ExportedType) {} | ||
// expected-remark @-1 {{struct 'ExportedType' is imported via 'ExportedClient', which reexports definition from 'LibCore'}} | ||
|
||
|
||
//--- SwiftLibClient_FileA.swift | ||
/// Prefer the import matching public-module-name. | ||
public import SwiftPublicNameCore // We should warn here. | ||
public import SwiftPublicName | ||
|
||
public func useTypesA(a: SwiftStruct) {} | ||
// expected-remark @-1 {{struct 'SwiftStruct' is imported via 'SwiftPublicName', which reexports definition from 'SwiftPublicName'}} | ||
|
||
//--- SwiftLibClient_FileB.swift | ||
/// Fallback on read definition site. | ||
public import SwiftPublicNameCore | ||
|
||
public func useTypesB(a: SwiftStruct) {} | ||
// expected-remark @-1 {{struct 'SwiftStruct' is imported via 'SwiftPublicName'}} | ||
|
||
|
||
//--- OverlayClient_FileA.swift | ||
/// Prefer a Swift overlay to an unrelated 3rd module. | ||
public import IndirectClangDepA // expected-warning {{public import of 'IndirectClangDepA' was not used in public declarations or inlinable code}} | ||
public import MixedDep | ||
|
||
public func useTypesA(a: UnderlyingType) {} | ||
// expected-remark @-1 {{struct 'UnderlyingType' is imported via 'MixedDep', which reexports definition from 'MixedDep'}} | ||
|
||
//--- OverlayClient_FileB.swift | ||
/// Fallback on any reexporter. | ||
public import IndirectClangDepA | ||
|
||
public func useTypesB(a: UnderlyingType) {} | ||
// expected-remark @-1 {{struct 'UnderlyingType' is imported via 'IndirectClangDepA', which reexports definition from 'MixedDep'}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we not need to use the public name here?
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.
We want the real module name here, the one that matches the import statement. This would be the diagnostics on a module with an
-public-module-name
otherwise:This is not covered anymore since I removed a commit. If I have to fix more things on this PR I'll look to add this back in the test.