Skip to content

Commit c536b0b

Browse files
Merge pull request #1882 from swiftwasm/main
[pull] swiftwasm from main
2 parents bcde167 + 62a6a46 commit c536b0b

File tree

10 files changed

+330
-239
lines changed

10 files changed

+330
-239
lines changed

docs/TypeChecker.rst renamed to docs/TypeChecker.md

Lines changed: 106 additions & 124 deletions
Large diffs are not rendered by default.

include/swift/AST/NameLookup.h

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -396,31 +396,6 @@ class VectorDeclConsumer : public VisibleDeclConsumer {
396396
}
397397
};
398398

399-
/// A consumer that inserts found decls with a matching name into an
400-
/// externally-owned SmallVector.
401-
class NamedDeclConsumer : public VisibleDeclConsumer {
402-
virtual void anchor() override;
403-
public:
404-
DeclNameRef name;
405-
SmallVectorImpl<LookupResultEntry> &results;
406-
bool isTypeLookup;
407-
408-
NamedDeclConsumer(DeclNameRef name,
409-
SmallVectorImpl<LookupResultEntry> &results,
410-
bool isTypeLookup)
411-
: name(name), results(results), isTypeLookup(isTypeLookup) {}
412-
413-
virtual void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason,
414-
DynamicLookupInfo dynamicLookupInfo = {}) override {
415-
// Give clients an opportunity to filter out non-type declarations early,
416-
// to avoid circular validation.
417-
if (isTypeLookup && !isa<TypeDecl>(VD))
418-
return;
419-
if (VD->getName().matchesRef(name.getFullName()))
420-
results.push_back(LookupResultEntry(VD));
421-
}
422-
};
423-
424399
/// A consumer that filters out decls that are not accessible from a given
425400
/// DeclContext.
426401
class AccessFilteringDeclConsumer final : public VisibleDeclConsumer {
@@ -619,18 +594,33 @@ class AbstractASTScopeDeclConsumer {
619594
virtual ~AbstractASTScopeDeclConsumer() = default;
620595

621596
/// Called for every ValueDecl visible from the lookup.
622-
/// Returns true if the lookup can be stopped at this point.
623-
/// BaseDC is per legacy
597+
///
624598
/// Takes an array in order to batch the consumption before setting
625599
/// IndexOfFirstOuterResult when necessary.
600+
///
601+
/// \param baseDC either a type context or the local context of a
602+
/// `self` parameter declaration. See LookupResult for a discussion
603+
/// of type -vs- instance lookup results.
604+
///
605+
/// \return true if the lookup should be stopped at this point.
626606
virtual bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
627607
NullablePtr<DeclContext> baseDC = nullptr) = 0;
628608

629-
/// Eventually this functionality should move into ASTScopeLookup
609+
/// Look for members of a nominal type or extension scope.
610+
///
611+
/// \return true if the lookup should be stopped at this point.
630612
virtual bool
631613
lookInMembers(DeclContext *const scopeDC,
632614
NominalTypeDecl *const nominal) = 0;
633615

616+
/// Called right before looking at the parent scope of a BraceStmt.
617+
///
618+
/// \return true if the lookup should be stopped at this point.
619+
virtual bool
620+
finishLookupInBraceStmt(BraceStmt *stmt) {
621+
return false;
622+
}
623+
634624
#ifndef NDEBUG
635625
virtual void startingNextLookupStep() = 0;
636626
virtual void finishingLookup(std::string) const = 0;
@@ -686,7 +676,11 @@ class ASTScope {
686676

687677
/// Lookup that only finds local declarations and does not trigger
688678
/// interface type computation.
679+
///
680+
/// \param stopAfterInnermostBraceStmt If lookup should consider
681+
/// local declarations inside the innermost syntactic scope only.
689682
static void lookupLocalDecls(SourceFile *, DeclName, SourceLoc,
683+
bool stopAfterInnermostBraceStmt,
690684
SmallVectorImpl<ValueDecl *> &);
691685

692686
/// Returns the result if there is exactly one, nullptr otherwise.

lib/AST/ASTScopeLookup.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,13 @@ bool BraceStmtScope::lookupLocalsOrMembers(DeclConsumer consumer) const {
384384
localBindings.push_back(vd);
385385
}
386386
}
387-
return consumer.consume(localBindings, DeclVisibilityKind::LocalVariable);
387+
if (consumer.consume(localBindings, DeclVisibilityKind::LocalVariable))
388+
return true;
389+
390+
if (consumer.finishLookupInBraceStmt(stmt))
391+
return true;
392+
393+
return false;
388394
}
389395

390396
bool PatternEntryInitializerScope::lookupLocalsOrMembers(

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ using namespace swift::namelookup;
4545

4646
void VisibleDeclConsumer::anchor() {}
4747
void VectorDeclConsumer::anchor() {}
48-
void NamedDeclConsumer::anchor() {}
4948

5049
ValueDecl *LookupResultEntry::getBaseDecl() const {
5150
if (BaseDC == nullptr)

lib/AST/UnqualifiedLookup.cpp

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,6 @@ namespace {
8888
SmallVectorImpl<LookupResultEntry> &results) const;
8989
};
9090

91-
enum class AddGenericParameters { Yes, No };
92-
93-
#ifndef NDEBUG
94-
/// A consumer for debugging that lets the UnqualifiedLookupFactory know when
95-
/// finding something.
96-
class InstrumentedNamedDeclConsumer : public NamedDeclConsumer {
97-
virtual void anchor() override;
98-
UnqualifiedLookupFactory *factory;
99-
100-
public:
101-
InstrumentedNamedDeclConsumer(UnqualifiedLookupFactory *factory,
102-
DeclNameRef name,
103-
SmallVectorImpl<LookupResultEntry> &results,
104-
bool isTypeLookup)
105-
: NamedDeclConsumer(name, results, isTypeLookup), factory(factory) {}
106-
107-
virtual void foundDecl(ValueDecl *VD, DeclVisibilityKind Reason,
108-
DynamicLookupInfo dynamicLookupInfo = {}) override {
109-
unsigned before = results.size();
110-
NamedDeclConsumer::foundDecl(VD, Reason, dynamicLookupInfo);
111-
unsigned after = results.size();
112-
if (after > before)
113-
factory->addedResult(results.back());
114-
}
115-
};
116-
#endif
11791
// Inputs
11892
const DeclNameRef Name;
11993
DeclContext *const DC;
@@ -128,12 +102,7 @@ namespace {
128102
const Options options;
129103
const bool isOriginallyTypeLookup;
130104
const NLOptions baseNLOptions;
131-
// Transputs
132-
#ifndef NDEBUG
133-
InstrumentedNamedDeclConsumer Consumer;
134-
#else
135-
NamedDeclConsumer Consumer;
136-
#endif
105+
137106
// Outputs
138107
SmallVectorImpl<LookupResultEntry> &Results;
139108
size_t &IndexOfFirstOuterResult;
@@ -279,11 +248,6 @@ UnqualifiedLookupFactory::UnqualifiedLookupFactory(
279248
options(options),
280249
isOriginallyTypeLookup(options.contains(Flags::TypeLookup)),
281250
baseNLOptions(computeBaseNLOptions(options, isOriginallyTypeLookup)),
282-
#ifdef NDEBUG
283-
Consumer(Name, Results, isOriginallyTypeLookup),
284-
#else
285-
Consumer(this, Name, Results, isOriginallyTypeLookup),
286-
#endif
287251
Results(Results),
288252
IndexOfFirstOuterResult(IndexOfFirstOuterResult)
289253
{}
@@ -675,9 +639,6 @@ UnqualifiedLookupRequest::evaluate(Evaluator &evaluator,
675639
}
676640

677641
#pragma mark debugging
678-
#ifndef NDEBUG
679-
void UnqualifiedLookupFactory::InstrumentedNamedDeclConsumer::anchor() {}
680-
#endif
681642

682643
void UnqualifiedLookupFactory::ResultFinderForTypeContext::dump() const {
683644
(void)factory;
@@ -775,13 +736,16 @@ namespace {
775736

776737
class ASTScopeDeclConsumerForLocalLookup
777738
: public AbstractASTScopeDeclConsumer {
778-
SmallVectorImpl<ValueDecl *> &results;
779739
DeclName name;
740+
bool stopAfterInnermostBraceStmt;
741+
SmallVectorImpl<ValueDecl *> &results;
780742

781743
public:
782744
ASTScopeDeclConsumerForLocalLookup(
783-
SmallVectorImpl<ValueDecl *> &results, DeclName name)
784-
: results(results), name(name) {}
745+
DeclName name, bool stopAfterInnermostBraceStmt,
746+
SmallVectorImpl<ValueDecl *> &results)
747+
: name(name), stopAfterInnermostBraceStmt(stopAfterInnermostBraceStmt),
748+
results(results) {}
785749

786750
bool consume(ArrayRef<ValueDecl *> values, DeclVisibilityKind vis,
787751
NullablePtr<DeclContext> baseDC) override {
@@ -792,14 +756,18 @@ class ASTScopeDeclConsumerForLocalLookup
792756
results.push_back(value);
793757
}
794758

795-
return !results.empty();
759+
return (!stopAfterInnermostBraceStmt && !results.empty());
796760
}
797761

798762
bool lookInMembers(DeclContext *const,
799763
NominalTypeDecl *const) override {
800764
return true;
801765
}
802766

767+
bool finishLookupInBraceStmt(BraceStmt *stmt) override {
768+
return stopAfterInnermostBraceStmt;
769+
}
770+
803771
#ifndef NDEBUG
804772
void startingNextLookupStep() override {}
805773
void finishingLookup(std::string) const override {}
@@ -812,15 +780,19 @@ class ASTScopeDeclConsumerForLocalLookup
812780
/// Lookup that only finds local declarations and does not trigger
813781
/// interface type computation.
814782
void ASTScope::lookupLocalDecls(SourceFile *sf, DeclName name, SourceLoc loc,
783+
bool stopAfterInnermostBraceStmt,
815784
SmallVectorImpl<ValueDecl *> &results) {
816-
ASTScopeDeclConsumerForLocalLookup consumer(results, name);
785+
ASTScopeDeclConsumerForLocalLookup consumer(name, stopAfterInnermostBraceStmt,
786+
results);
817787
ASTScope::unqualifiedLookup(sf, loc, consumer);
818788
}
819789

820790
ValueDecl *ASTScope::lookupSingleLocalDecl(SourceFile *sf, DeclName name,
821791
SourceLoc loc) {
822792
SmallVector<ValueDecl *, 1> result;
823-
ASTScope::lookupLocalDecls(sf, name, loc, result);
793+
ASTScope::lookupLocalDecls(sf, name, loc,
794+
/*finishLookupInBraceStmt=*/false,
795+
result);
824796
if (result.size() != 1)
825797
return nullptr;
826798
return result[0];

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,12 +3206,6 @@ void AttributeChecker::visitNonEphemeralAttr(NonEphemeralAttr *attr) {
32063206
attr->setInvalid();
32073207
}
32083208

3209-
void TypeChecker::checkParameterAttributes(ParameterList *params) {
3210-
for (auto param: *params) {
3211-
checkDeclAttributes(param);
3212-
}
3213-
}
3214-
32153209
void AttributeChecker::checkOriginalDefinedInAttrs(Decl *D,
32163210
ArrayRef<OriginallyDefinedInAttr*> Attrs) {
32173211
if (Attrs.empty())

0 commit comments

Comments
 (0)