Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ed76647
Use parseDeclNameRef in a few more places
beccadax May 8, 2025
3534654
[NFC] Add DeclNameLoc to specialize/dynamicReplacement
beccadax May 9, 2025
3b9e0ee
[NFC] Make ASTDumper more defensive
beccadax Aug 8, 2025
fb0461b
[NFC] Tweak source loc of @_implements error
beccadax Aug 12, 2025
99213ac
[NFC] Make pattern type checking more defensive
beccadax Aug 12, 2025
9a98834
[NFC-ish] Do lookahead without llvm::function_ref
beccadax Aug 13, 2025
53d7406
[NFC] Add tok::colon_colon to parser
beccadax Aug 13, 2025
8499baa
Parse module selectors in permitted locations
beccadax Aug 13, 2025
430104b
Allow `::` as an alias for `.` in scoped imports
beccadax May 9, 2025
687f347
[NFC] [ASTGen] Don’t form PBDs without SourceLocs
beccadax Aug 6, 2025
ea6f661
Update and test ASTGen for module selectors
beccadax Aug 13, 2025
3d52834
[NFC] Add skeleton of module selector lookup test
beccadax Aug 13, 2025
977b8a7
[NFC] Improve some lookup-related doc comments
beccadax May 10, 2025
3d449c5
[NFC] Add representations for DeclNameRef/Loc with module selector
beccadax May 10, 2025
e8e3346
[NFC] Audit some DeclName➡️DeclNameRef conversions
beccadax May 14, 2025
6608d38
Handle module selectors in qualified lookup
beccadax May 9, 2025
c2dedb0
Root unqualified lookups with module selectors at file scope
beccadax May 15, 2025
f31ab47
Handle module selectors in unqualified lookup
beccadax May 15, 2025
c754d06
Handle module selectors in UDRE lookups
beccadax May 13, 2025
c13cbda
FIXME operators unexpectedly passing
beccadax May 15, 2025
ca3b6d1
Handle module selectors with local vars right
beccadax May 8, 2025
b7e1b70
Improve module selector type lookup diagnostics
beccadax Aug 13, 2025
d9c83ac
Improve module selector expr lookup diagnostics
beccadax Aug 13, 2025
2e84375
Improve module selector constraint solver diagnostics
beccadax May 15, 2025
fb6e7e7
Improve module selector @_dynamicReplacement diagnostics
beccadax May 10, 2025
804ee6b
[NFC] Pipe PrintDiagnosticNames through swiftinterface loader
beccadax Aug 20, 2025
1c737e0
Fix lookup into Builtin with module selector
beccadax Aug 20, 2025
35f9aa7
[wip] Emit module selectors in swiftinterfaces
beccadax Aug 20, 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
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 @@ -3038,11 +3038,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