Skip to content

Commit 6e010c6

Browse files
authored
Merge pull request #4170 from swiftwasm/main
2 parents 4b74caf + 5cff292 commit 6e010c6

File tree

86 files changed

+1402
-438
lines changed

Some content is hidden

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

86 files changed

+1402
-438
lines changed

docs/SIL.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5304,7 +5304,7 @@ move_value
53045304

53055305
::
53065306

5307-
sil-instruction ::= 'move_value' sil-operand
5307+
sil-instruction ::= 'move_value' '[lexical]'? sil-operand
53085308

53095309
%1 = move_value %0 : $@_moveOnly A
53105310

@@ -5327,6 +5327,9 @@ NOTE: This instruction is used in an experimental feature called 'move only
53275327
values'. A move_value instruction is an instruction that introduces (or injects)
53285328
a type `T` into the move only value space.
53295329

5330+
The ``lexical`` attribute specifies that the value corresponds to a local
5331+
variable in the Swift source.
5332+
53305333
release_value
53315334
`````````````
53325335

include/swift/AST/Attr.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,10 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(distributed, DistributedActor,
657657
APIBreakingToAdd | APIBreakingToRemove,
658658
118)
659659

660-
// 119 is unused
660+
SIMPLE_DECL_ATTR(_primaryAssociatedType,
661+
PrimaryAssociatedType, OnAssociatedType | UserInaccessible |
662+
APIStableToAdd | ABIStableToAdd | APIBreakingToRemove | ABIStableToRemove,
663+
119)
661664

662665
SIMPLE_DECL_ATTR(_assemblyVision, EmitAssemblyVisionRemarks,
663666
OnFunc | UserInaccessible | NotSerialized | OnNominalType |

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4372,6 +4372,11 @@ class ProtocolDecl final : public NominalTypeDecl {
43724372
/// a protocol having nested types (ObjC protocols).
43734373
ArrayRef<AssociatedTypeDecl *> getAssociatedTypeMembers() const;
43744374

4375+
/// Returns the primary associated type, or nullptr if there isn't one. This is
4376+
/// the associated type that is parametrized with a same-type requirement in a
4377+
/// parametrized protocol type of the form SomeProtocol<SomeArgType>.
4378+
AssociatedTypeDecl *getPrimaryAssociatedType() const;
4379+
43754380
/// Returns a protocol requirement with the given name, or nullptr if the
43764381
/// name has multiple overloads, or no overloads at all.
43774382
ValueDecl *getSingleRequirement(DeclName name) const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,8 @@ ERROR(inheritance_from_non_protocol_or_class,none,
27732773
"inheritance from non-protocol, non-class type %0", (Type))
27742774
ERROR(inheritance_from_non_protocol,none,
27752775
"inheritance from non-protocol type %0", (Type))
2776+
ERROR(inheritance_from_parametrized_protocol,none,
2777+
"cannot inherit from parametrized protocol type %0", (Type))
27762778
ERROR(superclass_not_first,none,
27772779
"superclass %0 must appear first in the inheritance clause", (Type))
27782780
ERROR(superclass_not_open,none,
@@ -2790,6 +2792,8 @@ ERROR(inheritance_from_class_with_missing_vtable_entries,none,
27902792
"cannot inherit from class %0 because it has overridable members that "
27912793
"could not be loaded",
27922794
(Identifier))
2795+
NOTE(inheritance_from_class_with_missing_vtable_entry, none,
2796+
"could not deserialize %0", (DeclName))
27932797
ERROR(inheritance_from_class_with_missing_vtable_entries_versioned,none,
27942798
"cannot inherit from class %0 (compiled with Swift %1) because it has "
27952799
"overridable members that could not be loaded in Swift %2",
@@ -3712,6 +3716,12 @@ ERROR(not_a_generic_definition,none,
37123716
"cannot specialize a non-generic definition", ())
37133717
ERROR(not_a_generic_type,none,
37143718
"cannot specialize non-generic type %0", (Type))
3719+
ERROR(parametrized_protocol_not_supported,none,
3720+
"protocol type with generic argument can only be used as a generic constraint", ())
3721+
ERROR(protocol_does_not_have_primary_assoc_type,none,
3722+
"cannot specialize protocol type %0", (Type))
3723+
ERROR(protocol_cannot_have_multiple_generic_arguments,none,
3724+
"protocol type %0 can only be specialized with exactly one argument", (Type))
37153725
ERROR(cannot_specialize_self,none,
37163726
"cannot specialize 'Self'", ())
37173727
NOTE(specialize_explicit_type_instead,none,

include/swift/AST/ExistentialLayout.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ namespace swift {
2626
class ProtocolType;
2727
class ProtocolCompositionType;
2828

29+
struct PrimaryAssociatedTypeRequirement {
30+
AssociatedTypeDecl *AssocType;
31+
Type Argument;
32+
};
33+
2934
struct ExistentialLayout {
3035
enum Kind { Class, Error, Opaque };
3136

@@ -37,6 +42,7 @@ struct ExistentialLayout {
3742

3843
ExistentialLayout(ProtocolType *type);
3944
ExistentialLayout(ProtocolCompositionType *type);
45+
ExistentialLayout(ParametrizedProtocolType *type);
4046

4147
/// The explicit superclass constraint, if any.
4248
Type explicitSuperclass;
@@ -108,6 +114,10 @@ struct ExistentialLayout {
108114

109115
/// Zero or more protocol constraints from a ProtocolCompositionType
110116
ArrayRef<Type> protocols;
117+
118+
/// Zero or more primary associated type requirements from a
119+
/// ParametrizedProtocolType
120+
ArrayRef<PrimaryAssociatedTypeRequirement> sameTypeRequirements;
111121
};
112122

113123
}

include/swift/AST/TypeCheckRequests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,26 @@ class ExistentialRequiresAnyRequest :
313313
void cacheResult(bool value) const;
314314
};
315315

316+
/// Find the primary associated type of the given protocol.
317+
class PrimaryAssociatedTypeRequest :
318+
public SimpleRequest<PrimaryAssociatedTypeRequest,
319+
AssociatedTypeDecl *(ProtocolDecl *),
320+
RequestFlags::Cached> {
321+
public:
322+
using SimpleRequest::SimpleRequest;
323+
324+
private:
325+
friend SimpleRequest;
326+
327+
// Evaluation.
328+
AssociatedTypeDecl *
329+
evaluate(Evaluator &evaluator, ProtocolDecl *decl) const;
330+
331+
public:
332+
// Caching.
333+
bool isCached() const { return true; }
334+
};
335+
316336
class PolymorphicEffectRequirementsRequest :
317337
public SimpleRequest<PolymorphicEffectRequirementsRequest,
318338
PolymorphicEffectRequirementList(EffectKind, ProtocolDecl *),

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ SWIFT_REQUEST(TypeChecker, PropertyWrapperTypeInfoRequest,
233233
NoLocationInfo)
234234
SWIFT_REQUEST(TypeChecker, ProtocolRequiresClassRequest, bool(ProtocolDecl *),
235235
SeparatelyCached, NoLocationInfo)
236+
SWIFT_REQUEST(TypeChecker, PrimaryAssociatedTypeRequest,
237+
AssociatedTypeDecl *(ProtocolDecl *),
238+
Cached, NoLocationInfo)
236239
SWIFT_REQUEST(TypeChecker, RequirementRequest,
237240
Requirement(WhereClauseOwner, unsigned, TypeResolutionStage),
238241
Cached, HasNearestLocation)

include/swift/AST/TypeDifferenceVisitor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ class CanTypeDifferenceVisitor : public CanTypePairVisitor<Impl, bool> {
339339
type1->getMembers(), type2->getMembers());
340340
}
341341

342+
bool visitParametrizedProtocolType(CanParametrizedProtocolType type1,
343+
CanParametrizedProtocolType type2) {
344+
if (asImpl().visit(type1.getBaseType(), type2.getBaseType()))
345+
return true;
346+
347+
return asImpl().visit(type1.getArgumentType(),
348+
type2.getArgumentType());
349+
}
350+
342351
bool visitExistentialType(CanExistentialType type1,
343352
CanExistentialType type2) {
344353
return asImpl().visit(type1.getConstraintType(),

include/swift/AST/TypeMatcher.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,27 @@ class TypeMatcher {
305305
TRIVIAL_CASE(SILBoxType)
306306
TRIVIAL_CASE(ProtocolCompositionType)
307307

308+
bool visitParametrizedProtocolType(CanParametrizedProtocolType firstParametrizedProto,
309+
Type secondType,
310+
Type sugaredFirstType) {
311+
if (auto secondParametrizedProto = secondType->getAs<ParametrizedProtocolType>()) {
312+
if (!this->visit(firstParametrizedProto.getBaseType(),
313+
secondParametrizedProto->getBaseType(),
314+
sugaredFirstType->castTo<ParametrizedProtocolType>()
315+
->getBaseType())) {
316+
return false;
317+
}
318+
319+
return this->visit(firstParametrizedProto.getArgumentType(),
320+
secondParametrizedProto->getArgumentType(),
321+
sugaredFirstType->castTo<ParametrizedProtocolType>()
322+
->getArgumentType());
323+
}
324+
325+
return mismatch(firstParametrizedProto.getPointer(), secondType,
326+
sugaredFirstType);
327+
}
328+
308329
bool visitExistentialType(CanExistentialType firstExistential,
309330
Type secondType,
310331
Type sugaredFirstType) {

include/swift/AST/TypeNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ ARTIFICIAL_TYPE(SILBlockStorage, Type)
161161
ARTIFICIAL_TYPE(SILBox, Type)
162162
ARTIFICIAL_TYPE(SILToken, Type)
163163
TYPE(ProtocolComposition, Type)
164+
TYPE(ParametrizedProtocol, Type)
164165
TYPE(Existential, Type)
165166
TYPE(LValue, Type)
166167
TYPE(InOut, Type)

0 commit comments

Comments
 (0)