Files
swift-mirror/test/ModuleInterface/concurrency.swift
John McCall 41cdfb04ad Introduce a proper TypeAttribute class hierarchy.
The old TypeAttributes reprsentation wasn't too bad for a small number of
simple attributes.  Unfortunately, the number of attributes has grown over
the years by quite a bit, which makes TypeAttributes fairly bulky even at
just a single SourceLoc per attribute.  The bigger problem is that we want
to carry more information than that on some of these attributes, which is
all super ad hoc and awkward.  And given that we want to do some things
for each attribute we see, like diagnosing unapplied attributes, the linear
data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in
with the new representation better.  The most significant change here is the
change to how we handle implicit noescape, where now we're passing the
escaping attribute's presence down in the context instead of resetting the
context anytime we see any attributes at all.  This should be cleaner overall.

The source range changes around some of the @escaping checking is really a
sort of bugfix --- the existing code was really jumping from the @ sign
all the way past the autoclosure keyword in a way that I'm not sure always
works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these
parameter specifiers; it seems better now, at least.
2024-01-28 22:30:26 -05:00

84 lines
2.9 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -enable-experimental-concurrency -DLIBRARY -module-name Library
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -enable-experimental-concurrency
// REQUIRES: concurrency
#if LIBRARY
@available(SwiftStdlib 5.5, *)
public func fn() async {
fatalError()
}
@available(SwiftStdlib 5.5, *)
public func reasyncFn(_: () async -> ()) reasync {
fatalError()
}
@available(SwiftStdlib 5.5, *)
public func takesSendable(
_ block: @Sendable @escaping () async throws -> Void
) { }
@available(SwiftStdlib 5.5, *)
public func takesMainActor(
_ block: @MainActor @escaping () -> Void
) { }
@MainActor(unsafe)
public protocol UnsafeMainProtocol {
func requirement()
}
public struct InferredUnsafeMainActor: UnsafeMainProtocol {
public func requirement() {}
}
@preconcurrency @MainActor
public protocol PreconcurrencyMainProtocol {
func requirement()
}
public struct InferredPreconcurrencyMainActor: PreconcurrencyMainProtocol {
public func requirement() {}
}
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -I %t
#else
import Library
@available(SwiftStdlib 5.5, *)
func callFn() async {
await fn()
}
#endif
// RUN: %FileCheck %s < %t/Library.swiftinterface
// CHECK: // swift-module-flags:{{.*}} -enable-experimental-concurrency
// CHECK: public func fn() async
// CHECK: public func reasyncFn(_: () async -> ()) reasync
// CHECK: public func takesSendable(_ block: {{@escaping @Sendable|@Sendable @escaping}} () async throws ->
// CHECK: public func takesMainActor(_ block: {{@escaping @_Concurrency.MainActor|@MainActor @escaping}} () ->
// CHECK: @_Concurrency.MainActor @preconcurrency public protocol UnsafeMainProtocol {
// CHECK-NEXT: @_Concurrency.MainActor @preconcurrency func requirement()
// CHECK-NEXT: }
// CHECK: @_Concurrency.MainActor @preconcurrency public struct InferredUnsafeMainActor :
// CHECK-NEXT: @_Concurrency.MainActor @preconcurrency public func requirement()
// CHECK-NEXT: }
// CHECK: @preconcurrency @_Concurrency.MainActor public protocol PreconcurrencyMainProtocol {
// CHECK-NEXT: @_Concurrency.MainActor @preconcurrency func requirement()
// CHECK-NEXT: }
// CHECK: @_Concurrency.MainActor @preconcurrency public struct InferredPreconcurrencyMainActor :
// CHECK-NEXT: @_Concurrency.MainActor @preconcurrency public func requirement()
// CHECK-NEXT: }
// RUN: %target-swift-emit-module-interface(%t/LibraryPreserveTypesAsWritten.swiftinterface) %s -enable-experimental-concurrency -DLIBRARY -module-name LibraryPreserveTypesAsWritten -module-interface-preserve-types-as-written
// RUN: %target-swift-typecheck-module-from-interface(%t/LibraryPreserveTypesAsWritten.swiftinterface) -enable-experimental-concurrency
// RUN: %FileCheck %s < %t/LibraryPreserveTypesAsWritten.swiftinterface