Skip to content

Commit 080cf3f

Browse files
committed
Revert "Merge pull request swiftlang#5778 from CodaFi/fine-imported-goods"
This reverts commit 8e4e857, reversing changes made to eaa7cb9.
1 parent 38f8fd0 commit 080cf3f

27 files changed

+343
-1156
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: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,8 @@ struct IfConfigDeclClause {
19121912

19131913
ArrayRef<Decl*> Members;
19141914

1915-
/// True if this is the active clause of the #if block.
1915+
/// True if this is the active clause of the #if block. Since this is
1916+
/// evaluated at parse time, this is always known.
19161917
bool isActive;
19171918

19181919
IfConfigDeclClause(SourceLoc Loc, Expr *Cond, ArrayRef<Decl*> Members,
@@ -1932,13 +1933,13 @@ class IfConfigDecl : public Decl {
19321933
ArrayRef<IfConfigDeclClause> Clauses;
19331934
SourceLoc EndLoc;
19341935
bool HadMissingEnd;
1935-
bool HasBeenResolved = false;
19361936
public:
19371937

19381938
IfConfigDecl(DeclContext *Parent, ArrayRef<IfConfigDeclClause> Clauses,
19391939
SourceLoc EndLoc, bool HadMissingEnd)
1940-
: Decl(DeclKind::IfConfig, Parent), Clauses(Clauses),
1941-
EndLoc(EndLoc), HadMissingEnd(HadMissingEnd) {}
1940+
: Decl(DeclKind::IfConfig, Parent), Clauses(Clauses), EndLoc(EndLoc),
1941+
HadMissingEnd(HadMissingEnd) {
1942+
}
19421943

19431944
ArrayRef<IfConfigDeclClause> getClauses() const { return Clauses; }
19441945

@@ -1948,15 +1949,11 @@ class IfConfigDecl : public Decl {
19481949
if (Clause.isActive) return &Clause;
19491950
return nullptr;
19501951
}
1951-
19521952
const ArrayRef<Decl*> getActiveMembers() const {
19531953
if (auto *Clause = getActiveClause())
19541954
return Clause->Members;
19551955
return {};
19561956
}
1957-
1958-
bool isResolved() const { return HasBeenResolved; }
1959-
void setResolved() { HasBeenResolved = true; }
19601957

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

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,7 @@ ERROR(unsupported_conditional_compilation_binary_expression,none,
13381338
ERROR(unsupported_conditional_compilation_unary_expression,none,
13391339
"expected unary '!' expression", ())
13401340
ERROR(unsupported_platform_condition_expression,none,
1341-
"unexpected platform condition "
1342-
"(expected 'canImport', 'os', 'arch', or 'swift')",
1341+
"unexpected platform condition (expected 'os', 'arch', or 'swift')",
13431342
())
13441343
ERROR(platform_condition_expected_one_argument,none,
13451344
"expected only one argument to platform condition",

include/swift/AST/Module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,13 @@ class SourceFile final : public FileUnit {
831831
std::vector<Decl*> Decls;
832832

833833
/// The list of local type declarations in the source file.
834-
llvm::SetVector<TypeDecl *> LocalTypeDecls;
834+
TinyPtrVector<TypeDecl*> LocalTypeDecls;
835835

836836
/// A set of special declaration attributes which require the
837837
/// Foundation module to be imported to work. If the foundation
838838
/// module is still not imported by the time type checking is
839839
/// complete, we diagnose.
840-
llvm::SetVector<const DeclAttribute *> AttrsRequiringFoundation;
840+
std::map<DeclAttrKind, const DeclAttribute *> AttrsRequiringFoundation;
841841

842842
/// A mapping from Objective-C selectors to the methods that have
843843
/// those selectors.

include/swift/AST/Stmt.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,11 @@ struct IfConfigStmtClause {
667667

668668
/// Elements inside the clause
669669
ArrayRef<ASTNode> Elements;
670-
671-
/// True if this is the active clause of the #if block.
670+
671+
/// True if this is the active clause of the #if block. Since this is
672+
/// evaluated at parse time, this is always known.
672673
bool isActive;
673-
674+
674675
IfConfigStmtClause(SourceLoc Loc, Expr *Cond,
675676
ArrayRef<ASTNode> Elements, bool isActive)
676677
: Loc(Loc), Cond(Cond), Elements(Elements), isActive(isActive) {
@@ -685,7 +686,6 @@ class IfConfigStmt : public Stmt {
685686
ArrayRef<IfConfigStmtClause> Clauses;
686687
SourceLoc EndLoc;
687688
bool HadMissingEnd;
688-
bool HasBeenResolved = false;
689689

690690
public:
691691
IfConfigStmt(ArrayRef<IfConfigStmtClause> Clauses, SourceLoc EndLoc,
@@ -700,11 +700,8 @@ class IfConfigStmt : public Stmt {
700700

701701
bool hadMissingEnd() const { return HadMissingEnd; }
702702

703-
bool isResolved() { return HasBeenResolved; }
704-
void setResolved() { HasBeenResolved = true; }
705-
706703
const ArrayRef<IfConfigStmtClause> &getClauses() const { return Clauses; }
707-
704+
708705
ArrayRef<ASTNode> getActiveClauseElements() const {
709706
for (auto &Clause : Clauses)
710707
if (Clause.isActive)

include/swift/AST/StmtTransformer.h

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

include/swift/Parse/Parser.h

Lines changed: 9 additions & 15 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,7 +619,7 @@ class Parser {
620619
BraceItemListKind::Brace);
621620
ParserResult<BraceStmt> parseBraceItemList(Diag<> ID);
622621

623-
void parseIfConfigClauseElements(bool isInactive,
622+
void parseIfConfigClauseElements(bool isActive,
624623
BraceItemListKind Kind,
625624
SmallVectorImpl<ASTNode> &Elements);
626625

@@ -647,7 +646,7 @@ class Parser {
647646
PD_InExtension = 1 << 8,
648647
PD_InStruct = 1 << 9,
649648
PD_InEnum = 1 << 10,
650-
PD_InLoop = 1 << 11,
649+
PD_InLoop = 1 << 11
651650
};
652651

653652
/// Options that control the parsing of declarations.
@@ -1230,14 +1229,9 @@ class Parser {
12301229
ParserResult<Stmt> parseStmtSwitch(LabeledStmtInfo LabelInfo);
12311230
ParserResult<CaseStmt> parseStmtCase();
12321231

1233-
/// 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>
1237-
classifyConditionalCompilationExpr(Expr *condition,
1238-
ASTContext &context,
1239-
DiagnosticEngine &diags,
1240-
bool fullCheck = false);
1232+
/// Evaluate the condition of an #if directive.
1233+
ConditionalCompilationExprState
1234+
evaluateConditionalCompilationExpr(Expr *condition);
12411235

12421236
//===--------------------------------------------------------------------===//
12431237
// Generics Parsing

include/swift/Parse/ParserResult.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,74 @@ 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+
};
233+
234+
class ConditionalCompilationExprState {
235+
236+
uint8_t ConditionActive : 1;
237+
uint8_t Kind : 7;
238+
public:
239+
ConditionalCompilationExprState() : ConditionActive(false) {
240+
setKind(ConditionalCompilationExprKind::Unknown);
241+
}
242+
243+
ConditionalCompilationExprState(bool ConditionActive,
244+
ConditionalCompilationExprKind Kind)
245+
: ConditionActive(ConditionActive) {
246+
setKind(Kind);
247+
}
248+
249+
bool isConditionActive() const {
250+
return ConditionActive;
251+
}
252+
253+
void setConditionActive(bool A) {
254+
ConditionActive = A;
255+
}
256+
257+
ConditionalCompilationExprKind getKind() const {
258+
return static_cast<ConditionalCompilationExprKind>(Kind);
259+
}
260+
261+
void setKind(ConditionalCompilationExprKind K) {
262+
Kind = static_cast<uint8_t>(K);
263+
assert(getKind() == K);
264+
}
265+
266+
bool shouldParse() const {
267+
if (getKind() == ConditionalCompilationExprKind::Error)
268+
return true;
269+
return ConditionActive ||
270+
(getKind() != ConditionalCompilationExprKind::CompilerVersion &&
271+
getKind() != ConditionalCompilationExprKind::LanguageVersion);
272+
}
273+
274+
static ConditionalCompilationExprState error() {
275+
return {false, ConditionalCompilationExprKind::Error};
276+
}
277+
};
278+
279+
ConditionalCompilationExprState
280+
operator&&(const ConditionalCompilationExprState lhs,
281+
const ConditionalCompilationExprState rhs);
282+
ConditionalCompilationExprState
283+
operator||(const ConditionalCompilationExprState lhs,
284+
const ConditionalCompilationExprState rhs);
285+
ConditionalCompilationExprState
286+
operator!(const ConditionalCompilationExprState Result);
287+
220288
} // namespace swift
221289

222290
#endif // LLVM_SWIFT_PARSER_PARSER_RESULT_H

include/swift/Parse/Scope.h

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

57-
bool isStaticallyInactiveConfigBlock() const;
58-
57+
bool isInactiveConfigBlock() const;
58+
5959
SavedScope saveCurrentScope();
6060
};
6161

@@ -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() {

0 commit comments

Comments
 (0)