[AST] Get it a deterministic traverse order for classMembers

Make sure the traversal order for classMembers in deterministic in the
mdoule by sorting them first.

Also fix the comparsion function for `DeclName` to make sure there
aren't two DeclNames with different OpaquePointer can be evaluated to
equal.

rdar://147513165
This commit is contained in:
Steven Wu
2025-03-20 11:00:34 -07:00
parent deb1d9696d
commit b8879eef88
3 changed files with 47 additions and 15 deletions

View File

@@ -694,13 +694,17 @@ void SourceLookupCache::lookupClassMembers(ImportPath::Access accessPath,
VisibleDeclConsumer &consumer) {
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
if (!accessPath.empty()) {
for (auto &member : ClassMembers) {
// Non-simple names are also stored under their simple name, so make
// sure to only report them once.
if (!member.first.isSimpleName())
continue;
std::vector<std::pair<DeclName, TinyPtrVector<ValueDecl *>>> OrderedMembers;
for (auto &member : ClassMembers) {
if (!member.first.isSimpleName())
continue;
OrderedMembers.emplace_back(member.first, member.second);
}
llvm::sort(OrderedMembers,
[](auto &LHS, auto &RHS) { return LHS.first < RHS.first; });
if (!accessPath.empty()) {
for (auto &member : OrderedMembers) {
for (ValueDecl *vd : member.second) {
auto *nominal = vd->getDeclContext()->getSelfNominalTypeDecl();
if (nominal && nominal->getName() == accessPath.front().Item)
@@ -712,12 +716,7 @@ void SourceLookupCache::lookupClassMembers(ImportPath::Access accessPath,
return;
}
for (auto &member : ClassMembers) {
// Non-simple names are also stored under their simple name, so make sure to
// only report them once.
if (!member.first.isSimpleName())
continue;
for (auto &member : OrderedMembers) {
for (ValueDecl *vd : member.second)
if (ABIRoleInfo(vd).matchesOptions(OptionSet<ModuleLookupFlags>())) // FIXME: figure this out
consumer.foundDecl(vd, DeclVisibilityKind::DynamicLookup,