Skip to content

Commit 230dd86

Browse files
authored
Merge pull request #9970 from jrose-apple/pdm-most
Per-library preparations for removal of getName on ValueDecl
2 parents 325a969 + 8946015 commit 230dd86

25 files changed

+126
-110
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,11 +2942,13 @@ void ClangImporter::Implementation::lookupValue(
29422942
decl = cast_or_null<ValueDecl>(
29432943
importDeclReal(clangDecl->getMostRecentDecl(), CurrentVersion));
29442944
if (!decl) continue;
2945-
} else {
2945+
} else if (!name.isSpecial()) {
29462946
// Try to import a macro.
29472947
auto clangMacro = entry.get<clang::MacroInfo *>();
29482948
decl = importMacro(name.getBaseIdentifier(), clangMacro);
29492949
if (!decl) continue;
2950+
} else {
2951+
continue;
29502952
}
29512953

29522954
// If we found a declaration from the standard library, make sure

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,8 @@ namespace {
27712771
// context.
27722772
if (errorWrapper) {
27732773
auto enumeratorValue = cast<ValueDecl>(enumeratorDecl);
2774-
auto alias = importEnumCaseAlias(enumeratorValue->getName(),
2774+
auto name = enumeratorValue->getBaseName().getIdentifier();
2775+
auto alias = importEnumCaseAlias(name,
27752776
constant,
27762777
enumeratorValue,
27772778
decl,

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static bool shouldHideDeclFromCompletionResults(const ValueDecl *D) {
300300
}
301301

302302
// Hide editor placeholders.
303-
if (D->getName().isEditorPlaceholder())
303+
if (D->getBaseName().isEditorPlaceholder())
304304
return true;
305305

306306
if (!D->isUserAccessible())
@@ -4268,17 +4268,10 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
42684268
Builder.addBraceStmtWithCursor();
42694269
}
42704270

4271-
llvm::StringSet<> SatisfiedAssociatedTypes;
4272-
42734271
// Implement swift::VisibleDeclConsumer.
42744272
void foundDecl(ValueDecl *D, DeclVisibilityKind Reason) override {
4275-
if (Reason == DeclVisibilityKind::MemberOfCurrentNominal) {
4276-
if (isa<TypeAliasDecl>(D)) {
4277-
auto *VD = dyn_cast<ValueDecl>(D);
4278-
SatisfiedAssociatedTypes.insert(VD->getName().str());
4279-
}
4273+
if (Reason == DeclVisibilityKind::MemberOfCurrentNominal)
42804274
return;
4281-
}
42824275

42834276
if (shouldHideDeclFromCompletionResults(D))
42844277
return;
@@ -5118,7 +5111,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
51185111
Lookup.setIsStaticMetatype(ParsedExpr->isStaticallyDerivedMetatype());
51195112
}
51205113
if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(ParsedExpr)) {
5121-
Lookup.setIsSelfRefExpr(DRE->getDecl()->getName() == Context.Id_self);
5114+
Lookup.setIsSelfRefExpr(DRE->getDecl()->getFullName() == Context.Id_self);
51225115
}
51235116

51245117
if (isInsideObjCSelector())

lib/IDE/IDETypeChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ collectDefaultImplementationForProtocolMembers(ProtocolDecl *PD,
3232
continue;
3333

3434
// Skip decls with empty names, e.g. setter/getters for properties.
35-
if (VD->getName().empty())
35+
if (VD->getBaseName().empty())
3636
continue;
3737

3838
ResolvedMemberResult Result = resolveValueMember(*DC, BaseTy,

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ void swift::ide::printSubmoduleInterface(
480480
auto *RHSValue = dyn_cast<ValueDecl>(RHS);
481481

482482
if (LHSValue && RHSValue) {
483-
StringRef LHSName = LHSValue->getName().str();
484-
StringRef RHSName = RHSValue->getName().str();
483+
auto LHSName = LHSValue->getBaseName();
484+
auto RHSName = RHSValue->getBaseName();
485485
if (int Ret = LHSName.compare(RHSName))
486486
return Ret < 0;
487487
// FIXME: this is not sufficient to establish a total order for overloaded

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,8 @@ void swift::ide::getLocationInfo(const ValueDecl *VD,
10071007
NameLen = getCharLength(SM, R);
10081008
} else {
10091009
if (VD->hasName()) {
1010-
NameLen = VD->getName().getLength();
1010+
// TODO: Handle special names
1011+
NameLen = VD->getBaseName().getIdentifier().getLength();
10111012
} else {
10121013
NameLen = getCharLength(SM, VD->getLoc());
10131014
}

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ void Parser::setLocalDiscriminator(ValueDecl *D) {
20522052
if (!getScopeInfo().isInactiveConfigBlock())
20532053
SF.LocalTypeDecls.insert(TD);
20542054

2055-
Identifier name = D->getName();
2055+
Identifier name = D->getBaseName().getIdentifier();
20562056
unsigned discriminator = CurLocalContext->claimNextNamedDiscriminator(name);
20572057
D->setLocalDiscriminator(discriminator);
20582058
}

lib/Parse/ParseType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
413413
bool walkToTypeReprPre(TypeRepr *T) override {
414414
if (auto ident = dyn_cast<ComponentIdentTypeRepr>(T)) {
415415
if (auto decl = ident->getBoundDecl()) {
416-
if (isa<GenericTypeParamDecl>(decl))
417-
ident->overwriteIdentifier(decl->getName());
416+
if (auto genericParam = dyn_cast<GenericTypeParamDecl>(decl))
417+
ident->overwriteIdentifier(genericParam->getName());
418418
}
419419
}
420420
return true;

lib/Parse/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ void Parser::diagnoseRedefinition(ValueDecl *Prev, ValueDecl *New) {
770770
assert(New != Prev && "Cannot conflict with self");
771771
diagnose(New->getLoc(), diag::decl_redefinition, New->isDefinition());
772772
diagnose(Prev->getLoc(), diag::previous_decldef, Prev->isDefinition(),
773-
Prev->getName());
773+
Prev->getName());
774774
}
775775

776776
struct ParserUnit::Implementation {

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2604,8 +2604,9 @@ class ModuleWriter {
26042604
assert(*lhs != *rhs && "duplicate top-level decl");
26052605

26062606
auto getSortName = [](const Decl *D) -> StringRef {
2607+
// TODO: Handle special names
26072608
if (auto VD = dyn_cast<ValueDecl>(D))
2608-
return VD->getName().str();
2609+
return VD->getBaseName().getIdentifier().str();
26092610

26102611
if (auto ED = dyn_cast<ExtensionDecl>(D)) {
26112612
auto baseClass = ED->getExtendedType()->getClassOrBoundGenericClass();

lib/SIL/SILFunctionType.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,8 +1479,11 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) {
14791479
case AccessorKind::IsGetter:
14801480
// Getter selectors can belong to families if their name begins with the
14811481
// wrong thing.
1482-
if (FD->getAccessorStorageDecl()->isObjC() || c.isForeign)
1483-
return getSelectorFamily(FD->getAccessorStorageDecl()->getName());
1482+
if (FD->getAccessorStorageDecl()->isObjC() || c.isForeign) {
1483+
// TODO: Handle special names (subscript).
1484+
auto name = FD->getAccessorStorageDecl()->getBaseName().getIdentifier();
1485+
return getSelectorFamily(name);
1486+
}
14841487
return SelectorFamily::None;
14851488

14861489
// Other accessors are never selector family members.

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,8 @@ SpecializedEmitter::forDecl(SILGenModule &SGM, SILDeclRef function) {
10001000
if (!isa<BuiltinUnit>(decl->getDeclContext()))
10011001
return None;
10021002

1003-
const BuiltinInfo &builtin = SGM.M.getBuiltinInfo(decl->getName());
1003+
auto name = decl->getBaseName().getIdentifier();
1004+
const BuiltinInfo &builtin = SGM.M.getBuiltinInfo(name);
10041005
switch (builtin.ID) {
10051006
// All the non-SIL, non-type-trait builtins should use the
10061007
// named-builtin logic, which just emits the builtin as a call to a
@@ -1016,7 +1017,7 @@ SpecializedEmitter::forDecl(SILGenModule &SGM, SILDeclRef function) {
10161017
#define BUILTIN_TYPE_TRAIT_OPERATION(Id, Name)
10171018
#include "swift/AST/Builtins.def"
10181019
case BuiltinValueKind::None:
1019-
return SpecializedEmitter(decl->getName());
1020+
return SpecializedEmitter(name);
10201021

10211022
// Do a second pass over Builtins.def, ignoring all the cases for
10221023
// which we emitted something above.

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ namespace {
13521352
// If this is a simple property access, then we must have a conflict.
13531353
if (!subscripts) {
13541354
assert(isa<VarDecl>(decl));
1355-
SGF.SGM.diagnose(loc1, diag::writeback_overlap_property,decl->getName())
1355+
SGF.SGM.diagnose(loc1, diag::writeback_overlap_property, decl->getBaseName())
13561356
.highlight(loc1.getSourceRange());
13571357
SGF.SGM.diagnose(loc2, diag::writebackoverlap_note)
13581358
.highlight(loc2.getSourceRange());
@@ -1891,7 +1891,7 @@ LValue SILGenLValue::visitRec(Expr *e, AccessKind accessKind,
18911891
// this handles the case in initializers where there is actually a stack
18921892
// allocation for it as well.
18931893
if (isa<ParamDecl>(DRE->getDecl()) &&
1894-
DRE->getDecl()->getName() == SGF.getASTContext().Id_self &&
1894+
DRE->getDecl()->getFullName() == SGF.getASTContext().Id_self &&
18951895
DRE->getDecl()->isImplicit()) {
18961896
Ctx = SGFContext::AllowGuaranteedPlusZero;
18971897
if (SGF.SelfInitDelegationState != SILGenFunction::NormalSelf) {

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,12 @@ ValueDecl *DIMemoryObjectInfo::
257257
getPathStringToElement(unsigned Element, std::string &Result) const {
258258
auto &Module = MemoryInst->getModule();
259259

260+
// TODO: Handle special names
260261
if (isAnyInitSelf())
261262
Result = "self";
262263
else if (ValueDecl *VD =
263264
dyn_cast_or_null<ValueDecl>(getLoc().getAsASTNode<Decl>()))
264-
Result = VD->getName().str();
265+
Result = VD->getBaseName().getIdentifier().str();
265266
else
266267
Result = "<unknown>";
267268

@@ -1147,7 +1148,7 @@ static SILInstruction *isSuperInitUse(UpcastInst *Inst) {
11471148
if (auto *DTB = dyn_cast<DerivedToBaseExpr>(LocExpr->getArg()))
11481149
if (auto *DRE = dyn_cast<DeclRefExpr>(DTB->getSubExpr()))
11491150
if (DRE->getDecl()->isImplicit() &&
1150-
DRE->getDecl()->getName().str() == "self")
1151+
DRE->getDecl()->getBaseName() == "self")
11511152
return User;
11521153
}
11531154

lib/SILOptimizer/Mandatory/DIMemoryUseCollectorOwnership.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ DIMemoryObjectInfo::getPathStringToElement(unsigned Element,
276276
Result = "self";
277277
else if (ValueDecl *VD =
278278
dyn_cast_or_null<ValueDecl>(getLoc().getAsASTNode<Decl>()))
279-
Result = VD->getName().str();
279+
Result = VD->getBaseName().getIdentifier().str();
280280
else
281281
Result = "<unknown>";
282282

@@ -1155,10 +1155,12 @@ static SILInstruction *isSuperInitUse(UpcastInst *Inst) {
11551155
// (derived_to_base_expr implicit type='C'
11561156
// (declref_expr type='D' decl='self'))
11571157
if (auto *DTB = dyn_cast<DerivedToBaseExpr>(LocExpr->getArg()))
1158-
if (auto *DRE = dyn_cast<DeclRefExpr>(DTB->getSubExpr()))
1158+
if (auto *DRE = dyn_cast<DeclRefExpr>(DTB->getSubExpr())) {
1159+
ASTContext &Ctx = DRE->getDecl()->getASTContext();
11591160
if (DRE->getDecl()->isImplicit() &&
1160-
DRE->getDecl()->getName().str() == "self")
1161+
DRE->getDecl()->getBaseName() == Ctx.Id_self)
11611162
return User;
1163+
}
11621164
}
11631165

11641166
return nullptr;

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,9 @@ void LifetimeChecker::handleInOutUse(const DIMemoryUse &Use) {
11031103
// about the method. The magic numbers used by the diagnostic are:
11041104
// 0 -> method, 1 -> property, 2 -> subscript, 3 -> operator.
11051105
unsigned Case = ~0;
1106-
Identifier MethodName;
1106+
DeclBaseName MethodName;
11071107
if (FD && FD->isAccessor()) {
1108-
MethodName = FD->getAccessorStorageDecl()->getName();
1108+
MethodName = FD->getAccessorStorageDecl()->getBaseName();
11091109
Case = isa<SubscriptDecl>(FD->getAccessorStorageDecl()) ? 2 : 1;
11101110
} else if (FD && FD->isOperator()) {
11111111
MethodName = FD->getName();
@@ -1383,9 +1383,9 @@ bool LifetimeChecker::diagnoseMethodCall(const DIMemoryUse &Use,
13831383
if (Method) {
13841384
if (!shouldEmitError(Inst)) return true;
13851385

1386-
Identifier Name;
1386+
DeclBaseName Name;
13871387
if (Method->isAccessor())
1388-
Name = Method->getAccessorStorageDecl()->getName();
1388+
Name = Method->getAccessorStorageDecl()->getBaseName();
13891389
else
13901390
Name = Method->getName();
13911391

lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static void diagnoseExclusivityViolation(const AccessedStorage &Storage,
501501
auto D = diagnose(Ctx, AccessForMainDiagnostic->getLoc().getSourceLoc(),
502502
DiagnosticID,
503503
VD->getDescriptiveKind(),
504-
VD->getName(),
504+
VD->getBaseName(),
505505
AccessKindForMain);
506506
D.highlight(rangeForMain);
507507
tryFixItWithCallToCollectionSwapAt(PriorAccess, NewAccess,

lib/Serialization/Deserialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3793,7 +3793,7 @@ Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
37933793
if (!nominal) {
37943794
XRefTracePath tinyTrace{*nominalOrError.get()->getModuleContext()};
37953795
DeclName fullName = cast<ValueDecl>(nominalOrError.get())->getFullName();
3796-
tinyTrace.addValue(fullName.getBaseName());
3796+
tinyTrace.addValue(fullName.getBaseIdentifier());
37973797
return llvm::make_error<XRefError>("declaration is not a nominal type",
37983798
tinyTrace, fullName);
37993799
}

lib/Serialization/ModuleFile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,14 @@ namespace {
314314
class ModuleFile::DeclTableInfo {
315315
public:
316316
using internal_key_type = StringRef;
317-
using external_key_type = Identifier;
317+
using external_key_type = DeclBaseName;
318318
using data_type = SmallVector<std::pair<uint8_t, DeclID>, 8>;
319319
using hash_value_type = uint32_t;
320320
using offset_type = unsigned;
321321

322322
internal_key_type GetInternalKey(external_key_type ID) {
323-
return ID.str();
323+
// TODO: Handle special names
324+
return ID.getIdentifier().str();
324325
}
325326

326327
hash_value_type ComputeHash(internal_key_type key) {
@@ -338,6 +339,7 @@ class ModuleFile::DeclTableInfo {
338339
}
339340

340341
static internal_key_type ReadKey(const uint8_t *data, unsigned length) {
342+
// TODO: Handle special names
341343
return StringRef(reinterpret_cast<const char *>(data), length);
342344
}
343345

0 commit comments

Comments
 (0)