Stream: t-lang/wg-unsafe-code-guidelines

Topic: `throws` C++/`_Either` C compatibility


Nicole Mazzuca (Aug 09 2018 at 05:07, on Zulip):

Have people been thinking about how to make us compatible with https://docs.google.com/viewer?a=v&pid=forums&srcid=MTEwODAzNzI2MjM1OTc0MjE3MjkBMDIyMjg0NDY2NTc4NzYyMDQzODYBX1RlYjRCNjREQUFKATAuMQFpc29jcHAub3JnAXYy&authuser=0 ?

Ability to communicate high-level errors between the three systems languages is a high priority thing for the new static exceptions proposal.

nikomatsakis (Aug 09 2018 at 10:26, on Zulip):

I haven't looked at that specific proposal, but I do think that we should find ways to be "officially" compatible with various other exception mechanisms

nikomatsakis (Aug 09 2018 at 10:26, on Zulip):

this came up in the context of setjmp etc as well

nikomatsakis (Aug 09 2018 at 10:26, on Zulip):

and Microsoft's error handling mechanism, the name of which escapes me just now

RalfJ (Aug 09 2018 at 10:34, on Zulip):

woah that stuff looks extremely familiar

RalfJ (Aug 09 2018 at 10:34, on Zulip):

are they copying this from Rust verbatim? ;)

RalfJ (Aug 09 2018 at 10:35, on Zulip):

they even have try!...

RalfJ (Aug 09 2018 at 10:36, on Zulip):

I don't wish to mention the `m word' in this paper,

:joy:

Nicole Mazzuca (Aug 09 2018 at 14:17, on Zulip):

SEH, but to be clear this is _extremely_ different. This has a similar ABI to Rust Either<T, E>, and is written like those throws functions that may or may not have gotten int

RalfJ (Aug 09 2018 at 14:23, on Zulip):

to me this sounds like having two return continuations

RalfJ (Aug 09 2018 at 14:23, on Zulip):

in CPS terminology

RalfJ (Aug 09 2018 at 14:23, on Zulip):

which they also avoid talking about, but still, that's exactly what it is?

Nicole Mazzuca (Aug 09 2018 at 14:24, on Zulip):

similar, yeah, but using the return slot

Nicole Mazzuca (Aug 09 2018 at 14:24, on Zulip):

it's really just Result<T, E>

Nicole Mazzuca (Aug 09 2018 at 14:24, on Zulip):

with a special ABI

RalfJ (Aug 09 2018 at 14:38, on Zulip):

So it always jumps back to the same address, and the only special thing is an enum layout optimization where the tag is stored in some flag register?

Nicole Mazzuca (Aug 09 2018 at 14:38, on Zulip):

yep

RalfJ (Aug 09 2018 at 14:38, on Zulip):

makes sense

RalfJ (Aug 09 2018 at 14:38, on Zulip):

did they do this after seeing how well it works in Rust?

Nicole Mazzuca (Aug 09 2018 at 14:39, on Zulip):

I dunno

RalfJ (Aug 09 2018 at 14:39, on Zulip):

Rust isn't mentioned, except for the changelog saying it used to be mentioned^^

Nicole Mazzuca (Aug 09 2018 at 14:39, on Zulip):

I think they mostly took it from Haskell?

Nicole Mazzuca (Aug 09 2018 at 14:39, on Zulip):

but I imagine that Rust was also a major inspiration

RalfJ (Aug 09 2018 at 14:39, on Zulip):

so Haskell has sth. like try!?

Nicole Mazzuca (Aug 09 2018 at 14:39, on Zulip):

but the older papers included a "what this might look like in Rust"

Nicole Mazzuca (Aug 09 2018 at 14:40, on Zulip):

because they really want ABI-compat for this between the three languages

Nicole Mazzuca (Aug 09 2018 at 14:40, on Zulip):

Haskell has monads, so it doesn't need try

RalfJ (Aug 09 2018 at 14:40, on Zulip):

well for us it would be a special ABI, I guess, for functions returning Result.

RalfJ (Aug 09 2018 at 14:40, on Zulip):

but everything else would just work

Nicole Mazzuca (Aug 09 2018 at 14:40, on Zulip):

yeah, that was their plan

Nicole Mazzuca (Aug 09 2018 at 14:41, on Zulip):

what ever happened with throws functions?

Nicole Mazzuca (Aug 09 2018 at 14:41, on Zulip):

fn blah() -> T throws U

nikomatsakis (Aug 09 2018 at 15:05, on Zulip):

we've talked about enhancing the Rust ABI to treat Result specially

nikomatsakis (Aug 09 2018 at 15:05, on Zulip):

seems like it would be good to be compatible, in that case

alercah (Aug 12 2018 at 19:33, on Zulip):

I think @RalfJ meant SEH for Windows?

Is there a specific reason that unwinding isn't cross-language compatible? The Itanium ABI, at least, is specifically designed to allow interplay between unwinding mechanisms in a safe way.

alercah (Aug 12 2018 at 19:33, on Zulip):

(I need to read the paper still)

alercah (Aug 12 2018 at 19:33, on Zulip):

FWIW if this ends up with anyone going to a C++ committee meeting, I'd be happy to have an excuse as I would love to meet up with a number of friends. ;)

alercah (Aug 12 2018 at 20:35, on Zulip):

(Ah, I see that unwinding isn't directly related to this proposal because it mostly intends to avoid it, but it is necessary for setjmp and SEH as well as existing C++ exceptions)

alercah (Aug 12 2018 at 21:39, on Zulip):

Wow, I dislike the proposed C++ type using void* and suggesting putting a pointer to a dynamic allocation into a intptr_t. I agree that we could do it with special ABI, but we'd have to be careful whether that imposes a performance hit because of having to translate between the memory and calling-convention representations.

alercah (Aug 12 2018 at 21:41, on Zulip):

Possibly it would make sense to have an extern "throws" ABI as an interim measure?

Darsstar (Oct 18 2018 at 07:18, on Zulip):

The author of the paper had some progress to report yesterday:

The WG14 discussion on this just closed. I won't repeat my notes here as it is bad form to do so (official minutes only!), but I think I am allowed to say that the vote went as follows:

Does WG14 like the general direction of N2289?

Favour: 15 Opposed: 2 Abstentions: 2

Nicole Mazzuca (Oct 18 2018 at 17:23, on Zulip):

woot! :D

Last update: Nov 20 2019 at 12:10UTC