mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
@_implementationOnly was designed for use from resilient modules only, using it from non-resilient modules in unsupported. This change adds a warning about it. If anyone hits this warning, they should either enable library-evolution or consider adopting the new `internal import` when it is available as it handles this scenario properly. What leads to a crash: an @_implementationOnly import fully hides the dependency from indirect clients. This can lead to the compiler being unaware of some internal details of a non-resilient module when building a client against it. In turn this may lead to run time crashes from miscompilation. In general one could still use @_implementationOnly in a non-resilient modules as long as it's referenced only from function bodies. However, references from even non-public properties does lead to important memory layout information being hidden from clients of the module. rdar://78129903
24 lines
921 B
Swift
24 lines
921 B
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
|
|
/// Build 2 libs.
|
|
// RUN: %target-swift-frontend -emit-module %t/empty.swift -o %t/A.swiftmodule \
|
|
// RUN: -enable-library-evolution -swift-version 5
|
|
// RUN: %target-swift-frontend -emit-module %t/empty.swift -o %t/B.swiftmodule \
|
|
// RUN: -enable-library-evolution -swift-version 5
|
|
|
|
/// Build a client with and without library-evolution.
|
|
// RUN: %target-swift-frontend -typecheck %t/client-non-resilient.swift -I %t -verify
|
|
// RUN: %target-swift-frontend -typecheck %t/client-resilient.swift -I %t -verify \
|
|
// RUN: -enable-library-evolution -swift-version 5
|
|
|
|
//--- empty.swift
|
|
|
|
//--- client-non-resilient.swift
|
|
@_implementationOnly import A // expected-warning {{using '@_implementationOnly' without enabling library evolution for 'main' may lead to instability during execution}}
|
|
import B
|
|
|
|
//--- client-resilient.swift
|
|
@_implementationOnly import A
|
|
import B
|