Skip to content

Commit 62e4811

Browse files
committed
Remove support for nominal type patterns, which have never been supported in an
official swift release and have bitrotted.
1 parent 9d1ab28 commit 62e4811

20 files changed

+24
-799
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,21 +2456,6 @@ ERROR(condition_optional_element_pattern_not_valid_type,none,
24562456
(Type))
24572457
ERROR(enum_element_pattern_not_member_of_enum,none,
24582458
"enum case '%0' is not a member of type %1", (StringRef, Type))
2459-
ERROR(nominal_type_pattern_not_nominal_type,none,
2460-
"non-nominal type %0 cannot be used with property pattern syntax", (Type))
2461-
ERROR(nominal_type_pattern_type_mismatch,none,
2462-
"type %0 of pattern does not match deduced type %1", (Type, Type))
2463-
ERROR(nominal_type_pattern_property_not_found,none,
2464-
"property '%0' not found in type %1", (StringRef, Type))
2465-
ERROR(nominal_type_pattern_property_ambiguous,none,
2466-
"property name '%0' in type %1 is ambiguous", (StringRef, Type))
2467-
ERROR(nominal_type_pattern_not_property,none,
2468-
"member '%0' of type %1 is not a property", (StringRef, Type))
2469-
ERROR(nominal_type_pattern_static_property,none,
2470-
"cannot match type property '%0' of type %1 in a 'case' pattern",
2471-
(StringRef, Type))
2472-
ERROR(nominal_type_subpattern_without_property_name,none,
2473-
"subpattern of a struct or class pattern must have a keyword name", ())
24742459
ERROR(ambiguous_enum_pattern_type,none,
24752460
"generic enum type %0 is ambiguous without explicit generic parameters "
24762461
"when matching value of type %1", (Type, Type))

include/swift/AST/Pattern.h

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -451,102 +451,6 @@ class IsPattern : public Pattern {
451451
return P->getKind() == PatternKind::Is;
452452
}
453453
};
454-
455-
namespace detail {
456-
/// A nominal type subpattern record.
457-
class NominalTypePatternElement {
458-
/// The location of the property name.
459-
SourceLoc PropertyLoc;
460-
/// The location of the colon.
461-
SourceLoc ColonLoc;
462-
/// The referenced property name.
463-
Identifier PropertyName;
464-
/// The referenced property.
465-
VarDecl *Property;
466-
/// The subpattern.
467-
Pattern *SubPattern;
468-
public:
469-
NominalTypePatternElement(SourceLoc PropLoc, Identifier PropName,
470-
VarDecl *Prop, SourceLoc ColonLoc, Pattern *SubP)
471-
: PropertyLoc(PropLoc), ColonLoc(ColonLoc),
472-
PropertyName(PropName), Property(Prop),
473-
SubPattern(SubP)
474-
{}
475-
476-
SourceLoc getPropertyLoc() const { return PropertyLoc; }
477-
SourceLoc getColonLoc() const { return ColonLoc; }
478-
479-
VarDecl *getProperty() const { return Property; }
480-
void setProperty(VarDecl *v) { Property = v; }
481-
482-
Identifier getPropertyName() const { return PropertyName; }
483-
484-
const Pattern *getSubPattern() const { return SubPattern; }
485-
Pattern *getSubPattern() { return SubPattern; }
486-
void setSubPattern(Pattern *p) { SubPattern = p; }
487-
};
488-
} // end namespace detail
489-
490-
/// A pattern that matches a nominal type and destructures elements out of it.
491-
/// The match succeeds if the loaded property values all match their associated
492-
/// subpatterns.
493-
class NominalTypePattern final : public Pattern,
494-
private llvm::TrailingObjects<NominalTypePattern,
495-
detail::NominalTypePatternElement> {
496-
friend TrailingObjects;
497-
498-
public:
499-
/// A nominal type subpattern record.
500-
using Element = detail::NominalTypePatternElement;
501-
502-
private:
503-
TypeLoc CastType;
504-
SourceLoc LParenLoc, RParenLoc;
505-
506-
unsigned NumElements;
507-
508-
NominalTypePattern(TypeLoc CastTy, SourceLoc LParenLoc,
509-
ArrayRef<Element> Elements,
510-
SourceLoc RParenLoc,
511-
Optional<bool> implicit = None)
512-
: Pattern(PatternKind::NominalType), CastType(CastTy),
513-
LParenLoc(LParenLoc), RParenLoc(RParenLoc),
514-
NumElements(Elements.size())
515-
{
516-
if (implicit.hasValue() ? *implicit : !CastTy.hasLocation())
517-
setImplicit();
518-
std::uninitialized_copy(Elements.begin(), Elements.end(),
519-
getTrailingObjects<Element>());
520-
}
521-
522-
public:
523-
static NominalTypePattern *create(TypeLoc CastTy, SourceLoc LParenLoc,
524-
ArrayRef<Element> Elements,
525-
SourceLoc RParenLoc,
526-
ASTContext &C,
527-
Optional<bool> implicit = None);
528-
529-
TypeLoc &getCastTypeLoc() { return CastType; }
530-
TypeLoc getCastTypeLoc() const { return CastType; }
531-
532-
ArrayRef<Element> getElements() const {
533-
return {getTrailingObjects<Element>(), NumElements};
534-
}
535-
MutableArrayRef<Element> getMutableElements() {
536-
return {getTrailingObjects<Element>(), NumElements};
537-
}
538-
539-
SourceLoc getLoc() const { return CastType.getSourceRange().Start; }
540-
SourceLoc getLParenLoc() const { return LParenLoc; }
541-
SourceLoc getRParenLoc() const { return RParenLoc; }
542-
SourceRange getSourceRange() const {
543-
return {getLoc(), RParenLoc};
544-
}
545-
546-
static bool classof(const Pattern *P) {
547-
return P->getKind() == PatternKind::NominalType;
548-
}
549-
};
550454

551455
/// A pattern that matches an enum case. If the enum value is in the matching
552456
/// case, then the value is extracted. If there is a subpattern, it is then

include/swift/AST/PatternNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ PATTERN(Any, Pattern)
3535
PATTERN(Typed, Pattern)
3636
PATTERN(Var, Pattern)
3737
REFUTABLE_PATTERN(Is, Pattern)
38-
REFUTABLE_PATTERN(NominalType, Pattern)
3938
REFUTABLE_PATTERN(EnumElement, Pattern)
4039
REFUTABLE_PATTERN(OptionalSome, Pattern)
4140
REFUTABLE_PATTERN(Bool, Pattern)

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ namespace swift {
136136
/// \brief Perform all dynamic allocations using malloc/free instead of
137137
/// optimized custom allocator, so that memory debugging tools can be used.
138138
bool UseMalloc = false;
139-
140-
/// \brief Enable experimental "switch" pattern-matching features.
141-
bool EnableExperimentalPatterns = false;
142139

143140
/// \brief Enable experimental property behavior feature.
144141
bool EnableExperimentalPropertyBehaviors = false;

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ def dump_clang_diagnostics : Flag<["-"], "dump-clang-diagnostics">,
223223
def emit_verbose_sil : Flag<["-"], "emit-verbose-sil">,
224224
HelpText<"Emit locations during SIL emission">;
225225

226-
def enable_experimental_patterns : Flag<["-"], "enable-experimental-patterns">,
227-
HelpText<"Enable experimental 'switch' pattern matching features">;
228-
229226
def enable_experimental_property_behaviors :
230227
Flag<["-"], "enable-experimental-property-behaviors">,
231228
HelpText<"Enable experimental property behaviors">;

include/swift/Serialization/DeclTypeRecordNodes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ PATTERN(NAMED)
147147
PATTERN(ANY)
148148
PATTERN(TYPED)
149149
PATTERN(ISA)
150-
PATTERN(NOMINAL_TYPE)
151-
TRAILING_INFO(NOMINAL_TYPE_PATTERN_ELT)
152150
PATTERN(VAR)
153151

154152
OTHER(PARAMETERLIST, 226)

include/swift/Serialization/ModuleFormat.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,6 @@ namespace decls_block {
10731073
BCFixed<1> // implicit?
10741074
>;
10751075

1076-
using NominalTypePatternLayout = BCRecordLayout<
1077-
NOMINAL_TYPE_PATTERN,
1078-
TypeIDField, // type
1079-
BCVBR<5>, // number of elements
1080-
BCFixed<1> // implicit?
1081-
// The elements trail the record.
1082-
>;
1083-
1084-
using NominalTypePatternEltLayout = BCRecordLayout<
1085-
NOMINAL_TYPE_PATTERN_ELT,
1086-
DeclIDField // property
1087-
// The element pattern trails the record.
1088-
>;
1089-
10901076
using VarPatternLayout = BCRecordLayout<
10911077
VAR_PATTERN,
10921078
BCFixed<1>, // isLet?

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,6 @@ namespace {
310310
}
311311
OS << ')';
312312
}
313-
void visitNominalTypePattern(NominalTypePattern *P) {
314-
printCommon(P, "pattern_nominal") << ' ';
315-
P->getCastTypeLoc().getType().print(OS);
316-
// FIXME: We aren't const-correct.
317-
for (auto &elt : P->getMutableElements()) {
318-
OS << '\n';
319-
OS.indent(Indent) << elt.getPropertyName() << ": ";
320-
printRec(elt.getSubPattern());
321-
}
322-
OS << ')';
323-
}
324313
void visitExprPattern(ExprPattern *P) {
325314
printCommon(P, "pattern_expr");
326315
OS << '\n';

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,20 +1377,6 @@ void PrintAST::printPattern(const Pattern *pattern) {
13771377
break;
13781378
}
13791379

1380-
case PatternKind::NominalType: {
1381-
auto type = cast<NominalTypePattern>(pattern);
1382-
type->getCastTypeLoc().getType().print(Printer, Options);
1383-
Printer << "(";
1384-
interleave(type->getElements().begin(), type->getElements().end(),
1385-
[&](const NominalTypePattern::Element &elt) {
1386-
Printer << elt.getPropertyName().str() << ":";
1387-
printPattern(elt.getSubPattern());
1388-
}, [&] {
1389-
Printer << ", ";
1390-
});
1391-
break;
1392-
}
1393-
13941380
case PatternKind::EnumElement: {
13951381
auto elt = cast<EnumElementPattern>(pattern);
13961382
// FIXME: Print element expr.

lib/AST/ASTWalker.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,16 +1413,6 @@ Pattern *Traversal::visitIsPattern(IsPattern *P) {
14131413
return P;
14141414
}
14151415

1416-
Pattern *Traversal::visitNominalTypePattern(NominalTypePattern *P) {
1417-
for (auto &elt : P->getMutableElements()) {
1418-
if (Pattern *newSub = doIt(elt.getSubPattern()))
1419-
elt.setSubPattern(newSub);
1420-
else
1421-
return nullptr;
1422-
}
1423-
return P;
1424-
}
1425-
14261416
Pattern *Traversal::visitEnumElementPattern(EnumElementPattern *P) {
14271417
if (!P->hasSubPattern())
14281418
return P;

lib/AST/NameLookupImpl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
6060
return checkPattern(Pat->getSemanticsProvidingPattern(), Reason);
6161
case PatternKind::Named:
6262
return checkValueDecl(cast<NamedPattern>(Pat)->getDecl(), Reason);
63-
64-
case PatternKind::NominalType: {
65-
for (auto &elt : cast<NominalTypePattern>(Pat)->getElements())
66-
checkPattern(elt.getSubPattern(), Reason);
67-
return;
68-
}
6963
case PatternKind::EnumElement: {
7064
auto *OP = cast<EnumElementPattern>(Pat);
7165
if (OP->hasSubPattern())

lib/AST/Pattern.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &OS, PatternKind kind) {
3737
return OS << "pattern type annotation";
3838
case PatternKind::Is:
3939
return OS << "prefix 'is' pattern";
40-
case PatternKind::NominalType:
41-
return OS << "type destructuring pattern";
4240
case PatternKind::Expr:
4341
return OS << "expression pattern";
4442
case PatternKind::Var:
@@ -167,11 +165,6 @@ void Pattern::forEachVariable(const std::function<void(VarDecl*)> &fn) const {
167165
elt.getPattern()->forEachVariable(fn);
168166
return;
169167

170-
case PatternKind::NominalType:
171-
for (auto elt : cast<NominalTypePattern>(this)->getElements())
172-
elt.getSubPattern()->forEachVariable(fn);
173-
return;
174-
175168
case PatternKind::EnumElement:
176169
if (auto SP = cast<EnumElementPattern>(this)->getSubPattern())
177170
SP->forEachVariable(fn);
@@ -220,11 +213,6 @@ void Pattern::forEachNode(const std::function<void(Pattern*)> &f) {
220213
elt.getPattern()->forEachNode(f);
221214
return;
222215

223-
case PatternKind::NominalType:
224-
for (auto elt : cast<NominalTypePattern>(this)->getElements())
225-
elt.getSubPattern()->forEachNode(f);
226-
return;
227-
228216
case PatternKind::EnumElement: {
229217
auto *OP = cast<EnumElementPattern>(this);
230218
if (OP->hasSubPattern())
@@ -374,14 +362,3 @@ SourceRange TypedPattern::getSourceRange() const {
374362
return { SubPattern->getSourceRange().Start, PatType.getSourceRange().End };
375363
}
376364

377-
NominalTypePattern *NominalTypePattern::create(TypeLoc CastTy,
378-
SourceLoc LParenLoc,
379-
ArrayRef<Element> Elements,
380-
SourceLoc RParenLoc,
381-
ASTContext &C,
382-
Optional<bool> implicit) {
383-
void *buf = C.Allocate(totalSizeToAlloc<Element>(Elements.size()),
384-
alignof(Element));
385-
return ::new (buf) NominalTypePattern(CastTy, LParenLoc, Elements, RParenLoc,
386-
implicit);
387-
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
734734

735735
Opts.UseMalloc |= Args.hasArg(OPT_use_malloc);
736736

737-
Opts.EnableExperimentalPatterns |=
738-
Args.hasArg(OPT_enable_experimental_patterns);
739-
740737
Opts.EnableExperimentalPropertyBehaviors |=
741738
Args.hasArg(OPT_enable_experimental_property_behaviors);
742739

lib/SILGen/SILGenDecl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,6 @@ struct InitializationForPattern
918918
InitializationPtr visitExprPattern(ExprPattern *P) {
919919
return InitializationPtr(new ExprPatternInitialization(P, patternFailDest));
920920
}
921-
InitializationPtr visitNominalTypePattern(NominalTypePattern *P) {
922-
P->dump();
923-
llvm_unreachable("pattern not supported in let/else yet");
924-
}
925921
};
926922

927923
} // end anonymous namespace

0 commit comments

Comments
 (0)