mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report. Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected. This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
95 lines
4.4 KiB
Swift
95 lines
4.4 KiB
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-swift-frontend %s -module-name UseOptional -enable-experimental-cxx-interop -clang-header-expose-decls=all-public -typecheck -verify -emit-clang-header-path %t/useopt.h
|
|
|
|
// RUN: %check-interop-cxx-header-in-clang(%t/useopt.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY)
|
|
|
|
// RUN: %FileCheck %s < %t/useopt.h
|
|
|
|
public struct SmallStruct {
|
|
let x: Int16
|
|
}
|
|
|
|
public class Klass {
|
|
let x: Int16
|
|
|
|
init(_ x: Int16) {
|
|
self.x = x
|
|
}
|
|
}
|
|
|
|
public func createCIntOpt(_ val: CInt) -> Optional<CInt> {
|
|
return val
|
|
}
|
|
|
|
public func takeCIntOpt(_ val: Optional<CInt>) {
|
|
print(String(describing: val))
|
|
}
|
|
|
|
public func createSmallStructOpt(_ val: Int16) -> SmallStruct? {
|
|
return SmallStruct(x: val)
|
|
}
|
|
|
|
public func takeSmallStructOpt(_ val: Optional<SmallStruct>) {
|
|
print(String(describing: val))
|
|
}
|
|
|
|
public func createKlassOpt(_ val: Int16) -> Klass? {
|
|
return Klass(val)
|
|
}
|
|
|
|
public func takeKlassOpt(_ val: Klass?) {
|
|
print(String(describing: val))
|
|
}
|
|
|
|
public func resetOpt<T>(_ val: inout Optional<T>) {
|
|
val = .none
|
|
}
|
|
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK swift::Optional<int> createCIntOpt(int val) noexcept SWIFT_SYMBOL("s:11UseOptional13createCIntOptys5Int32VSgADF") SWIFT_WARN_UNUSED_RESULT {
|
|
// CHECK-NEXT: return swift::_impl::_impl_Optional<int>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
|
|
// CHECK-NEXT: UseOptional::_impl::swift_interop_returnDirect_UseOptional_[[CINTENC:[a-z0-9_]+]](result, UseOptional::_impl::$s11UseOptional13createCIntOptys5Int32VSgADF(val));
|
|
// CHECK-NEXT: });
|
|
// CHECK-NEXT: }
|
|
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK swift::Optional<Klass> createKlassOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional14createKlassOptyAA0D0CSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT {
|
|
// CHECK-NEXT: return swift::_impl::_impl_Optional<Klass>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
|
|
// CHECK-NEXT: UseOptional::_impl::swift_interop_returnDirect_UseOptional_[[CLASSENC:[a-z0-9_]+]](result, UseOptional::_impl::$s11UseOptional14createKlassOptyAA0D0CSgs5Int16VF(val));
|
|
// CHECK-NEXT: });
|
|
// CHECK-NEXT: }
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK swift::Optional<SmallStruct> createSmallStructOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional20createSmallStructOptyAA0dE0VSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT {
|
|
// CHECK-NEXT: return swift::_impl::_impl_Optional<SmallStruct>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
|
|
// CHECK-NEXT: UseOptional::_impl::swift_interop_returnDirect_UseOptional_uint32_t_0_4(result, UseOptional::_impl::$s11UseOptional20createSmallStructOptyAA0dE0VSgs5Int16VF(val));
|
|
// CHECK-NEXT: });
|
|
// CHECK-NEXT: }
|
|
|
|
|
|
// CHECK: template<class T_0_0>
|
|
// CHECK-NEXT: #ifdef __cpp_concepts
|
|
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0>
|
|
// CHECK-NEXT: #endif
|
|
// CHECK-NEXT: SWIFT_INLINE_THUNK void resetOpt(swift::Optional<T_0_0>& val) noexcept SWIFT_SYMBOL("s:11UseOptional8resetOptyyxSgzlF") {
|
|
// CHECK-NEXT: #ifndef __cpp_concepts
|
|
// CHECK-NEXT: static_assert(swift::isUsableInGenericContext<T_0_0>, "type cannot be used in a Swift generic context");
|
|
// CHECK-NEXT: #endif
|
|
// CHECK-NEXT: _impl::$s11UseOptional8resetOptyyxSgzlF(swift::_impl::_impl_Optional<T_0_0>::getOpaquePointer(val), swift::TypeMetadataTrait<T_0_0>::getTypeMetadata());
|
|
// CHECK-NEXT: }
|
|
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK void takeCIntOpt(const swift::Optional<int>& val) noexcept SWIFT_SYMBOL("s:11UseOptional11takeCIntOptyys5Int32VSgF") {
|
|
// CHECK-NEXT: UseOptional::_impl::$s11UseOptional11takeCIntOptyys5Int32VSgF(UseOptional::_impl::swift_interop_passDirect_UseOptional_[[CINTENC]](swift::_impl::_impl_Optional<int>::getOpaquePointer(val)));
|
|
// CHECK-NEXT: }
|
|
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK void takeKlassOpt(const swift::Optional<Klass>& val) noexcept SWIFT_SYMBOL("s:11UseOptional12takeKlassOptyyAA0D0CSgF") {
|
|
// CHECK-NEXT: UseOptional::_impl::$s11UseOptional12takeKlassOptyyAA0D0CSgF(UseOptional::_impl::swift_interop_passDirect_UseOptional_[[CLASSENC]](swift::_impl::_impl_Optional<Klass>::getOpaquePointer(val)));
|
|
// CHECK-NEXT: }
|
|
|
|
|
|
// CHECK: SWIFT_INLINE_THUNK void takeSmallStructOpt(const swift::Optional<SmallStruct>& val) noexcept SWIFT_SYMBOL("s:11UseOptional18takeSmallStructOptyyAA0dE0VSgF") {
|
|
// CHECK-NEXT: UseOptional::_impl::$s11UseOptional18takeSmallStructOptyyAA0dE0VSgF(UseOptional::_impl::swift_interop_passDirect_UseOptional_uint32_t_0_4(swift::_impl::_impl_Optional<SmallStruct>::getOpaquePointer(val)));
|
|
// CHECK-NEXT: }
|