Skip to content

Commit 1142fe6

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 e1fccd3 commit 1142fe6

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
@@ -493,7 +493,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
493493
IsStatic : 1
494494
);
495495

496-
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1+1+1,
496+
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 2+1+1+1+1+1+1+1+1,
497497
/// Encodes whether this is a 'let' binding.
498498
Introducer : 2,
499499

@@ -517,7 +517,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
517517
NoAttachedPropertyWrappers : 1,
518518

519519
/// Whether this variable has no property wrapper auxiliary variables.
520-
NoPropertyWrapperAuxiliaryVariables : 1
520+
NoPropertyWrapperAuxiliaryVariables : 1,
521+
522+
/// Whether this variable is a placeholder that is introducing during
523+
/// type-checking that has its type inferred from its use.
524+
IsPlaceholderVar : 1
521525
);
522526

523527
SWIFT_INLINE_BITFIELD(ParamDecl, VarDecl, 1+2+NumDefaultArgumentKindBits,
@@ -6757,6 +6761,15 @@ class VarDecl : public AbstractStorageDecl {
67576761
Bits.VarDecl.IsLazyStorageProperty = IsLazyStorage;
67586762
}
67596763

6764+
/// Whether this variable is a placeholder that is introducing during
6765+
/// type-checking that has its type inferred from its use.
6766+
bool isPlaceholderVar() const {
6767+
return Bits.VarDecl.IsPlaceholderVar;
6768+
}
6769+
void setIsPlaceholderVar() {
6770+
Bits.VarDecl.IsPlaceholderVar = true;
6771+
}
6772+
67606773
/// Retrieve the backing storage property for a lazy property.
67616774
VarDecl *getLazyStorageProperty() const;
67626775

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8010,6 +8010,7 @@ VarDecl::VarDecl(DeclKind kind, bool isStatic, VarDecl::Introducer introducer,
80108010
Bits.VarDecl.IsTopLevelGlobal = false;
80118011
Bits.VarDecl.NoAttachedPropertyWrappers = false;
80128012
Bits.VarDecl.NoPropertyWrapperAuxiliaryVariables = false;
8013+
Bits.VarDecl.IsPlaceholderVar = false;
80138014
}
80148015

80158016
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
@@ -2779,20 +2779,13 @@ void ConjunctionElement::findReferencedVariables(
27792779

27802780
Type constraints::isPlaceholderVar(PatternBindingDecl *PB) {
27812781
auto *var = PB->getSingleVar();
2782-
if (!var)
2783-
return Type();
2784-
2785-
if (!var->getName().hasDollarPrefix())
2782+
if (!var || !var->isPlaceholderVar())
27862783
return Type();
27872784

27882785
auto *pattern = PB->getPattern(0);
27892786
auto *typedPattern = dyn_cast<TypedPattern>(pattern);
27902787
if (!typedPattern || !typedPattern->hasType())
27912788
return Type();
27922789

2793-
auto type = typedPattern->getType();
2794-
if (!type->hasPlaceholder())
2795-
return Type();
2796-
2797-
return type;
2790+
return typedPattern->getType();
27982791
}

0 commit comments

Comments
 (0)