Move some types in STLExtras.h which are named and behave identically to
STL types from future standards into a dedicated header. This keeps them
organized (they are not "extras" in the same sense as most types in
STLExtras.h are) and fixes circular dependencies in future patches.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Remove SHIM macro; it wasn't actually doing anything (there was a typo in the
lint identifier), it seems like clang-tidy just ignored the identifier when it
was wrapped in a macro.
I don't think "shim" is the right term here - if anything I'd think things like our range-based adapters to standard algorithms (llvm::sort(R, C) -> std::sort(R.begin(), R.end(), C)) is a "shim" in the sense of the word that I know of - a thin adapter ( https://en.wikipedia.org/wiki/Shim_(computing) - "a shim is a library that transparently intercepts API calls and changes the arguments passed, handles the operation itself or redirects the operation elsewhere.").
These are STL reimplementations, though that's a bit of a mouthful. STLCompat.h, perhaps?
llvm/include/llvm/ADT/STLShims.h | ||
---|---|---|
23 | I'm not sure this macro is adding value - what's the motivation for it compared to a comment pointing out that a given thing is intended to be equivalent to the standard entity of the same name? |
Oh, and the patch description specifically calls out "STL types" - but presumably we might put STL variables in here too (like the _v variants of various traits)
Sure, I'm amenable to other names. I originally planned to use "polyfill" (https://en.wikipedia.org/wiki/Polyfill_(programming)) but landed on shim because:
- It is shorter
- It is an older term (I hoped more people would understand the use in this context)
- The term "polyfill" seems to almost universally apply to javascript (see e.g. http://speakingjs.com/es5/ch30.html#shim_vs_polyfill)
The definition of "shim" I was going for is the one from that speakingjs book: "A shim is a library that brings a new API to an older environment, using only the means of that environment."
I don't like just "reimplementation", even though it is accurate, because it doesn't really convey the intent; we will be deleting our version ASAP. We really don't care about the implementation per-se, we just want to code to a future specification. If we were dissatisfied with the standard implementations then "reimplementation" would seem more apt.
I also feel like just "Compat" is a bit ambiguous, but maybe I just think of "backwards" compat first. What do you think about STLForwardCompat.h ? That also brings up the questionof what happens when someone compiles LLVM with a newer standard than C++14, i.e. is this really "compatible" with the newer standards if we don't detect whether they are present? I am not sure how best to approach doing that in general.
Ah, yeah, that's not one I've come across personally.
The definition of "shim" I was going for is the one from that speakingjs book: "A shim is a library that brings a new API to an older environment, using only the means of that environment."
Yeah, it's certainly got some related use.
I don't like just "reimplementation", even though it is accurate, because it doesn't really convey the intent; we will be deleting our version ASAP. We really don't care about the implementation per-se, we just want to code to a future specification. If we were dissatisfied with the standard implementations then "reimplementation" would seem more apt.
I also feel like just "Compat" is a bit ambiguous, but maybe I just think of "backwards" compat first. What do you think about STLForwardCompat.h ? That also brings up the questionof what happens when someone compiles LLVM with a newer standard than C++14, i.e. is this really "compatible" with the newer standards if we don't detect whether they are present? I am not sure how best to approach doing that in general.
ForwardCompat sounds OK to me, but given the other definition of shim, I'm probably OK-ish with that too.
Re: Newer standards. I think it's still compatible/doesn't make the name wrong if people are compiling in C++14 mode. But if we really wanted to, probably the closer we get to migrating to building with C++>14 by default, we might change these shims/whatever they are to be defined as aliases for the real implementations when compiling with a version that supports the implementation to help align things if they happen to be divergent in any way. Then eventually when the newer version is adopted as an LLVM requirement, we'd remove the fallback (so the llvm::* would only be an alias for the std:: version at that point) and then eventually remove the aliases.
llvm/include/llvm/ADT/STLForwardCompat.h | ||
---|---|---|
36–37 ↗ | (On Diff #338254) | Hmm, seems this isn't actually conforming implementation (the standard one says that it short-circuits - doesn't try to evaluate later expressions if an early one is true/false - and that the type returned by std::conditional is the type of that last condition that proved the rule, I think?). But probably close enough since it's already committed. |
llvm/unittests/ADT/STLForwardCompatTest.cpp | ||
22–30 ↗ | (On Diff #338254) | Was there no existing testing of conjunction? (ie: something that should be deleted as the testing is added/moved here?) |
llvm/include/llvm/ADT/STLForwardCompat.h | ||
---|---|---|
36–37 ↗ | (On Diff #338254) | My understanding of the definition of std::conditional led me to believe this definition does satisfy the "short-circuiting" property, and I tried to include at least a (potentially incomplete?) trivial test of that using an incomplete_type following an element that proves the rule of the predicate (i.e. false for conjunction, true for disjunction) |
llvm/unittests/ADT/STLForwardCompatTest.cpp | ||
22–30 ↗ | (On Diff #338254) | Not sure, I assume it just wasn't noticed in review? There are tests of it indirectly via Any, see https://reviews.llvm.org/D48807 |
(good enough to commit - but happy to also keep discussing the finer nuances of spec conformance here if you like)
llvm/include/llvm/ADT/STLForwardCompat.h | ||
---|---|---|
36–37 ↗ | (On Diff #338254) | Oh, right you are! Is it worth testing the exact type of disjunction/conjunction, rather than only their boolean value? To test that aspect of the spec conformance? Hmm - wonder what the spec says about whether the type parameters must be able to be derived from? |
llvm/unittests/ADT/STLForwardCompatTest.cpp | ||
22–30 ↗ | (On Diff #338254) | Yep, my bad. Thanks for adding in testing now |
I'm not sure this macro is adding value - what's the motivation for it compared to a comment pointing out that a given thing is intended to be equivalent to the standard entity of the same name?