Files
swift-mirror/test/Sema/implementation-only-import-from-non-resilient.swift
Alexis Laferrière fabb345624 [Sema] Warn on uses of @_implementationOnly imports without library-evolution
@_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
2023-07-05 16:20:42 -07:00

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