Skip to content

Commit ed561cc

Browse files
authored
Merge pull request #4272 from swiftwasm/katei/merge-main-2022-02-18
2 parents 07e14a8 + f130d63 commit ed561cc

File tree

316 files changed

+12024
-4242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

316 files changed

+12024
-4242
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* [SE-0341][]:
9+
10+
Opaque types can now be used in the parameters of functions and subscripts, wher they provide a shorthand syntax for the introduction of a generic parameter. For example, the following:
11+
12+
```swift
13+
func horizontal(_ v1: some View, _ v2: some View) -> some View {
14+
HStack {
15+
v1
16+
v2
17+
}
18+
}
19+
```
20+
21+
is equivalent to
22+
23+
```swift
24+
func horizontal<V1: View, V2: View>(_ v1: V1, _ v2: V2) -> some View {
25+
HStack {
26+
v1
27+
v2
28+
}
29+
}
30+
```
31+
32+
With this, `some` in a parameter type provides a generalization where the
33+
caller chooses the parameter's type as well as its value, whereas `some` in
34+
the result type provides a generalization where the callee chooses the
35+
resulting type and value.
36+
837
* The compiler now correctly emits warnings for more kinds of expressions where a protocol conformance is used and may be unavailable at runtime. Previously, member reference expressions and type erasing expressions that used potentially unavailable conformances were not diagnosed, leading to potential crashes at runtime.
938

1039
```swift
@@ -8962,6 +8991,7 @@ Swift 1.0
89628991
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
89638992
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
89648993
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
8994+
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
89658995

89668996
[SR-75]: <https://bugs.swift.org/browse/SR-75>
89678997
[SR-106]: <https://bugs.swift.org/browse/SR-106>

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ final public class DeallocStackInst : Instruction, UnaryInstruction {
220220
}
221221

222222
final public class DeallocStackRefInst : Instruction, UnaryInstruction {
223-
public var allocRef: AllocRefInst { operand as! AllocRefInst }
223+
public var allocRef: AllocRefInstBase { operand as! AllocRefInstBase }
224224
}
225225

226226
final public class CondFailInst : Instruction, UnaryInstruction {

include/swift/AST/ASTContext.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -674,20 +674,30 @@ class ASTContext final {
674674
FuncDecl *getRecordGenericSubstitutionOnDistributedInvocationEncoder(
675675
NominalTypeDecl *nominal) const;
676676

677-
// Retrieve the declaration of DistributedInvocationEncoder.recordArgument(_:).
677+
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordArgument(_:).
678678
//
679679
// \param nominal optionally provide a 'NominalTypeDecl' from which the
680680
// function decl shall be extracted. This is useful to avoid witness calls
681681
// through the protocol which is looked up when nominal is null.
682-
FuncDecl *getRecordArgumentOnDistributedInvocationEncoder(
682+
AbstractFunctionDecl *getRecordArgumentOnDistributedInvocationEncoder(
683683
NominalTypeDecl *nominal) const;
684684

685-
// Retrieve the declaration of DistributedInvocationEncoder.recordErrorType(_:).
686-
FuncDecl *getRecordErrorTypeOnDistributedInvocationEncoder(
685+
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordReturnType(_:).
686+
AbstractFunctionDecl *getRecordReturnTypeOnDistributedInvocationEncoder(
687687
NominalTypeDecl *nominal) const;
688688

689-
// Retrieve the declaration of DistributedInvocationEncoder.recordReturnType(_:).
690-
FuncDecl *getRecordReturnTypeOnDistributedInvocationEncoder(
689+
// Retrieve the declaration of DistributedTargetInvocationEncoder.recordErrorType(_:).
690+
AbstractFunctionDecl *getRecordErrorTypeOnDistributedInvocationEncoder(
691+
NominalTypeDecl *nominal) const;
692+
693+
// Retrieve the declaration of
694+
// DistributedTargetInvocationDecoder.getDecodeNextArgumentOnDistributedInvocationDecoder(_:).
695+
AbstractFunctionDecl *getDecodeNextArgumentOnDistributedInvocationDecoder(
696+
NominalTypeDecl *nominal) const;
697+
698+
// Retrieve the declaration of
699+
// getOnReturnOnDistributedTargetInvocationResultHandler.onReturn(_:).
700+
AbstractFunctionDecl *getOnReturnOnDistributedTargetInvocationResultHandler(
691701
NominalTypeDecl *nominal) const;
692702

693703
// Retrieve the declaration of DistributedInvocationEncoder.doneRecording().
@@ -876,6 +886,10 @@ class ASTContext final {
876886
/// compiler for the target platform.
877887
AvailabilityContext getSwift56Availability();
878888

889+
/// Get the runtime availability of features introduced in the Swift 5.7
890+
/// compiler for the target platform.
891+
AvailabilityContext getSwift57Availability();
892+
879893
// Note: Update this function if you add a new getSwiftXYAvailability above.
880894
/// Get the runtime availability for a particular version of Swift (5.0+).
881895
AvailabilityContext
@@ -1337,11 +1351,8 @@ class ASTContext final {
13371351
/// alternative specified via the -entry-point-function-name frontend flag.
13381352
std::string getEntryPointFunctionName() const;
13391353

1340-
/// Find the type of SerializationRequirement on the passed nominal.
1341-
///
1342-
/// This type exists as a typealias/associatedtype on all distributed actors,
1343-
/// actor systems, and related serialization types.
1344-
Type getDistributedSerializationRequirementType(NominalTypeDecl *);
1354+
Type getAssociatedTypeOfDistributedSystemOfActor(NominalTypeDecl *actor,
1355+
Identifier member);
13451356

13461357
/// Find the concrete invocation decoder associated with the given actor.
13471358
NominalTypeDecl *

include/swift/AST/ASTNode.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines the ASTNode, which is a union of Stmt, Expr, and Decl.
13+
// This file defines the ASTNode, which is a union of Stmt, Expr, Decl,
14+
// Pattern, TypeRepr, StmtCondition, and CaseLabelItem.
1415
//
1516
//===----------------------------------------------------------------------===//
1617

@@ -43,11 +44,9 @@ namespace swift {
4344
enum class PatternKind : uint8_t;
4445
enum class StmtKind;
4546

46-
using StmtCondition = llvm::MutableArrayRef<StmtConditionElement>;
47-
4847
struct ASTNode
4948
: public llvm::PointerUnion<Expr *, Stmt *, Decl *, Pattern *, TypeRepr *,
50-
StmtCondition *, CaseLabelItem *> {
49+
StmtConditionElement *, CaseLabelItem *> {
5150
// Inherit the constructors from PointerUnion.
5251
using PointerUnion::PointerUnion;
5352

include/swift/AST/ASTPrinter.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,14 @@ void getInheritedForPrinting(
385385

386386
StringRef getAccessorKindString(AccessorKind value);
387387

388-
bool printCompatibilityFeatureChecksPre(ASTPrinter &printer, Decl *decl);
389-
void printCompatibilityFeatureChecksPost(
390-
ASTPrinter &printer,
391-
llvm::function_ref<void()> printElse = []() -> void {});
388+
/// Call the given function nested appropriately within #if checks
389+
/// for the compiler features that it uses. Note that printBody
390+
/// may be called multiple times if the declaration uses suppressible
391+
/// features.
392+
bool printWithCompatibilityFeatureChecks(ASTPrinter &printer,
393+
PrintOptions &options,
394+
Decl *decl,
395+
llvm::function_ref<void()> printBody);
392396

393397
} // namespace swift
394398

include/swift/AST/Decl.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6412,6 +6412,31 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64126412
/// 'DistributedActorSystem' protocol.
64136413
bool isDistributedActorSystemRemoteCall(bool isVoidReturn) const;
64146414

6415+
/// Determines if this function is a 'recordArgument' function,
6416+
/// which is used as ad-hoc protocol requirement by the
6417+
/// 'DistributedTargetInvocationEncoder' protocol.
6418+
bool isDistributedTargetInvocationEncoderRecordArgument() const;
6419+
6420+
/// Determines if this function is a 'recordReturnType' function,
6421+
/// which is used as ad-hoc protocol requirement by the
6422+
/// 'DistributedTargetInvocationEncoder' protocol.
6423+
bool isDistributedTargetInvocationEncoderRecordReturnType() const;
6424+
6425+
/// Determines if this function is a 'recordErrorType' function,
6426+
/// which is used as ad-hoc protocol requirement by the
6427+
/// 'DistributedTargetInvocationEncoder' protocol.
6428+
bool isDistributedTargetInvocationEncoderRecordErrorType() const;
6429+
6430+
/// Determines if this function is a 'decodeNextArgument' function,
6431+
/// which is used as ad-hoc protocol requirement by the
6432+
/// 'DistributedTargetInvocationDecoder' protocol.
6433+
bool isDistributedTargetInvocationDecoderDecodeNextArgument() const;
6434+
6435+
/// Determines if this function is a 'onReturn' function,
6436+
/// which is used as ad-hoc protocol requirement by the
6437+
/// 'DistributedTargetInvocationResultHandler' protocol.
6438+
bool isDistributedTargetInvocationResultHandlerOnReturn() const;
6439+
64156440
/// For a method of a class, checks whether it will require a new entry in the
64166441
/// vtable.
64176442
bool needsNewVTableEntry() const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4707,10 +4707,6 @@ ERROR(any_not_existential,none,
47074707
ERROR(existential_requires_any,none,
47084708
"protocol %0 as a type must be explicitly marked as 'any'",
47094709
(Identifier))
4710-
ERROR(explicit_existential_not_supported,none,
4711-
"explicit 'any' not supported; use frontend flag "
4712-
"-enable-explicit-existential-types to enable this feature",
4713-
())
47144710

47154711
ERROR(nonisolated_let,none,
47164712
"'nonisolated' is meaningless on 'let' declarations because "
@@ -4988,7 +4984,7 @@ ERROR(unable_to_parse_c_function_type,none,
49884984

49894985
// Opaque types
49904986
ERROR(unsupported_opaque_type,none,
4991-
"'some' types are only implemented for the declared type of properties and subscripts and the return type of functions", ())
4987+
"'some' types are only permitted in properties, subscripts, and functions", ())
49924988

49934989
ERROR(opaque_type_unsupported_pattern,none,
49944990
"'some' type can only be declared on a single property declaration", ())
@@ -4997,9 +4993,9 @@ ERROR(opaque_type_in_protocol_requirement,none,
49974993
"'some' type cannot be the return type of a protocol requirement; did you mean to add an associated type?",
49984994
())
49994995
ERROR(opaque_type_in_parameter,none,
5000-
"'some' cannot appear in parameter position in result "
5001-
"type %0",
5002-
(Type))
4996+
"'some' cannot appear in parameter position in %select{result|parameter}0"
4997+
" type %1",
4998+
(bool, Type))
50034999

50045000
// Function differentiability
50055001
ERROR(attr_only_on_parameters_of_differentiable,none,

include/swift/AST/DistributedDecl.h

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

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ IDENTIFIER(invocation)
276276
IDENTIFIER(invocationDecoder)
277277
IDENTIFIER(makeInvocationEncoder)
278278
IDENTIFIER(on)
279+
IDENTIFIER(onReturn)
279280
IDENTIFIER(recordArgument)
280281
IDENTIFIER(recordErrorType)
281282
IDENTIFIER(recordGenericSubstitution)

include/swift/AST/KnownStdlibTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ KNOWN_STDLIB_TYPE_DECL(String, NominalTypeDecl, 0)
4949
KNOWN_STDLIB_TYPE_DECL(StaticString, NominalTypeDecl, 0)
5050
KNOWN_STDLIB_TYPE_DECL(Substring, NominalTypeDecl, 0)
5151
KNOWN_STDLIB_TYPE_DECL(Array, NominalTypeDecl, 1)
52+
KNOWN_STDLIB_TYPE_DECL(_ContiguousArrayStorage, NominalTypeDecl, 1)
5253
KNOWN_STDLIB_TYPE_DECL(Set, NominalTypeDecl, 1)
5354
KNOWN_STDLIB_TYPE_DECL(Sequence, NominalTypeDecl, 1)
5455
KNOWN_STDLIB_TYPE_DECL(Dictionary, NominalTypeDecl, 2)

0 commit comments

Comments
 (0)