|
| 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 `ActorSystem` type for the given actor. |
| 35 | +Type getDistributedActorSystemType(NominalTypeDecl *actor); |
| 36 | + |
| 37 | +/// Determine the `ID` type for the given actor. |
| 38 | +Type getDistributedActorIDType(NominalTypeDecl *actor); |
| 39 | + |
| 40 | +/// Get specific 'SerializationRequirement' as defined in 'nominal' |
| 41 | +/// type, which must conform to the passed 'protocol' which is expected |
| 42 | +/// to require the 'SerializationRequirement'. |
| 43 | +Type getDistributedSerializationRequirementType( |
| 44 | + NominalTypeDecl *nominal, ProtocolDecl *protocol); |
| 45 | + |
| 46 | +///// Determine the serialization requirement for the given actor, actor system |
| 47 | +///// or other type that has the SerializationRequirement associated type. |
| 48 | +//Type getDistributedSerializationRequirementType( |
| 49 | +// NominalTypeDecl *nominal, ProtocolDecl *protocol); |
| 50 | + |
| 51 | +Type getDistributedActorSystemActorIDRequirementType( |
| 52 | + NominalTypeDecl *system); |
| 53 | + |
| 54 | + |
| 55 | +/// Get the specific protocols that the `SerializationRequirement` specifies, |
| 56 | +/// and all parameters / return types of distributed targets must conform to. |
| 57 | +/// |
| 58 | +/// E.g. if a system declares `typealias SerializationRequirement = Codable` |
| 59 | +/// then this will return `{encodableProtocol, decodableProtocol}`. |
| 60 | +/// |
| 61 | +/// Returns an empty set if the requirement was `Any`. |
| 62 | +llvm::SmallPtrSet<ProtocolDecl *, 2> |
| 63 | +getDistributedSerializationRequirementProtocols( |
| 64 | + NominalTypeDecl *decl, ProtocolDecl* protocol); |
| 65 | + |
| 66 | +/// Desugar and flatten the `SerializationRequirement` type into a set of |
| 67 | +/// specific protocol declarations. |
| 68 | +llvm::SmallPtrSet<ProtocolDecl *, 2> |
| 69 | +flattenDistributedSerializationTypeToRequiredProtocols( |
| 70 | + TypeBase *serializationRequirement); |
| 71 | + |
| 72 | +/// Check if the `allRequirements` represent *exactly* the |
| 73 | +/// `Encodable & Decodable` (also known as `Codable`) requirement. |
| 74 | +/// |
| 75 | +/// If so, we can emit slightly nicer diagnostics. |
| 76 | +bool checkDistributedSerializationRequirementIsExactlyCodable( |
| 77 | + ASTContext &C, |
| 78 | + const llvm::SmallPtrSetImpl<ProtocolDecl *> &allRequirements); |
| 79 | + |
| 80 | +/// Get the `SerializationRequirement`, explode it into the specific |
| 81 | +/// protocol requirements and insert them into `requirements`. |
| 82 | +/// |
| 83 | +/// The passed `protocol` must be conformed to by the `decl`, e.g. a specific |
| 84 | +/// actor system implementation and the `DistributedActorSystem` protocol, |
| 85 | +/// or any of the specific encoder/decoder and the respective |
| 86 | +/// Distributed...Encoder/Decoder protocol etc. |
| 87 | +/// |
| 88 | +/// Returns false if failed to get the protocol decls. |
| 89 | +bool |
| 90 | +getDistributedSerializationRequirements( |
| 91 | + NominalTypeDecl *decl, |
| 92 | + ProtocolDecl *protocol, |
| 93 | + llvm::SmallPtrSetImpl<ProtocolDecl *> &requirementProtos); |
| 94 | + |
| 95 | +/// Given any set of generic requirements, locate those which are about the |
| 96 | +/// `SerializationRequirement`. Those need to be applied in the parameter and |
| 97 | +/// return type checking of distributed targets. |
| 98 | +llvm::SmallPtrSet<ProtocolDecl *, 2> |
| 99 | +extractDistributedSerializationRequirements( |
| 100 | + ASTContext &C, ArrayRef<Requirement> allRequirements); |
| 101 | +} |
| 102 | + |
| 103 | +#endif /* SWIFT_DECL_TYPECHECKDISTRIBUTED_H */ |
0 commit comments