Skip to content

Commit 0febbf0

Browse files
committed
Effectively revert swiftlang#5778
This reverts the contents of swiftlang#5778 and replaces it with a far simpler implementation of condition resolution along with canImport. When combined with the optimizations in swiftlang#6279 we get the best of both worlds with a performance win and a simpler implementation.
1 parent 7d427aa commit 0febbf0

18 files changed

+235
-852
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: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,15 +1949,13 @@ class IfConfigDecl : public Decl {
19491949
/// The array is ASTContext allocated.
19501950
ArrayRef<IfConfigDeclClause> Clauses;
19511951
SourceLoc EndLoc;
1952-
19531952
public:
19541953

19551954
IfConfigDecl(DeclContext *Parent, ArrayRef<IfConfigDeclClause> Clauses,
19561955
SourceLoc EndLoc, bool HadMissingEnd)
19571956
: Decl(DeclKind::IfConfig, Parent), Clauses(Clauses), EndLoc(EndLoc)
19581957
{
19591958
IfConfigDeclBits.HadMissingEnd = HadMissingEnd;
1960-
IfConfigDeclBits.HasBeenResolved = false;
19611959
}
19621960

19631961
ArrayRef<IfConfigDeclClause> getClauses() const { return Clauses; }
@@ -1974,9 +1972,6 @@ class IfConfigDecl : public Decl {
19741972
return Clause->Members;
19751973
return {};
19761974
}
1977-
1978-
bool isResolved() const { return IfConfigDeclBits.HasBeenResolved; }
1979-
void setResolved() { IfConfigDeclBits.HasBeenResolved = true; }
19801975

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

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,13 +1231,13 @@ class Parser {
12311231
ParserResult<CaseStmt> parseStmtCase();
12321232

12331233
/// 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>
1234+
/// be evaluated statically. The first member of the pair indicates whether
1235+
/// parsing of the condition body should occur, the second contains the result
1236+
/// of evaluating the conditional expression.
1237+
static ConditionalCompilationExprState
12371238
classifyConditionalCompilationExpr(Expr *condition,
12381239
ASTContext &context,
1239-
DiagnosticEngine &diags,
1240-
bool fullCheck = false);
1240+
DiagnosticEngine &diags);
12411241

12421242
//===--------------------------------------------------------------------===//
12431243
// 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/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)