Live data from Hacker News

Carbon’s most exciting feature is its calling convention

foonathan.net

131–140 of 223 posts

Re: Carbon’s most exciting feature is its calling convention

#131

I was very confused by what the author is pointing out in the opening Point / Print example. ("[T]he compiler is allowed to convert that to a T" -> wait, why did the compiler change a struct to an int32?) I think this boils down to: Carbon defaults to passing parameters that fit in a single register by value, and all others by const reference. This affects a few things you might take for granted in C++, like whether…

What's weird is that Point would fit in a register as well.

Re: Carbon’s most exciting feature is its calling convention

#133
post #55

Earlier quoted context omitted.

Consider this C code (also "works" if compiled as C++): int main(void) { int x = 0; int arr[1]; int *p = arr + 1; *p = 42; return x; } On a lot of systems (e.g., https://godbolt.org/z/jYqM8TT3Y ), it just so happens that `x` is right above `arr` on the stack, so that code will return 42. But that code is absolutely UB. The more general name for this concept is "pointer provenance". Basically, you can't pull pointer v…

That's a buffer overflow. The optimizer doesn't need to reason about changing the behavior of such things.

That’s the point - it’s UB to go off the end of an array, or more generally to dereference a pointer outside of the bounds of the target object (yes, buffer+buffer_length is a valid pointer for the purpose of comparisons, but dereferencing it would be UB).

However in practice you can do this, and walk the stack to find the parameters or what have you, and then you’ve got a pointer to a parameter without the compiler being aware of it. But this is all explicitly UB, so it’s ok for the compiler to be unaware of it, and it’s free to do whatever codegen it wants given the assumption that UB can never happen.

Re: Carbon’s most exciting feature is its calling convention

#134

Spent a terrible amount of time hunting down C++ bottlenecks. It has almost never been about unintended copying of structs or classes. It usually boils down to someone assuming that a particular collection or algorithm won't be on the critical path, and using a lazy O(N^2) solution. Then the codebase grows, use cases shift, someone puts another O(N^2) algorithm around an existing O(N^2) and the whole thing explodes.…

To chime in with my personal experience, I did actually lose almost two days on hunting down an unintended copy constructor call. The method expected a "const B&" but was called with a "const A&". It also happened to be called a lot. The actual type names were longer and very similar, and looking at the code it was hard to see they were different. Type B had a copy/conversion constructor from type A so every time the method was called all of the data contained in A would be cloned. I was very relieved when I finally found the issue but also wished that C++ wouldn't call (possibly expensive) constructors so hiddenly, even going so far as to not only do that for value types but even for reference types.

Re: Carbon’s most exciting feature is its calling convention

#135
post #97
post #58

Earlier quoted context omitted.

> The other safe languages have explicitly taken the view the interop with C++ is bad It's not that it's inherently bad, it's just insanely difficult to do and, probably, isn't worth the pain. Carbon's approach to solving this problem includes embedding a custom C++ compiler as part of its toolchain, and at this point it's just the idea, who knows if they will be able to actually do it. > they are all hell bent on no…

Interop with c++ is definitely inherently bad.

I get that this is kind of facetious, but don't you want things like your browser engine to be in a memory safe language?

Re: Carbon’s most exciting feature is its calling convention

#136
post #8
post #5

Earlier quoted context omitted.

I think the statute of limitations on “confusing name” when Mac OS Carbon was removed from OS X 10 years ago has passed.

Carbon was removed two years ago.

Well, the API was. There's still bits of it internally driving the menu and event systems, and a lot of app/icon/Finder behaviors.

Re: Carbon’s most exciting feature is its calling convention

#137
post #119

I searched on several sites to find out what their memory management strategy is but couldn’t figure it out. GC? ARC? Whatever Rust does? Would love to see where this fits. Exciting to see a neat new language though! Also my second favourite feature of rust and swift is Enums with associated values, I can’t see any info on this but I saw a blog mention they have it.

Scope-bound resource management, like C++. GC and ARC are for people that need shared ownership, which is pretty much always a bad idea.

So how do you implement multithreading if the above are a bad idea?

Re: Carbon’s most exciting feature is its calling convention

#138
post #89
post #79

Earlier quoted context omitted.

Gamedev, presumably. It's not unusual to have a LOT of triangles and coordinates flying around and GameDev is basically locked to C++ (for many good reasons even if I find C++ distasteful). Admittedly, those probably aren't running on 32-bit systems, nowadays ...

Carbon is probably Gamedev's best chance of moving beyond c++ But you are going to need some minimal buy-in from Microsoft first, if not Sony and Nintendo too. The great thing about carbon is that you can incrementally shift a codebase over from c++, and there are no problems interacting with existing c++ APIs, so the required amount of buy-in is pretty much just "yes, you can use a 3rd party compiler" and maybe some…

What about rust?

Re: Carbon’s most exciting feature is its calling convention

#139
I have to say, and pardon me for saying so, but Carbon seems to be utterly uninteresting to me. They are not solving any interesting problems that shows me that they are creating a modern language.

As an example, look at this issue from the mold linker: https://github.com/rui314/mold/issues/584

They are looking at creating an embeddable custom dynamic linker in order to greatly reduce loading times, by fixing locations as the file gets loaded in.

The equivalent in Carbon would (for example) be to create a new type of exception handling that changes how we think about exceptions, performance and their cost. Perhaps something like the static exceptions that Herb Sutter has been working on. Instead, they are not adding exceptions at all.

You will have to excuse my disappointment.

Re: Carbon’s most exciting feature is its calling convention

#140
My one annoyance with Carbon’s promise is the lack of ABI stability; I know why they are doing that, and I know that C++ has the same downside, but as someone who binds C libraries constantly in other languages and finds the pain of C++ and now likely Carbon frustrating, it makes me a little sad to see the same mistake repeated.

A C++ replacement that is just as difficult to bind/link/work with in other languages as C++ itself just seems like a missed mark, despite the fact I know this is not on their priority list at all.

I hope my read of this is wrong, and it will be easy to bind and link to from other languages after all.

Post reply on HN