Skip to content

Commit 6d5e01e

Browse files
authored
Merge pull request #61184 from xymus/default-require-explicit-avail-reland
[Sema] Require explicit availability on public modules (Landing again after we held it back)
2 parents 18dd738 + 875c0a0 commit 6d5e01e

8 files changed

+21
-7
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
735735
diagLevel);
736736
}
737737
} else if (Args.getLastArg(OPT_require_explicit_availability,
738-
OPT_require_explicit_availability_target)) {
738+
OPT_require_explicit_availability_target) ||
739+
Opts.LibraryLevel == LibraryLevel::API) {
739740
Opts.RequireExplicitAvailability = DiagnosticBehavior::Warning;
740741
}
741742

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ function(_compile_swift_files
483483
# The standard library and overlays are built resiliently when SWIFT_STDLIB_STABLE_ABI=On.
484484
if(SWIFTFILE_IS_STDLIB AND SWIFT_STDLIB_STABLE_ABI)
485485
list(APPEND swift_flags "-enable-library-evolution")
486-
list(APPEND swift_flags "-Xfrontend" "-library-level" "-Xfrontend" "api")
486+
list(APPEND swift_flags "-library-level" "api")
487+
list(APPEND swift_flags "-Xfrontend" "-require-explicit-availability=ignore")
487488
endif()
488489

489490
if("${SWIFT_SDK_${SWIFTFILE_SDK}_THREADING_PACKAGE}" STREQUAL "none")

test/ClangImporter/availability_spi_as_unavailable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public let c: SPIInterface1 // expected-error{{cannot use class 'SPIInterface1'
1313
public let d: SPIInterface2 // expected-error{{cannot use class 'SPIInterface2' here; it is an SPI imported from 'SPIContainer'}}
1414

1515
@inlinable
16-
public func inlinableUsingSPI() {
16+
public func inlinableUsingSPI() { // expected-warning{{public declarations should have an availability attribute with an introduction version}}
1717
SharedInterface.foo() // expected-error{{class method 'foo()' cannot be used in an '@inlinable' function because it is an SPI imported from 'SPIContainer'}}
1818
}
1919

test/ClangImporter/availability_spi_as_unavailable_bridging_header.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public let c: SPIInterface1 // expected-error{{cannot use class 'SPIInterface1'
99
public let d: SPIInterface2 // expected-error{{cannot use class 'SPIInterface2' here; it is an SPI imported from '__ObjC'}}
1010

1111
@inlinable
12-
public func inlinableUsingSPI() {
12+
public func inlinableUsingSPI() { // expected-warning{{public declarations should have an availability attribute with an introduction version}}
1313
SharedInterface.foo() // expected-error{{class method 'foo()' cannot be used in an '@inlinable' function because it is an SPI imported from '__ObjC'}}
1414
}

test/SPI/spi-only-and-library-level.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public struct LibStruct {}
2525
@_spiOnly import Lib
2626

2727
public func publicClient() -> LibStruct { fatalError() } // expected-error {{cannot use struct 'LibStruct' here; 'Lib' was imported for SPI only}}
28+
// expected-warning @-1 {{public declarations should have an availability attribute with an introduction version}}
2829
@_spi(X) public func spiClient() -> LibStruct { fatalError() }
2930

3031
//--- SPILib.swift

test/Sema/spi-available-inline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class MacOSSPIClass { public init() {} }
1010
@available(macOS 10.4, *)
1111
public class iOSSPIClass { public init() {} }
1212

13-
@inlinable public func foo() {
13+
@inlinable public func foo() { // expected-warning{{public declarations should have an availability attribute with an introduction version}}
1414
_ = MacOSSPIClass() // expected-error {{class 'MacOSSPIClass' cannot be used in an '@inlinable' function because it is SPI}}
1515
_ = iOSSPIClass()
1616
}

test/attr/attr_inlinable_available.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
// Check that `-library-level api` implies `-target-min-inlining-version min`
17-
// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-library-evolution -module-name Test -target %target-next-stable-abi-triple -library-level api
17+
// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-library-evolution -module-name Test -target %target-next-stable-abi-triple -library-level api -require-explicit-availability=ignore
1818

1919

2020
// Check that these rules are only applied when requested and that at least some
@@ -24,7 +24,7 @@
2424

2525
// Check that -target-min-inlining-version overrides -library-level, allowing
2626
// library owners to disable this behavior for API libraries if needed.
27-
// RUN: not %target-typecheck-verify-swift -swift-version 5 -enable-library-evolution -module-name Test -target %target-next-stable-abi-triple -target-min-inlining-version target -library-level api 2>&1 | %FileCheck --check-prefix NON_MIN %s
27+
// RUN: not %target-typecheck-verify-swift -swift-version 5 -enable-library-evolution -module-name Test -target %target-next-stable-abi-triple -target-min-inlining-version target -library-level api -require-explicit-availability=ignore 2>&1 | %FileCheck --check-prefix NON_MIN %s
2828

2929

3030
// Check that we respect -target-min-inlining-version by cranking it up high

test/attr/require_explicit_availability.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=warn \
1111
// RUN: -require-explicit-availability-target "macOS 10.10"
1212

13+
/// Using -library-level api defaults to enabling warnings, without fixits.
14+
// RUN: sed -e "s/}} {{.*/}}/" < %s > %t/NoFixits.swift
15+
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/NoFixits.swift \
16+
// RUN: -target %target-cpu-apple-macosx10.10 -library-level api
17+
18+
/// Explicitly disable the diagnostic.
19+
// RUN: sed -e 's/xpected-warning/not-something-expected/' < %s > %t/None.swift
20+
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/None.swift \
21+
// RUN: -target %target-cpu-apple-macosx10.10 -require-explicit-availability=ignore \
22+
// RUN: -require-explicit-availability-target "macOS 10.10" -library-level api
23+
1324
/// Upgrade the diagnostic to an error.
1425
// RUN: sed -e "s/xpected-warning/xpected-error/" < %s > %t/Errors.swift
1526
// RUN: %target-swift-frontend -typecheck -parse-as-library -verify %t/Errors.swift \

0 commit comments

Comments
 (0)