Skip to content

Commit 1ff8ca8

Browse files
authored
Merge pull request #2390 from swiftwasm/main
[pull] swiftwasm from main
2 parents d9daf49 + 212acff commit 1ff8ca8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+263
-234
lines changed

docs/HowToGuides/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Double-check that running `pwd` prints a path ending with `swift`.
126126
127127
### macOS
128128
129-
1. Install [Xcode 12.2 beta 3][Xcode] or newer:
129+
1. Install [Xcode 12.3][Xcode] or newer:
130130
The required version of Xcode changes frequently and is often a beta release.
131131
Check this document or the host information on <https://ci.swift.org> for the
132132
current required version.

include/swift/AST/ASTScope.h

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,16 @@ class ASTScopeImpl {
136136
/// storage declaration or is directly descended from it.
137137

138138
private:
139-
/// Always set by the constructor, so that when creating a child
140-
/// the parent chain is available.
141-
ASTScopeImpl *parent = nullptr; // null at the root
139+
/// The pointer:
140+
/// - Always set by the constructor, so that when creating a child
141+
/// the parent chain is available. Null at the root.
142+
/// The int:
143+
/// - A flag indicating if the scope has been expanded yet or not.
144+
llvm::PointerIntPair<ASTScopeImpl *, 1> parentAndWasExpanded;
142145

143146
/// Child scopes, sorted by source range.
144147
Children storedChildren;
145148

146-
bool wasExpanded = false;
147-
148-
/// Can clear storedChildren, so must remember this
149-
bool haveAddedCleanup = false;
150-
151149
mutable Optional<CharSourceRange> cachedCharSourceRange;
152150

153151
#pragma mark - constructor / destructor
@@ -177,8 +175,12 @@ class ASTScopeImpl {
177175

178176
#pragma mark - tree declarations
179177
protected:
180-
NullablePtr<ASTScopeImpl> getParent() { return parent; }
181-
NullablePtr<const ASTScopeImpl> getParent() const { return parent; }
178+
NullablePtr<ASTScopeImpl> getParent() {
179+
return parentAndWasExpanded.getPointer();
180+
}
181+
NullablePtr<const ASTScopeImpl> getParent() const {
182+
return parentAndWasExpanded.getPointer();
183+
}
182184

183185
const Children &getChildren() const { return storedChildren; }
184186

@@ -247,19 +249,13 @@ class ASTScopeImpl {
247249

248250
#pragma mark - Scope tree creation
249251
public:
250-
/// expandScope me, sending deferred nodes to my descendants.
251-
/// Return the scope into which to place subsequent decls
252-
ASTScopeImpl *expandAndBeCurrentDetectingRecursion(ScopeCreator &);
253-
254-
/// Expand or reexpand the scope if unexpanded or if not current.
255-
/// There are several places in the compiler that mutate the AST after the
256-
/// fact, above and beyond adding Decls to the SourceFile.
252+
/// Expand the scope if unexpanded.
257253
ASTScopeImpl *expandAndBeCurrent(ScopeCreator &);
258254

259-
bool getWasExpanded() const { return wasExpanded; }
255+
bool getWasExpanded() const { return parentAndWasExpanded.getInt(); }
260256

261257
protected:
262-
void setWasExpanded() { wasExpanded = true; }
258+
void setWasExpanded() { parentAndWasExpanded.setInt(1); }
263259
virtual ASTScopeImpl *expandSpecifically(ScopeCreator &) = 0;
264260

265261
public:
@@ -360,7 +356,7 @@ class ASTScopeImpl {
360356
/// what obtaines for scoping. However, guards are different. The scope after
361357
/// the guard else must hop into the innermoset scope of the guard condition.
362358
virtual NullablePtr<const ASTScopeImpl> getLookupParent() const {
363-
return parent;
359+
return getParent();
364360
}
365361

366362
#pragma mark - - lookup- local bindings
@@ -629,8 +625,6 @@ class IterableTypeScope : public GenericTypeScope {
629625

630626
public:
631627
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
632-
633-
void countBodies(ScopeCreator &) const;
634628
};
635629

636630
class NominalTypeScope final : public IterableTypeScope {

include/swift/AST/NameLookupRequests.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -350,30 +350,6 @@ class GenericParamListRequest :
350350
void cacheResult(GenericParamList *value) const;
351351
};
352352

353-
/// Expand the given ASTScope. Requestified to detect recursion.
354-
class ExpandASTScopeRequest
355-
: public SimpleRequest<ExpandASTScopeRequest,
356-
ast_scope::ASTScopeImpl *(ast_scope::ASTScopeImpl *,
357-
ast_scope::ScopeCreator *),
358-
RequestFlags::SeparatelyCached> {
359-
public:
360-
using SimpleRequest::SimpleRequest;
361-
362-
private:
363-
friend SimpleRequest;
364-
365-
// Evaluation.
366-
ast_scope::ASTScopeImpl *
367-
evaluate(Evaluator &evaluator, ast_scope::ASTScopeImpl *,
368-
ast_scope::ScopeCreator *) const;
369-
370-
public:
371-
// Separate caching.
372-
bool isCached() const;
373-
Optional<ast_scope::ASTScopeImpl *> getCachedResult() const;
374-
void cacheResult(ast_scope::ASTScopeImpl *) const {}
375-
};
376-
377353
/// The input type for an unqualified lookup request.
378354
class UnqualifiedLookupDescriptor {
379355
using LookupOptions = OptionSet<UnqualifiedLookupFlags>;

include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ SWIFT_REQUEST(NameLookup, DirectOperatorLookupRequest,
3131
SWIFT_REQUEST(NameLookup, DirectPrecedenceGroupLookupRequest,
3232
TinyPtrVector<PrecedenceGroupDecl *>(OperatorLookupDescriptor),
3333
Uncached, NoLocationInfo)
34-
SWIFT_REQUEST(NameLookup, ExpandASTScopeRequest,
35-
ast_scope::ASTScopeImpl* (ast_scope::ASTScopeImpl*, ast_scope::ScopeCreator*),
36-
SeparatelyCached,
37-
NoLocationInfo)
3834
SWIFT_REQUEST(NameLookup, ExtendedNominalRequest,
3935
NominalTypeDecl *(ExtensionDecl *), SeparatelyCached,
4036
NoLocationInfo)

include/swift/Basic/Statistics.def

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,12 @@ FRONTEND_STATISTIC(AST, NumModuleLookupValue)
144144
/// AnyObject lookup.
145145
FRONTEND_STATISTIC(AST, NumModuleLookupClassMember)
146146

147-
/// Number of body scopes for iterable types
148-
FRONTEND_STATISTIC(AST, NumIterableTypeBodyASTScopes)
149-
150-
/// Number of expansions of body scopes for iterable types
151-
FRONTEND_STATISTIC(AST, NumIterableTypeBodyASTScopeExpansions)
152-
153-
/// Number of brace statment scopes for iterable types
154-
FRONTEND_STATISTIC(AST, NumBraceStmtASTScopes)
155-
156-
/// Number of expansions of brace statement scopes for iterable types
157-
FRONTEND_STATISTIC(AST, NumBraceStmtASTScopeExpansions)
158-
159147
/// Number of ASTScope lookups
160148
FRONTEND_STATISTIC(AST, NumASTScopeLookups)
161149

150+
/// Number of ASTScope expansions
151+
FRONTEND_STATISTIC(AST, NumASTScopeExpansions)
152+
162153
/// Number of lookups of the cached import graph for a module or
163154
/// source file.
164155
FRONTEND_STATISTIC(AST, ImportSetFoldHit)

lib/AST/ASTScopeCreation.cpp

Lines changed: 19 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class ScopeCreator final {
8282
if (auto *ip = child->insertionPointForDeferredExpansion().getPtrOrNull())
8383
return ip;
8484

85-
ASTScopeImpl *insertionPoint =
86-
child->expandAndBeCurrentDetectingRecursion(*this);
85+
ASTScopeImpl *insertionPoint = child->expandAndBeCurrent(*this);
8786
return insertionPoint;
8887
}
8988

@@ -224,15 +223,18 @@ ASTSourceFileScope *ASTScope::createScopeTree(SourceFile *SF) {
224223
}
225224

226225
void ASTSourceFileScope::buildFullyExpandedTree() {
227-
expandAndBeCurrentDetectingRecursion(*scopeCreator);
226+
if (!getWasExpanded())
227+
expandAndBeCurrent(*scopeCreator);
228228
preOrderChildrenDo([&](ASTScopeImpl *s) {
229-
s->expandAndBeCurrentDetectingRecursion(*scopeCreator);
229+
if (!s->getWasExpanded())
230+
s->expandAndBeCurrent(*scopeCreator);
230231
});
231232
}
232233

233234
void ASTSourceFileScope::
234235
buildEnoughOfTreeForTopLevelExpressionsButDontRequestGenericsOrExtendedNominals() {
235-
expandAndBeCurrentDetectingRecursion(*scopeCreator);
236+
if (!getWasExpanded())
237+
expandAndBeCurrent(*scopeCreator);
236238
}
237239

238240
void ASTSourceFileScope::expandFunctionBody(AbstractFunctionDecl *AFD) {
@@ -242,7 +244,8 @@ void ASTSourceFileScope::expandFunctionBody(AbstractFunctionDecl *AFD) {
242244
if (sr.isInvalid())
243245
return;
244246
ASTScopeImpl *bodyScope = findInnermostEnclosingScope(sr.Start, nullptr);
245-
bodyScope->expandAndBeCurrentDetectingRecursion(*scopeCreator);
247+
if (!bodyScope->getWasExpanded())
248+
bodyScope->expandAndBeCurrent(*scopeCreator);
246249
}
247250

248251
ASTSourceFileScope::ASTSourceFileScope(SourceFile *SF,
@@ -411,8 +414,6 @@ class NodeAdder
411414
endLocForBraceStmt = *endLoc;
412415

413416
ASTContext &ctx = scopeCreator.getASTContext();
414-
if (auto *s = ctx.Stats)
415-
++s->getFrontendCounters().NumBraceStmtASTScopes;
416417

417418
return
418419
scopeCreator.constructExpandAndInsert<BraceStmtScope>(
@@ -578,44 +579,33 @@ ScopeCreator::addPatternBindingToScopeTree(PatternBindingDecl *patternBinding,
578579

579580
void ASTScopeImpl::addChild(ASTScopeImpl *child, ASTContext &ctx) {
580581
ASTScopeAssert(!child->getParent(), "child should not already have parent");
581-
child->parent = this;
582+
child->parentAndWasExpanded.setPointer(this);
582583

583584
#ifndef NDEBUG
584585
checkSourceRangeBeforeAddingChild(child, ctx);
585586
#endif
586587

587588
// If this is the first time we've added children, notify the ASTContext
588589
// that there's a SmallVector that needs to be cleaned up.
589-
// FIXME: If we had access to SmallVector::isSmall(), we could do better.
590-
if (storedChildren.empty() && !haveAddedCleanup) {
590+
if (storedChildren.empty())
591591
ctx.addDestructorCleanup(storedChildren);
592-
haveAddedCleanup = true;
593-
}
592+
594593
storedChildren.push_back(child);
595594
}
596595

597596
#pragma mark implementations of expansion
598597

599-
ASTScopeImpl *
600-
ASTScopeImpl::expandAndBeCurrentDetectingRecursion(ScopeCreator &scopeCreator) {
601-
return evaluateOrDefault(scopeCreator.getASTContext().evaluator,
602-
ExpandASTScopeRequest{this, &scopeCreator}, nullptr);
603-
}
604-
605-
ASTScopeImpl *
606-
ExpandASTScopeRequest::evaluate(Evaluator &evaluator, ASTScopeImpl *parent,
607-
ScopeCreator *scopeCreator) const {
608-
auto *insertionPoint = parent->expandAndBeCurrent(*scopeCreator);
609-
ASTScopeAssert(insertionPoint,
610-
"Used to return a null pointer if the insertion point would "
611-
"not be used, but it breaks the request dependency hashing");
612-
return insertionPoint;
613-
}
614-
615598
ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent(ScopeCreator &scopeCreator) {
616599
ASTScopeAssert(!getWasExpanded(),
617600
"Cannot expand the same scope twice");
618601

602+
// Set the flag before we actually expand, to detect re-entrant calls
603+
// via the above assertion.
604+
setWasExpanded();
605+
606+
if (auto *s = scopeCreator.getASTContext().Stats)
607+
++s->getFrontendCounters().NumASTScopeExpansions;
608+
619609
auto *insertionPoint = expandSpecifically(scopeCreator);
620610
ASTScopeAssert(!insertionPointForDeferredExpansion() ||
621611
insertionPointForDeferredExpansion().get() ==
@@ -624,8 +614,6 @@ ASTScopeImpl *ASTScopeImpl::expandAndBeCurrent(ScopeCreator &scopeCreator) {
624614
"accurate before expansion, the insertion point before "
625615
"expansion must be the same as after expansion.");
626616

627-
setWasExpanded();
628-
629617
return insertionPoint;
630618
}
631619

@@ -826,9 +814,6 @@ BraceStmtScope::expandAScopeThatCreatesANewInsertionPoint(
826814
nd, insertionPoint, endLoc);
827815
}
828816

829-
if (auto *s = scopeCreator.getASTContext().Stats)
830-
++s->getFrontendCounters().NumBraceStmtASTScopeExpansions;
831-
832817
return {
833818
insertionPoint,
834819
"For top-level code decls, need the scope under, say a guard statment."};
@@ -1085,24 +1070,17 @@ ASTScopeImpl *GenericTypeOrExtensionWherePortion::expandScope(
10851070

10861071
#pragma mark createBodyScope
10871072

1088-
void IterableTypeScope::countBodies(ScopeCreator &scopeCreator) const {
1089-
if (auto *s = scopeCreator.getASTContext().Stats)
1090-
++s->getFrontendCounters().NumIterableTypeBodyASTScopes;
1091-
}
1092-
10931073
void ExtensionScope::createBodyScope(ASTScopeImpl *leaf,
10941074
ScopeCreator &scopeCreator) {
10951075
scopeCreator.constructWithPortionExpandAndInsert<ExtensionScope,
10961076
IterableTypeBodyPortion>(
10971077
leaf, decl);
1098-
countBodies(scopeCreator);
10991078
}
11001079
void NominalTypeScope::createBodyScope(ASTScopeImpl *leaf,
11011080
ScopeCreator &scopeCreator) {
11021081
scopeCreator.constructWithPortionExpandAndInsert<NominalTypeScope,
11031082
IterableTypeBodyPortion>(
11041083
leaf, decl);
1105-
countBodies(scopeCreator);
11061084
}
11071085

11081086
#pragma mark createTrailingWhereClauseScope
@@ -1192,9 +1170,6 @@ void GenericTypeOrExtensionScope::expandBody(ScopeCreator &) {}
11921170
void IterableTypeScope::expandBody(ScopeCreator &scopeCreator) {
11931171
for (auto *d : getIterableDeclContext().get()->getMembers())
11941172
scopeCreator.addToScopeTree(ASTNode(d), this);
1195-
1196-
if (auto *s = scopeCreator.getASTContext().Stats)
1197-
++s->getFrontendCounters().NumIterableTypeBodyASTScopeExpansions;
11981173
}
11991174

12001175
#pragma mark getScopeCreator
@@ -1241,16 +1216,3 @@ void ast_scope::simple_display(llvm::raw_ostream &out,
12411216
const ScopeCreator *scopeCreator) {
12421217
scopeCreator->print(out);
12431218
}
1244-
1245-
//----------------------------------------------------------------------------//
1246-
// ExpandASTScopeRequest computation.
1247-
//----------------------------------------------------------------------------//
1248-
1249-
bool ExpandASTScopeRequest::isCached() const {
1250-
ASTScopeImpl *scope = std::get<0>(getStorage());
1251-
return scope->getWasExpanded();
1252-
}
1253-
1254-
Optional<ASTScopeImpl *> ExpandASTScopeRequest::getCachedResult() const {
1255-
return std::get<0>(getStorage());
1256-
}

lib/AST/ASTScopeLookup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ ASTScopeImpl::findInnermostEnclosingScope(SourceLoc loc,
6464
ASTScopeImpl *ASTScopeImpl::findInnermostEnclosingScopeImpl(
6565
SourceLoc loc, NullablePtr<raw_ostream> os, SourceManager &sourceMgr,
6666
ScopeCreator &scopeCreator) {
67-
expandAndBeCurrentDetectingRecursion(scopeCreator);
67+
if (!getWasExpanded())
68+
expandAndBeCurrent(scopeCreator);
6869
auto child = findChildContaining(loc, sourceMgr);
6970
if (!child)
7071
return this;

lib/AST/Attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
721721
// if the overriden decl is invisible from the interface. Otherwise, an error
722722
// will occur while building the Swift module because the overriding decl
723723
// doesn't override anything.
724-
// We couldn't skip every `override` keywords becuase they change the
724+
// We couldn't skip every `override` keywords because they change the
725725
// ABI if the overriden decl is also publically visible.
726726
// For public-override-internal case, having `override` doesn't have ABI
727727
// implication. Thus we can skip them.

lib/IDE/CompletionInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ bool CompletionInstance::shouldCheckDependencies() const {
607607
auto now = system_clock::now();
608608
auto threshold = DependencyCheckedTimestamp +
609609
seconds(Opts.DependencyCheckIntervalSecond);
610-
return threshold < now;
610+
return threshold <= now;
611611
}
612612

613613
void CompletionInstance::setOptions(CompletionInstance::Options NewOpts) {

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,20 @@ class SILCombiner :
4949

5050
DominanceAnalysis *DA;
5151

52-
// Determine the set of types a protocol conforms to in whole-module
53-
// compilation mode.
52+
/// Determine the set of types a protocol conforms to in whole-module
53+
/// compilation mode.
5454
ProtocolConformanceAnalysis *PCA;
5555

56-
// Class hierarchy analysis needed to confirm no derived classes of a sole
57-
// conforming class.
56+
/// Class hierarchy analysis needed to confirm no derived classes of a sole
57+
/// conforming class.
5858
ClassHierarchyAnalysis *CHA;
5959

6060
/// Worklist containing all of the instructions primed for simplification.
6161
SmallSILInstructionWorklist<256> Worklist;
6262

63+
/// A cache of "dead end blocks" through which all paths it is known that the
64+
/// program will terminate. This means that we are allowed to leak
65+
/// objects.
6366
DeadEndBlocks deadEndBlocks;
6467

6568
/// Variable to track if the SILCombiner made any changes.

0 commit comments

Comments
 (0)