Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/swift/AST/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,11 @@ class NamedPattern : public Pattern {
explicit NamedPattern(VarDecl *Var)
: Pattern(PatternKind::Named), Var(Var) { }

static NamedPattern *createImplicit(ASTContext &Ctx, VarDecl *Var) {
static NamedPattern *createImplicit(ASTContext &Ctx, VarDecl *Var,
Type ty = Type()) {
auto *NP = new (Ctx) NamedPattern(Var);
NP->setImplicit();
NP->setType(ty);
return NP;
}

Expand Down
10 changes: 8 additions & 2 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class Verifier : public ASTWalker {
return true;
}
bool shouldVerifyChecked(Stmt *S) { return true; }
bool shouldVerifyChecked(Pattern *S) { return S->hasType(); }
bool shouldVerifyChecked(Pattern *S) { return true; }
bool shouldVerifyChecked(Decl *S) { return true; }

// Only verify functions if they have bodies we can safely walk.
Expand Down Expand Up @@ -582,8 +582,14 @@ class Verifier : public ASTWalker {
return;
}
}
void verifyChecked(Pattern *P) {
if (!P->hasType()) {
Out << "pattern has no type\n";
P->dump(Out);
abort();
}
}
void verifyChecked(Stmt *S) {}
void verifyChecked(Pattern *P) { }
void verifyChecked(Decl *D) {}

void verifyChecked(Type type) {
Expand Down
8 changes: 2 additions & 6 deletions lib/Sema/CodeSynthesisDistributedActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ static VarDecl *addImplicitDistributedActorIDProperty(
propDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
propDecl->setInterfaceType(propertyType);

Pattern *propPat = NamedPattern::createImplicit(C, propDecl);
propPat->setType(propertyType);

Pattern *propPat = NamedPattern::createImplicit(C, propDecl, propertyType);
propPat = TypedPattern::createImplicit(C, propPat, propertyType);
propPat->setType(propertyType);

Expand Down Expand Up @@ -151,9 +149,7 @@ static VarDecl *addImplicitDistributedActorActorSystemProperty(
propDecl->copyFormalAccessFrom(nominal, /*sourceIsParentContext*/ true);
propDecl->setInterfaceType(propertyType);

Pattern *propPat = NamedPattern::createImplicit(C, propDecl);
propPat->setType(propertyType);

Pattern *propPat = NamedPattern::createImplicit(C, propDecl, propertyType);
propPat = TypedPattern::createImplicit(C, propPat, propertyType);
propPat->setType(propertyType);

Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/DerivedConformanceDifferentiable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ getOrSynthesizeTangentVectorStruct(DerivedConformance &derived, Identifier id) {
auto memberTanType =
getTangentVectorInterfaceType(memberContextualType, parentDC);
tangentProperty->setInterfaceType(memberTanType);
Pattern *memberPattern = NamedPattern::createImplicit(C, tangentProperty);
memberPattern->setType(memberTanType);
Pattern *memberPattern =
NamedPattern::createImplicit(C, tangentProperty, memberTanType);
memberPattern =
TypedPattern::createImplicit(C, memberPattern, memberTanType);
memberPattern->setType(memberTanType);
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/DerivedConformanceEquatableHashable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
derived.Nominal->isActor())
hashValueDecl->getAttrs().add(new (C) NonisolatedAttr(/*IsImplicit*/ true));

Pattern *hashValuePat = NamedPattern::createImplicit(C, hashValueDecl);
hashValuePat->setType(intType);
Pattern *hashValuePat =
NamedPattern::createImplicit(C, hashValueDecl, intType);
hashValuePat = TypedPattern::createImplicit(C, hashValuePat, intType);
hashValuePat->setType(intType);

Expand Down
7 changes: 3 additions & 4 deletions lib/Sema/DerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ DerivedConformance::declareDerivedProperty(SynthesizedIntroducer intro,
propDecl->copyFormalAccessFrom(Nominal, /*sourceIsParentContext*/ true);
propDecl->setInterfaceType(propertyInterfaceType);

Pattern *propPat = NamedPattern::createImplicit(Context, propDecl);
propPat->setType(propertyContextType);
Pattern *propPat =
NamedPattern::createImplicit(Context, propDecl, propertyContextType);

propPat = TypedPattern::createImplicit(Context, propPat, propertyContextType);
propPat->setType(propertyContextType);
Expand Down Expand Up @@ -759,8 +759,7 @@ DeclRefExpr *DerivedConformance::convertEnumToIndex(SmallVectorImpl<ASTNode> &st
indexVar->setImplicit();

// generate: var indexVar
Pattern *indexPat = NamedPattern::createImplicit(C, indexVar);
indexPat->setType(intType);
Pattern *indexPat = NamedPattern::createImplicit(C, indexVar, intType);
indexPat = TypedPattern::createImplicit(C, indexPat, intType);
indexPat->setType(intType);
auto *indexBind = PatternBindingDecl::createImplicit(
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/PCMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class Instrumenter : InstrumenterBase {
VD->setInterfaceType(MaybeLoadInitExpr->getType()->mapTypeOutOfContext());
VD->setImplicit();

NamedPattern *NP = NamedPattern::createImplicit(Context, VD);
NamedPattern *NP = NamedPattern::createImplicit(Context, VD, VD->getType());
PatternBindingDecl *PBD = PatternBindingDecl::createImplicit(
Context, StaticSpellingKind::None, NP, MaybeLoadInitExpr, TypeCheckDC);

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/PlaygroundTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ class Instrumenter : InstrumenterBase {
VD->setInterfaceType(MaybeLoadInitExpr->getType()->mapTypeOutOfContext());
VD->setImplicit();

NamedPattern *NP = NamedPattern::createImplicit(Context, VD);
NamedPattern *NP = NamedPattern::createImplicit(Context, VD, VD->getType());
PatternBindingDecl *PBD = PatternBindingDecl::createImplicit(
Context, StaticSpellingKind::None, NP, MaybeLoadInitExpr, TypeCheckDC);

Expand Down
17 changes: 9 additions & 8 deletions lib/Sema/TypeCheckStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,8 +1485,7 @@ synthesizeLazyGetterBody(AccessorDecl *Get, VarDecl *VD, VarDecl *Storage,
Tmp1VD->setInterfaceType(VD->getValueInterfaceType());
Tmp1VD->setImplicit();

auto *Named = NamedPattern::createImplicit(Ctx, Tmp1VD);
Named->setType(Tmp1VD->getType());
auto *Named = NamedPattern::createImplicit(Ctx, Tmp1VD, Tmp1VD->getType());
auto *Let =
BindingPattern::createImplicit(Ctx, VarDecl::Introducer::Let, Named);
Let->setType(Named->getType());
Expand Down Expand Up @@ -1551,7 +1550,8 @@ synthesizeLazyGetterBody(AccessorDecl *Get, VarDecl *VD, VarDecl *Storage,
InitValue = new (Ctx) LazyInitializerExpr(InitValue);
InitValue->setType(initType);

Pattern *Tmp2PBDPattern = NamedPattern::createImplicit(Ctx, Tmp2VD);
Pattern *Tmp2PBDPattern =
NamedPattern::createImplicit(Ctx, Tmp2VD, Tmp2VD->getType());
Tmp2PBDPattern =
TypedPattern::createImplicit(Ctx, Tmp2PBDPattern, Tmp2VD->getType());

Expand Down Expand Up @@ -1794,7 +1794,8 @@ synthesizeObservedSetterBody(AccessorDecl *Set, TargetImpl target,
SourceLoc(), Ctx.getIdentifier("tmp"), Set);
OldValue->setImplicit();
OldValue->setInterfaceType(VD->getValueInterfaceType());
auto *tmpPattern = NamedPattern::createImplicit(Ctx, OldValue);
auto *tmpPattern =
NamedPattern::createImplicit(Ctx, OldValue, OldValue->getType());
auto *tmpPBD = PatternBindingDecl::createImplicit(
Ctx, StaticSpellingKind::None, tmpPattern, OldValueExpr, Set);
SetterBody.push_back(tmpPBD);
Expand Down Expand Up @@ -2619,8 +2620,8 @@ LazyStoragePropertyRequest::evaluate(Evaluator &evaluator,

// Create the pattern binding decl for the storage decl. This will get
// default initialized to nil.
Pattern *PBDPattern = NamedPattern::createImplicit(Context, Storage);
PBDPattern->setType(StorageTy);
Pattern *PBDPattern =
NamedPattern::createImplicit(Context, Storage, StorageTy);
PBDPattern = TypedPattern::createImplicit(Context, PBDPattern, StorageTy);
auto *InitExpr = new (Context) NilLiteralExpr(SourceLoc(), /*Implicit=*/true);
InitExpr->setType(Storage->getType());
Expand Down Expand Up @@ -3032,8 +3033,8 @@ PropertyWrapperInitializerInfoRequest::evaluate(Evaluator &evaluator,
PropertyWrapperValuePlaceholderExpr *wrappedValue = nullptr;

auto createPBD = [&](VarDecl *singleVar) -> PatternBindingDecl * {
Pattern *pattern = NamedPattern::createImplicit(ctx, singleVar);
pattern->setType(singleVar->getType());
Pattern *pattern =
NamedPattern::createImplicit(ctx, singleVar, singleVar->getType());
pattern = TypedPattern::createImplicit(ctx, pattern, singleVar->getType());
PatternBindingDecl *pbd = PatternBindingDecl::createImplicit(
ctx, var->getCorrectStaticSpelling(), pattern, /*init*/nullptr,
Expand Down