Skip to content

Commit 3f27308

Browse files
committed
[AST] Add bit to VarDecl for isPlaceholderVar
This allows the query to be consistent both during type-checking and after.
1 parent 2e500ef commit 3f27308

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

include/swift/AST/Decl.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
487487
IsStatic : 1
488488
);
489489

490-
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1+1+1,
490+
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1+1+1+1,
491491
/// Encodes whether this is a 'let' binding.
492492
Introducer : 2,
493493

@@ -511,7 +511,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
511511
NoAttachedPropertyWrappers : 1,
512512

513513
/// Whether this variable has no property wrapper auxiliary variables.
514-
NoPropertyWrapperAuxiliaryVariables : 1
514+
NoPropertyWrapperAuxiliaryVariables : 1,
515+
516+
/// Whether this variable is a placeholder that is introducing during
517+
/// type-checking that has its type inferred from its use.
518+
IsPlaceholderVar : 1
515519
);
516520

517521
SWIFT_INLINE_BITFIELD(ParamDecl, VarDecl, 1+2+NumDefaultArgumentKindBits,
@@ -6746,6 +6750,15 @@ class VarDecl : public AbstractStorageDecl {
67466750
Bits.VarDecl.IsLazyStorageProperty = IsLazyStorage;
67476751
}
67486752

6753+
/// Whether this variable is a placeholder that is introducing during
6754+
/// type-checking that has its type inferred from its use.
6755+
bool isPlaceholderVar() const {
6756+
return Bits.VarDecl.IsPlaceholderVar;
6757+
}
6758+
void setIsPlaceholderVar() {
6759+
Bits.VarDecl.IsPlaceholderVar = true;
6760+
}
6761+
67496762
/// Retrieve the backing storage property for a lazy property.
67506763
VarDecl *getLazyStorageProperty() const;
67516764

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7977,6 +7977,7 @@ VarDecl::VarDecl(DeclKind kind, bool isStatic, VarDecl::Introducer introducer,
79777977
Bits.VarDecl.IsTopLevelGlobal = false;
79787978
Bits.VarDecl.NoAttachedPropertyWrappers = false;
79797979
Bits.VarDecl.NoPropertyWrapperAuxiliaryVariables = false;
7980+
Bits.VarDecl.IsPlaceholderVar = false;
79807981
}
79817982

79827983
Type VarDecl::getTypeInContext() const {

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class ResultBuilderTransform
124124
SmallVectorImpl<ASTNode> &container,
125125
Type type = Type(), Expr *initExpr = nullptr) {
126126
auto *var = builder.buildVar(loc);
127+
var->setIsPlaceholderVar();
127128
Pattern *placeholder = TypedPattern::createImplicit(
128129
ctx, NamedPattern::createImplicit(ctx, var),
129130
type ? type : PlaceholderType::get(ctx, var));

lib/Sema/CSSyntacticElement.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,20 +2774,13 @@ void ConjunctionElement::findReferencedVariables(
27742774

27752775
Type constraints::isPlaceholderVar(PatternBindingDecl *PB) {
27762776
auto *var = PB->getSingleVar();
2777-
if (!var)
2778-
return Type();
2779-
2780-
if (!var->getName().hasDollarPrefix())
2777+
if (!var || !var->isPlaceholderVar())
27812778
return Type();
27822779

27832780
auto *pattern = PB->getPattern(0);
27842781
auto *typedPattern = dyn_cast<TypedPattern>(pattern);
27852782
if (!typedPattern || !typedPattern->hasType())
27862783
return Type();
27872784

2788-
auto type = typedPattern->getType();
2789-
if (!type->hasPlaceholder())
2790-
return Type();
2791-
2792-
return type;
2785+
return typedPattern->getType();
27932786
}

0 commit comments

Comments
 (0)