Skip to content

Commit 12932c7

Browse files
committed
[Distributed] Introduce DistributedDecl.h for greater reuse
1 parent bffd956 commit 12932c7

9 files changed

+335
-179
lines changed

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,9 @@ class ASTContext final {
13511351
/// alternative specified via the -entry-point-function-name frontend flag.
13521352
std::string getEntryPointFunctionName() const;
13531353

1354+
Type getAssociatedTypeOfDistributedSystem(NominalTypeDecl *actor,
1355+
Identifier member);
1356+
13541357
/// Find the type of SerializationRequirement on the passed nominal.
13551358
///
13561359
/// This type exists as a typealias/associatedtype on all distributed actors,

include/swift/AST/DistributedDecl.h

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)