Skip to content

Commit 106cadd

Browse files
author
ematejska
authored
Merge pull request #6736 from ematejska/Merge-#6547-to-3.1-branch
Merge #6547 to 3.1 branch
2 parents b16a83e + c9c328d commit 106cadd

28 files changed

+289
-924
lines changed

include/swift/AST/AST.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "swift/AST/ParameterList.h"
2828
#include "swift/AST/Pattern.h"
2929
#include "swift/AST/Stmt.h"
30-
#include "swift/AST/StmtTransformer.h"
3130
#include "swift/AST/Types.h"
3231
#include "swift/AST/TypeRepr.h"
3332

include/swift/AST/Decl.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,8 @@ class alignas(1 << DeclAlignInBits) Decl {
584584

585585
/// Whether this decl is missing its closing '#endif'.
586586
unsigned HadMissingEnd : 1;
587-
588-
/// Whether this condition has been resolved either statically by Parse or
589-
/// later by Condition Resolution.
590-
unsigned HasBeenResolved : 1;
591587
};
592-
enum { NumIfConfigDeclBits = NumDeclBits + 2 };
588+
enum { NumIfConfigDeclBits = NumDeclBits + 1 };
593589
static_assert(NumIfConfigDeclBits <= 32, "fits in an unsigned");
594590

595591
protected:
@@ -1932,8 +1928,7 @@ struct IfConfigDeclClause {
19321928

19331929
IfConfigDeclClause(SourceLoc Loc, Expr *Cond, ArrayRef<Decl*> Members,
19341930
bool isActive)
1935-
: Loc(Loc), Cond(Cond), Members(Members), isActive(isActive) {
1936-
}
1931+
: Loc(Loc), Cond(Cond), Members(Members), isActive(isActive) {}
19371932
};
19381933

19391934

@@ -1946,15 +1941,13 @@ class IfConfigDecl : public Decl {
19461941
/// The array is ASTContext allocated.
19471942
ArrayRef<IfConfigDeclClause> Clauses;
19481943
SourceLoc EndLoc;
1949-
19501944
public:
19511945

19521946
IfConfigDecl(DeclContext *Parent, ArrayRef<IfConfigDeclClause> Clauses,
19531947
SourceLoc EndLoc, bool HadMissingEnd)
19541948
: Decl(DeclKind::IfConfig, Parent), Clauses(Clauses), EndLoc(EndLoc)
19551949
{
19561950
IfConfigDeclBits.HadMissingEnd = HadMissingEnd;
1957-
IfConfigDeclBits.HasBeenResolved = false;
19581951
}
19591952

19601953
ArrayRef<IfConfigDeclClause> getClauses() const { return Clauses; }
@@ -1971,9 +1964,6 @@ class IfConfigDecl : public Decl {
19711964
return Clause->Members;
19721965
return {};
19731966
}
1974-
1975-
bool isResolved() const { return IfConfigDeclBits.HasBeenResolved; }
1976-
void setResolved() { IfConfigDeclBits.HasBeenResolved = true; }
19771967

19781968
SourceLoc getEndLoc() const { return EndLoc; }
19791969
SourceLoc getLoc() const { return Clauses[0].Loc; }

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ ERROR(unsupported_conditional_compilation_unary_expression,none,
13391339
"expected unary '!' expression", ())
13401340
ERROR(unsupported_platform_condition_expression,none,
13411341
"unexpected platform condition "
1342-
"(expected 'canImport', 'os', 'arch', or 'swift')",
1342+
"(expected 'os', 'arch', or 'swift')",
13431343
())
13441344
ERROR(platform_condition_expected_one_argument,none,
13451345
"expected only one argument to platform condition",

include/swift/AST/Stmt.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,6 @@ class IfConfigStmt : public Stmt {
685685
ArrayRef<IfConfigStmtClause> Clauses;
686686
SourceLoc EndLoc;
687687
bool HadMissingEnd;
688-
bool HasBeenResolved = false;
689688

690689
public:
691690
IfConfigStmt(ArrayRef<IfConfigStmtClause> Clauses, SourceLoc EndLoc,
@@ -699,9 +698,6 @@ class IfConfigStmt : public Stmt {
699698
SourceLoc getEndLoc() const { return EndLoc; }
700699

701700
bool hadMissingEnd() const { return HadMissingEnd; }
702-
703-
bool isResolved() { return HasBeenResolved; }
704-
void setResolved() { HasBeenResolved = true; }
705701

706702
const ArrayRef<IfConfigStmtClause> &getClauses() const { return Clauses; }
707703

include/swift/AST/StmtTransformer.h

Lines changed: 0 additions & 70 deletions
This file was deleted.

include/swift/Parse/Parser.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ namespace swift {
5959
TopLevelCode,
6060
/// The top-level of a file, when in parse-as-library mode.
6161
TopLevelLibrary,
62-
/// The body of the clause of an #if/#else/#endif block
63-
ConditionalBlock,
64-
/// The body of the clause of an #if/#else/#endif block that was statically
65-
/// determined to be inactive.
66-
StaticallyInactiveConditionalBlock,
62+
/// The body of the inactive clause of an #if/#else/#endif block
63+
InactiveConditionalBlock,
64+
/// The body of the active clause of an #if/#else/#endif block
65+
ActiveConditionalBlock,
6766
};
6867

6968

@@ -620,10 +619,6 @@ class Parser {
620619
BraceItemListKind::Brace);
621620
ParserResult<BraceStmt> parseBraceItemList(Diag<> ID);
622621

623-
void parseIfConfigClauseElements(bool isInactive,
624-
BraceItemListKind Kind,
625-
SmallVectorImpl<ASTNode> &Elements);
626-
627622
void parseTopLevelCodeDeclDelayed();
628623

629624
//===--------------------------------------------------------------------===//
@@ -1231,13 +1226,13 @@ class Parser {
12311226
ParserResult<CaseStmt> parseStmtCase();
12321227

12331228
/// Classify the condition of an #if directive according to whether it can
1234-
/// be evaluated statically. If evaluation is not possible, the result is
1235-
/// 'None'.
1236-
static Optional<bool>
1229+
/// be evaluated statically. The first member of the pair indicates whether
1230+
/// parsing of the condition body should occur, the second contains the result
1231+
/// of evaluating the conditional expression.
1232+
static ConditionalCompilationExprState
12371233
classifyConditionalCompilationExpr(Expr *condition,
12381234
ASTContext &context,
1239-
DiagnosticEngine &diags,
1240-
bool fullCheck = false);
1235+
DiagnosticEngine &diags);
12411236

12421237
//===--------------------------------------------------------------------===//
12431238
// Generics Parsing

include/swift/Parse/ParserResult.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,75 @@ template <typename T> ParserResult<T>::ParserResult(ParserStatus Status) {
217217
setHasCodeCompletion();
218218
}
219219

220+
enum class ConditionalCompilationExprKind {
221+
Unknown,
222+
Error,
223+
OS,
224+
Arch,
225+
LanguageVersion,
226+
CompilerVersion,
227+
Binary,
228+
Paren,
229+
DeclRef,
230+
Boolean,
231+
Integer,
232+
Import,
233+
};
234+
235+
class ConditionalCompilationExprState {
236+
237+
uint8_t ConditionActive : 1;
238+
uint8_t Kind : 7;
239+
public:
240+
ConditionalCompilationExprState() : ConditionActive(false) {
241+
setKind(ConditionalCompilationExprKind::Unknown);
242+
}
243+
244+
ConditionalCompilationExprState(bool ConditionActive,
245+
ConditionalCompilationExprKind Kind)
246+
: ConditionActive(ConditionActive) {
247+
setKind(Kind);
248+
}
249+
250+
bool isConditionActive() const {
251+
return ConditionActive;
252+
}
253+
254+
void setConditionActive(bool A) {
255+
ConditionActive = A;
256+
}
257+
258+
ConditionalCompilationExprKind getKind() const {
259+
return static_cast<ConditionalCompilationExprKind>(Kind);
260+
}
261+
262+
void setKind(ConditionalCompilationExprKind K) {
263+
Kind = static_cast<uint8_t>(K);
264+
assert(getKind() == K);
265+
}
266+
267+
bool shouldParse() const {
268+
if (getKind() == ConditionalCompilationExprKind::Error)
269+
return true;
270+
return ConditionActive ||
271+
(getKind() != ConditionalCompilationExprKind::CompilerVersion &&
272+
getKind() != ConditionalCompilationExprKind::LanguageVersion);
273+
}
274+
275+
static ConditionalCompilationExprState error() {
276+
return {false, ConditionalCompilationExprKind::Error};
277+
}
278+
};
279+
280+
ConditionalCompilationExprState
281+
operator&&(const ConditionalCompilationExprState lhs,
282+
const ConditionalCompilationExprState rhs);
283+
ConditionalCompilationExprState
284+
operator||(const ConditionalCompilationExprState lhs,
285+
const ConditionalCompilationExprState rhs);
286+
ConditionalCompilationExprState
287+
operator!(const ConditionalCompilationExprState Result);
288+
220289
} // namespace swift
221290

222291
#endif // LLVM_SWIFT_PARSER_PARSER_RESULT_H

include/swift/Parse/Scope.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ScopeInfo {
5454
/// scope.
5555
void addToScope(ValueDecl *D, Parser &TheParser);
5656

57-
bool isStaticallyInactiveConfigBlock() const;
57+
bool isInactiveConfigBlock() const;
5858

5959
SavedScope saveCurrentScope();
6060
};
@@ -91,7 +91,7 @@ class SavedScope {
9191
ScopeInfo::ScopedHTDetachedScopeTy HTDetachedScope;
9292
unsigned Depth;
9393
ScopeKind Kind;
94-
bool IsStaticallyInactiveConfigBlock;
94+
bool IsInactiveConfigBlock;
9595

9696
SavedScope() = delete;
9797
SavedScope(const SavedScope &) = delete;
@@ -103,9 +103,9 @@ class SavedScope {
103103
~SavedScope() = default;
104104

105105
SavedScope(ScopeInfo::ScopedHTDetachedScopeTy &&HTDetachedScope,
106-
unsigned Depth, ScopeKind Kind, bool IsStaticallyInactiveConfigBlock)
106+
unsigned Depth, ScopeKind Kind, bool isInactiveConfigBlock)
107107
: HTDetachedScope(std::move(HTDetachedScope)), Depth(Depth), Kind(Kind),
108-
IsStaticallyInactiveConfigBlock(IsStaticallyInactiveConfigBlock) {}
108+
IsInactiveConfigBlock(isInactiveConfigBlock) {}
109109
};
110110

111111
/// Scope - This class represents lexical scopes. These objects are created
@@ -125,13 +125,12 @@ class Scope {
125125
unsigned PrevResolvableDepth;
126126
unsigned Depth;
127127
ScopeKind Kind;
128-
bool IsStaticallyInactiveConfigBlock;
128+
bool IsInactiveConfigBlock;
129129

130130
/// \brief Save this scope so that it can be re-entered later. Transfers the
131131
/// ownership of the scope frame to returned object.
132132
SavedScope saveScope() {
133-
return SavedScope(HTScope.detach(), Depth, Kind,
134-
IsStaticallyInactiveConfigBlock);
133+
return SavedScope(HTScope.detach(), Depth, Kind, IsInactiveConfigBlock);
135134
}
136135

137136
unsigned getDepth() const {
@@ -142,7 +141,7 @@ class Scope {
142141

143142
public:
144143
/// \brief Create a lexical scope of the specified kind.
145-
Scope(Parser *P, ScopeKind SC, bool IsStaticallyInactiveConfigBlock = false);
144+
Scope(Parser *P, ScopeKind SC, bool isInactiveConfigBlock = false);
146145

147146
/// \brief Re-enter the specified scope, transferring the ownership of the
148147
/// scope frame to the new object.
@@ -175,15 +174,10 @@ inline ValueDecl *ScopeInfo::lookupValueName(DeclName Name) {
175174
return Res.second;
176175
}
177176

178-
inline bool ScopeInfo::isStaticallyInactiveConfigBlock() const {
179-
auto scope = CurScope;
180-
while (scope) {
181-
if (scope->IsStaticallyInactiveConfigBlock) {
182-
return true;
183-
}
184-
scope = scope->PrevScope;
185-
}
186-
return false;
177+
inline bool ScopeInfo::isInactiveConfigBlock() const {
178+
if (!CurScope)
179+
return false;
180+
return CurScope->IsInactiveConfigBlock;
187181
}
188182

189183
inline SavedScope ScopeInfo::saveCurrentScope() {

include/swift/Subsystems.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,6 @@ namespace swift {
130130
bool TokenizeInterpolatedString = true,
131131
ArrayRef<Token> SplitTokens = ArrayRef<Token>());
132132

133-
/// Once parsing is complete, this walks the AST to resolve condition clauses
134-
/// and other top-level validation.
135-
void performConditionResolution(SourceFile &SF);
136-
137-
/// \brief Finish condition resolution for the bodies of function nodes that
138-
/// were delayed during the first parsing pass.
139-
void performDelayedConditionResolution(Decl *D, SourceFile &BSF,
140-
SmallVectorImpl<Decl *> &ExtraTLCDs);
141-
142133
/// Once parsing is complete, this walks the AST to resolve imports, record
143134
/// operators, and do other top-level validation.
144135
///

lib/AST/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ add_swift_library(swiftAST STATIC
3939
RawComment.cpp
4040
SILLayout.cpp
4141
Stmt.cpp
42-
StmtTransformer.cpp
4342
SourceEntityWalker.cpp
4443
Substitution.cpp
4544
SubstitutionMap.cpp

0 commit comments

Comments
 (0)