Episode Transcript
Transcripts are displayed as originally observed. Some content, including advertisements may have changed.
Use Ctrl + F to search
0:00
Episode 375 of CPPcast with
0:02
guest David van der Waals, recorded
0:04
22nd of January 2024. This
0:08
episode is sponsored by Native Instruments,
0:11
innovative hardware and software that inspires
0:13
musicians, creators, and DJs. And
0:16
Sonar, the home of Clean Code. In
0:34
this episode, we talk about the Linux kernel,
0:38
and about the implementation of StitKlam. Then
0:44
we are joined by David van der Waals. David
0:48
talks to us about reflection for C++ 26.
1:00
Welcome to Episode 375 of CPPcast,
1:02
the first podcast for C++ developers
1:04
by C++ developers. I'm
1:08
your host Timo Dumler, joined by my co-host Phil
1:10
Nash. Phil, how are you doing today? I'm
1:13
all right, Timo, how are you doing? I'm not too bad.
1:16
Staying inside, the weather
1:18
is pretty bad outside. We have
1:20
about a meter of snow. It's
1:23
very cold, and there's
1:25
some kind of snowstorm outside, so I'm just
1:27
not gonna go anywhere for now. As
1:30
long as I'm inside, I'm good. How are you doing,
1:32
Phil? What's the weather where you are? We
1:35
have a lot of weather here as well. We had a
1:37
big storm pass through last night, maybe headed your way even.
1:40
Quite high winds for the UK, at least, I
1:42
think up to 99 miles an hour at times.
1:44
So a lot of trees down in the area. We couldn't
1:47
get our car out of our driveway this morning. So
1:49
yeah, we're just dealing with all that at the moment.
1:52
But no snow this week. We had some last week.
1:54
That's fun. Yeah, I also couldn't get our car out of
1:57
the driveway two days ago because it got
1:59
stuck in the snow. I had to spend about an
2:01
hour with a shovel to dig
2:03
it out of there and to be able to go anywhere. So
2:05
that was fun. No
2:08
joke. All right. So at the top
2:10
of every episode, I'd like to read a piece
2:12
of feedback. And this time we got a
2:14
comment from Hamlam who wrote the following on Reddit. I
2:17
love this podcast series, but so referring
2:19
to the last episode, which I recorded
2:21
with Guy and Wille as the guest.
2:24
So Hamlam writes, I love this podcast
2:26
series, but this time I was particularly
2:28
annoyed by the audio quality. The
2:30
guest host audio was almost inaudible to me while
2:33
listening to it in my car, commuting to and
2:35
from work. My suggestion would be
2:37
to make sure that participants have a reasonable
2:39
microphone and also record their audio locally in
2:41
high quality, then use that audio for mixing
2:43
the final audio for the podcast. Well,
2:46
thank you very much for the feedback. I
2:48
do have to say yes, that's mostly
2:51
on me. So
2:53
what happened is that when we sat down to
2:55
record, I noticed that Guy's audio was quite poor
2:57
and I had trouble
2:59
understanding him. So I said, okay, can we figure
3:01
this out? So it was this awkward few minutes where
3:03
you kind of watched him fiddling with his audio settings and
3:05
stuff, but it just wouldn't get better.
3:07
And what I should have done is to say,
3:10
okay, we're going to actually figure this out before
3:13
recording. And what I did
3:15
instead is, oh, Phil was going to fix it
3:17
in post. It's fine. And he recorded. He went
3:19
ahead and recorded anyway. It turned out that the
3:21
source material actually wasn't that good. I don't know
3:23
what the problem on Guy's side was, but we
3:25
should have sat down and fixed it
3:27
before recording. So that one is on me. I apologize.
3:30
I'm going to make sure it's not
3:32
going to happen again, hopefully. Yeah. Yeah.
3:35
I will take a bit of the blame as well because
3:37
I'm usually the one that says, it's okay, we can fix
3:39
it in post because I've got these really great plugins, which
3:41
are fully enough for actually provided
3:43
by the people sponsoring us today. And
3:45
they usually will sort out just about any
3:47
problem that we have. So I'm usually
3:50
fine to say, we'll fix it in post. This
3:52
time, no matter what I did, we couldn't
3:54
seem to recover it. So sorry
3:56
about that. We will do better. Alright,
4:00
so we'd like to hear your thoughts about
4:02
the show. You can always reach out to
4:04
us on X Master on LinkedIn or email
4:06
us at feedback at cppcust.com. Joining
4:08
us today is David van der Ford. David
4:11
is a Belgian computer scientist who lives
4:13
in Tampa, Florida, USA. He's
4:15
the Vice President of Engineering at the
4:18
Edison Design Group, where he contributes primarily
4:20
to the implementation of their C++ compiler
4:22
front-end. He's an active member
4:25
of the C++ Standardization Committee. His recent
4:27
work in that context has primarily been
4:29
about developing a compile-time reflection mechanism. David
4:32
is also one of the five members of the
4:34
committee's direction group. He's the primary
4:36
author of the well-regarded book, C++
4:38
Templates, A Complete Guide, now available in
4:41
its second edition. David, welcome to the
4:43
show. Hi Timor, thank
4:45
you. Hi Phil. So it's been
4:47
like four or five years, I think, since you've been to the
4:49
show. So it's a great honor to have you back. Thank you
4:52
very much for joining us. Oh, my
4:54
pleasure. Now we're gonna talk
4:56
about reflection in the main part
4:58
of this episode. Just wanna
5:00
pick on the EDG part, because I know you've been
5:02
there for a long time now. And
5:04
I hear about EDG a lot over the
5:06
years, but mostly as the
5:09
front end for Visual Studio's IntelliSense, and
5:11
back in the day, the Comio C++ compiler, I
5:13
think used it as the front end as well. I
5:15
remember rightly, was the reason that
5:18
it was the only compiler that ever actually got
5:20
full conformance with C++98, but
5:22
I don't think it's around anymore. What
5:25
else is it used for these days? So
5:27
we have a fairly broad set
5:30
of customers. So some of our
5:32
customers are people that sell chips
5:34
and want a C++ compiler, you
5:37
know, with their particular development kits.
5:39
And so they're the traditional compiler
5:41
sender. So we have
5:43
a few of those. You
5:45
mentioned Visual Studio uses
5:48
our front-end product in IntelliSense. A
5:51
lot of our customers these days
5:53
do source analysis. So they take
5:55
our product, reparse C++, and
5:58
one of the reasons why component to go
6:01
with us rather than some other
6:03
solution is that we cover all three
6:05
of the minimum implementation. So you can
6:07
tell our product, please parse C++ as
6:10
if you were GCC 7.3.1. Just
6:15
making something up. Or with the same
6:17
executable, you can say, oh, no, please parse it as
6:19
if you were Microsoft Visual
6:23
C++ version 19.23. And
6:27
sometimes we even go down to the build number. And
6:30
we implement all these
6:32
extensions, their bugs, things like that.
6:35
So a lot of our customers will do source
6:37
analysis based on that. Some will do source-to-source information.
6:40
So they'll take your source code, then
6:43
insert in our representation of it
6:45
some stuff, and then we regenerate
6:47
C++ from that. So
6:49
yeah, a lot of applications in
6:51
that domain. Some will just
6:53
give you stats about your code.
6:58
A lot of these days is security
7:00
stuff where
7:02
some application will look at your code and
7:05
say here and there and there you have
7:07
vulnerabilities. Yeah, it's pretty broad,
7:09
but still a fair number of soft-plan
7:11
traditional C++ compilers. Okay.
7:15
So you have to match the bugs of the
7:18
other compilers. Yeah, yes. Does that mean you have a load
7:20
of test cases that check that you've got the right bugs?
7:23
Right. So you'd be surprised
7:25
at the fraction of my work which
7:27
consists in trying to figure
7:30
out what the boundary of the bug is. I'm
7:33
not allowed to look at the source code of any
7:35
other compilers. In some cases, impossible. I don't have access
7:37
to Microsoft source days anyway. But
7:39
I'm not allowed to look at GCC source code
7:41
or client source code. I
7:43
think maybe technically I could client, but I don't.
7:46
I just send a whole bunch of... So I get
7:49
the test cases and say, hey, you're doing something different.
7:52
And then I try to make a whole bunch of
7:54
adjacent test cases trying to figure out, oh, that's what
7:56
they do. And sometimes, there
7:59
are a lot of times at the end... I'm like, okay, I know
8:01
what you're doing and I emulate that. Sometimes
8:03
it's a little different where I'm like, okay,
8:05
I know what you're doing, but
8:07
I really don't want to do that in my compilers. Can
8:11
I do something that's close enough? And
8:14
that will do something like that. And it's on a case by
8:16
case basis, but it's a lot of
8:19
the problem reports we get to
8:21
our product are of that kind
8:23
where you're like, okay, well, we know this
8:25
is not not standard
8:27
C++, but we would like you to parse it anyway, or
8:29
we'd like you to behave this way or that way anyway.
8:33
Sounds fun. Yeah, that sounds fun indeed.
8:36
It is actually, it is fun. It's
8:38
sometimes it's frustrating sometimes, you know, as
8:40
you're asked to emulate, you know, some
8:42
are done some really gnarly emulation. You're
8:44
like, yes. All
8:49
right. But yeah, it's an interesting job. All right, so David,
8:51
we'll get more into your work in just a few minutes.
8:53
But first, we have a couple of news articles to talk
8:56
about. So feel free to comment on any of these. Okay.
8:59
The first news item is that the keynotes from
9:01
meeting C++ 2023, which is a big conference in
9:06
Berlin happened two months ago. So
9:09
those keynotes have been released on YouTube and
9:11
all three of them are pretty great and
9:14
worth watching. So you got six impossible things
9:16
by Kevin Henny, helping open communities
9:18
thrive by Lydia Pincher and proxy plus plus
9:20
by Ivan Chukic. So you can go ahead
9:22
and watch those and they're all pretty awesome.
9:26
I think a lot of the other videos from
9:28
meeting C++ are available now as well. I know the
9:30
ones that my talk is. I don't know who else.
9:33
Yeah. So this this one is from like a couple of weeks
9:35
ago, so they might have released more. Yeah. Right.
9:38
So the next piece of news
9:40
is a post on foronics.com, which
9:43
is a website that I have to admit I
9:45
haven't come across before, but apparently it is a
9:47
leading website or even the leading website for like
9:49
Linux news. Yeah. And
9:51
there is a post
9:54
there, which I found really interesting. Actually, thank
9:57
you to Nis Minard who suggested that we
9:59
include this as. news item. And
10:01
that blog post says a 2024 discussion
10:03
whether to convert the Linux kernel from
10:05
C to modern C++. So
10:08
it's kind of a summary of an
10:10
old discussion, but one that has been
10:12
recently reignited, whether
10:14
the Linux kernel should actually be converted from C to
10:16
C++. And
10:19
so the argument is that C++ actually has grown
10:21
up to be a better C for
10:24
the kind of embedded programming that as
10:26
you're doing when you're developing an OS kernel, and
10:29
that in particular C++ 20 is a total
10:31
game changer when it comes to meta programming.
10:33
It adds concepts, it adds a bunch
10:36
of other stuff that makes kind of scalable
10:38
programming, you know, much easier and better.
10:41
And also like many things for which
10:44
they require kind of GCC specific extensions
10:46
and see another very, very elaborate stuff
10:49
like in C++ and modern C++ like C++
10:51
20 and later, you can just write them like
10:53
really easily. So that's
10:55
interesting. Of course, the question
10:57
is, if you want to rewrite the kernel or part
10:59
of the kernel in a different language, why not just
11:02
use Rust? They're actually already doing that already.
11:04
I think parts of the kernel have been rewritten in
11:06
Rust or at least they add Rust components to it
11:08
or something. So the
11:11
argument is that rewriting large parts
11:13
of the kernel in Rust isn't a good
11:15
idea because it's too different. Whereas
11:19
conversion from C to C or such can actually
11:21
happen gradually, right? You can already almost compile the
11:23
kernel, it just like switched to compiler
11:25
from C to C++ and it will almost already
11:27
compile. And then you can just
11:29
gradually add like new features at
11:32
whichever rate you want. And obviously the idea is not
11:34
that you you know, add
11:36
every possible C++ feature under the sun,
11:38
but just have like a defined subset
11:40
of C++ which is like kernel C++
11:42
which is the thing you're going
11:44
to be using much like they already do it
11:47
for C. And yeah, the argument is maybe that's
11:49
what the notes people should be doing. And yeah,
11:51
I don't know. I think people have probably very different
11:53
opinion on this. I'm personally not a Linux guy very
11:56
much. So I don't really have
11:58
an opinion on this, but I'm curious. is
12:00
what the other people think about this? So
12:04
it's an old question. Back in the 90s
12:06
it came up and
12:10
Linus Torvald had some
12:12
choice words about C++ at the time. I
12:15
remember he was quite strongly, he had a
12:17
very strongly worded, a few
12:19
very strongly worded statements about why he thinks
12:21
C++ is rubbish and what I remember. Yes,
12:25
and I think he had some more in the
12:28
21st century as well. Now the
12:30
person who brought this up, if I remember
12:32
correctly, is Peter Andven, who is a respected
12:34
kernel contributor. And he pointed
12:36
out first, when we say that
12:38
the Linux kernel is written in C, it
12:41
really isn't. It's written in the GCC dialect
12:43
of C. And actually,
12:45
about 20 years ago, my company was
12:47
asked to do quite a bit of
12:50
work to be able to compile the
12:52
Linux kernel. And it's
12:54
not trivial. Meaning, we
12:56
already had a C frontend
12:59
with a bunch of dialects, but
13:01
we had to add a lot of stuff to be
13:03
able to get to the point where we could compile
13:05
the Linux kernel. And then
13:07
I think a few years ago, the Spanish switch from C89
13:10
plus GCC extensions to
13:12
C11. But
13:14
I think Peter Andven was saying there's really
13:16
a lot of
13:19
the special extensions
13:21
that they use that could be instead more
13:24
simply done using C++ constructs. And
13:27
also, they could use data
13:30
sources. Like templates are really amazing. Once
13:32
you have templates, you can replicate data
13:34
structures much more cleanly throughout
13:36
your code base without a lot of
13:38
macrohacking. So I think he was pointing
13:41
out that that would also be a really nice thing
13:44
to be able to do in the Linux kernel. Because
13:47
kernel has a fair number of important
13:49
data structures that have to be implemented
13:51
efficiently. Yeah, I think for our
13:53
audience, most people won't take
13:55
a lot of convincing to suggest that C++
13:57
will bring a lot to the table. I
14:01
think the Linux development community is
14:03
a very different approach to
14:05
this. So very interesting to see how this
14:07
plays out. But I like the way that
14:09
this sort of has come full
14:12
circle. So today we're talking about what
14:15
about successful languages to C++, like Carbon
14:17
and some of the others. And
14:20
here we're still talking about C++ as a successful
14:22
language to see. And exactly
14:24
the same principles again. So yeah,
14:26
interesting to see how this plays out. That's not a hard
14:29
one for this point. And
14:31
that idea of gradually moving is
14:33
really important. The
14:36
EDG frontend until, I don't
14:40
remember exactly, but maybe five or six years ago, it
14:42
was still C. And
14:44
so we very gradually moved to C++. And
14:48
if you just were to jump anywhere in
14:51
the code base, it would feel very
14:53
much like C. A
14:56
lot of other benefits is just being able, same as
14:58
with the kernel, to be able to drop in some
15:00
template instances here and there instead of having to
15:03
re-implement a linked list for the NN20s file.
15:08
Being there, done that. Right.
15:11
Speaking of implementing stuff for
15:14
the hundredth time, the last
15:17
block, the last news item I want to
15:19
mention today is a blog post about stdclamp,
15:22
which also, there's also a very interesting Reddit
15:24
discussion about it. And
15:27
so the observation was that stdclamp
15:29
actually generates less efficient assembly than
15:31
if you just write stdmin of
15:33
max, stdmax min value, like kind
15:35
of the naive kind of one-liner implementation
15:38
using stdmin and stdmax on GC and
15:41
Clang, which seems
15:43
surprising. But if you
15:45
read the blog post, the reason is very subtle. One
15:48
reason is that kind of the naive implementation
15:50
of stdmin of max,
15:52
stdmax is actually incorrect because the
15:55
Standard version specifies the behavior for negative zero
15:57
and specifies the. The
16:00
Behavior Finance. Which. Like
16:02
the min max kind of thing doesn't give you. Are
16:05
that if you if you like. Supple, At
16:07
around in a way that it behaves the
16:09
same than he actually do get the same
16:11
assembly and another reason is that the for
16:14
a parody order in which the argument or
16:16
past to clamp also affects the generated assembly
16:18
a decent x eighty six. Because.
16:20
Of the limitations of the instructions said on
16:22
the requirements imposed by the calling convention and
16:24
stuff like that. So. On
16:26
the blog post go into a lot of depth
16:29
on on the stuff. I was very interesting. So
16:32
yeah, that caught my attention this week. Isis
16:34
A Saw the post come by on
16:36
Reddit when I didn't click through some.
16:39
Amateur. That. He. Only skimmed
16:41
the article. I didn't
16:44
get to see. It
16:46
at examined crushes like. A
16:49
see the Standard Libraries definition.
16:51
Or instance, I never place where the
16:53
satellite breeze definitions holding us back. Can
16:56
be I have an easier. More.
16:58
More performance. Implementation. Of
17:00
to clamp if we relaxed. Some of those fifty tons
17:02
of the could do a knife in from to yeah.
17:05
Or whether some other side effects about so that that's
17:07
funny or if you don't care about what happens when
17:09
it's not know when it's negative zero. Or.
17:12
Were you don't care whether the negative zero
17:14
smaller than positive zero weather the equal or
17:16
whatever. Thing. Yeah, you get to
17:18
and more efficient Limitation: Funny enough, I had that
17:21
as an example in my paper for. Assume
17:23
between I haven't seen as a three three
17:25
where you can take the. Camp.
17:28
Implementation and went like be just before
17:30
you call clamp you add. In.
17:32
A Square Brackets gotta get assume is
17:34
not non and is not zero, whatever.
17:36
And you actually get better assembly code
17:38
as well even if you stand that
17:40
from. Of cause then
17:42
if you do pass a non than everything
17:44
crashes horribly so don't do that. But this
17:46
was I see it those you wanna that
17:48
one of their kind of use cases on.
17:51
That. I had for assumptions that the know. Sometimes.
17:53
You don't want to implemented yourself. A.
17:56
you just want to use the senate lobby thing but you
17:58
don't care about all the as in similar for stuff
18:00
like std midpoint or std lerp
18:03
or whatever. Lots of these numeric things, but you
18:05
just don't care about these edge cases, but they
18:07
slow down your code. So you
18:09
can just kind of add assumptions to just throw away
18:11
those extra instructions. If you have a clever compiler, then
18:13
you can do that. I
18:17
mean, you can also sometimes get the opposite. Sometimes if
18:19
you add an assumption, it triggers weird
18:21
stuff. Like I've seen this on GCC, where
18:23
previously it would like
18:25
auto vectorize your code. And then if you add
18:27
an assumption, suddenly it doesn't. And then slower instead
18:29
of faster. So you see stuff like this as
18:32
well. So you got to be careful, but yeah.
18:35
I haven't counted this topic before. It's a
18:37
fascinating topic. Yeah.
18:40
So it sounds like one of the, those
18:42
problems are generalized to really
18:45
want a pair of functions, one which has
18:47
a narrow contract and
18:49
with assumptions and another which has
18:51
a wider contract and a little
18:53
bit of a performance. All right. So
18:55
now we're getting into contracts. So I don't want
18:57
to keep talking about this because then you can
18:59
do a whole episode about that. That's obviously one
19:01
of my favorite topics. So let's park that here.
19:03
I believe Phil, you have one more news item
19:06
for us today. Yes. So the last
19:08
time I was on, which was not last episode, but the
19:10
one before, I mentioned
19:12
that C++ online tickets were
19:15
available. And at the time that I said it,
19:17
as we recorded, they weren't. And I thought,
19:19
oh, it's going to be coming out in about 10 days. They'll be
19:21
online by then. And I realized the night
19:24
before, as I was editing, they still weren't online. So I
19:26
had to quickly put them online. I did like a soft
19:28
launch. So the page is available. You could
19:30
only get there from the C++ link. But
19:34
then I'm now fully available. So
19:36
I'm going to reiterate that and we'll put another link, proper
19:39
link in the show notes. But also to point
19:41
out that if you buy a workshop, some
19:44
great workshops on offer and
19:46
very reasonably priced, you actually get the whole conference
19:48
thrown in for free. So it's
19:50
a great way to get a
19:52
workshop and a conference for a
19:55
very good value. So that's what I had to say on
19:57
that. All right. That's great. Can
19:59
you remind us when that... takes place? Yes, because
20:01
we also changed the dates, which I think I did mention
20:03
last time as well. It's going to be the end of
20:05
February. We'll check the exact dates
20:08
29th of February to the second of March. Right,
20:10
so a bit more than a month from now.
20:13
Yes, yes. All right. Okay,
20:15
so that wraps up the
20:17
news items for today. So we can move
20:19
on to our main topic for today. And
20:22
this is really I think quite special
20:24
because over the last year or
20:26
so, like when Phil and I were, have been
20:28
since Phil and I have taken over the show, you
20:31
know, we've had episodes and many, many different topics,
20:33
but almost in every
20:35
episode, we just kept coming back to like
20:38
the kind of two hottest topics that in
20:40
C++ right now, or what seems to be
20:42
the hottest topics. One of them was safety.
20:44
And the other one is
20:47
reflection. And I think almost every episode
20:49
we have either a news item, about
20:51
reflection, or somebody mentioned
20:53
something that relates to reflection and how it would
20:55
be awesome to have it in C++. So it's
20:59
mentioned, I think, in almost every episode. And
21:02
now, you know, recently, this
21:04
paper P2996 came out
21:06
that had the title reflection for C++26.
21:09
And it looks like we might actually
21:11
get reflection now in the next upcoming
21:13
C++ standard. So a lot
21:15
of people are very excited about this. So we
21:17
thought we have to have an episode about this.
21:19
This is such an interesting topic.
21:22
And so we invited David, who is the expert on
21:24
the topic and one of the authors of that paper
21:26
to talk to us about it. So David, thank you
21:29
again very much for joining us today. Oh,
21:31
my pleasure. I'm glad to be here. So,
21:34
so this paper P2996, let's
21:37
talk a little bit about the history of that.
21:39
How did this paper come about? Like, so
21:42
I've been following it very loosely. I haven't
21:44
actually participated in any of the standardization work
21:46
on reflection, but I'm doing other
21:49
stuff on the committee, but you kind of hear like
21:51
what's going on a little bit here and there.
21:53
There's like a paper here that people discuss or
21:55
like something there that just was released. So I
21:57
was kind of loosely following it and whatever. another
22:00
remember, like we had the reflections here. That was
22:02
a while ago, right? That was stuff
22:04
by like David Sankal and a few other people.
22:07
I like so Norman and
22:10
Matthew, Matthew, yeah,
22:12
exactly. Yeah, yeah. So
22:14
everything was kind of template based, like you have to
22:16
write colon colon type everywhere. And it was kind of
22:18
a bit difficult to use. And I
22:21
remember you had some papers saying, no, we shouldn't
22:23
be doing that we should have like a value
22:25
based reflection where you reflect on a property and
22:27
you get an object back, right? And you can
22:29
write more kind of procedural code, even though it's
22:31
obviously compile time, but more
22:33
procedural code kind of
22:36
to work with that much more easily. Then
22:38
I remember it was maybe somewhere around the
22:40
Prague meeting. It was the last meeting before
22:42
the lockdown, or maybe roughly around that time.
22:44
I remember there was a paper
22:46
by Andrew Sutton, which had like a hundred pages where
22:49
there was a lot of new syntax and
22:51
like, Oh, let's do this, let's do this, let's do this.
22:53
And I didn't really understand that paper. There
22:55
was like a lot going on there. But
22:58
then there was like, I think a few years where just nothing
23:01
happened, or probably a lot of stuff happened in
23:03
the background, but nothing visible to me. Like there
23:05
was just like the reflection
23:07
study group wasn't sitting, there were no
23:09
new papers coming out. And I was
23:11
thinking, okay, that's
23:14
very sad. You know, everybody says we need
23:16
reflection, but apparently somebody just stopped
23:18
the funding for this. And now nobody's working on
23:20
it anymore or something. I don't know. So there
23:22
was several years of silence. And all of a
23:25
sudden now there's just like revival where there's this
23:27
amazing new paper that came out and people
23:29
are talking about, we might already get it
23:31
in C++26. Anyway, like, can
23:33
you fill in the blanks? What actually happened there? And
23:35
like, who's involved in this
23:37
effort? And like, where does it come from? Okay.
23:40
Can I go even back a little
23:42
bit further? Absolutely. We have time. Okay.
23:46
Well, I could go all the way back because My
23:48
interest in this comes from my very
23:51
first touching C++ in the late eighties
23:53
and early 1990s. But I Won't go
23:55
back there. But Like you mentioned, the
23:57
TS came out of... The
24:00
Formation of As You Seven And I don't
24:02
know why, but I completely missed that. So
24:04
when Sandler, Truth and top of on
24:06
people. Started. Up. As
24:09
she seven than this are doing this work. I've
24:13
done just about every meeting of the on
24:15
committee and I I did not see what
24:17
was going on there. Some. Point:
24:20
I did see what would later
24:22
become Tts and I thought. You
24:24
know, I don't think it's a good way of doing things. says.
24:27
You know to to use template method
24:29
programming. As the matter
24:31
programming model going forward can it's It's hard
24:33
to debug it's it doesn't look like the
24:35
recipe professor. It's a different way of programming.
24:38
So. It's a fanatic. We've
24:41
been able to. Extract that
24:43
are out of. A complex.
24:46
And wouldn't be nicer if you could. Actually.
24:48
Program using for Roots and the standard library
24:51
and and a guy that. Twice.
24:54
A rather an initial paper. For.
24:56
As the southern about that. And
24:59
Andrew certain had been working
25:02
with Herb. On another
25:04
project which was another classes that.
25:06
He. Froze seen Herbs talks about as yes
25:09
as a paper. That also generally quite
25:11
lot of attention everybody was talking about
25:13
and and. To. Stopped at
25:15
some point. Oh around the
25:17
same time as as submit this paper saying you
25:20
know we should work go with value based programming.
25:22
Andrew came with his own
25:25
paper, which. Was
25:27
somewhere in between. So template
25:29
with affirming and and value bit from
25:31
it it's is a bit like ah
25:33
if you know Louis the Arms or
25:35
Hannah Library this way which it is
25:37
under the. Under the Covers is a
25:40
lot of stuff of myth burning, but it presents itself
25:42
more like I'm. A value base
25:44
kind of. Interface.
25:47
Oh retention thirty seven meeting.
25:50
And. Represented are are
25:52
are points and as the sudden agree that the
25:54
was a lot from their. Ah
25:57
and Andrew and I started
25:59
setting. and agreeing to
26:01
work together to work
26:03
out what it actually would take to have
26:07
a value-based reflection. So
26:10
out of that discussion came P1240. But P1240 was a
26:12
fairly large paper, fairly
26:16
ambitious, and it
26:19
showed how we thought we could get
26:22
to useful reflection-based,
26:25
value-based reflection and meta-programming.
26:29
And so I started implementing that
26:31
in the EDG front end, but I did
26:33
it on my own time,
26:36
and my own time was very limited. At the time,
26:38
I still had young kids, and
26:40
so I'd do that while I drive them to
26:42
their class and while they're in class, I try
26:44
to, you know, add one
26:46
part through or something. Like, it progress very
26:49
slowly. Andrew and
26:51
Wyatt Childers, who at the time
26:53
was working for Andrew and Andrew's
26:55
new company, Lock3, made
26:58
the same effort in Clang,
27:00
and they got a lot farther. So the implementation
27:03
was fairly complete, and so
27:05
he showed, you know, he showed how it could
27:07
be done. But we also
27:09
started talking about, well, what comes after
27:11
P1240? So P1240 is mostly asking
27:14
questions about the program
27:17
and getting back values. And there were a
27:19
few things you could do afterwards to affect
27:22
the program, but it's mostly pure reflection,
27:24
meaning examining what your program consists of,
27:27
right? So you could ask what
27:29
the names of your enumerations are. That's usually
27:31
the number one application we want our enums,
27:34
enum names to be reflected as strengths. And
27:37
it's solved that problem and some others. But
27:40
we were thinking, like, how can we scale
27:42
this up, and what will be the future for that? And
27:45
so then we came up with this idea
27:47
of injection. I say came up with,
27:50
there was a presentation I made at
27:52
the committee in Oxford in 2003, I
27:54
believe, that
27:57
actually showed injection and precursor
28:02
to const-eval functions and things like
28:04
that and had most
28:07
of the features there but we brought them
28:09
into a modern language at
28:11
that point. I may have seen that talk. Oh,
28:13
excellent. The slides for it
28:16
are available on the on
28:19
wg21.link but I don't remember the number it's
28:21
like 1700 or so. In any case what
28:26
Andrew then did was take all these ideas
28:29
and bring it together in a vision paper.
28:31
So that huge paper you're talking about is
28:33
not necessarily a proposal. It's more like here's
28:35
what we could do if we
28:37
were willing to push this
28:39
trip. So here's a possible future
28:42
and a future that we think would be
28:44
very desirable in the long term. And
28:46
so in addition to being
28:48
able to do reflection so asking questions it
28:51
has a mechanism to inject bits of code
28:53
here and there in your program. So the
28:55
function is no longer limited to returning a
28:58
value it can also as a side effect
29:00
generate more C++ code
29:02
and that's a very very powerful idea.
29:05
And lock 3 implemented some of that. There's
29:07
different ways you could think of injecting. You could inject
29:10
strings for example. You could say well you know I
29:12
can build a string and at any time I can
29:14
say compile or please take my string and
29:16
compile that. That's actually super
29:19
powerful. It's a little harder
29:21
to debug. Now you
29:23
need tools that because you don't longer see your
29:25
source code it's somewhere inside the
29:28
compiler. What lock 3
29:30
did was it also developed a
29:32
notion of fragments where you actually
29:35
make little patterns that you can then inject
29:37
in the code. It's a little easier to
29:39
debug. It
29:42
also has the advantage that you can parse it
29:44
up front. On
29:46
the flip side it's a little harder to use. In
29:50
any case so that was the situation going on
29:52
there. In Prague we
29:54
made some good
29:57
progress and the P1240 paper was essentially
30:00
accepted as the way to go forward.
30:03
And then the pandemic hit. So
30:06
during the pandemic, as you said, we didn't
30:08
meet too often, but we met a few
30:10
times. And then someone
30:14
suggested that maybe we revised the
30:16
decision to go with P1240. Couldn't
30:19
we still do
30:21
something in between the TS and
30:26
P1240, so a constant
30:28
value-based reflection. And
30:31
there were a couple of, as you said, the meetings around
30:34
that. And there was a meeting that
30:36
was scheduled where, and I prepared for
30:38
that meeting, I actually had a presentation that would
30:40
show that all the things that the
30:43
other party suggested were hard to do
30:45
in our model could actually be done
30:47
without too much effort. But
30:50
that meeting for some, there
30:52
was a scheduling problem and it
30:54
was scheduled, but it didn't happen. It got canceled last
30:56
minute. And so we never followed
30:58
up. Like you say, for over
31:01
a year, probably, there were no more meetings of SG7.
31:04
I'm not entirely sure why. I think we all
31:07
kind of got distracted. I certainly had some personal
31:09
issues in my family life. And
31:11
then, I don't
31:13
know, maybe six months
31:15
ago, maybe a little more. I
31:18
thought, I started talking with
31:20
Barry Revlin. And if you
31:22
know Barry, he's responsible for about half
31:25
of what C++23 has to offer. He's
31:28
a very productive guy,
31:30
very smart. And if
31:33
you can get him on your team, things
31:36
move along. And so we talked
31:38
about reflection because he's also interested in that. And
31:41
I asked him if he would be willing to help with
31:45
coming up with something and try to aim it at C++26. And
31:49
that's where P2996 came from. So
31:52
he said, okay, what are the minimum viable
31:54
products you could come up with and
31:57
bring it to C++26? And
32:00
so we P296R0, so
32:03
the paper that was presented in
32:05
Kona, was written really quickly.
32:09
It's a paper that has a hard
32:12
time standing on its own, in my opinion, because
32:14
it relies very much on
32:16
details that are in P1240. So
32:18
they take out of P1240 a bunch
32:20
of ideas, simplify it some,
32:23
actually add a few things to compensate
32:26
for that oversimplification, and
32:28
then say, okay, we can get this done in CCO26. I
32:32
also got my company let
32:34
me work on this a little bit more
32:36
on company time. And
32:39
so soon after Kona, I
32:41
implemented a fair amount of P296
32:44
to the point where most of the examples that are in
32:46
that paper are now supported in our
32:48
frontend. And we made that
32:51
available at the end of December. So
32:54
if you go on Godbolt right now, you
32:57
can click the EDG experimental
32:59
reflection compiler, and then
33:01
you can try the examples for P296
33:03
in adapted form. So
33:06
we, at the same time that
33:08
we released the EDG frontend with
33:10
that experimental support, we
33:14
made an update to P296, which is
33:16
R1, mostly thanks
33:18
to Barry. And
33:20
that has examples with links to
33:22
Godbolt that show, oh, look, it's
33:25
working. And
33:27
also it has more examples than the R0 version
33:30
of the paper. So
33:33
that's where we are for now behind the
33:35
scenes. We've been working hard at getting
33:38
ready for Tokyo, where we hope to have
33:40
a stronger
33:42
paper to discuss in
33:44
EWG and LEWG. When
33:47
I was reading the paper, I was clicking through
33:49
the Godbolt links to see most of the examples
33:51
you got there. As you say, some are in
33:53
slightly modified form. So that
33:56
was really useful just to actually
33:58
see it working, even though it's not. standardized
34:00
yet. I mean it sounds
34:03
like a really complex thing to implement just
34:05
in not quite the spare time you've got
34:07
some company time on it but so I mean was that
34:09
a difficult process to get that in? So
34:12
it's as features
34:15
go you know I
34:17
often think about the cost of implementation
34:19
versus the benefits you get. And
34:23
here it's not bad at all so a
34:25
lot of the reflection stuff everything that's meta
34:27
functions is actually typically simple in the sense
34:30
that the compiler already has all that information
34:32
it's just a matter of carrying them
34:34
into the constable world and
34:37
like creating vectors with reflection
34:40
and internally a reflection is a
34:42
kind of like a tagged pointer it says oh this
34:45
is a reflection of the constant value
34:47
or a type or variable right
34:49
and then a pointer to what the
34:51
compiler thinks it has a representation of that.
34:53
So that that's really not hard to do
34:57
for us my father horse is a splicer
34:59
so that is the opposite of
35:01
a reflection so once you have done some computation
35:03
with the representation of the program you want to
35:05
bring it back into the program and so we
35:07
have a notation to turn
35:10
a reflection value back
35:12
into a program construct that's
35:15
a little trickier. It's
35:17
not super complicated
35:20
it's a lot think of a variadic template
35:22
for example for us at least variadic templates
35:24
are very hard features to implement and
35:28
I talked to some of the client engineers
35:30
and it's all made it's pretty it's
35:33
wide-ranging whereas this is not to
35:35
be wide-ranging so individually a splice it can
35:37
be a little tricky but
35:40
it's not something that reaches everywhere into the compiler
35:42
once you've got it it works. So
35:45
I'd say it's actually
35:47
probably a little simpler than lambdas which is
35:49
a medium sized feature. That's interesting I would
35:52
not have expected this to be easier to
35:54
implement than lambdas. That's really quite interesting. It's
35:58
hard to compare right like also It
36:01
was 15 years ago that we implemented
36:03
Lambda, but I feel it's
36:06
on that order of magnitude. It's
36:08
a medium-sized feature. That's really interesting. So you're
36:10
going to get into more details about splices and all
36:13
of that in the second half of the episode. But
36:15
before we do that, I'm just
36:18
curious, what's the current state of the paper? Has
36:20
it been in the evolution study group now? Where
36:22
is it in the standardization process? Is it heading
36:24
for C++ 26 or where are we now? So
36:30
at the Kona meeting in November of 2023,
36:32
it was voted out of SG7. So
36:35
I think of the SG as sort of
36:38
the research arm of the committee. It's like
36:40
a subgroup that's like, okay, let's look at
36:43
the great questions, which way
36:45
they should be answered. And
36:47
we got out of there. And so that
36:49
was based on the P2996R0 paper. And
36:54
they said, yes, let's go with this direction. Now
36:56
give it to EWG and LEWG because
36:59
unfortunately this is a feature that requires
37:01
cooperation from both of those design groups.
37:04
That makes it a little more complicated. It's
37:06
going to require some synchronization
37:09
between those two groups. So that's where it is
37:11
now, but it hasn't actually been discussed in those forums
37:13
yet. That's going to start in Tokyo. We've
37:17
been working on internally
37:21
coming up with wording for
37:23
the proposed wording. Here's
37:25
what we think should be the
37:27
changes in the standard to implement
37:29
this. But also we need
37:31
to flesh out the discussion, the design discussion.
37:34
Why do we do this instead of that? Or
37:37
even PR2 options, what do you think we should do?
37:39
I think that's what we're going to discuss in Evolution
37:41
Working Group and Library Evolution Working Group. It's
37:48
the right design for
37:50
the general vision that SG7 has forwarded
37:52
to you. And once
37:54
we're done with that, we're
37:57
going to have to go to
37:59
the... core working group
38:02
and library working group to look at
38:04
that wording. There
38:06
is, I believe, a slight difference between
38:08
the way the library arm of the
38:10
committee works and the core
38:13
language arm of committee in
38:15
that evolution.
38:17
So the core language evolution
38:19
group will not forward something
38:21
to core without specific wording for
38:23
everything. So core
38:26
can then modify that, but it's the requirement.
38:28
I believe that that's not the case in
38:30
library. Oh, it is now. It is now.
38:32
When I was there in, what was it,
38:34
in Varna, I think, with the in-place vector
38:36
paper, they spent
38:38
like an hour going over the wording in library
38:40
evolution. And they said, oh, no, you need to
38:43
fix this and this and this. OK.
38:47
But I feel pretty good about it because we have
38:50
a lot of good people on the team. So I
38:52
mentioned Barry already. We've got Peter Dimov,
38:55
who's a long-standing expert on library
38:57
issues. We've got Andrew Sutton. He's
39:00
been in a different world lately, but he's
39:02
still an expert on reflection. So we have
39:04
his input there. We've got
39:07
Wyatt Chilott, who was one
39:09
of the main implementers of the Lock 3 implementation.
39:12
And he's now a colleague. He works with the G now.
39:16
And we have several other people who are helping
39:18
us flesh out the details of
39:21
this. So I think
39:23
we should have a pretty
39:25
good wording story for
39:27
our team to show. I mean, it's kind of interesting. It
39:29
sounds like you're in a very similar boat, we
39:32
are in SG21 with contracts. Also
39:35
a kind
39:38
of not small language feature, which
39:41
has a library API attached to
39:43
it as well. The
39:45
study group, now it needs to go to all
39:47
of these other groups. And
39:49
it needs wording and all of that. I think you're a little bit ahead of
39:51
us. You already voted it out of
39:53
SG7. We haven't yet voted our proposal out of SG21.
39:57
But hopefully we're going to do that by Tokyo.
40:00
Or. Even before Tatyana telecoms of you're not that
40:02
far behind but like let's see it's cannot
40:04
interesting as kind of the same process. But. It.
40:07
Looks like these are the two big like
40:09
language teacher heading for. Is. A twenty
40:11
six kind of a reflection and contract some.
40:14
I'm curious. was gonna get into wedding dropped
40:16
first ah know watching draft class to raise
40:18
it is it's a raise and since the
40:20
Coraline the car working group in the lower
40:22
working group are often the bottlenecks are getting
40:25
troops were were trying to of elbow you
40:27
guys out of mathematics there for a sign
40:29
ups as I get their Benson and then
40:31
you can wait until we're done. Results are
40:33
resisting Korea's our telecom frequency from every two
40:35
weeks to weekly to like prevent you from
40:37
doing the hats. Or
40:40
eyes. I'm I'm. Gonna start of the other guys
40:42
are. Writes itself
40:44
that saw it as an arm arms race
40:46
slurry. Gonna die for. Motor nice but competitions.
40:48
Yeah so you gotta have a little bit
40:51
deeper into Howard the Proposal for effect in
40:53
Wax. but our before we do that I
40:55
would like to read a message from our
40:57
sponsor for this episode. So. This
41:00
episode is supported by Native Instruments,
41:02
guided by their mission to make
41:04
music creation more inclusive and accessible.
41:07
They. Create innovative hardware and software
41:09
that inspire and empower musicians, engineers,
41:11
and Djs a fool's on earth
41:13
and levels of experience to express
41:16
themselves. Want. To work and
41:18
world class tools for music
41:20
and would you take out
41:22
their careers center at www.native
41:24
Minus instruments.com/careers. And
41:27
with that, we're back here with their bids. Can.
41:29
I make as a little note
41:31
about this the sir enough and
41:33
she just made yes oh. So
41:36
your listeners don't see this but
41:38
we are actually on and video.
41:41
Three way call. And
41:43
you talking about instruments? I notice in
41:46
the background of each of our. Of
41:49
the city of feeds off music instruments
41:51
of all three of us. are
41:53
the know that means anything but i guess
41:56
from was like committee of the it's i
41:58
think a particularly fun industry to use
42:00
C++ in, like a lot of audio stuff
42:02
is in C++ and it's
42:04
a very fun industry to work in. I've spent a
42:06
decade of my career in that industry. I've now lately
42:09
kind of moved away from that but yeah
42:12
it's a good, it's an interesting field to work in. There's
42:14
a lot of C++, that's a lot of music, it's
42:16
pretty cool. We need to do an audio
42:18
developers episode. Oh maybe
42:20
you should. If
42:23
you know Dave Abrahams, I believe he started off
42:25
or at least had part of his career in
42:27
the audio world as well. I'm not an audio
42:30
programmer, I just play a bit of music but
42:32
I thought that's interesting. Yeah
42:35
that is interesting. Well, so
42:38
let's talk a little bit more about reflection.
42:41
I want to in the remaining time dive
42:43
a little bit deeper into how your proposal
42:45
actually works. So you say it's
42:47
a reduced initial set of features, so it's
42:50
kind of a subset of like the bigger
42:52
picture. So what features are
42:54
actually in there and which are
42:56
not and why? Like what's in that
42:58
paper? Like very roughly, like
43:00
what can you do with it? Like
43:03
can you do conversion between steam and
43:05
enum? Can you like do serialization, de-serialization,
43:07
all of these like typical use cases
43:09
that people use horrible macro hacks for
43:11
today. Give it to yourself. Exactly. So
43:14
those were sort of a minimum
43:17
needed feature sets
43:19
right. When SG with 7 got
43:21
formed, I think it was Jeff
43:23
Schneider and some other people wrote
43:25
a paper of here's what we need and
43:28
these I think there were about seven items.
43:31
The enum to string was one of them, the
43:34
serialization for the ability to look at a struct
43:36
and ask a struct what are you composed of
43:39
and can access your values. So
43:42
that we support that.
43:44
You can think of it as three
43:47
parts. One is get
43:49
from a source construct to
43:52
a value that represents that construct. And
43:54
for that is the charit operator, prefix
43:56
charit allows you to
43:58
say charit. int and now you
44:00
have a value that represent the
44:02
int type but you could also do caret
44:05
42 and now you have a
44:07
representation of the value 42 or
44:10
caret some template name like std vector int.
44:14
So that's step one you bring things into
44:16
a domain that you can do computational. Then
44:19
we in anticipation of this
44:21
we had developed a C plus 20 a
44:24
whole bunch of extensions to conflict including
44:26
the const develop functions which are functions that
44:28
have to happen at compile time. So
44:32
with the const develop functions you can
44:34
do all kinds of manipulations of this
44:36
representation and part of the
44:38
proposal is there's a couple of
44:40
magic more than a couple. There's a series of
44:42
magic functions we call them
44:44
the meta functions or intrinsic meta functions
44:46
which allow you to given one of
44:48
these values ask questions about it or
44:50
even make transformations on it. So
44:53
you can ask are you a type? Are
44:56
you an instance of this template? And
45:00
then the third part is once you're done with
45:02
all your computation you have to bring it back
45:04
into your source
45:06
code. Like maybe you
45:08
want you have an enum
45:10
a reflection for an enumerator you want to turn
45:13
into a string. Well that's not so difficult we
45:15
already have strings but sometimes you
45:17
actually want to turn into a you
45:21
want to express a type not as a
45:23
name but as a computation as an expression. And
45:26
so for that we need a new notation and
45:29
for various reasons it
45:31
is useful for that notation to be delimited
45:33
meaning it has to be like parentheses or
45:35
brackets or braces. Unfortunately those three
45:37
are already all taken so we
45:39
ended up with a new
45:41
pair of tokens which is per bracket
45:44
colon square bracket to close so that
45:46
is that's what we call splifters. But once you
45:48
have computed a reflection value of
45:50
interest to you you
45:53
can use it
45:55
as if it were an actual language construct
45:57
by surrounding it with with
46:00
those tokens. So
46:03
with those three things, so the
46:05
charit operator bringing the reflection,
46:07
the splicer delimiters, and
46:09
then the magical meta functions,
46:12
you can do everything. And
46:15
you actually have a framework in which we can
46:17
do much more in the future. So people who
46:19
are anti-fix is not the last word in terms
46:21
of reflection. Like
46:26
Andrew's paper that sort of had this vision
46:28
going forward, we were
46:31
pretty convinced that this is a great platform
46:34
to extend around. And
46:38
we have internally implementations of other features
46:40
that are not proposed in the paper,
46:43
but that we have already done and show
46:45
that we will be able to do very powerful things
46:47
in the future. So
46:51
addressing really valuable use cases that everyone
46:53
has and getting rid of lots of
46:55
tedious boilerplate, that's one thing. But
46:58
as C++ developers, what we really want to know is what
47:00
color to paint the bike shed. So just
47:02
to focus on the syntax for the
47:04
moment, because that's one of the most visible things when
47:06
you first look at the paper. The
47:09
charit operator, that really stuck out to me after using C++
47:12
CLI years ago. That
47:14
reminds me a bit of that. But why did
47:16
you go with the charit operator? What were the
47:18
other things you considered? Like the Reflexfro
47:21
is what was used in the TS? Yes,
47:25
so the TS used Reflexfro as a new
47:27
token. And you can
47:29
think of it as meaning one of two things. Either
47:33
reflect expression or reflection
47:36
expression. The reflect
47:38
expression would mean that what it does is
47:40
it takes an expression and
47:42
reflects it. However, it turns out that
47:45
of all the things you can reflect, expressions are
47:47
the hardest, and the TS doesn't do
47:50
much of it. So it's
47:52
probably not a good token for that. Now, the
47:54
other one is interesting.
47:56
It's a reflection expression, which is true.
47:59
In fact, even more. true in our model where
48:01
it is an expression,
48:03
in the TS it was not an expression, it created right,
48:06
so it was a bit of a missed moment. But
48:09
for us it's a perfectly fine token and
48:11
I believe in
48:13
the very first version of P1240
48:16
we used that token and
48:20
even after that we used Reflexper,
48:22
it works great, it's
48:25
a little heavy because it turns
48:27
out that very often you
48:29
want to pass things by reflection, like
48:32
you want to pass an int to a
48:35
function as a parameter and saying
48:38
Reflexper, open parentheses, int, close parentheses, the
48:40
int is almost lost compared to the
48:42
length of the Reflexper and the parentheses
48:44
and so having the the carrot which,
48:47
the reason why we said we chose that one
48:50
is it has the idea of lift, you know,
48:52
go up in representation. Interesting, that
48:54
kind of makes sense, I like that.
48:58
In some languages it's called the lift
49:00
operator, so
49:02
that's why we chose that. It
49:04
does not conflict with the C plus CLI
49:08
notation because in
49:10
C plus CLI the carrot
49:12
is used for a, I think it's
49:14
called handle, right, it's a, or
49:16
yeah I think it's handle, the
49:18
percent is the reference
49:21
and the carrot is the handle but
49:23
it's only in the declarative right,
49:26
context where when you declare these things,
49:28
when you try to
49:30
indirect those things you still use the asterisk
49:33
and for us the lift is an operator
49:35
which is only in the, it's never declarative,
49:38
it's only in expressions so
49:41
there's no conflict there. I think there
49:43
is a conflict with objective C lambdas
49:46
which use carrot. Yeah
49:48
with the blocks which are C feature
49:51
and there's potentially a conflict there, that's
49:53
correct. All right, so
49:57
that's something we're going to have to look
49:59
at probably some. more. I
50:01
just get those people into Swift. So
50:06
but yeah, so that's where that's where that came from. But
50:09
you know, we could certainly do with reflex pair, it's
50:11
just not as as light of
50:13
notation, more typing work. And I don't mind typing.
50:16
But when you look at it in, you
50:19
know, when you apply meta functions on it,
50:21
like very often you'll do like, you
50:23
know, substitute this template with an
50:26
int. And being able to say
50:28
just hat int, as opposed to reflex pair
50:30
int, it makes the notation more, unless
50:33
you focus more on what's important. It's definitely
50:35
a lot cleaner. Yeah. I never
50:37
thought I'd say about the character operator, but there
50:40
it is. But you said that expressions
50:42
are not something you reflect on very
50:44
much. So what do you typically reflect
50:47
on? Is it just types or other
50:49
things? Functions,
50:52
functions, class class, that's probably the number
50:54
one, I'd say a lot
50:57
of problems come down to a form of
50:59
serialization, right? Or at least
51:01
looking at the structure of attack. So
51:04
I think that that's going to be the the
51:07
feature that gives the most boilerplate
51:09
savings in
51:12
the first in the first few years
51:14
of reflection hit in C++, when people
51:16
will no longer have to have
51:19
a separate Python script to, you
51:22
know, generate your structures from a pseudo
51:24
structure and definition. I
51:27
think a lot of people are excited about about
51:29
those applications. But but you can
51:31
reflect namespaces like you could you could
51:33
have code that looks in one namespace
51:35
in one configuration and not an database
51:37
in another configuration, for example, by having
51:39
two different namespaces and selecting with
51:42
a question mark operator, which one you want. That's
51:45
so powerful. That is
51:48
really cool. Or also same with types,
51:50
right? Like you have a you put
51:52
a bunch of types in this vector,
51:54
you sort them according to certain criteria,
51:57
and you use whichever is applicable. Um,
52:00
yeah, it's
52:02
a lot of it's what
52:05
I'm most excited about is to see what other people will
52:07
come up with. Um, yeah, I had, uh,
52:09
one person recently sent a really nice
52:11
email and they sent an implementation
52:13
of two pull caps. Now
52:15
I'm not, I started
52:17
my days in the committee in the standard library,
52:19
but I was only about one year's worth. And
52:22
then I moved down to the core language and
52:24
I'm no longer a, an expert. Um,
52:27
on the standard library, but I
52:29
was made to understand that two placards hard
52:31
to implement the people today. Two pull is
52:33
just in general, the most, one of the
52:35
most painful parts to implement in the standard
52:37
library, doing anything with them is,
52:40
it's just such a pain. And it shouldn't be
52:43
right. Because in every other programming, reasonable programming language
52:45
is just a built in thing. Well,
52:50
I don't, I, I want comments on that.
52:52
I know what StupiCad does, which is just
52:54
take two tuples and make a new people
52:56
with this with the concatenated values. Uh,
52:59
and apparently with the P
53:01
two nine visit demo version of the compiler,
53:03
he was able to implement it much more
53:06
in a much shorter way. And so that's
53:09
very exciting when something that we did not
53:11
anticipate, uh, gets done
53:13
using the same tools that that's that
53:15
shows us that we're probably on a
53:18
good, on a good track. Yeah. That's, that's really
53:20
cool. So, so you apply this carrot operator to
53:22
like a type or a namespace or a function,
53:24
you get an object back
53:26
that, um, kind of you can use
53:28
to do something. But so, so one
53:30
thing that I found surprising in the paper is I
53:33
would have expected that for a type, you get
53:35
like a meta type object back and for like
53:38
a variable, you get a meta variable back. And
53:40
then the meta type has like members saying, you
53:43
know, these are the members of the type and
53:45
this is like, whether the type is const or
53:47
whatever, whether. And so, so, but
53:50
that's not what happens. You get like this
53:52
method info object back, like whatever you reflect
53:54
on. It's just like one single opaque type
53:57
that you used to query everything. So
54:00
I was like, okay, this is not an obvious
54:02
design choice. Like what's, I remember there was some
54:04
debate about this, which I haven't followed, but like
54:06
there must be a reason, but I don't really
54:09
see it. Yes. So
54:12
there's a couple of reasons. And you're
54:14
right. This, this was perhaps the most
54:16
debated part in, in SG7.
54:19
But from my point of view, the number
54:21
one reason for it is
54:23
that we do not want another ABI. And what I
54:25
mean by that is today
54:27
there's a lot of decisions we've
54:30
made in the language that we cannot
54:32
walk back because the
54:34
ABI, we want ABI stability. All
54:37
right. Now reflection, what it
54:39
does is encodes in values, the
54:42
language, the language specification itself.
54:45
Right. And to give you an example,
54:49
that language specification right now is
54:51
able to move definitions around
54:53
fairly freely. In
54:56
C++03, the term
54:58
variable in the standard, meant
55:00
something a little different from what it meant
55:02
in C++11, in the sense that references were
55:05
not variable in C++03. They
55:07
were their own thing. So you had variables and
55:09
then you had references. There were two different things.
55:11
And C++11, they became one thing. All
55:14
right. Now, if we're going
55:16
to encode stuff like that into
55:19
the library, right? By
55:22
saying, well, you have a
55:25
variable info and you have a reference info. And
55:27
suddenly you say, well, our vocabulary
55:32
to describe this thing has changed. So
55:34
now we have to change the library to match it. You're
55:37
breaking all kinds of programs. You
55:40
see what's happening? Yeah. Another example is, for
55:42
example, structured bindings. Today's
55:45
structured bindings are sometimes variables and
55:47
sometimes not. Right.
55:51
But maybe in the future, they will always be variables
55:53
or maybe not. Right. So
55:56
do you want to encode that in
55:58
your type system? and
56:01
then find yourself cornered because
56:03
you can no longer evolve it because
56:05
plenty of programs have come to rely
56:07
on those
56:13
strict rules. Now,
56:15
first, there's still some of that dependency in the
56:17
value representation. But the value, because
56:19
it's a value, you can dynamically
56:21
depend on it. I
56:23
mean, dynamically select on it.
56:26
So if you write your programs correctly, even if the
56:28
language changes, and say
56:31
once you reflect on structure
56:34
bindings, for example, and you ask if this is a
56:36
variable, maybe a particular structure binding
56:38
today is a variable, but in the future it's
56:40
not, your logic could be
56:43
written in such a way that you would be
56:45
insensitive to that. You would do the correct thing
56:48
in any way. If you
56:50
know, Titus Winters used to be the
56:53
chair of Library Evolution, and he made
56:55
an astute observation. He said, it's
56:58
the higher you go up in abstraction, the harder
57:00
it is to evolve. So
57:04
changing the values returned by
57:06
a function from
57:08
one standard to the next, it can
57:10
be a little painful, but it's not horrible. Changing
57:14
a type, it's much,
57:16
much harder. And that's why we still
57:18
have the third vector bool as
57:20
a specialization. We cannot change its meaning
57:22
because it's at the type level. And
57:26
Titus pointed out that we now have a
57:28
higher level of abstraction, which is a concept.
57:31
And he predicted that we really have
57:33
to get these right because
57:35
concepts are so high level
57:37
that if you change what it means in the
57:40
future, there's not a
57:42
single program that's going to survive. Yeah, I
57:44
actually heard developers who say still they
57:46
are not going anywhere in your concepts
57:48
in their own libraries because once
57:50
you have them, you can never change them. So they just don't
57:53
use them, which I found strange, but
57:55
also plausible at the same time.
58:01
We want to understand how these things work. In
58:03
any case, that is my
58:05
primary reason for not wanting
58:08
to encode reflections as
58:10
a hierarchy of types or as a collection
58:12
of types, because
58:14
I do not believe we will get
58:16
it correct forever. And
58:20
we need that ability to be able to change
58:22
over time, evolve things over time. Now,
58:25
another possible answer is that
58:27
every compiler has different ways
58:29
of organizing its internals. And
58:34
so having
58:36
that type be a particular set
58:38
of types that maybe map one
58:40
compiler but not another, that
58:44
might be a great strategy to encourage
58:47
having a varied
58:49
ecosystem of implementations. And
58:53
then another one is that
58:56
by having this opaque type, it's
59:00
already ready to encode things that don't
59:03
exist yet. For
59:05
example, when lock3 added fragments,
59:08
it turns out fragments, the
59:10
value of a fragment can just be a reflection itself. And
59:14
it works really well in the
59:16
whole ecosystem with the meta functions and so
59:18
on. Nice. So
59:21
how do you interact with these infin
59:23
objects? So
59:25
you pass them through your meta
59:27
functions. You can ask them
59:29
questions. Are you a type? You
59:31
can even issue
59:34
errors if they're not the right thing. Now,
59:37
although it is
59:40
a dynamic thing, it's still
59:42
compile time. So you're not
59:44
going to generate bad code
59:47
unknowingly. If you try to, for
59:49
example, if you have, say, a
59:52
reflection for a variable, and then
59:55
you use a splicer to make it an actual
59:57
variable in your program. But
59:59
instead of just a of using it where a variable is
1:00:01
expected to use it, where type is expected. We're going to get
1:00:03
a nice error and say, Hey, you
1:00:05
know, I expected a type here, but you
1:00:08
gave me a reflection for variable X. Wait. So
1:00:10
is that like the library API that you mentioned
1:00:12
earlier, that you have something like std is type
1:00:14
and then you can ask it if it's a
1:00:17
type, stuff like that? That
1:00:19
that's yeah, yeah. You can do that, but
1:00:21
the splicer itself. So the compiler
1:00:23
knows when you use it, right? So say
1:00:25
you have that variable and you try to
1:00:27
say using X equal and
1:00:29
you spot the type there, right? Cause it has to be
1:00:31
a type and you've used that variable instead of just going
1:00:34
to say, Hey, this is not a type. This is a
1:00:36
reflection for a variable. Wait. So, so
1:00:38
just to recap, so splicer, that's like the
1:00:40
square bracket colon something, colon square bracket. Yes.
1:00:42
So is that like the opposite of the
1:00:44
carrot operator? Like it turns it back into
1:00:47
like a type or whatever it is. Exactly.
1:00:50
Yes. So, so basically it's like, if
1:00:53
you do cat, like some carrot, something,
1:00:55
and then a splice of that carrot,
1:00:57
you get exactly the, this like
1:00:59
a round thing. So you could say, you
1:01:02
could just say square bracket, colon, carrot
1:01:04
in square bracket, colon, sorry,
1:01:06
colon square bracket. And that's
1:01:08
as, as if you had just been in. So you can
1:01:10
use that anywhere in your code, like as a type, you
1:01:12
can say. Like square
1:01:14
bracket, colon, something, blah, blah, blah.
1:01:17
And then to declare a variable or whatever. Yes,
1:01:20
exactly. Ah, so it's like, it's making
1:01:23
a code injection now. It's
1:01:25
a, it's a, it's a limited form of code. And like,
1:01:27
you can only inject the things that you like the types
1:01:29
of entities they can reflect on, but it's
1:01:31
kind of like a code injection. Yeah.
1:01:34
And the things you can inject are types.
1:01:37
So wherever you expect the type name, you can put
1:01:39
a type, you can put a constant
1:01:41
value, you can refer to
1:01:44
a variable, a function, a namespace,
1:01:46
a data
1:01:48
member. Those
1:01:50
are the ones I can think of. So I don't
1:01:52
think the reflection has had that. Like, I think that
1:01:54
that's new. That's cool. It
1:01:57
had some versions of it, but for example,
1:02:00
How can do everything was. It.
1:02:02
Didn't have a new kind of thought of something.
1:02:05
The. The Ts if you want
1:02:07
to access the members of his tracks. You
1:02:10
has it was appointed. Members Are you? A.
1:02:12
It would provide. Must have bothered with give you
1:02:15
back point two members. That. Phrase
1:02:17
until you have a bit shields
1:02:19
and use flash then or or or
1:02:21
russians. Because. He can't pass on
1:02:23
to members that point to be feel to references.
1:02:26
As rest was the this proposal.
1:02:28
there's no problem. Or than an
1:02:30
uninformed a character that the did feel the can
1:02:33
represent. A reference
1:02:35
and when you use the spices and that from
1:02:37
it, that's what he gets. So you can say.
1:02:40
You know, Fireball dots.
1:02:43
Of spices, syntax and the info for a
1:02:45
bit fields and you have no access to
1:02:47
pick since not and it just works. On
1:02:51
can yeah I'll have to like. Play.
1:02:53
Around with that takes a little bit or up
1:02:55
my head around up and it looks sounds like
1:02:57
it's very elegant. Next thing. I
1:02:59
think it works really well. I think the some examples
1:03:02
of the I believe up with the a bit silly
1:03:04
complain the between and Twenty Nine and Six paper. But.
1:03:07
Yoga and not of be harbor and
1:03:09
on mine. Demo
1:03:11
version which a movie is fragile on
1:03:13
the stephanie Not for the baked but
1:03:15
you can do a lot of stuff
1:03:17
already with them and try it out.
1:03:20
And. Experiments with the to get a feel for
1:03:22
how to quote schools. So they put
1:03:24
their linked to the got poll thing to the
1:03:27
shown at somebody the container with it. Because.
1:03:31
Since. We're talking about spices to spring
1:03:33
things from soccer games. Come back to
1:03:35
the syntax. Timur decide
1:03:37
to since open square brackets Cleveland.
1:03:40
In. The finger spicing pneumonia
1:03:42
and it with code close square brackets
1:03:44
a odd syntax. I had to come
1:03:46
up with an album. And.
1:03:49
Are hours trying to look for. I
1:03:52
need a new dilemma. There's. An.
1:03:55
Inner that did all the good ones are
1:03:57
taken reflects the scarborough to for taken the
1:03:59
past. The Taken. So. We
1:04:01
can. We can do something like a component
1:04:04
we talked about unreasonable. If.
1:04:07
And we can discern do that. but again, it's kind of
1:04:09
heavy. and one of the
1:04:11
things that we would news is we we
1:04:14
sometimes the to earn. To
1:04:16
the some big ratings of the some
1:04:18
context where we don't really know where
1:04:20
the you mean a toilet or template
1:04:22
or something else. And.
1:04:25
So sometimes you have to sit tight.
1:04:27
name. And splice about us
1:04:29
as a template and a splice oh so
1:04:31
that we know that you the season this
1:04:33
token of the less than that to land
1:04:36
a record the orbital of that. Sort
1:04:39
so in that context having.
1:04:42
On Reflects for or some other token also makes
1:04:44
it not for lack of now you'd have to
1:04:46
sit them Blood on Reflects per. Something.
1:04:48
On. So. We just look for
1:04:51
it or how can we. We
1:04:53
still can are can we use and maybe
1:04:55
slightly modified to still looks like it's a
1:04:57
bracketed think of what's inside as an expression.
1:05:00
And is potentially not as president. Here
1:05:02
are competing expression for we really wanted
1:05:05
the limit or system of. Like.
1:05:07
A prefix. By any
1:05:09
have to three new characters and tips or
1:05:12
twenty six right you have Dollar Up and
1:05:14
the great like the Axe and thing. So.
1:05:17
You could have used any of those,
1:05:19
but. Do we could
1:05:21
be could have now are numbered. This
1:05:23
was done before this. The source characters
1:05:26
were. Made. Available. right?
1:05:29
By so. I could see
1:05:31
for example how the back to cooperate on
1:05:33
may be like back in between back illegal
1:05:35
or the kind of a dimension but it
1:05:37
looks like a quotes ah. Now.
1:05:40
We I'm. We may not
1:05:43
want to use that because own. If
1:05:45
we go with injection in the future.
1:05:49
Wanting to need an injection into your rejections?
1:05:51
You are you. You make a fragment of
1:05:53
new code that you want to inject, but
1:05:55
somewhere inside of their. Humid. Hot
1:05:57
you may have to escape. From.
1:06:00
that pattern and say, oh, now this
1:06:02
next expression is actually in the context
1:06:04
surrounding the fragment of going to be
1:06:06
injected. And the back ticks could be a
1:06:08
really nice syntax
1:06:10
for that. Maybe. Or maybe we
1:06:12
grab it for
1:06:15
this. Again,
1:06:17
we don't have, you know, that's, I think
1:06:19
that's the kind of a back shed that
1:06:22
we will discuss in the evolution working group.
1:06:24
So in Tokyo, we're going to have a
1:06:26
day on reflection and evolution. That sounds interesting.
1:06:29
Well, this certainly there's going to be a time
1:06:32
for it. I don't know how much time we
1:06:34
will be given, but
1:06:36
I expect that it's going to be discussed
1:06:38
at least in the evolution working group, maybe
1:06:40
also in my revolution. So you also
1:06:42
need to look at that side of the problem.
1:06:46
Interesting times. But yeah,
1:06:49
interestingly, you know, syntax in a way is
1:06:51
the easiest, but it's also the hardest to
1:06:54
get agreement on. And you
1:06:56
know that from. Oh, yes,
1:06:58
you had very painful discussions
1:07:00
about syntax in Kona. From
1:07:03
an implementation perspective, this is not the
1:07:05
hard part, right? Like, you know, we
1:07:08
can make it work. I
1:07:10
like to square brackets with a little something
1:07:13
like I considered just a period. So a
1:07:15
square bracket period, or bracket
1:07:17
slash. Now the thing is, we're also thinking
1:07:19
of all the kinds of splices. Like
1:07:22
one idea is to be able to splice a whole
1:07:24
declaration in, in one shot. And
1:07:27
so possibly this would be square brackets with
1:07:29
a different thing to
1:07:33
say, you know, oh, here is not just a spice
1:07:35
of a small language element. It's a spice of the
1:07:38
whole declaration. Yeah, I think in contract
1:07:40
somebody at some point suggested square bracket
1:07:43
curly brace. Okay.
1:07:45
Instead of double square bracket, which we ended
1:07:47
up not using because it looks weird. But
1:07:50
yeah, there's infinite possibilities. So
1:07:53
those are also still available. Right.
1:07:55
Right. Or maybe there's another race there
1:07:58
between contract and deflection work. We
1:08:00
have to make sure you guys don't
1:08:02
grab our various syntax opportunities. Okay.
1:08:07
So no, I think we're done with syntax. So
1:08:09
you're good. I very much hope you're not going
1:08:11
to reopen the syntax debate there. You
1:08:14
can have all the syntax. Okay.
1:08:18
Okay. So, um, yeah, we've been talking about this
1:08:20
for over an hour now. I think we're kind
1:08:22
of running out of time. All
1:08:25
right. Yeah. Which was kind of expected because
1:08:27
it's such an exciting topic. Yeah. So
1:08:30
I guess a traditional last question, is
1:08:32
there anything else apart from reflection going
1:08:34
on in the world of CFS that
1:08:36
you find particularly interesting or exciting right
1:08:38
now? I, um, can
1:08:41
I go a little bit outside of CFS? Yeah.
1:08:43
Sure. Because
1:08:46
I, I keep an eye on, like I like Rust
1:08:48
as a language, right? I think a lot of us
1:08:50
do. It's an interesting programming language and
1:08:52
it, it, it took a,
1:08:55
an original approach to,
1:08:57
to safety and
1:08:59
that was like 15 years ago. Uh,
1:09:02
but now there's a couple of other
1:09:05
languages and there's one in particular. It's
1:09:08
called Hilo. Um, Dave
1:09:10
Abrahams came to C. He
1:09:14
presented vowel. Yeah. The vowel
1:09:16
language and Hilo is an evolution of that.
1:09:19
What is it called? Hilo H I
1:09:21
L O. Yeah. H Y H Y L O. I've
1:09:25
never heard about that. Okay. Well,
1:09:28
it's just Val renamed. Oh,
1:09:30
it's Val renamed. Okay. Yeah. We had an episode on
1:09:32
valve. We had like a DME
1:09:34
on the show who was one of the people working on
1:09:36
it. Okay. Yeah. So
1:09:39
that's, um, and it's evolved. So Hilo
1:09:41
has developed some ideas a little bit further.
1:09:44
And I think that's super interesting. So yeah.
1:09:46
Yeah. It's a, I love,
1:09:48
I love looking at new ideas in that space.
1:09:51
Uh, Ross, Ross is fantastic, but
1:09:54
it's not, it's
1:09:56
not easy. Like it's, uh,
1:09:58
for someone like. it's hard for Rust
1:10:01
to be your first programming language, right?
1:10:05
Because the margin of entry is
1:10:08
a little bit high. And so I'm
1:10:10
interested in people who are looking at, well,
1:10:13
is there a way we can tackle
1:10:16
that problem a little bit
1:10:18
like Rust, but also trying
1:10:20
to simplify it? Which is not easy.
1:10:22
So I'm not sure if Hylo
1:10:24
is the answer, but I
1:10:27
did find it very interesting to read what they...
1:10:30
Yeah, kind of somewhere in between, right? You can
1:10:32
either say there's just no pointers or reference to
1:10:34
anything and then you're done, or you can do
1:10:36
what Rust does. I think
1:10:38
Val or now Hylo is
1:10:41
kind of in between. So maybe that's kind of
1:10:45
the compromise that you need to actually
1:10:47
have a problem
1:10:49
language that's easy to work with and still gives you
1:10:51
all these guarantees. But it's
1:10:54
still expressive enough, right? Yeah,
1:10:57
that's always tricky. And
1:11:00
yeah, ultimately I always come back
1:11:02
to C++, so it's not a
1:11:04
safe but I can write what I'm trying
1:11:07
to express a little more directly and I'm enjoying it. Yeah.
1:11:12
Okay, well, I think we do need to wrap
1:11:14
this up. So anything else you
1:11:16
want to tell us before we let you go, such
1:11:18
as where people can reach you, do you want to
1:11:20
find out more? No,
1:11:23
I'm good. I'm sure you can find
1:11:25
my email in the papers. I
1:11:29
do not answer emails very well. I'm sorry, I get
1:11:31
too much of it. But
1:11:34
I still gladly receive them and
1:11:37
I try to read them, but I cannot keep up.
1:11:41
Okay, well, thanks very much for having on the show,
1:11:43
talking to us all about reflection. Four three
1:11:45
plus plus 26, we're going to hold you to
1:11:47
that. So... Thank you. Thank you
1:11:49
for your time. Thank you
1:11:51
guys. Thank you very much. That was great. Thank
1:11:53
you so much. Thanks so
1:11:55
much for listening in as we chat about C++. We'd love
1:11:58
to hear what you think of the project. Please
1:12:00
let us know if we're discussing the stuff you're
1:12:02
interested in. Or if you have a
1:12:04
suggestion for a guest or topic we'd love to hear
1:12:07
about that too. You can email
1:12:09
all your thoughts to feedback at cppcast.com.
1:12:11
We'd also appreciate it if you can follow
1:12:14
CPPcast on Twitter or Mastodon. You
1:12:16
can also follow me and Phil individually on
1:12:18
Twitter or Mastodon. All those
1:12:20
links, as well as the show notes,
1:12:23
can be found on the podcast website
1:12:25
at cppcast.com. The
1:12:28
theme music for this episode was provided by podcastthemes.com.
Podchaser is the ultimate destination for podcast data, search, and discovery. Learn More