Skip to content

Commit 36ebf9b

Browse files
authored
Merge pull request #4214 from swiftwasm/main
2 parents 15b30e3 + 8fc787e commit 36ebf9b

File tree

94 files changed

+879
-317
lines changed

Some content is hidden

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

94 files changed

+879
-317
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,8 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
861861
void print(raw_ostream &OS) const;
862862
void print(raw_ostream &OS, const PrintOptions &Opts) const;
863863

864+
void printInherited(ASTPrinter &Printer, const PrintOptions &Options) const;
865+
864866
/// Pretty-print the given declaration.
865867
///
866868
/// \param Printer ASTPrinter object.

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,8 +2780,8 @@ ERROR(inheritance_from_non_protocol_or_class,none,
27802780
"inheritance from non-protocol, non-class type %0", (Type))
27812781
ERROR(inheritance_from_non_protocol,none,
27822782
"inheritance from non-protocol type %0", (Type))
2783-
ERROR(inheritance_from_parametrized_protocol,none,
2784-
"cannot inherit from parametrized protocol type %0", (Type))
2783+
ERROR(inheritance_from_parameterized_protocol,none,
2784+
"cannot inherit from protocol type with generic argument %0", (Type))
27852785
ERROR(superclass_not_first,none,
27862786
"superclass %0 must appear first in the inheritance clause", (Type))
27872787
ERROR(superclass_not_open,none,
@@ -3723,7 +3723,7 @@ ERROR(not_a_generic_definition,none,
37233723
"cannot specialize a non-generic definition", ())
37243724
ERROR(not_a_generic_type,none,
37253725
"cannot specialize non-generic type %0", (Type))
3726-
ERROR(parametrized_protocol_not_supported,none,
3726+
ERROR(parameterized_protocol_not_supported,none,
37273727
"protocol type with generic argument can only be used as a generic constraint", ())
37283728
ERROR(protocol_does_not_have_primary_assoc_type,none,
37293729
"cannot specialize protocol type %0", (Type))

include/swift/AST/ExistentialLayout.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct ExistentialLayout {
4242

4343
ExistentialLayout(ProtocolType *type);
4444
ExistentialLayout(ProtocolCompositionType *type);
45-
ExistentialLayout(ParametrizedProtocolType *type);
45+
ExistentialLayout(ParameterizedProtocolType *type);
4646

4747
/// The explicit superclass constraint, if any.
4848
Type explicitSuperclass;
@@ -116,7 +116,7 @@ struct ExistentialLayout {
116116
ArrayRef<Type> protocols;
117117

118118
/// Zero or more primary associated type requirements from a
119-
/// ParametrizedProtocolType
119+
/// ParameterizedProtocolType
120120
ArrayRef<PrimaryAssociatedTypeRequirement> sameTypeRequirements;
121121
};
122122

include/swift/AST/PrintOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ struct PrintOptions {
486486
/// Whether to print inheritance lists for types.
487487
bool PrintInherited = true;
488488

489+
/// Whether to print a space before the `:` of an inheritance list in a type
490+
/// decl.
491+
bool PrintSpaceBeforeInheritance = true;
492+
489493
/// Whether to print feature checks for compatibility with older Swift
490494
/// compilers that might parse the result.
491495
bool PrintCompatibilityFeatureChecks = false;

include/swift/AST/TypeDifferenceVisitor.h

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

342-
bool visitParametrizedProtocolType(CanParametrizedProtocolType type1,
343-
CanParametrizedProtocolType type2) {
342+
bool visitParameterizedProtocolType(CanParameterizedProtocolType type1,
343+
CanParameterizedProtocolType type2) {
344344
if (asImpl().visit(type1.getBaseType(), type2.getBaseType()))
345345
return true;
346346

include/swift/AST/TypeMatcher.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,20 @@ 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>()) {
308+
bool visitParameterizedProtocolType(CanParameterizedProtocolType firstParametrizedProto,
309+
Type secondType,
310+
Type sugaredFirstType) {
311+
if (auto secondParametrizedProto = secondType->getAs<ParameterizedProtocolType>()) {
312312
if (!this->visit(firstParametrizedProto.getBaseType(),
313313
secondParametrizedProto->getBaseType(),
314-
sugaredFirstType->castTo<ParametrizedProtocolType>()
314+
sugaredFirstType->castTo<ParameterizedProtocolType>()
315315
->getBaseType())) {
316316
return false;
317317
}
318318

319319
return this->visit(firstParametrizedProto.getArgumentType(),
320320
secondParametrizedProto->getArgumentType(),
321-
sugaredFirstType->castTo<ParametrizedProtocolType>()
321+
sugaredFirstType->castTo<ParameterizedProtocolType>()
322322
->getArgumentType());
323323
}
324324

include/swift/AST/TypeNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ ARTIFICIAL_TYPE(SILBlockStorage, Type)
161161
ARTIFICIAL_TYPE(SILBox, Type)
162162
ARTIFICIAL_TYPE(SILToken, Type)
163163
TYPE(ProtocolComposition, Type)
164-
TYPE(ParametrizedProtocol, Type)
164+
TYPE(ParameterizedProtocol, Type)
165165
TYPE(Existential, Type)
166166
TYPE(LValue, Type)
167167
TYPE(InOut, Type)

include/swift/AST/Types.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5243,7 +5243,7 @@ class ProtocolCompositionType final : public TypeBase,
52435243
BEGIN_CAN_TYPE_WRAPPER(ProtocolCompositionType, Type)
52445244
END_CAN_TYPE_WRAPPER(ProtocolCompositionType, Type)
52455245

5246-
/// ParametrizedProtocolType - A type that constrains the primary associated
5246+
/// ParameterizedProtocolType - A type that constrains the primary associated
52475247
/// type of a protocol to an argument type.
52485248
///
52495249
/// Written like a bound generic type, eg Sequence<Int>.
@@ -5259,7 +5259,7 @@ END_CAN_TYPE_WRAPPER(ProtocolCompositionType, Type)
52595259
/// \code
52605260
/// T : Sequence where T.Element == Int.
52615261
/// \endcode
5262-
class ParametrizedProtocolType final : public TypeBase,
5262+
class ParameterizedProtocolType final : public TypeBase,
52635263
public llvm::FoldingSetNode {
52645264
friend struct ExistentialLayout;
52655265

@@ -5294,18 +5294,18 @@ class ParametrizedProtocolType final : public TypeBase,
52945294

52955295
// Implement isa/cast/dyncast/etc.
52965296
static bool classof(const TypeBase *T) {
5297-
return T->getKind() == TypeKind::ParametrizedProtocol;
5297+
return T->getKind() == TypeKind::ParameterizedProtocol;
52985298
}
52995299

53005300
private:
5301-
ParametrizedProtocolType(const ASTContext *ctx,
5302-
ProtocolType *base, Type arg,
5303-
RecursiveTypeProperties properties);
5301+
ParameterizedProtocolType(const ASTContext *ctx,
5302+
ProtocolType *base, Type arg,
5303+
RecursiveTypeProperties properties);
53045304
};
5305-
BEGIN_CAN_TYPE_WRAPPER(ParametrizedProtocolType, Type)
5305+
BEGIN_CAN_TYPE_WRAPPER(ParameterizedProtocolType, Type)
53065306
PROXY_CAN_TYPE_SIMPLE_GETTER(getBaseType)
53075307
PROXY_CAN_TYPE_SIMPLE_GETTER(getArgumentType)
5308-
END_CAN_TYPE_WRAPPER(ParametrizedProtocolType, Type)
5308+
END_CAN_TYPE_WRAPPER(ParameterizedProtocolType, Type)
53095309

53105310
/// An existential type, spelled with \c any .
53115311
///
@@ -6365,7 +6365,8 @@ inline bool TypeBase::isConstraintType() const {
63656365

63666366
inline bool CanType::isConstraintTypeImpl(CanType type) {
63676367
return (isa<ProtocolType>(type) ||
6368-
isa<ProtocolCompositionType>(type));
6368+
isa<ProtocolCompositionType>(type) ||
6369+
isa<ParameterizedProtocolType>(type));
63696370
}
63706371

63716372
inline bool TypeBase::isExistentialType() {

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ namespace swift {
321321
/// keyword.
322322
bool EnableExplicitExistentialTypes = true;
323323

324-
/// Enable support for protocol types parametrized by primary
324+
/// Enable support for protocol types parameterized by primary
325325
/// associated type.
326-
bool EnableParametrizedProtocolTypes = false;
326+
bool EnableParameterizedProtocolTypes = false;
327327

328328
/// Enable experimental flow-sensitive concurrent captures.
329329
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;

include/swift/IDE/RefactoringKinds.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ CURSOR_REFACTORING(MemberwiseInitLocalRefactoring, "Generate Memberwise Initiali
5454

5555
CURSOR_REFACTORING(AddEquatableConformance, "Add Equatable Conformance", add.equatable.conformance)
5656

57+
CURSOR_REFACTORING(AddExplicitCodableImplementation, "Add Explicit Codable Implementation", add.explicit-codable-implementation)
58+
5759
CURSOR_REFACTORING(ConvertCallToAsyncAlternative, "Convert Call to Async Alternative", convert.call-to-async)
5860

5961
CURSOR_REFACTORING(ConvertToAsync, "Convert Function to Async", convert.func-to-async)

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,9 @@ def enable_explicit_existential_types :
517517
Flag<["-"], "enable-explicit-existential-types">,
518518
HelpText<"Enable experimental support for explicit existential types">;
519519

520-
def enable_parametrized_protocol_types :
521-
Flag<["-"], "enable-parametrized-protocol-types">,
522-
HelpText<"Enable experimental support for primary associated types and parametrized protocols">;
520+
def enable_parameterized_protocol_types :
521+
Flag<["-"], "enable-parameterized-protocol-types">,
522+
HelpText<"Enable experimental support for primary associated types and parameterized protocols">;
523523

524524
def enable_deserialization_recovery :
525525
Flag<["-"], "enable-deserialization-recovery">,

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ struct ASTContext::Implementation {
405405
llvm::FoldingSet<UnboundGenericType> UnboundGenericTypes;
406406
llvm::FoldingSet<BoundGenericType> BoundGenericTypes;
407407
llvm::FoldingSet<ProtocolCompositionType> ProtocolCompositionTypes;
408-
llvm::FoldingSet<ParametrizedProtocolType> ParametrizedProtocolTypes;
408+
llvm::FoldingSet<ParameterizedProtocolType> ParameterizedProtocolTypes;
409409
llvm::FoldingSet<LayoutConstraintInfo> LayoutConstraints;
410410
llvm::DenseMap<std::pair<OpaqueTypeDecl *, SubstitutionMap>,
411411
GenericEnvironment *> OpaqueArchetypeEnvironments;
@@ -3404,9 +3404,9 @@ ProtocolCompositionType::build(const ASTContext &C, ArrayRef<Type> Members,
34043404
return compTy;
34053405
}
34063406

3407-
Type ParametrizedProtocolType::get(const ASTContext &C,
3408-
ProtocolType *baseTy,
3409-
Type argTy) {
3407+
Type ParameterizedProtocolType::get(const ASTContext &C,
3408+
ProtocolType *baseTy,
3409+
Type argTy) {
34103410
bool isCanonical = baseTy->isCanonical();
34113411
RecursiveTypeProperties properties = baseTy->getRecursiveProperties();
34123412
properties |= argTy->getRecursiveProperties();
@@ -3416,16 +3416,16 @@ Type ParametrizedProtocolType::get(const ASTContext &C,
34163416

34173417
void *InsertPos = nullptr;
34183418
llvm::FoldingSetNodeID ID;
3419-
ParametrizedProtocolType::Profile(ID, baseTy, argTy);
3419+
ParameterizedProtocolType::Profile(ID, baseTy, argTy);
34203420

34213421
if (auto paramTy
3422-
= C.getImpl().getArena(arena).ParametrizedProtocolTypes
3422+
= C.getImpl().getArena(arena).ParameterizedProtocolTypes
34233423
.FindNodeOrInsertPos(ID, InsertPos))
34243424
return paramTy;
34253425

3426-
auto paramTy = new (C, arena) ParametrizedProtocolType(
3426+
auto paramTy = new (C, arena) ParameterizedProtocolType(
34273427
isCanonical ? &C : nullptr, baseTy, argTy, properties);
3428-
C.getImpl().getArena(arena).ParametrizedProtocolTypes.InsertNode(
3428+
C.getImpl().getArena(arena).ParameterizedProtocolTypes.InsertNode(
34293429
paramTy, InsertPos);
34303430
return paramTy;
34313431
}

lib/AST/ASTDumper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,9 +3942,9 @@ namespace {
39423942
PrintWithColorRAII(OS, ParenthesisColor) << ')';
39433943
}
39443944

3945-
void visitParametrizedProtocolType(ParametrizedProtocolType *T,
3946-
StringRef label) {
3947-
printCommon(label, "parametrized_protocol_type");
3945+
void visitParameterizedProtocolType(ParameterizedProtocolType *T,
3946+
StringRef label) {
3947+
printCommon(label, "parameterized_protocol_type");
39483948
printRec("base", T->getBaseType());
39493949
printRec("arg", T->getArgumentType());
39503950
PrintWithColorRAII(OS, ParenthesisColor) << ')';

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
12661266
return appendExistentialLayout(layout, sig, forDecl);
12671267
}
12681268

1269-
case TypeKind::ParametrizedProtocol: {
1269+
case TypeKind::ParameterizedProtocol: {
12701270
llvm::errs() << "Not implemented\n";
12711271
abort();
12721272
}

lib/AST/ASTPrinter.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
863863
Decl *attachingTo);
864864
void printWhereClauseFromRequirementSignature(ProtocolDecl *proto,
865865
Decl *attachingTo);
866+
void printInherited(const Decl *decl);
866867

867868
void printGenericSignature(GenericSignature genericSig,
868869
unsigned flags);
@@ -891,7 +892,6 @@ class PrintAST : public ASTVisitor<PrintAST> {
891892
bool openBracket = true, bool closeBracket = true);
892893
void printGenericDeclGenericParams(GenericContext *decl);
893894
void printDeclGenericRequirements(GenericContext *decl);
894-
void printInherited(const Decl *decl);
895895
void printBodyIfNecessary(const AbstractFunctionDecl *decl);
896896

897897
void printEnumElement(EnumElementDecl *elt);
@@ -2416,7 +2416,10 @@ void PrintAST::printInherited(const Decl *decl) {
24162416
if (TypesToPrint.empty())
24172417
return;
24182418

2419-
Printer << " : ";
2419+
if (Options.PrintSpaceBeforeInheritance) {
2420+
Printer << " ";
2421+
}
2422+
Printer << ": ";
24202423

24212424
interleave(TypesToPrint, [&](InheritedEntry inherited) {
24222425
if (inherited.isUnchecked)
@@ -4195,7 +4198,12 @@ void PrintAST::visitLoadExpr(LoadExpr *expr) {
41954198
}
41964199

41974200
void PrintAST::visitTypeExpr(TypeExpr *expr) {
4198-
printType(expr->getType());
4201+
if (auto metaType = expr->getType()->castTo<AnyMetatypeType>()) {
4202+
// Don't print `.Type` for an expr.
4203+
printType(metaType->getInstanceType());
4204+
} else {
4205+
printType(expr->getType());
4206+
}
41994207
}
42004208

42014209
void PrintAST::visitArrayExpr(ArrayExpr *expr) {
@@ -4278,6 +4286,8 @@ void PrintAST::visitBinaryExpr(BinaryExpr *expr) {
42784286
Printer << " ";
42794287
if (auto operatorRef = expr->getFn()->getMemberOperatorRef()) {
42804288
Printer << operatorRef->getDecl()->getBaseName();
4289+
} else if (auto *operatorRef = dyn_cast<DeclRefExpr>(expr->getFn())) {
4290+
Printer << operatorRef->getDecl()->getBaseName();
42814291
}
42824292
Printer << " ";
42834293
visit(expr->getRHS());
@@ -4588,6 +4598,16 @@ void PrintAST::visitBraceStmt(BraceStmt *stmt) {
45884598
}
45894599

45904600
void PrintAST::visitReturnStmt(ReturnStmt *stmt) {
4601+
if (!stmt->hasResult()) {
4602+
if (auto *FD = dyn_cast<AbstractFunctionDecl>(Current)) {
4603+
if (auto *Body = FD->getBody()) {
4604+
if (Body->getLastElement().dyn_cast<Stmt *>() == stmt) {
4605+
// Don't print empty return.
4606+
return;
4607+
}
4608+
}
4609+
}
4610+
}
45914611
Printer << tok::kw_return;
45924612
if (stmt->hasResult()) {
45934613
Printer << " ";
@@ -4777,6 +4797,11 @@ bool Decl::print(ASTPrinter &Printer, const PrintOptions &Opts) const {
47774797
return printer.visit(const_cast<Decl *>(this));
47784798
}
47794799

4800+
void Decl::printInherited(ASTPrinter &Printer, const PrintOptions &Opts) const {
4801+
PrintAST printer(Printer, Opts);
4802+
printer.printInherited(this);
4803+
}
4804+
47804805
bool Decl::shouldPrintInContext(const PrintOptions &PO) const {
47814806
// Skip getters/setters. They are part of the variable or subscript.
47824807
if (isa<AccessorDecl>(this))
@@ -5921,7 +5946,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
59215946
}
59225947
}
59235948

5924-
void visitParametrizedProtocolType(ParametrizedProtocolType *T) {
5949+
void visitParameterizedProtocolType(ParameterizedProtocolType *T) {
59255950
visit(T->getBaseType());
59265951
Printer << "<";
59275952
visit(T->getArgumentType());

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4500,9 +4500,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
45004500
}
45014501

45024502
// Check whether we have a reasonable constraint type at all.
4503-
if (!constraintType->is<ProtocolType>() &&
4504-
!constraintType->is<ProtocolCompositionType>() &&
4505-
!constraintType->is<ParametrizedProtocolType>() &&
4503+
if (!constraintType->isConstraintType() &&
45064504
!constraintType->getClassOrBoundGenericClass()) {
45074505
if (source.getLoc().isValid() && !constraintType->hasError()) {
45084506
Impl->HadAnyError = true;
@@ -4516,7 +4514,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
45164514
}
45174515

45184516
// Parametrized protocol requirements.
4519-
if (auto *paramProtoType = constraintType->getAs<ParametrizedProtocolType>()) {
4517+
if (auto *paramProtoType = constraintType->getAs<ParameterizedProtocolType>()) {
45204518
bool anyErrors = false;
45214519

45224520
auto *protoDecl = paramProtoType->getBaseType()->getDecl();

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
133133
return;
134134
}
135135

136-
if (auto *paramType = constraintType->getAs<ParametrizedProtocolType>()) {
136+
if (auto *paramType = constraintType->getAs<ParameterizedProtocolType>()) {
137137
auto *protoDecl = paramType->getBaseType()->getDecl();
138138

139139
desugarConformanceRequirement(subjectType, paramType->getBaseType(),
@@ -212,9 +212,7 @@ static void realizeTypeRequirement(Type subjectType, Type constraintType,
212212
SmallVectorImpl<StructuralRequirement> &result) {
213213
SmallVector<Requirement, 2> reqs;
214214

215-
if (constraintType->is<ProtocolType>() ||
216-
constraintType->is<ProtocolCompositionType>() ||
217-
constraintType->is<ParametrizedProtocolType>()) {
215+
if (constraintType->isConstraintType()) {
218216
// Handle conformance requirements.
219217
desugarConformanceRequirement(subjectType, constraintType, reqs);
220218
} else if (constraintType->getClassOrBoundGenericClass()) {

0 commit comments

Comments
 (0)