Remix.run Logo
uecker 17 hours ago

Except doing this manually does not allow me to directly call a C++ lambda, a Go closure, an Ada closure etc which I can not even express in C. So compatibility can not become worse, it is already maximally bad. And even where you can build a compatible solution in C, there are now different choices. Your examples already directly shows this contradicting your claim that here is only one option.

Adding such a type as a vocabulary type would fix all this. You can argue that we fix an object layout for a pointer pair, but this seems an acceptable trade-off to me. This seems far from your previous claim that this "requires design decisions that are equivalent to choosing a specific layout for objects in an object-oriented language." Note also that such a type can always adapt to different calling conventions of other languages by using the address of a static thunk as code pointer so it is very generic.

klodolph 43 minutes ago | parent | next [-]

C++ lambdas and Go closures are incompatible with each other. If you pick something that lets C call Go closures (which are fat pointers passed around), it is likely to be incompatible with whatever your C++ library is doing.

jcranmer 5 hours ago | parent | prev | next [-]

A C++ lambda (as essentially is the case for a Rust lambda as well) is just an unnameable class object with an overloaded call operator, which makes the closure function body itself just a regular member function ABI-wise. You're not calling these things outside of the language, because they're only really callable via the language-specific static dispatch mechanism of templates. If you need to be able to dynamically call a lambda, you're going to be stuffing them in an object that contains a pointer to the lambda object and a pointer to the function of the actual body, something that looks essentially like what GP's assertion of what a lambda ABI looks like.

uecker 4 hours ago | parent [-]

You can stuff it into something such as std::function_ref which erases the Voldemort type and then it can be dynamically called without needing templates. And this could be from C or other languages if only there was a common type in C we could use.

inigyou 7 hours ago | parent | prev [-]

C++ lambdas have different sizes, so you can't embed an arbitrary one into another structure.

uecker 6 hours ago | parent [-]

I does not need to be embedded. I just need a pointer to it.