|
| 1 | +//===-- DistributedDecl.h - Distributed declaration utils -------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// This file provides functions for working with declarations of distributed |
| 14 | +// actors and declarations related to them, like associated types and protocols. |
| 15 | +// |
| 16 | +//===----------------------------------------------------------------------===// |
| 17 | + |
| 18 | +#ifndef SWIFT_DECL_TYPECHECKDISTRIBUTED_H |
| 19 | +#define SWIFT_DECL_TYPECHECKDISTRIBUTED_H |
| 20 | + |
| 21 | +#include "swift/AST/ConcreteDeclRef.h" |
| 22 | +#include "swift/AST/DiagnosticEngine.h" |
| 23 | +#include "swift/AST/Type.h" |
| 24 | + |
| 25 | +namespace swift { |
| 26 | + |
| 27 | +class ClassDecl; |
| 28 | +class ConstructorDecl; |
| 29 | +class Decl; |
| 30 | +class DeclContext; |
| 31 | +class FuncDecl; |
| 32 | +class NominalTypeDecl; |
| 33 | + |
| 34 | +/// Determine the distributed actor transport type for the given actor. |
| 35 | +Type getDistributedActorSystemType(NominalTypeDecl *actor); |
| 36 | + |
| 37 | +/// Determine the distributed actor identity type for the given actor. |
| 38 | +Type getDistributedActorIDType(NominalTypeDecl *actor); |
| 39 | + |
| 40 | +Type getDistributedActorSystemSerializationRequirementType( |
| 41 | + NominalTypeDecl *system); |
| 42 | + |
| 43 | +/// Determine the serialization requirement for the given actor, actor system |
| 44 | +/// or other type that has the SerializationRequirement associated type. |
| 45 | +Type getDistributedSerializationRequirementType(NominalTypeDecl *nominal); |
| 46 | + |
| 47 | +/// Get the specific protocols that the `SerializationRequirement` specifies, |
| 48 | +/// and all parameters / return types of distributed targets must conform to. |
| 49 | +/// |
| 50 | +/// E.g. if a system declares `typealias SerializationRequirement = Codable` |
| 51 | +/// then this will return `{encodableProtocol, decodableProtocol}`. |
| 52 | +/// |
| 53 | +/// Returns an empty set if the requirement was `Any`. |
| 54 | +llvm::SmallPtrSet<ProtocolDecl *, 2> |
| 55 | +getDistributedSerializationRequirementProtocols(NominalTypeDecl *decl); |
| 56 | + |
| 57 | +llvm::SmallPtrSet<ProtocolDecl *, 2> |
| 58 | +flattenDistributedSerializationTypeToRequiredProtocols( |
| 59 | + TypeBase *serializationRequirement); |
| 60 | + |
| 61 | +/// Check if the `allRequirements` represent *exactly* the |
| 62 | +/// `Encodable & Decodable` (also known as `Codable`) requirement. |
| 63 | +/// If so, we can emit slightly nicer diagnostics. |
| 64 | +bool checkDistributedSerializationRequirementIsExactlyCodable( |
| 65 | + ASTContext &C, |
| 66 | + const llvm::SmallPtrSetImpl<ProtocolDecl *> &allRequirements); |
| 67 | + |
| 68 | +/// Given any set of generic requirements, locate those which are about the |
| 69 | +/// `SerializationRequirement`. Those need to be applied in the parameter and |
| 70 | +/// return type checking of distributed targets. |
| 71 | +llvm::SmallPtrSet<ProtocolDecl *, 2> |
| 72 | +extractDistributedSerializationRequirements( |
| 73 | + ASTContext &C, ArrayRef<Requirement> allRequirements); |
| 74 | +} |
| 75 | + |
| 76 | +#endif /* SWIFT_DECL_TYPECHECKDISTRIBUTED_H */ |
0 commit comments