This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Fix circular include dependency by using std::array. NFC
ClosedPublic

Authored by zyounan on Jan 9 2023, 9:31 PM.

Details

Summary

2db6b34ea introduces circular dependency on llvm::ArrayRef. By inspecting commit history,
it appears that we have some issue using deduction guide on std::array.
Why don't we try std::array with explicit template arguments?

Diff Detail

Event Timeline

zyounan created this revision.Jan 9 2023, 9:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 9:31 PM
zyounan requested review of this revision.Jan 9 2023, 9:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 9:31 PM

Pipeline failed due to missing include header llvm/ADT/Hashing.h

In file included from /var/lib/buildkite-agent/builds/llvm-project/clang-tools-extra/clangd/Config.cpp:9:
/var/lib/buildkite-agent/builds/llvm-project/clang-tools-extra/clangd/Config.h:158:18: error: no member named 'hash_combine' in namespace 'llvm'
    return llvm::hash_combine(Val.Kind, Val.Location, Val.MountPoint);

This header was included by ArrayRef.h which is included by STLExtras.h before.

#include "llvm/ADT/Hashing.h"

I don't think it's a good idea to dive into every TU and revise this include dependency. Let's add this to STLExtras.h directly.

zyounan updated this revision to Diff 487686.Jan 9 2023, 10:33 PM

Add header llvm/ADT/Hashing.h, which is included by ArrayRef.h before. This header may be dependent by some TUs indirectly.

Ping. Is this OK for trunk?

This revision is now accepted and ready to land.Jan 13 2023, 4:23 PM
zyounan added a comment.EditedJan 13 2023, 7:41 PM

LGTM

Thanks. Can you help me commit this PR?

Ping again. Sorry I don't have commit access to main branch.

zyounan updated this revision to Diff 491024.Jan 20 2023, 8:28 PM
zyounan added a reviewer: MaskRay.

Fix issue

zyounan added a subscriber: eklepilkina.EditedJan 20 2023, 8:28 PM

Can anyone else help me to commit this PR? I mean we should land this patch ASAP, as many of PRs are now depending on llvm::ArrayRef without including ADT/ArrayRef.h but ADT/STLExtras.h, which would make it extremely harder to resolve this circular dependency later.

Patch D139553 is a good example to demonstrate this.

/repo/llvm-project/llvm/include/llvm/MC/SubtargetFeature.h:192:32: error: no template named 'ArrayRef'
  void addFeaturesVector(const ArrayRef<std::string> OtherFeatures);
                               ^
/repo/llvm-project/llvm/lib/MC/SubtargetFeature.cpp:45:25: error: out-of-line definition of 'addFeaturesVector' does not match any declaration in 'llvm::SubtargetFeatures'
void SubtargetFeatures::addFeaturesVector(
                        ^~~~~~~~~~~~~~~~~
2 errors generated.

I have updated this patch to fix this new issue.

@eklepilkina, please note that this patch doesn't have functional changes but add a header.

Also ping @JDevlieghere again.


Sorry for my silly mistake, I don't know that Phabricator drops the author info. Please use zyounan<zyn7109@gmail.com> for the commit. Thank you again for your time.

MaskRay accepted this revision.Jan 21 2023, 5:43 AM