Skip to content

Commit b9aee05

Browse files
committed
(Mostly) get rid of Parser::setLocalDiscriminator.
The parser no longer sets local discriminators, and this function is currently only responsible for adding local type declarations to the source file. Rename it and remove most of the former callers so it does just that.
1 parent 9e61b01 commit b9aee05

File tree

4 files changed

+10
-47
lines changed

4 files changed

+10
-47
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,7 @@ class Parser {
990990
/// 'isLine = true' indicates parsing #line instead of #sourcelocation
991991
ParserStatus parseLineDirective(bool isLine = false);
992992

993-
void setLocalDiscriminator(ValueDecl *D);
994-
void setLocalDiscriminatorToParamList(ParameterList *PL);
993+
void recordLocalType(TypeDecl *TD);
995994

996995
/// Skip an `#if` configuration block containing only attributes.
997996
///

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4612,22 +4612,13 @@ void Parser::consumeDecl(ParserPosition BeginParserPosition,
46124612
}
46134613
}
46144614

4615-
void Parser::setLocalDiscriminator(ValueDecl *D) {
4615+
void Parser::recordLocalType(TypeDecl *TD) {
46164616
// If we're not in a local context, this is unnecessary.
4617-
if (!CurLocalContext || !D->getDeclContext()->isLocalContext())
4617+
if (!CurLocalContext || !TD->getDeclContext()->isLocalContext())
46184618
return;
46194619

4620-
if (auto TD = dyn_cast<TypeDecl>(D))
4621-
if (!InInactiveClauseEnvironment)
4622-
SF.LocalTypeDecls.insert(TD);
4623-
}
4624-
4625-
void Parser::setLocalDiscriminatorToParamList(ParameterList *PL) {
4626-
for (auto P : *PL) {
4627-
if (!P->hasName() || P->isImplicit())
4628-
continue;
4629-
setLocalDiscriminator(P);
4630-
}
4620+
if (!InInactiveClauseEnvironment)
4621+
SF.LocalTypeDecls.insert(TD);
46314622
}
46324623

46334624
/// Set the original declaration in `@differentiable` attributes.
@@ -5984,7 +5975,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
59845975

59855976
auto *TAD = new (Context) TypeAliasDecl(TypeAliasLoc, EqualLoc, Id, IdLoc,
59865977
genericParams, CurDeclContext);
5987-
setLocalDiscriminator(TAD);
5978+
recordLocalType(TAD);
59885979
ParserResult<TypeRepr> UnderlyingTy;
59895980

59905981
if (Tok.is(tok::colon) || Tok.is(tok::equal)) {
@@ -7086,7 +7077,6 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
70867077
pattern->forEachVariable([&](VarDecl *VD) {
70877078
VD->setStatic(StaticLoc.isValid());
70887079
VD->getAttrs() = Attributes;
7089-
setLocalDiscriminator(VD);
70907080
VD->setTopLevelGlobal(topLevelDecl);
70917081

70927082
// Set original declaration in `@differentiable` attributes.
@@ -7426,7 +7416,6 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
74267416
}
74277417

74287418
DefaultArgs.setFunctionContext(FD, FD->getParameters());
7429-
setLocalDiscriminator(FD);
74307419

74317420
if (Flags.contains(PD_InProtocol)) {
74327421
if (Tok.is(tok::l_brace)) {
@@ -7448,7 +7437,6 @@ Parser::parseAbstractFunctionBodyImpl(AbstractFunctionDecl *AFD) {
74487437

74497438
// Establish the new context.
74507439
ParseFunctionBody CC(*this, AFD);
7451-
setLocalDiscriminatorToParamList(AFD->getParameters());
74527440

74537441
if (auto *Stats = Context.Stats)
74547442
++Stats->getFrontendCounters().NumFunctionsParsed;
@@ -7656,7 +7644,7 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
76567644

76577645
EnumDecl *ED = new (Context) EnumDecl(EnumLoc, EnumName, EnumNameLoc,
76587646
{ }, GenericParams, CurDeclContext);
7659-
setLocalDiscriminator(ED);
7647+
recordLocalType(ED);
76607648
ED->getAttrs() = Attributes;
76617649

76627650
ContextChange CC(*this, ED);
@@ -7928,7 +7916,7 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
79287916
{ },
79297917
GenericParams,
79307918
CurDeclContext);
7931-
setLocalDiscriminator(SD);
7919+
recordLocalType(SD);
79327920
SD->getAttrs() = Attributes;
79337921

79347922
ContextChange CC(*this, SD);
@@ -8018,7 +8006,7 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
80188006
ClassDecl *CD = new (Context) ClassDecl(ClassLoc, ClassName, ClassNameLoc,
80198007
{ }, GenericParams, CurDeclContext,
80208008
isExplicitActorDecl);
8021-
setLocalDiscriminator(CD);
8009+
recordLocalType(CD);
80228010
CD->getAttrs() = Attributes;
80238011

80248012
// Parsed classes never have missing vtable entries.

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,6 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20362036
Context.Id_dollarInterpolation, CurDeclContext);
20372037
InterpolationVar->setImplicit(true);
20382038
InterpolationVar->setUserAccessible(false);
2039-
setLocalDiscriminator(InterpolationVar);
20402039

20412040
Stmts.push_back(InterpolationVar);
20422041

@@ -2796,9 +2795,7 @@ ParserResult<Expr> Parser::parseExprClosure() {
27962795
ParseFunctionBody cc(*this, closure);
27972796

27982797
// Handle parameters.
2799-
if (params) {
2800-
setLocalDiscriminatorToParamList(params);
2801-
} else {
2798+
if (!params) {
28022799
// There are no parameters; allow anonymous closure variables.
28032800
// FIXME: We could do this all the time, and then provide Fix-Its
28042801
// to map $i -> the appropriately-named argument. This might help

lib/Parse/ParseStmt.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,6 @@ ParserResult<Stmt> Parser::parseStmtDefer() {
903903
/*Throws=*/false,
904904
/*GenericParams*/ nullptr, params, TupleType::getEmpty(Context),
905905
CurDeclContext);
906-
setLocalDiscriminator(tempDecl);
907906
ParserStatus Status;
908907
{
909908
// Change the DeclContext for any variables declared in the defer to be within
@@ -1077,7 +1076,6 @@ static void parseGuardedPattern(Parser &P, GuardedPattern &result,
10771076
// represents tuples and var patterns as tupleexprs and
10781077
// unresolved_pattern_expr nodes, instead of as proper pattern nodes.
10791078
patternResult.get()->forEachVariable([&](VarDecl *VD) {
1080-
P.setLocalDiscriminator(VD);
10811079
boundDecls.push_back(VD);
10821080
});
10831081

@@ -1106,7 +1104,6 @@ static void parseGuardedPattern(Parser &P, GuardedPattern &result,
11061104
status.setIsParseError();
11071105
}
11081106
repeatedDecls.push_back(VD);
1109-
P.setLocalDiscriminator(VD);
11101107
});
11111108

11121109
for (auto previous : boundDecls) {
@@ -1653,12 +1650,6 @@ Parser::parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,
16531650
}
16541651

16551652
result.push_back({IntroducerLoc, ThePattern.get(), Init.get()});
1656-
1657-
// Add variable bindings from the pattern to our current scope and mark
1658-
// them as being having a non-pattern-binding initializer.
1659-
ThePattern.get()->forEachVariable([&](VarDecl *VD) {
1660-
setLocalDiscriminator(VD);
1661-
});
16621653
return Status;
16631654
}
16641655

@@ -2114,12 +2105,6 @@ ParserResult<CaseStmt> Parser::parseStmtCatch() {
21142105
caseBodyDecls.emplace(Result);
21152106
}
21162107

2117-
if (caseBodyDecls) {
2118-
for (auto *v : *caseBodyDecls) {
2119-
setLocalDiscriminator(v);
2120-
}
2121-
}
2122-
21232108
auto bodyResult = parseBraceItemList(diag::expected_lbrace_after_catch);
21242109
status |= bodyResult;
21252110
if (bodyResult.isNull()) {
@@ -2610,12 +2595,6 @@ ParserResult<CaseStmt> Parser::parseStmtCase(bool IsActive) {
26102595

26112596
assert(!CaseLabelItems.empty() && "did not parse any labels?!");
26122597

2613-
if (CaseBodyDecls) {
2614-
for (auto *v : *CaseBodyDecls) {
2615-
setLocalDiscriminator(v);
2616-
}
2617-
}
2618-
26192598
SmallVector<ASTNode, 8> BodyItems;
26202599

26212600
SourceLoc StartOfBody = Tok.getLoc();

0 commit comments

Comments
 (0)