Skip to content

Commit 36de3a8

Browse files
authored
Merge pull request #81459 from beccadax/mod-squad-serialize
2 parents f2ef2d3 + b6be852 commit 36de3a8

18 files changed

+255
-138
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,23 @@ BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
215215
BridgedSourceLoc cLParenLoc, BridgedArrayRef cLabelLocs,
216216
BridgedSourceLoc cRParenLoc);
217217

218+
SWIFT_NAME("BridgedDeclNameLoc.createParsed(_:moduleSelectorLoc:baseNameLoc:"
219+
"lParenLoc:argumentLabelLocs:rParenLoc:)")
220+
BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
221+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
222+
BridgedSourceLoc cBaseNameLoc, BridgedSourceLoc cLParenLoc,
223+
BridgedArrayRef cLabelLocs, BridgedSourceLoc cRParenLoc);
224+
218225
SWIFT_NAME("BridgedDeclNameLoc.createParsed(_:)")
219226
BridgedDeclNameLoc
220227
BridgedDeclNameLoc_createParsed(BridgedSourceLoc cBaseNameLoc);
221228

229+
SWIFT_NAME("BridgedDeclNameLoc.createParsed(_:moduleSelectorLoc:baseNameLoc:)")
230+
BridgedDeclNameLoc
231+
BridgedDeclNameLoc_createParsed(
232+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
233+
BridgedSourceLoc cBaseNameLoc);
234+
222235
//===----------------------------------------------------------------------===//
223236
// MARK: ASTContext
224237
//===----------------------------------------------------------------------===//

include/swift/AST/DeclNameLoc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "swift/Basic/LLVM.h"
2121
#include "swift/Basic/SourceLoc.h"
2222

23+
#include "llvm/ADT/ArrayRef.h"
24+
2325
class BridgedDeclNameLoc;
2426

2527
namespace swift {
@@ -71,13 +73,24 @@ class DeclNameLoc {
7173
explicit DeclNameLoc(SourceLoc baseNameLoc)
7274
: DeclNameLoc(baseNameLoc.getOpaquePointerValue(), 0) {}
7375

76+
explicit DeclNameLoc(ASTContext &ctx, SourceLoc moduleSelectorLoc,
77+
SourceLoc baseNameLoc)
78+
: DeclNameLoc(baseNameLoc) { }
79+
7480
/// Create declaration name location information for a compound
7581
/// name.
7682
DeclNameLoc(ASTContext &ctx, SourceLoc baseNameLoc,
7783
SourceLoc lParenLoc,
7884
ArrayRef<SourceLoc> argumentLabelLocs,
7985
SourceLoc rParenLoc);
8086

87+
DeclNameLoc(ASTContext &ctx, SourceLoc moduleSelectorLoc,
88+
SourceLoc baseNameLoc,
89+
SourceLoc lParenLoc,
90+
ArrayRef<SourceLoc> argumentLabelLocs,
91+
SourceLoc rParenLoc)
92+
: DeclNameLoc(ctx, baseNameLoc, lParenLoc, argumentLabelLocs, rParenLoc) { }
93+
8194
/// Whether the location information is valid.
8295
bool isValid() const { return getBaseNameLoc().isValid(); }
8396

@@ -111,6 +124,10 @@ class DeclNameLoc {
111124
return getSourceLocs()[FirstArgumentLabelIndex + index];
112125
}
113126

127+
SourceLoc getModuleSelectorLoc() const {
128+
return SourceLoc();
129+
}
130+
114131
SourceLoc getStartLoc() const {
115132
return getBaseNameLoc();
116133
}

include/swift/AST/Identifier.h

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -693,65 +693,73 @@ class DeclNameRef {
693693
void *getOpaqueValue() const { return FullName.getOpaqueValue(); }
694694
static DeclNameRef getFromOpaqueValue(void *p);
695695

696+
explicit DeclNameRef(ASTContext &C, Identifier moduleSelector,
697+
DeclName fullName)
698+
: FullName(fullName) { }
699+
700+
explicit DeclNameRef(ASTContext &C, Identifier moduleSelector,
701+
DeclBaseName baseName, ArrayRef<Identifier> argLabels)
702+
: FullName(C, baseName, argLabels) { }
703+
696704
explicit DeclNameRef(DeclName FullName)
697705
: FullName(FullName) { }
698706

699-
explicit DeclNameRef(DeclBaseName BaseName)
700-
: FullName(BaseName) { }
707+
bool hasModuleSelector() const {
708+
return false;
709+
}
701710

702-
explicit DeclNameRef(Identifier BaseName)
703-
: FullName(BaseName) { }
711+
Identifier getModuleSelector() const {
712+
return Identifier();
713+
}
704714

705715
/// The name of the declaration being referenced.
706716
DeclName getFullName() const {
707717
return FullName;
708718
}
709719

710-
DeclName &getFullName() {
711-
return FullName;
712-
}
713-
714720
/// The base name of the declaration being referenced.
715721
DeclBaseName getBaseName() const {
716-
return FullName.getBaseName();
722+
return getFullName().getBaseName();
717723
}
718724

719725
Identifier getBaseIdentifier() const {
720-
return FullName.getBaseIdentifier();
726+
return getFullName().getBaseIdentifier();
721727
}
722728

723729
ArrayRef<Identifier> getArgumentNames() const {
724-
return FullName.getArgumentNames();
730+
return getFullName().getArgumentNames();
725731
}
726732

727733
bool isSimpleName() const {
728-
return FullName.isSimpleName();
734+
return getFullName().isSimpleName();
729735
}
730736

731737
bool isSimpleName(DeclBaseName name) const {
732-
return FullName.isSimpleName(name);
738+
return getFullName().isSimpleName(name);
733739
}
734740

735741
bool isSimpleName(StringRef name) const {
736-
return FullName.isSimpleName(name);
742+
return getFullName().isSimpleName(name);
737743
}
738744

739745
bool isSpecial() const {
740-
return FullName.isSpecial();
746+
return getFullName().isSpecial();
741747
}
742748

743749
bool isOperator() const {
744-
return FullName.isOperator();
750+
return getFullName().isOperator();
745751
}
746752

747-
bool mustAlwaysBeEscaped() const { return FullName.mustAlwaysBeEscaped(); }
753+
bool mustAlwaysBeEscaped() const {
754+
return getFullName().mustAlwaysBeEscaped();
755+
}
748756

749757
bool isCompoundName() const {
750-
return FullName.isCompoundName();
758+
return getFullName().isCompoundName();
751759
}
752760

753761
explicit operator bool() const {
754-
return (bool)FullName;
762+
return (bool)getFullName();
755763
}
756764

757765
/// Compare two declaration names, producing -1 if \c *this comes before
@@ -791,7 +799,7 @@ class DeclNameRef {
791799
return lhs.compare(rhs) >= 0;
792800
}
793801

794-
DeclNameRef withoutArgumentLabels() const;
802+
DeclNameRef withoutArgumentLabels(ASTContext &C) const;
795803
DeclNameRef withArgumentLabels(ASTContext &C,
796804
ArrayRef<Identifier> argumentNames) const;
797805

@@ -824,16 +832,15 @@ inline DeclNameRef DeclNameRef::getFromOpaqueValue(void *p) {
824832
return DeclNameRef(DeclName::getFromOpaqueValue(p));
825833
}
826834

827-
inline DeclNameRef DeclNameRef::withoutArgumentLabels() const {
828-
return DeclNameRef(getBaseName());
835+
inline DeclNameRef DeclNameRef::withoutArgumentLabels(ASTContext &C) const {
836+
return DeclNameRef(C, getModuleSelector(), getBaseName());
829837
}
830838

831839
inline DeclNameRef DeclNameRef::withArgumentLabels(
832840
ASTContext &C, ArrayRef<Identifier> argumentNames) const {
833-
return DeclNameRef(DeclName(C, getBaseName(), argumentNames));
841+
return DeclNameRef(C, getModuleSelector(), getBaseName(), argumentNames);
834842
}
835843

836-
837844
inline DeclNameRef DeclNameRef::createSubscript() {
838845
return DeclNameRef(DeclBaseName::createSubscript());
839846
}

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ EXPERIMENTAL_FEATURE(CDecl, false)
508508
/// Allow use of `@extensible` on public enums
509509
SUPPRESSIBLE_EXPERIMENTAL_FEATURE(ExtensibleAttribute, false)
510510

511+
/// Allow use of `Module::name` syntax
512+
EXPERIMENTAL_FEATURE(ModuleSelector, false)
513+
511514
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
512515
#undef EXPERIMENTAL_FEATURE
513516
#undef UPCOMING_FEATURE

lib/AST/Bridging/DeclBridging.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,23 @@ BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
7070
BridgedASTContext cContext, BridgedSourceLoc cBaseNameLoc,
7171
BridgedSourceLoc cLParenLoc, BridgedArrayRef cLabelLocs,
7272
BridgedSourceLoc cRParenLoc) {
73+
return BridgedDeclNameLoc_createParsed(
74+
cContext, BridgedSourceLoc(), cBaseNameLoc, cLParenLoc, cLabelLocs,
75+
cRParenLoc);
76+
}
77+
78+
BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
79+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
80+
BridgedSourceLoc cBaseNameLoc, BridgedSourceLoc cLParenLoc,
81+
BridgedArrayRef cLabelLocs, BridgedSourceLoc cRParenLoc) {
7382

7483
ASTContext &context = cContext.unbridged();
7584
SmallVector<SourceLoc, 4> labelLocs;
7685
for (auto &cLabelLoc : cLabelLocs.unbridged<BridgedSourceLoc>())
7786
labelLocs.push_back(cLabelLoc.unbridged());
7887

79-
return DeclNameLoc(context, cBaseNameLoc.unbridged(), cLParenLoc.unbridged(),
88+
return DeclNameLoc(context, cModuleSelectorLoc.unbridged(),
89+
cBaseNameLoc.unbridged(), cLParenLoc.unbridged(),
8090
labelLocs, cRParenLoc.unbridged());
8191
}
8292

@@ -85,6 +95,14 @@ BridgedDeclNameLoc_createParsed(BridgedSourceLoc cBaseNameLoc) {
8595
return DeclNameLoc(cBaseNameLoc.unbridged());
8696
}
8797

98+
BridgedDeclNameLoc
99+
BridgedDeclNameLoc_createParsed(
100+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
101+
BridgedSourceLoc cBaseNameLoc) {
102+
return DeclNameLoc(cContext.unbridged(), cModuleSelectorLoc.unbridged(),
103+
cBaseNameLoc.unbridged());
104+
}
105+
88106
//===----------------------------------------------------------------------===//
89107
// MARK: Decls
90108
//===----------------------------------------------------------------------===//

lib/AST/FeatureSet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ UNINTERESTING_FEATURE(MacrosOnImports)
126126
UNINTERESTING_FEATURE(NonisolatedNonsendingByDefault)
127127
UNINTERESTING_FEATURE(KeyPathWithMethodMembers)
128128

129+
// TODO: Return true for inlinable function bodies with module selectors in them
130+
UNINTERESTING_FEATURE(ModuleSelector)
131+
129132
static bool usesFeatureNonescapableTypes(Decl *decl) {
130133
auto containsNonEscapable =
131134
[](SmallVectorImpl<InverseRequirement> &inverseReqs) {

lib/AST/Identifier.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void swift::simple_display(llvm::raw_ostream &out, DeclName name) {
5555
}
5656

5757
raw_ostream &llvm::operator<<(raw_ostream &OS, DeclNameRef I) {
58+
if (I.hasModuleSelector())
59+
OS << I.getModuleSelector() << "::";
5860
OS << I.getFullName();
5961
return OS;
6062
}
@@ -208,17 +210,27 @@ void DeclNameRef::dump() const {
208210
}
209211

210212
StringRef DeclNameRef::getString(llvm::SmallVectorImpl<char> &scratch,
211-
bool skipEmptyArgumentNames) const {
212-
return FullName.getString(scratch, skipEmptyArgumentNames);
213+
bool skipEmptyArgumentNames) const {
214+
{
215+
llvm::raw_svector_ostream out(scratch);
216+
print(out, skipEmptyArgumentNames);
217+
}
218+
219+
return StringRef(scratch.data(), scratch.size());
213220
}
214221

215-
llvm::raw_ostream &DeclNameRef::print(llvm::raw_ostream &os,
216-
bool skipEmptyArgumentNames) const {
217-
return FullName.print(os, skipEmptyArgumentNames);
222+
llvm::raw_ostream &
223+
DeclNameRef::print(llvm::raw_ostream &os,
224+
bool skipEmptyArgumentNames) const {
225+
if (hasModuleSelector())
226+
os << getModuleSelector() << "::";
227+
return getFullName().print(os, skipEmptyArgumentNames);
218228
}
219229

220230
llvm::raw_ostream &DeclNameRef::printPretty(llvm::raw_ostream &os) const {
221-
return FullName.printPretty(os);
231+
if (hasModuleSelector())
232+
os << getModuleSelector() << "::";
233+
return getFullName().printPretty(os);
222234
}
223235

224236
ObjCSelector::ObjCSelector(ASTContext &ctx, unsigned numArgs,

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,8 +4449,9 @@ bool MissingMemberFailure::diagnoseAsError() {
44494449
auto &cs = getConstraintSystem();
44504450

44514451
auto result = cs.performMemberLookup(
4452-
ConstraintKind::ValueMember, getName().withoutArgumentLabels(),
4453-
metatypeTy, FunctionRefInfo::doubleBaseNameApply(), getLocator(),
4452+
ConstraintKind::ValueMember,
4453+
getName().withoutArgumentLabels(getASTContext()), metatypeTy,
4454+
FunctionRefInfo::doubleBaseNameApply(), getLocator(),
44544455
/*includeInaccessibleMembers=*/true);
44554456

44564457
// If there are no `init` members at all produce a tailored

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8389,9 +8389,10 @@ ValueDecl *RenamedDeclRequest::evaluate(Evaluator &evaluator,
83898389
if (attr->Rename.empty())
83908390
return nullptr;
83918391

8392+
auto &ctx = attached->getASTContext();
83928393
auto attachedContext = attached->getDeclContext();
83938394
auto parsedName = parseDeclName(attr->Rename);
8394-
auto nameRef = parsedName.formDeclNameRef(attached->getASTContext());
8395+
auto nameRef = parsedName.formDeclNameRef(ctx);
83958396

83968397
// Handle types separately
83978398
if (isa<NominalTypeDecl>(attached)) {
@@ -8400,7 +8401,7 @@ ValueDecl *RenamedDeclRequest::evaluate(Evaluator &evaluator,
84008401

84018402
SmallVector<ValueDecl *, 1> lookupResults;
84028403
attachedContext->lookupQualified(attachedContext->getParentModule(),
8403-
nameRef.withoutArgumentLabels(),
8404+
nameRef.withoutArgumentLabels(ctx),
84048405
attr->getLocation(), NL_OnlyTypes,
84058406
lookupResults);
84068407
if (lookupResults.size() == 1)

lib/Sema/TypeCheckPattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static EnumElementDecl *
138138
lookupUnqualifiedEnumMemberElement(DeclContext *DC, DeclNameRef name,
139139
SourceLoc UseLoc) {
140140
// FIXME: We should probably pay attention to argument labels someday.
141-
name = name.withoutArgumentLabels();
141+
name = name.withoutArgumentLabels(DC->getASTContext());
142142

143143
auto lookup =
144144
TypeChecker::lookupUnqualified(DC, name, UseLoc,
@@ -153,7 +153,7 @@ static LookupResult lookupMembers(DeclContext *DC, Type ty, DeclNameRef name,
153153
return LookupResult();
154154

155155
// FIXME: We should probably pay attention to argument labels someday.
156-
name = name.withoutArgumentLabels();
156+
name = name.withoutArgumentLabels(DC->getASTContext());
157157

158158
// Look up the case inside the enum.
159159
// FIXME: We should be able to tell if this is a private lookup.

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ swift::lookupValueWitnesses(DeclContext *DC, ValueDecl *req, bool *ignoringNames
14891489
lookupValueWitnessesViaImplementsAttr(DC, req, witnesses);
14901490

14911491
auto reqName = req->createNameRef();
1492-
auto reqBaseName = reqName.withoutArgumentLabels();
1492+
auto reqBaseName = reqName.withoutArgumentLabels(DC->getASTContext());
14931493

14941494
// An operator function is the only kind of witness that requires global
14951495
// lookup. However, because global lookup doesn't enter local contexts,

lib/Serialization/DeclTypeRecordNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ OTHER(DERIVATIVE_FUNCTION_CONFIGURATION, 154)
213213

214214
OTHER(ERROR_FLAG, 155)
215215
OTHER(ABI_ONLY_COUNTERPART, 156)
216+
OTHER(DECL_NAME_REF, 157)
216217

217218
TRAILING_INFO(CONDITIONAL_SUBSTITUTION)
218219
TRAILING_INFO(CONDITIONAL_SUBSTITUTION_COND)
219220

220221
OTHER(LIFETIME_DEPENDENCE, 160)
221-
222222
TRAILING_INFO(INHERITED_PROTOCOLS)
223223

224224
#ifndef DECL_ATTR

0 commit comments

Comments
 (0)