[llvm-bugs] [Bug 25670] New: [Feature] Add a builtin for indexing into parameter packs
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Nov 29 15:08:44 PST 2015
https://llvm.org/bugs/show_bug.cgi?id=25670
Bug ID: 25670
Summary: [Feature] Add a builtin for indexing into parameter
packs
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: ldionne.2 at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 15363
--> https://llvm.org/bugs/attachment.cgi?id=15363&action=edit
Initial version of the proposed patch.
This patch adds a `__nth_element` builtin that allows fetching the n-th type of
a parameter pack with very little compile-time overhead. The patch was inspired
by r252036 and r252115 by David Majnemer, which add a similar
`__make_integer_seq` builtin for efficiently creating a
`std::integer_sequence`. At its core, the builtin makes the following
specialization
__nth_element<i, T1, ..., Tn>
equivalent to Ti. Further analysis of the problem this patch is trying to solve
is available on a blog post I just wrote [1]. The post also present benchmarks
showing the compile-time improvement over existing techniques.
The patch is currently in a very rough state. It is my first time contributing
to Clang, and I encountered some issues that I hacked around just to get a
working solution. If there is interest in this patch, I will gladly improve it
until it is in an acceptable state, but I will most likely need some pointers
to do so. Things that are hacky right now:
1. I wasn't able to create a non-type template parameter from a builtin type.
Hence, `__nth_element` must currently be used as `__nth_element<TypeOfTheIndex,
Index, Ts...>` instead of just `__nth_element<Index, Ts...>`, while forcing
`Index` to be something like `unsigned long`. This way, I was able to copy
Majnemer's code that creates non-type template parameters. This is probably
trivial to change, but I couldn't figure it out immediately.
2. I wasn't sure how to retrieve an actual integer from an `APSInt`, so right
now I use `getExtValue()`. This is probably wrong, as I didn't really
understand what I was doing.
There are certainly other issues that a code review would address, if we make
it that far. Also, the name `__nth_element` is badly chosen, since it seems to
refer to the `nth_element` algorithm of the standard library. We should settle
on something else, but I have no preference.
Louis
[1]: http://ldionne.com/2015/11/29/efficient-parameter-pack-indexing
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151129/b8883657/attachment.html>
More information about the llvm-bugs
mailing list