Thread overview
How does Circle's CTFE compare to D?
Dec 04, 2021
Johannes Riecken
Dec 04, 2021
Johannes Riecken
Dec 04, 2021
Paulo Pinto
Dec 04, 2021
Tejas
Dec 04, 2021
Paulo Pinto
December 04, 2021

I've watched Don't constexpr all the things, which is a talk explaining how Cirlce does meta-programming and I found it very interesting that it looks as simple as I as a newbie would imagine meta-programming should be, i.e. it can execute any C++ function or library function at compile time. Here are two interesting examples:

int i = 0;
int f() { return ++i; }
int main()
{
    std::cout << (@meta f()) << std::endl; // Outputs 1
    std::cout << (@meta f()) << std::endl; // Outputs 2
    std::cout << i << std::endl; // Outputs 0
}
#include <fstream>
#include <iterator>
#include <string>
@meta std::ifstream f("file.txt");
@meta std::string str(std::istreambuf_iterator<char>(t),
std::istreambuf_iterator<char>());
const char file_contents[] = @string(str);

How does Circle's approach compare with D's (or with the vision of the direction of D's CTFE)? Is it likely that Circle's meta-programming also requires ten-thousands of lines of extra compiler code? I personally tend to prefer code generation over meta-programming, as I find that simpler to reason about and it works in any language, but I see the benefits of CTFE as well.

December 04, 2021

On Saturday, 4 December 2021 at 08:43:14 UTC, Johannes Riecken wrote:

>

I've watched Don't constexpr all the things, which is a talk explaining how Cirlce does meta-programming and I found it very interesting that it looks as simple as I as a newbie would imagine meta-programming should be, i.e. it can execute any C++ function or library function at compile time.

Circle is primarily interesting because it pushes the boundaries for C++, but does it allow the execution of any C++ function? I/O can make things very complicated as you either have to impose a specific compilation order or use some other ordering or constraining principle to avoid dependency issues or feedback loops. This in turns makes it impossible to accept the execution of any C++ function!

D's CTFE is somewhat more flexible than C++ constexpr, but C++ constexpr/consteval also works as an interface specification, meaning: if a function in a library is marked as compile time then you can rely on it for the future and across platforms.

The question is, what kind of language do you want? A language for writing small short lived self-contained programs that makes programming frictionless, or a language for writing larger long lived portable programs that depends on third party code bases that receive upgrades over time?

There are many really cute languages for writing small short lived self-contained programs, but they rarely get traction. (There are counter examples: PhP, Perl, …)

December 04, 2021

On Saturday, 4 December 2021 at 09:49:39 UTC, Ola Fosheim Grøstad wrote:

>

D's CTFE is somewhat more flexible than C++ constexpr, but C++ constexpr/consteval also works as an interface specification, meaning: if a function in a library is marked as compile time then you can rely on it for the future and across platforms.

Just a simple example to make this obvious, let's say you use a matrix library that in a later is optimized so that it uses cpuid() to detect the CPU type. If you CTFE this you end up getting the CPU type of the machine the program was compiled on! Not what you wanted. There are many functions that are platform dependent, so general CTFE is not possible for a system level programming language.

December 04, 2021
> >

Is it likely that Circle's meta-programming also requires ten-thousands of lines of extra compiler code?

I see that Circle isn't open-source so that question seems impossible to answer.

On Saturday, 4 December 2021 at 09:49:39 UTC, Ola Fosheim Grøstad wrote:

>

Circle is primarily interesting because it pushes the boundaries for C++, but does it allow the execution of any C++ function? I/O can make things very complicated as you either have to impose a specific compilation order or use some other ordering or constraining principle to avoid dependency issues or feedback loops. This in turns makes it impossible to accept the execution of any C++ function!

Interesting point. Do you have an example for that? Going top to bottom seems like a good choice.

>

D's CTFE is somewhat more flexible than C++ constexpr, but C++ constexpr/consteval also works as an interface specification, meaning: if a function in a library is marked as compile time then you can rely on it for the future and across platforms.

For functions without side effects that interface specification would be equivalent to adding something like static assert f(3) == 9 to a compile-time function f in D?

>

There are many really cute languages for writing small short lived self-contained programs, but they rarely get traction. (There are counter examples: PhP, Perl, …)

My understanding from the talk is that Circle can compile C++, too, so if Sean Baxter adds a few well-specified and easily understandable features in a bug-free way, then I don't see the lack of traction being a major issue.

December 04, 2021

On Saturday, 4 December 2021 at 09:49:39 UTC, Ola Fosheim Grøstad wrote:

>

On Saturday, 4 December 2021 at 08:43:14 UTC, Johannes Riecken wrote:

>

[...]

Circle is primarily interesting because it pushes the boundaries for C++, but does it allow the execution of any C++ function? I/O can make things very complicated as you either have to impose a specific compilation order or use some other ordering or constraining principle to avoid dependency issues or feedback loops. This in turns makes it impossible to accept the execution of any C++ function!

...

Yes it does, have fun with Circle.

https://github.com/seanbaxter/circle/blob/master/embed/embed.md

December 04, 2021

On Saturday, 4 December 2021 at 14:00:22 UTC, Paulo Pinto wrote:

>

On Saturday, 4 December 2021 at 09:49:39 UTC, Ola Fosheim Grøstad wrote:

>

On Saturday, 4 December 2021 at 08:43:14 UTC, Johannes Riecken wrote:

>

[...]

Circle is primarily interesting because it pushes the boundaries for C++, but does it allow the execution of any C++ function? I/O can make things very complicated as you either have to impose a specific compilation order or use some other ordering or constraining principle to avoid dependency issues or feedback loops. This in turns makes it impossible to accept the execution of any C++ function!

...

Yes it does, have fun with Circle.

https://github.com/seanbaxter/circle/blob/master/embed/embed.md

That tone didn't sound very positive

What do you think about Circle?
I personally dislike the @meta everywhere :(
Plus, C++ syntax D:

December 04, 2021

On Saturday, 4 December 2021 at 14:44:10 UTC, Tejas wrote:

>

On Saturday, 4 December 2021 at 14:00:22 UTC, Paulo Pinto wrote:

>

On Saturday, 4 December 2021 at 09:49:39 UTC, Ola Fosheim Grøstad wrote:

>

On Saturday, 4 December 2021 at 08:43:14 UTC, Johannes Riecken wrote:

>

[...]

Circle is primarily interesting because it pushes the boundaries for C++, but does it allow the execution of any C++ function? I/O can make things very complicated as you either have to impose a specific compilation order or use some other ordering or constraining principle to avoid dependency issues or feedback loops. This in turns makes it impossible to accept the execution of any C++ function!

...

Yes it does, have fun with Circle.

https://github.com/seanbaxter/circle/blob/master/embed/embed.md

That tone didn't sound very positive

What do you think about Circle?
I personally dislike the @meta everywhere :(
Plus, C++ syntax D:

You are reading more than what it is there.

I think Circle is the right approach instead of constepxr, constinit, consteval, and whatever might still come up, like reflect.

C++ syntax, regardless how obtuse it might be, is available to me on my work computers as standard IT image.

December 04, 2021

On Saturday, 4 December 2021 at 13:53:27 UTC, Johannes Riecken wrote:

>

Interesting point. Do you have an example for that? Going top to bottom seems like a good choice.

Depends on what you want to do. If the compilation of one source-file creates a file that another source-file wants to read, how do you know what the order should be? A key point of C++ is that you can have concurrent builds.

>

For functions without side effects that interface specification would be equivalent to adding something like static assert f(3) == 9 to a compile-time function f in D?

In D you can test if a function is executed on compile time, but in C++ it is part of the function type (signature).

The key difference is that in C++ the compiler checks that a compile-time function is limited to a reasonable subset when it is defined even if it isn't used. Which is useful for library authors. Within an application there is no practical difference, really.

>

My understanding from the talk is that Circle can compile C++, too, so if Sean Baxter adds a few well-specified and easily understandable features in a bug-free way, then I don't see the lack of traction being a major issue.

It is a C++-family compiler, so you are right, it could pick up some interest for that reason alone! I guess some would use it if it was open source. I personally wouldn't as C++ does not need more complexity and features that does not match the rest of the language. (What was Sutter thinking when he came up with the syntax for "inspect"/"is"/"as"?)

This is something D needs to take advantage of. KISS! (Keep It Simple Stupid ;^)

December 04, 2021

On Saturday, 4 December 2021 at 15:35:20 UTC, Paulo Pinto wrote:

>

I think Circle is the right approach instead of constepxr, constinit, consteval, and whatever might still come up, like

These are constraints that allows you to catch bugs and inefficiencies at compile time.

Circle does not offer a replacement for constraints?