Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

What is research but a blind date with knowledge? -- Will Harvey


devel / comp.lang.c / Looking for feedback about a (draft) proposal for generics in C

SubjectAuthor
* Looking for feedback about a (draft) proposal for generics in CLeandro T. C. Melo
`* Re: Looking for feedback about a (draft) proposal for generics in CKyleH
 `- Re: Looking for feedback about a (draft) proposal for generics in CLeandro T. C. Melo

1
Looking for feedback about a (draft) proposal for generics in C

<c56409a2-9384-4984-99df-2d2d116162d6n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26865&group=comp.lang.c#26865

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:1917:b0:767:d99d:f42d with SMTP id bj23-20020a05620a191700b00767d99df42dmr64653qkb.6.1690807789845;
Mon, 31 Jul 2023 05:49:49 -0700 (PDT)
X-Received: by 2002:a05:6870:a8aa:b0:1bb:8ad0:1fa7 with SMTP id
eb42-20020a056870a8aa00b001bb8ad01fa7mr12105631oab.7.1690807789426; Mon, 31
Jul 2023 05:49:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 31 Jul 2023 05:49:48 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2804:14c:5ba4:4111:2951:8b08:1ce3:7b9a;
posting-account=WxWJQwoAAADFD37rSGjdugaCbTS5Ui5a
NNTP-Posting-Host: 2804:14c:5ba4:4111:2951:8b08:1ce3:7b9a
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c56409a2-9384-4984-99df-2d2d116162d6n@googlegroups.com>
Subject: Looking for feedback about a (draft) proposal for generics in C
From: ltcm...@gmail.com (Leandro T. C. Melo)
Injection-Date: Mon, 31 Jul 2023 12:49:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1532
 by: Leandro T. C. Melo - Mon, 31 Jul 2023 12:49 UTC

Hi.

In the past years, I've worked on a type inference technique that can underlie — what I believe is — a nice implementation of generics in C; at https://ltcmelo.com/n2698.pdf you'll find a (draft) proposal that I wrote for it, and at http://www.genericsinc.info a prototype implementation.

What do you think about it? I'm looking for constructive feedback.

Regards,
Leandro

Re: Looking for feedback about a (draft) proposal for generics in C

<16dd8caa-319f-40c5-8dff-ffd946fe4710n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26924&group=comp.lang.c#26924

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:8787:0:b0:767:f368:79e8 with SMTP id j129-20020a378787000000b00767f36879e8mr68608qkd.0.1690989509967;
Wed, 02 Aug 2023 08:18:29 -0700 (PDT)
X-Received: by 2002:a9d:6198:0:b0:6b9:dc90:e351 with SMTP id
g24-20020a9d6198000000b006b9dc90e351mr17464952otk.6.1690989509659; Wed, 02
Aug 2023 08:18:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 2 Aug 2023 08:18:29 -0700 (PDT)
In-Reply-To: <c56409a2-9384-4984-99df-2d2d116162d6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=174.164.41.170; posting-account=ysW2ZQoAAAD0ARogcszUYQxvBmMQf9zT
NNTP-Posting-Host: 174.164.41.170
References: <c56409a2-9384-4984-99df-2d2d116162d6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <16dd8caa-319f-40c5-8dff-ffd946fe4710n@googlegroups.com>
Subject: Re: Looking for feedback about a (draft) proposal for generics in C
From: kyle.ha...@gmail.com (KyleH)
Injection-Date: Wed, 02 Aug 2023 15:18:29 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3431
 by: KyleH - Wed, 2 Aug 2023 15:18 UTC

On Monday, July 31, 2023 at 5:49:57 AM UTC-7, Leandro T. C. Melo wrote:
> Hi.
>
> In the past years, I've worked on a type inference technique that can underlie — what I believe is — a nice implementation of generics in C; at https://ltcmelo.com/n2698.pdf you'll find a (draft) proposal that I wrote for it, and at http://www.genericsinc.info a prototype implementation.
>
> What do you think about it? I'm looking for constructive feedback.

Interesting. I appreciate the implementation so that I can see the code generated. One of the things I like about C is that you see what you get. There isn't any hidden code (mostly). The existing C11 _Generic, while hiding a bit, at least has a single location that you can look at to find out which actual function is called. And you can use existing functions if they have the right argument pattern. However, _Generic only handles functions.

You proposal looks nice for the writer of code, but less nice than _Generic for the reader of code. I think that is a step backward for long term code maintenance. The tradeoff here is that you have less code (the generic code) to read to understand something. You also have the possibility of more generic libraries with value rather than pointer members (i.e. not just plain void*) and, if I understood correctly, you should get more type safety (as much as C allows).

For generic structs, this looks pretty interesting. The third example in your demo shows this. Why does it generate a version of the struct with a void* member? Have you used this to build some generic library such as a linked list or binary tree?

Where does the monomorphised code go? This is a standing issue with C++ that has had several implementations, each with some tradeoffs. For a long time, most compilers would not notice identical code being generated and you could get a code explosion.

It seems like the type promotion rules in C are going to be a bit challenging here, but I can't come up with a good example, so take that with a grain of salt.

If these answers are in the proposal, let me know!

Best,
Kyle

Re: Looking for feedback about a (draft) proposal for generics in C

<175f2b43-93bf-4d08-a023-1be6233b838an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29472&group=comp.lang.c#29472

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:4b2f:0:b0:640:116e:d176 with SMTP id s15-20020ad44b2f000000b00640116ed176mr105020qvw.3.1696099500467;
Sat, 30 Sep 2023 11:45:00 -0700 (PDT)
X-Received: by 2002:a9d:674a:0:b0:6b9:5156:a493 with SMTP id
w10-20020a9d674a000000b006b95156a493mr2329957otm.4.1696099500142; Sat, 30 Sep
2023 11:45:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 30 Sep 2023 11:44:59 -0700 (PDT)
In-Reply-To: <16dd8caa-319f-40c5-8dff-ffd946fe4710n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=201.17.210.197; posting-account=WxWJQwoAAADFD37rSGjdugaCbTS5Ui5a
NNTP-Posting-Host: 201.17.210.197
References: <c56409a2-9384-4984-99df-2d2d116162d6n@googlegroups.com> <16dd8caa-319f-40c5-8dff-ffd946fe4710n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <175f2b43-93bf-4d08-a023-1be6233b838an@googlegroups.com>
Subject: Re: Looking for feedback about a (draft) proposal for generics in C
From: ltcm...@gmail.com (Leandro T. C. Melo)
Injection-Date: Sat, 30 Sep 2023 18:45:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5190
 by: Leandro T. C. Melo - Sat, 30 Sep 2023 18:44 UTC

On Wednesday, August 2, 2023 at 12:18:38 PM UTC-3, KyleH wrote:
> On Monday, July 31, 2023 at 5:49:57 AM UTC-7, Leandro T. C. Melo wrote:
> > Hi.
> >
> > In the past years, I've worked on a type inference technique that can underlie — what I believe is — a nice implementation of generics in C; at https://ltcmelo.com/n2698.pdf you'll find a (draft) proposal that I wrote for it, and at http://www.genericsinc.info a prototype implementation.
> >
> > What do you think about it? I'm looking for constructive feedback.
> Interesting. I appreciate the implementation so that I can see the code generated. One of the things I like about C is that you see what you get. There isn't any hidden code (mostly). The existing C11 _Generic, while hiding a bit, at least has a single location that you can look at to find out which actual function is called. And you can use existing functions if they have the right argument pattern. However, _Generic only handles functions.
>
> You proposal looks nice for the writer of code, but less nice than _Generic for the reader of code. I think that is a step backward for long term code maintenance. The tradeoff here is that you have less code (the generic code) to read to understand something. You also have the possibility of more generic libraries with value rather than pointer members (i.e. not just plain void*) and, if I understood correctly, you should get more type safety (as much as C allows).
>
> For generic structs, this looks pretty interesting. The third example in your demo shows this. Why does it generate a version of the struct with a void* member? Have you used this to build some generic library such as a linked list or binary tree?
>
> Where does the monomorphised code go? This is a standing issue with C++ that has had several implementations, each with some tradeoffs. For a long time, most compilers would not notice identical code being generated and you could get a code explosion.
>
> It seems like the type promotion rules in C are going to be a bit challenging here, but I can't come up with a good example, so take that with a grain of salt.
>
> If these answers are in the proposal, let me know!
>
> Best,
> Kyle

Hi Kyle,

Thank you for your feedback!

Yes, there's hidden code implied in my proposal; but not so hidden...
in principle, a compiler/plugin could/should offer a command line
option that outputs the non-generic translation; for a plugin, the
output itself would be the non-generic translation so that it's input
to the compiler. This would be analogous to a TypeScript compiler that
outputs JavaScript. How useful would that be to you?

That said, I didn't understand why you consider this reduced
"visibility" a step backwards for code maintenance: for the provider
of generic libraries, I see it as a step forward; for the consumer, I
don't see a significant change in either direction. Could you further
elaborate on this matter?

The void* member in the struct is just an artifact of the
implementation, it can be eliminated. I've started porting non-generic
implementations of data-structures from popular libraries, but I
haven't yet finished.

In regards to the monomorphized code, I think that my first comment
might have addressed your question. Yet, I believe that it's
straightforward to detect (and discard) duplicate code.

Type promotions can be tricky for type inference in general, but with
the technique that I brief on the proposal they can be handled in the
same way that the conversions between int and double (which are
implemented in the prototyp) are handled.

Sorry for taking so long to reply.

Kind regards,
Leandro

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor