This is an archive of the discontinued LLVM Phabricator instance.

[libc] Enhance ArrayRef + unittests
ClosedPublic

Authored by gchatelet on Apr 18 2021, 12:58 PM.

Details

Summary

This patch mostly adds unittests for ArrayRef and MutableArrayRef, additionnaly:

  • We mimic the behavior of std::vector and disallow CV qualified type (ArrayRef<const X> is not allowed). This is to make sure that the type traits are always valid (e.g. value_type, pointer, ...).
  • In the previous implementation ArrayRef would define value_type as const T but this is not correct, it should be T for both MutableArrayRef and ArrayRef.
  • We add the equals method to ease testing,
  • We define the constructor taking an Array outside of the base implementation to ensure we match const Array<T>& and not Array<const T>& in the case of ArrayRef.

Diff Detail

Event Timeline

gchatelet created this revision.Apr 18 2021, 12:58 PM
gchatelet requested review of this revision.Apr 18 2021, 12:58 PM
sivachandra accepted this revision.Apr 20 2021, 12:33 AM

Overall, a very nice change. Thanks for doing it. The clang-tidy warnings in the equals method are legitimate and should be fixed before submitting.

libc/utils/CPP/ArrayRef.h
90

Calling it equals is a bit misleading when we are comparing references. Unless this name is inspired from other places in llvm-project, may be name it equalData or something like that?

113

Since this is a struct, may be make the using statements private?

125

Same here?

This revision is now accepted and ready to land.Apr 20 2021, 12:33 AM
gchatelet marked 3 inline comments as done.Apr 21 2021, 6:18 AM
gchatelet added inline comments.
libc/utils/CPP/ArrayRef.h
90

I agree it's not ideal but I tried to stick to the llvm's ArrayRef naming.

gchatelet updated this revision to Diff 339207.Apr 21 2021, 6:18 AM
gchatelet marked an inline comment as done.
  • Made internal using and static_assert private.
This revision was landed with ongoing or failed builds.Apr 21 2021, 6:25 AM
This revision was automatically updated to reflect the committed changes.