Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2052a42
Use parseDeclNameRef in a few more places
beccadax May 8, 2025
2903835
[NFC] Add DeclNameLoc to specialize/dynamicReplacement
beccadax May 9, 2025
9681117
[NFC] Make ASTDumper more defensive
beccadax Aug 8, 2025
b59d388
[NFC] Tweak source loc of @_implements error
beccadax Aug 12, 2025
3cf4244
[NFC] Make pattern type checking more defensive
beccadax Aug 12, 2025
679c927
[NFC-ish] Do lookahead without llvm::function_ref
beccadax Aug 13, 2025
d2e4867
[NFC] Add tok::colon_colon to parser
beccadax Aug 13, 2025
ab30cc9
Parse module selectors in permitted locations
beccadax Aug 13, 2025
be19784
Allow `::` as an alias for `.` in scoped imports
beccadax May 9, 2025
98a17d6
[NFC] [ASTGen] Don’t form PBDs without SourceLocs
beccadax Aug 6, 2025
fe22d37
Update and test ASTGen for module selectors
beccadax Aug 13, 2025
1a5d37e
Introduce separately-imported stdlib overlays
beccadax Sep 17, 2025
c7394c0
[NFC] Add skeleton of module selector lookup test
beccadax Aug 13, 2025
bbeb979
[NFC] Improve some lookup-related doc comments
beccadax May 10, 2025
a80945c
Make DeclNameRef able to store a module selector
beccadax Sep 11, 2025
e2a6d90
[NFC] Audit some DeclName➡️DeclNameRef conversions
beccadax May 14, 2025
5246c00
Handle module selectors in qualified lookup
beccadax May 9, 2025
57870fc
Root unqualified lookups with module selectors at file scope
beccadax May 15, 2025
8e57a5d
Handle module selectors in unqualified lookup
beccadax May 15, 2025
6a82e35
Handle module selectors in UDRE lookups
beccadax May 13, 2025
d0794b0
Handle module selectors with local vars right
beccadax May 8, 2025
d27cc02
Improve module selector type lookup diagnostics
beccadax Aug 13, 2025
2cd9e81
Improve module selector expr lookup diagnostics
beccadax Aug 13, 2025
f51a6d1
Improve module selector constraint solver diagnostics
beccadax May 15, 2025
ca217e5
Improve module selector @_dynamicReplacement diagnostics
beccadax May 10, 2025
da31d96
Fix lookup into Builtin with module selector
beccadax Aug 20, 2025
a3f7770
[NFC] Pipe PrintDiagnosticNames through swiftinterface loader
beccadax Aug 20, 2025
7a35d1f
[wip] Emit module selectors in swiftinterfaces
beccadax Aug 20, 2025
2d66635
[wip] Support module selectors in ParsedDeclNames
beccadax Aug 26, 2025
2d37acd
Support cross-import overlays for module selectors
beccadax Sep 16, 2025
303480e
Forbid module selectors on dependent member types
beccadax Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions include/swift/AST/ASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,29 @@ class BridgedDeclNameRef {
BRIDGED_INLINE swift::DeclNameRef unbridged() const;
};

SWIFT_NAME("BridgedDeclNameRef.createParsed(_:baseName:argumentLabels:)")
BridgedDeclNameRef BridgedDeclNameRef_createParsed(BridgedASTContext cContext,
swift::DeclBaseName baseName,
BridgedArrayRef cLabels);
SWIFT_NAME("BridgedDeclNameRef.createParsed(_:moduleSelector:baseName:"
"argumentLabels:)")
BridgedDeclNameRef
BridgedDeclNameRef_createParsed(BridgedASTContext cContext,
swift::Identifier cModuleSelector,
swift::DeclBaseName cBaseName,
BridgedArrayRef cLabels);

SWIFT_NAME("BridgedDeclNameRef.createParsed(_:)")
SWIFT_NAME("BridgedDeclNameRef.createParsed(_:moduleSelector:baseName:)")
BridgedDeclNameRef
BridgedDeclNameRef_createParsed(swift::DeclBaseName baseName);
BridgedDeclNameRef_createParsed(BridgedASTContext cContext,
swift::Identifier cModuleSelector,
swift::DeclBaseName cBaseName);

class BridgedDeclNameLoc {
const void *_Nullable LocationInfo;
size_t NumArgumentLabels;
uint32_t NumArgumentLabels;
bool HasModuleSelectorLoc;

public:
BridgedDeclNameLoc() : LocationInfo(nullptr), NumArgumentLabels(0) {}
BridgedDeclNameLoc()
: LocationInfo(nullptr), NumArgumentLabels(0), HasModuleSelectorLoc(false)
{}

BRIDGED_INLINE BridgedDeclNameLoc(swift::DeclNameLoc loc);

Expand Down Expand Up @@ -941,11 +949,12 @@ BridgedDocumentationAttr BridgedDocumentationAttr_createParsed(

SWIFT_NAME(
"BridgedDynamicReplacementAttr.createParsed(_:atLoc:attrNameLoc:lParenLoc:"
"replacedFunction:rParenLoc:)")
"replacedFunction:replacedFunctionLoc:rParenLoc:)")
BridgedDynamicReplacementAttr BridgedDynamicReplacementAttr_createParsed(
BridgedASTContext cContext, swift::SourceLoc atLoc,
swift::SourceLoc attrNameLoc, swift::SourceLoc lParenLoc,
BridgedDeclNameRef cReplacedFunction, swift::SourceLoc rParenLoc);
BridgedASTContext cContext, swift::SourceLoc cAtLoc,
swift::SourceLoc cAttrNameLoc, swift::SourceLoc cLParenLoc,
BridgedDeclNameRef cReplacedFunction,
BridgedDeclNameLoc cReplacedFunctionLoc, swift::SourceLoc cRParenLoc);

SWIFT_NAME("BridgedEffectsAttr.createParsed(_:atLoc:range:effectKind:)")
BridgedEffectsAttr BridgedEffectsAttr_createParsed(
Expand Down Expand Up @@ -1276,22 +1285,24 @@ enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedSpecializationKind : uint8_t {
};

SWIFT_NAME("BridgedSpecializeAttr.createParsed(_:atLoc:range:whereClause:"
"exported:kind:taretFunction:spiGroups:availableAttrs:)")
"exported:kind:targetFunction:targetFunctionLoc:spiGroups:"
"availableAttrs:)")
BridgedSpecializeAttr BridgedSpecializeAttr_createParsed(
BridgedASTContext cContext, swift::SourceLoc atLoc,
swift::SourceRange range, BridgedNullableTrailingWhereClause cWhereClause,
bool exported, BridgedSpecializationKind cKind,
BridgedDeclNameRef cTargetFunction, BridgedArrayRef cSPIGroups,
BridgedArrayRef cAvailableAttrs);
BridgedDeclNameRef cTargetFunction, BridgedDeclNameLoc cTargetFunctionLoc,
BridgedArrayRef cSPIGroups, BridgedArrayRef cAvailableAttrs);

SWIFT_NAME("BridgedSpecializedAttr.createParsed(_:atLoc:range:whereClause:"
"exported:kind:taretFunction:spiGroups:availableAttrs:)")
"exported:kind:targetFunction:targetFunctionLoc:spiGroups:"
"availableAttrs:)")
BridgedSpecializedAttr BridgedSpecializedAttr_createParsed(
BridgedASTContext cContext, swift::SourceLoc atLoc,
swift::SourceRange range, BridgedNullableTrailingWhereClause cWhereClause,
bool exported, BridgedSpecializationKind cKind,
BridgedDeclNameRef cTargetFunction, BridgedArrayRef cSPIGroups,
BridgedArrayRef cAvailableAttrs);
BridgedDeclNameRef cTargetFunction, BridgedDeclNameLoc cTargetFunctionLoc,
BridgedArrayRef cSPIGroups, BridgedArrayRef cAvailableAttrs);

SWIFT_NAME(
"BridgedSPIAccessControlAttr.createParsed(_:atLoc:range:spiGroupName:)")
Expand Down Expand Up @@ -2544,9 +2555,10 @@ BridgedOpaqueReturnTypeOfTypeAttr_createParsed(
// MARK: TypeReprs
//===----------------------------------------------------------------------===//

SWIFT_NAME("BridgedUnqualifiedIdentTypeRepr.createParsed(_:loc:name:)")
SWIFT_NAME("BridgedUnqualifiedIdentTypeRepr.createParsed(_:name:loc:)")
BridgedUnqualifiedIdentTypeRepr BridgedUnqualifiedIdentTypeRepr_createParsed(
BridgedASTContext cContext, swift::SourceLoc loc, swift::Identifier id);
BridgedASTContext cContext, BridgedDeclNameRef cName,
BridgedDeclNameLoc cLoc);

SWIFT_NAME(
"BridgedArrayTypeRepr.createParsed(_:base:leftSquareLoc:rightSquareLoc:)")
Expand Down Expand Up @@ -2580,8 +2592,8 @@ BridgedCompileTimeLiteralTypeRepr_createParsed(BridgedASTContext cContext,
SWIFT_NAME("BridgedDeclRefTypeRepr.createParsed(_:base:name:nameLoc:"
"genericArguments:angleRange:)")
BridgedDeclRefTypeRepr BridgedDeclRefTypeRepr_createParsed(
BridgedASTContext cContext, BridgedTypeRepr cBase, swift::Identifier name,
swift::SourceLoc loc, BridgedArrayRef cGenericArguments,
BridgedASTContext cContext, BridgedTypeRepr cBase, BridgedDeclNameRef cName,
BridgedDeclNameLoc cLoc, BridgedArrayRef cGenericArguments,
swift::SourceRange angleRange);

SWIFT_NAME("BridgedDictionaryTypeRepr.createParsed(_:leftSquareLoc:keyType:"
Expand All @@ -2606,8 +2618,8 @@ BridgedFunctionTypeRepr BridgedFunctionTypeRepr_createParsed(
SWIFT_NAME("BridgedUnqualifiedIdentTypeRepr.createParsed(_:name:nameLoc:"
"genericArgs:leftAngleLoc:rightAngleLoc:)")
BridgedUnqualifiedIdentTypeRepr BridgedUnqualifiedIdentTypeRepr_createParsed(
BridgedASTContext cContext, swift::Identifier name,
swift::SourceLoc nameLoc, BridgedArrayRef genericArgs,
BridgedASTContext cContext, BridgedDeclNameRef cName,
BridgedDeclNameLoc cNameLoc, BridgedArrayRef genericArgs,
swift::SourceLoc lAngleLoc, swift::SourceLoc rAngleLoc);

SWIFT_NAME("BridgedOptionalTypeRepr.createParsed(_:base:questionLoc:)")
Expand Down
6 changes: 4 additions & 2 deletions include/swift/AST/ASTBridgingImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ swift::DeclNameRef BridgedDeclNameRef::unbridged() const {

BridgedDeclNameLoc::BridgedDeclNameLoc(swift::DeclNameLoc loc)
: LocationInfo(loc.LocationInfo),
NumArgumentLabels(loc.NumArgumentLabels) {}
NumArgumentLabels(loc.NumArgumentLabels),
HasModuleSelectorLoc(loc.HasModuleSelectorLoc) {}

swift::DeclNameLoc BridgedDeclNameLoc::unbridged() const {
return swift::DeclNameLoc(LocationInfo, NumArgumentLabels);
return swift::DeclNameLoc(LocationInfo, NumArgumentLabels,
HasModuleSelectorLoc);
}

//===----------------------------------------------------------------------===//
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,10 @@ class ASTContext final {
return const_cast<ASTContext *>(this)->getStdlibModule(false);
}

/// Names of underscored modules whose contents, if imported, should be
/// treated as separately-imported overlays of the standard library module.
Identifier StdlibOverlayNames[2];

/// Insert an externally-sourced module into the set of known loaded modules
/// in this context.
void addLoadedModule(ModuleDecl *M);
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/AccessNotes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class AccessNoteDeclName {
public:
/// The names of the parent/contextual declarations containing the declaration
/// the access note should apply to.
std::vector<Identifier> parentNames;
std::vector<DeclNameRef> parentNames;

/// The name of the declaration the access note should be applied to. (For
/// accessors, this is actually the name of the storage it's attached to.)
DeclName name;
DeclNameRef name;

/// For accessors, the kind of accessor; for non-accessors, \c None.
std::optional<AccessorKind> accessorKind;
Expand Down
45 changes: 34 additions & 11 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1253,19 +1253,22 @@ class DynamicReplacementAttr final
friend class DynamicallyReplacedDeclRequest;

DeclNameRef ReplacedFunctionName;
DeclNameLoc ReplacedFunctionNameLoc;
LazyMemberLoader *Resolver = nullptr;
uint64_t ResolverContextData;

/// Create an @_dynamicReplacement(for:) attribute written in the source.
DynamicReplacementAttr(SourceLoc atLoc, SourceRange baseRange,
DeclNameRef replacedFunctionName,
DeclNameLoc replacedFunctionNameLoc,
SourceRange parenRange);

DynamicReplacementAttr(DeclNameRef name, AbstractFunctionDecl *f)
: DeclAttribute(DeclAttrKind::DynamicReplacement, SourceLoc(),
SourceRange(),
/*Implicit=*/false),
ReplacedFunctionName(name), Resolver(nullptr), ResolverContextData(0) {
ReplacedFunctionName(name), ReplacedFunctionNameLoc(),
Resolver(nullptr), ResolverContextData(0) {
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
}

Expand All @@ -1274,8 +1277,8 @@ class DynamicReplacementAttr final
: DeclAttribute(DeclAttrKind::DynamicReplacement, SourceLoc(),
SourceRange(),
/*Implicit=*/false),
ReplacedFunctionName(name), Resolver(Resolver),
ResolverContextData(Data) {
ReplacedFunctionName(name), ReplacedFunctionNameLoc(),
Resolver(Resolver), ResolverContextData(Data) {
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
}

Expand All @@ -1296,7 +1299,8 @@ class DynamicReplacementAttr final
public:
static DynamicReplacementAttr *
create(ASTContext &Context, SourceLoc AtLoc, SourceLoc DynReplLoc,
SourceLoc LParenLoc, DeclNameRef replacedFunction, SourceLoc RParenLoc);
SourceLoc LParenLoc, DeclNameRef replacedFunction,
DeclNameLoc replacedFunctionNameLoc, SourceLoc RParenLoc);

static DynamicReplacementAttr *create(ASTContext &ctx,
DeclNameRef replacedFunction,
Expand All @@ -1311,6 +1315,10 @@ class DynamicReplacementAttr final
return ReplacedFunctionName;
}

DeclNameLoc getReplacedFunctionNameLoc() const {
return ReplacedFunctionNameLoc;
}

/// Retrieve the location of the opening parentheses, if there is one.
SourceLoc getLParenLoc() const;

Expand Down Expand Up @@ -1800,6 +1808,7 @@ class AbstractSpecializeAttr
GenericSignature specializedSignature;

DeclNameRef targetFunctionName;
DeclNameLoc targetFunctionNameLoc;
LazyMemberLoader *resolver = nullptr;
uint64_t resolverContextData;
size_t numSPIGroups;
Expand All @@ -1812,7 +1821,9 @@ class AbstractSpecializeAttr
TrailingWhereClause *clause,
bool exported,
SpecializationKind kind, GenericSignature specializedSignature,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName,
DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
size_t typeErasedParamsCount);

Expand Down Expand Up @@ -1896,6 +1907,10 @@ class AbstractSpecializeAttr
return targetFunctionName;
}

DeclNameLoc getTargetFunctionNameLoc() const {
return targetFunctionNameLoc;
}

/// \p forDecl is the value decl that the attribute belongs to.
ValueDecl *getTargetFunctionDecl(const ValueDecl *forDecl) const;

Expand Down Expand Up @@ -1925,19 +1940,23 @@ class SpecializeAttr final : public AbstractSpecializeAttr,
TrailingWhereClause *clause,
bool exported,
SpecializationKind kind, GenericSignature specializedSignature,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName,
DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
size_t typeErasedParamsCount) :
AbstractSpecializeAttr(DeclAttrKind::Specialize, atLoc, Range, clause,
exported, kind, specializedSignature, targetFunctionName,
spiGroups, availabilityAttrs, typeErasedParamsCount) {}
targetFunctionNameLoc, spiGroups, availabilityAttrs,
typeErasedParamsCount) {}

public:
static SpecializeAttr *
create(ASTContext &Ctx, SourceLoc atLoc, SourceRange Range,
TrailingWhereClause *clause, bool exported,
SpecializationKind kind,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName, DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
GenericSignature specializedSignature = nullptr);

Expand Down Expand Up @@ -1981,19 +2000,23 @@ class SpecializedAttr final : public AbstractSpecializeAttr ,
TrailingWhereClause *clause,
bool exported,
SpecializationKind kind, GenericSignature specializedSignature,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName,
DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
size_t typeErasedParamsCount) :
AbstractSpecializeAttr(DeclAttrKind::Specialized, atLoc, Range, clause,
exported, kind, specializedSignature, targetFunctionName,
spiGroups, availabilityAttrs, typeErasedParamsCount) {}
targetFunctionNameLoc, spiGroups, availabilityAttrs,
typeErasedParamsCount) {}

public:
static SpecializedAttr *
create(ASTContext &Ctx, SourceLoc atLoc, SourceRange Range,
TrailingWhereClause *clause, bool exported,
SpecializationKind kind,
DeclNameRef targetFunctionName, ArrayRef<Identifier> spiGroups,
DeclNameRef targetFunctionName, DeclNameLoc targetFunctionNameLoc,
ArrayRef<Identifier> spiGroups,
ArrayRef<AvailableAttr *> availabilityAttrs,
GenericSignature specializedSignature = nullptr);

Expand Down
9 changes: 4 additions & 5 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3062,11 +3062,10 @@ class ValueDecl : public Decl {
return Name.getBaseIdentifier();
}

/// Generates a DeclNameRef referring to this declaration with as much
/// specificity as possible.
DeclNameRef createNameRef() const {
return DeclNameRef(Name);
}
/// Generates a DeclNameRef referring to this declaration.
///
/// \param moduleSelector If true, the name ref includes the module name.
DeclNameRef createNameRef(bool moduleSelector = false) const;

/// Retrieve the C declaration name that names this function, or empty
/// string if it has none.
Expand Down
Loading