Skip to content

Commit 82e8a18

Browse files
authored
Merge pull request #1818 from swiftwasm/master
[pull] swiftwasm from master
2 parents 3fc1272 + 734b8a2 commit 82e8a18

Some content is hidden

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

45 files changed

+497
-422
lines changed

include/swift/AST/ASTScope.h

Lines changed: 17 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,11 @@ class ASTScopeImpl {
345345
virtual SourceRange sourceRangeForDeferredExpansion() const;
346346

347347
public:
348-
virtual NullablePtr<AbstractStorageDecl>
349-
getEnclosingAbstractStorageDecl() const;
350-
351348
bool isATypeDeclScope() const;
352349

353350
private:
354351
virtual ScopeCreator &getScopeCreator();
355352

356-
#pragma mark - - creation queries
357-
public:
358-
virtual bool isThisAnAbstractStorageDecl() const { return false; }
359-
360353
#pragma mark - lookup
361354

362355
public:
@@ -849,9 +842,6 @@ class GenericParamScope final : public ASTScopeImpl {
849842
void printSpecifics(llvm::raw_ostream &out) const override;
850843

851844
public:
852-
NullablePtr<AbstractStorageDecl>
853-
getEnclosingAbstractStorageDecl() const override;
854-
855845
NullablePtr<const void> addressForPrinting() const override {
856846
return paramList;
857847
}
@@ -887,9 +877,6 @@ class AbstractFunctionDeclScope final : public ASTScopeImpl {
887877
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
888878
Decl *getDecl() const { return decl; }
889879

890-
NullablePtr<AbstractStorageDecl>
891-
getEnclosingAbstractStorageDecl() const override;
892-
893880
NullablePtr<const void> getReferrent() const override;
894881

895882
protected:
@@ -914,8 +901,7 @@ class ParameterListScope final : public ASTScopeImpl {
914901
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
915902

916903
private:
917-
AnnotatedInsertionPoint
918-
expandAScopeThatCreatesANewInsertionPoint(ScopeCreator &);
904+
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
919905
SourceLoc fixupEndForBadInput(SourceRange) const;
920906

921907
public:
@@ -924,17 +910,16 @@ class ParameterListScope final : public ASTScopeImpl {
924910
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
925911
virtual NullablePtr<DeclContext> getDeclContext() const override;
926912

927-
NullablePtr<AbstractStorageDecl>
928-
getEnclosingAbstractStorageDecl() const override;
929913
NullablePtr<const void> addressForPrinting() const override { return params; }
930914
};
931915

932-
class AbstractFunctionBodyScope : public ASTScopeImpl {
916+
/// Body of functions, methods, constructors, destructors and accessors.
917+
class FunctionBodyScope : public ASTScopeImpl {
933918
public:
934919
AbstractFunctionDecl *const decl;
935920

936-
AbstractFunctionBodyScope(AbstractFunctionDecl *e) : decl(e) {}
937-
virtual ~AbstractFunctionBodyScope() {}
921+
FunctionBodyScope(AbstractFunctionDecl *e) : decl(e) {}
922+
virtual ~FunctionBodyScope() {}
938923

939924
protected:
940925
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
@@ -956,19 +941,11 @@ class AbstractFunctionBodyScope : public ASTScopeImpl {
956941
bool lookupLocalsOrMembers(DeclConsumer) const override;
957942

958943
public:
944+
std::string getClassName() const override;
959945
NullablePtr<ASTScopeImpl> insertionPointForDeferredExpansion() override;
960946
SourceRange sourceRangeForDeferredExpansion() const override;
961947
};
962948

963-
/// Body of functions and methods.
964-
class FunctionBodyScope final : public AbstractFunctionBodyScope {
965-
public:
966-
FunctionBodyScope(AbstractFunctionDecl *e)
967-
: AbstractFunctionBodyScope(e) {}
968-
std::string getClassName() const override;
969-
bool lookupLocalsOrMembers(DeclConsumer consumer) const override;
970-
};
971-
972949
class DefaultArgumentInitializerScope final : public ASTScopeImpl {
973950
public:
974951
ParamDecl *const decl;
@@ -1001,17 +978,19 @@ class DefaultArgumentInitializerScope final : public ASTScopeImpl {
1001978

1002979
class AttachedPropertyWrapperScope final : public ASTScopeImpl {
1003980
public:
1004-
VarDecl *const decl;
981+
CustomAttr *attr;
982+
VarDecl *decl;
983+
1005984
/// Because we have to avoid request cycles, we approximate the test for an
1006985
/// AttachedPropertyWrapper with one based on source location. We might get
1007986
/// false positives, that that doesn't hurt anything. However, the result of
1008987
/// the conservative source range computation doesn't seem to be stable. So
1009988
/// keep the original here, and use it for source range queries.
1010-
1011989
const SourceRange sourceRangeWhenCreated;
1012990

1013-
AttachedPropertyWrapperScope(VarDecl *e)
1014-
: decl(e), sourceRangeWhenCreated(getSourceRangeOfVarDecl(e)) {
991+
AttachedPropertyWrapperScope(CustomAttr *attr, VarDecl *decl)
992+
: attr(attr), decl(decl),
993+
sourceRangeWhenCreated(attr->getTypeRepr()->getSourceRange()) {
1015994
ASTScopeAssert(sourceRangeWhenCreated.isValid(),
1016995
"VarDecls must have ranges to be looked-up");
1017996
}
@@ -1027,7 +1006,10 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
10271006
NullablePtr<const void> addressForPrinting() const override { return decl; }
10281007
virtual NullablePtr<DeclContext> getDeclContext() const override;
10291008

1030-
static SourceRange getSourceRangeOfVarDecl(const VarDecl *);
1009+
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
1010+
return attr;
1011+
}
1012+
NullablePtr<const void> getReferrent() const override;
10311013

10321014
private:
10331015
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
@@ -1068,11 +1050,8 @@ class AbstractPatternEntryScope : public ASTScopeImpl {
10681050

10691051
protected:
10701052
void printSpecifics(llvm::raw_ostream &out) const override;
1071-
void forEachVarDeclWithLocalizableAccessors(
1072-
ScopeCreator &scopeCreator, function_ref<void(VarDecl *)> foundOne) const;
10731053

10741054
public:
1075-
bool isLastEntry() const;
10761055
NullablePtr<Decl> getDeclIfAny() const override { return decl; }
10771056
Decl *getDecl() const { return decl; }
10781057
};
@@ -1116,8 +1095,7 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
11161095
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
11171096

11181097
private:
1119-
AnnotatedInsertionPoint
1120-
expandAScopeThatCreatesANewInsertionPoint(ScopeCreator &);
1098+
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
11211099

11221100
public:
11231101
std::string getClassName() const override;
@@ -1296,9 +1274,6 @@ class SpecializeAttributeScope final : public ASTScopeImpl {
12961274
return specializeAttr;
12971275
}
12981276

1299-
NullablePtr<AbstractStorageDecl>
1300-
getEnclosingAbstractStorageDecl() const override;
1301-
13021277
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
13031278
return specializeAttr;
13041279
}
@@ -1329,9 +1304,6 @@ class DifferentiableAttributeScope final : public ASTScopeImpl {
13291304
return differentiableAttr;
13301305
}
13311306

1332-
NullablePtr<AbstractStorageDecl>
1333-
getEnclosingAbstractStorageDecl() const override;
1334-
13351307
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
13361308
return differentiableAttr;
13371309
}
@@ -1373,44 +1345,6 @@ class SubscriptDeclScope final : public ASTScopeImpl {
13731345

13741346
protected:
13751347
NullablePtr<const GenericParamList> genericParams() const override;
1376-
NullablePtr<AbstractStorageDecl>
1377-
getEnclosingAbstractStorageDecl() const override {
1378-
return decl;
1379-
}
1380-
public:
1381-
bool isThisAnAbstractStorageDecl() const override { return true; }
1382-
};
1383-
1384-
class VarDeclScope final : public ASTScopeImpl {
1385-
1386-
public:
1387-
VarDecl *const decl;
1388-
VarDeclScope(VarDecl *e) : decl(e) {}
1389-
virtual ~VarDeclScope() {}
1390-
1391-
protected:
1392-
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
1393-
1394-
private:
1395-
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
1396-
1397-
public:
1398-
std::string getClassName() const override;
1399-
SourceRange
1400-
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
1401-
1402-
protected:
1403-
void printSpecifics(llvm::raw_ostream &out) const override;
1404-
1405-
public:
1406-
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
1407-
Decl *getDecl() const { return decl; }
1408-
NullablePtr<const void> getReferrent() const override;
1409-
NullablePtr<AbstractStorageDecl>
1410-
getEnclosingAbstractStorageDecl() const override {
1411-
return decl;
1412-
}
1413-
bool isThisAnAbstractStorageDecl() const override { return true; }
14141348
};
14151349

14161350
class EnumElementScope : public ASTScopeImpl {

include/swift/AST/FileUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class FileUnit : public DeclContext {
241241
/// \see ModuleDecl::getImportedModulesForLookup
242242
virtual void getImportedModulesForLookup(
243243
SmallVectorImpl<ModuleDecl::ImportedModule> &imports) const {
244-
return getImportedModules(imports, ModuleDecl::ImportFilterKind::Public);
244+
return getImportedModules(imports, ModuleDecl::ImportFilterKind::Exported);
245245
}
246246

247247
/// Generates the list of libraries needed to link this file, based on its

include/swift/AST/Module.h

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,27 +648,52 @@ class ModuleDecl : public DeclContext, public TypeDecl {
648648
/// \sa getImportedModules
649649
enum class ImportFilterKind {
650650
/// Include imports declared with `@_exported`.
651-
Public = 1 << 0,
651+
Exported = 1 << 0,
652652
/// Include "regular" imports with no special annotation.
653-
Private = 1 << 1,
653+
Default = 1 << 1,
654654
/// Include imports declared with `@_implementationOnly`.
655655
ImplementationOnly = 1 << 2,
656-
/// Include imports of SPIs declared with `@_spi`
656+
/// Include imports of SPIs declared with `@_spi`. Non-SPI imports are
657+
/// included whether or not this flag is specified.
657658
SPIAccessControl = 1 << 3,
658-
/// Include imports shadowed by a separately-imported overlay (i.e. a
659-
/// cross-import overlay). Unshadowed imports are included whether or not
660-
/// this flag is specified.
661-
ShadowedBySeparateOverlay = 1 << 4
659+
/// Include imports shadowed by a cross-import overlay. Unshadowed imports
660+
/// are included whether or not this flag is specified.
661+
ShadowedByCrossImportOverlay = 1 << 4
662662
};
663663
/// \sa getImportedModules
664664
using ImportFilter = OptionSet<ImportFilterKind>;
665665

666666
/// Looks up which modules are imported by this module.
667667
///
668-
/// \p filter controls whether public, private, or any imports are included
669-
/// in this list.
668+
/// \p filter controls which imports are included in the list.
669+
///
670+
/// There are three axes for categorizing imports:
671+
/// 1. Privacy: Exported/Private/ImplementationOnly (mutually exclusive).
672+
/// 2. SPI/non-SPI: An import of any privacy level may be @_spi("SPIName").
673+
/// 3. Shadowed/Non-shadowed: An import of any privacy level may be shadowed
674+
/// by a cross-import overlay.
675+
///
676+
/// It is also possible for SPI imports to be shadowed by a cross-import
677+
/// overlay.
678+
///
679+
/// If \p filter contains multiple privacy levels, modules at all the privacy
680+
/// levels are included.
681+
///
682+
/// If \p filter contains \c ImportFilterKind::SPIAccessControl, then both
683+
/// SPI and non-SPI imports are included. Otherwise, only non-SPI imports are
684+
/// included.
685+
///
686+
/// If \p filter contains \c ImportFilterKind::ShadowedByCrossImportOverlay,
687+
/// both shadowed and non-shadowed imports are included. Otherwise, only
688+
/// non-shadowed imports are included.
689+
///
690+
/// Clang modules have some additional complexities; see the implementation of
691+
/// \c ClangModuleUnit::getImportedModules for details.
692+
///
693+
/// \pre \p filter must contain at least one privacy level, i.e. one of
694+
/// \c Exported or \c Private or \c ImplementationOnly.
670695
void getImportedModules(SmallVectorImpl<ImportedModule> &imports,
671-
ImportFilter filter = ImportFilterKind::Public) const;
696+
ImportFilter filter = ImportFilterKind::Exported) const;
672697

673698
/// Looks up which modules are imported by this module, ignoring any that
674699
/// won't contain top-level decls.

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ struct PrintOptions {
499499
}
500500

501501
/// Retrieve the set of options suitable for diagnostics printing.
502-
static PrintOptions printForDiagnostics() {
502+
static PrintOptions printForDiagnostics(AccessLevel accessFilter) {
503503
PrintOptions result = printVerbose();
504504
result.PrintAccess = true;
505505
result.Indent = 4;
@@ -512,7 +512,7 @@ struct PrintOptions {
512512
result.ExcludeAttrList.push_back(DAK_Optimize);
513513
result.ExcludeAttrList.push_back(DAK_Rethrows);
514514
result.PrintOverrideKeyword = false;
515-
result.AccessFilter = AccessLevel::Public;
515+
result.AccessFilter = accessFilter;
516516
result.PrintIfConfig = false;
517517
result.ShouldQualifyNestedDeclarations =
518518
QualifyNestedDeclarations::TypesOnly;
@@ -522,7 +522,7 @@ struct PrintOptions {
522522

523523
/// Retrieve the set of options suitable for interface generation.
524524
static PrintOptions printInterface() {
525-
PrintOptions result = printForDiagnostics();
525+
PrintOptions result = printForDiagnostics(AccessLevel::Public);
526526
result.SkipUnavailable = true;
527527
result.SkipImplicit = true;
528528
result.SkipSwiftPrivateClangDecls = true;

include/swift/Basic/OptionSet.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "llvm/ADT/None.h"
2121

22+
#include <cassert>
2223
#include <type_traits>
2324
#include <cstdint>
2425
#include <initializer_list>
@@ -98,6 +99,14 @@ class OptionSet {
9899
return Storage == set.Storage;
99100
}
100101

102+
/// Check if this option set contains any options from \p set.
103+
///
104+
/// \pre \p set must be non-empty.
105+
bool containsAny(OptionSet set) const {
106+
assert((bool)set && "argument must be non-empty");
107+
return (bool)((*this) & set);
108+
}
109+
101110
// '==' and '!=' are deliberately not defined because they provide a pitfall
102111
// where someone might use '==' but really want 'contains'. If you actually
103112
// want '==' behavior, use 'containsOnly'.

lib/AST/ASTScope.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,6 @@ NullablePtr<ClosureExpr> ASTScopeImpl::getClosureIfClosureScope() const {
9191
return nullptr;
9292
}
9393

94-
// Conservative, because using precise info would be circular
95-
SourceRange
96-
AttachedPropertyWrapperScope::getSourceRangeOfVarDecl(const VarDecl *const vd) {
97-
SourceRange sr;
98-
for (auto *attr : vd->getAttrs().getAttributes<CustomAttr>()) {
99-
if (sr.isInvalid())
100-
sr = attr->getTypeRepr()->getSourceRange();
101-
else
102-
sr.widen(attr->getTypeRepr()->getSourceRange());
103-
}
104-
return sr;
105-
}
106-
10794
SourceManager &ASTScopeImpl::getSourceManager() const {
10895
return getASTContext().SourceMgr;
10996
}
@@ -211,7 +198,6 @@ DEFINE_GET_CLASS_NAME(TopLevelCodeScope)
211198
DEFINE_GET_CLASS_NAME(SpecializeAttributeScope)
212199
DEFINE_GET_CLASS_NAME(DifferentiableAttributeScope)
213200
DEFINE_GET_CLASS_NAME(SubscriptDeclScope)
214-
DEFINE_GET_CLASS_NAME(VarDeclScope)
215201
DEFINE_GET_CLASS_NAME(EnumElementScope)
216202
DEFINE_GET_CLASS_NAME(IfStmtScope)
217203
DEFINE_GET_CLASS_NAME(WhileStmtScope)

0 commit comments

Comments
 (0)