Skip to content

Commit b6a425a

Browse files
committed
Sema: Avoid diagnosing required availability in swiftinterface files.
The `-require-explicit-availability` compiler flag is designed to help developers find declarations that they've written with missing availability. The flag is not printed in swiftinterface files, though, so if a module has both `-library-level=api` and also has `-require-explicity-availability=ignore` (as the Swift stdlib does) then the result is that superfluous diagnostics are emitted when typechecking the emitted module interface that should have been suppressed by the `ignore` flag. Suppress these diagnostics when typechecking swiftinterface files since they are only designed to be seen by the owner of the module when they are building the module from source and they don't have much value in the context of interface verification.
1 parent a1cdd33 commit b6a425a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3456,6 +3456,12 @@ static bool declNeedsExplicitAvailability(const Decl *decl) {
34563456
if (!ctx.supportsVersionedAvailability())
34573457
return false;
34583458

3459+
// Don't enforce explicit availability requirements in .swiftinterface files.
3460+
// These diagnostics are only designed to be emitted when building from
3461+
// source.
3462+
if (decl->getDeclContext()->isInSwiftinterface())
3463+
return false;
3464+
34593465
// Skip non-public decls.
34603466
if (auto valueDecl = dyn_cast<const ValueDecl>(decl)) {
34613467
AccessScope scope =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// -require-explicit-availability is not printed in interfaces, so no warnings
2+
// should be emitted when verifying the interface.
3+
// RUN: %target-swift-emit-module-interface(%t_require.swiftinterface) -require-explicit-availability=warn %s
4+
// RUN: %target-swift-typecheck-module-from-interface(%t_require.swiftinterface) -verify
5+
6+
// -library-level=api implies -require-explicit-availability=warn and it _is_
7+
// printed in the interface. Still, no diagnostics about required explicit
8+
// availability should be emitted when verifying the interface.
9+
// RUN: %target-swift-emit-module-interface(%t_api.swiftinterface) -library-level=api %s
10+
// RUN: %target-swift-typecheck-module-from-interface(%t_api.swiftinterface) -verify
11+
12+
public struct NoAvailability { }

0 commit comments

Comments
 (0)