carbon-language / carbon-lang

Carbon Language's main repository: documents, design, implementation, and related tools. (NOTE: Carbon Language is experimental; see README)
http://docs.carbon-lang.dev/
Other
32.24k stars 1.48k forks source link

Use `As` and `ImplicitAs` interfaces for conversions. #4209

Closed zygoloid closed 3 weeks ago

zygoloid commented 1 month ago

Add these interfaces to the core library. For now, they're two separate interfaces because we don't yet support one interface extending another.

This collapses a lot of the layering in check: for example, the call building logic depends on implicit conversions, conversions now depend on the overloaded operator machinery, and that machinery depends on building calls.

In passing, improve the diagnostics for failing to find a name required from the prelude. Also convert all the transitively-called code from NodeId to LocId given the latter is what the conversion machinery has available.

zygoloid commented 1 month ago

I've run out of time to work on this; if someone wants to take over while I'm on vacation that'd be great. The remaining issue is that at least one test crashes, but only when built with -c opt.

The crash is a CHECK failure:

CHECK failure at ./toolchain/base/value_store.h:174: id.index >= 0: instInvalidParseSubtree

coming from within a call to Convert. But that doesn't make any sense to me: instInvalidParseSubtree is meaningless, InvalidParseSubtree is a kind of Node, not a kind of Inst. Also, why does this only happen in an opt build? (The check message doesn't appear to end up in the log file unless a flush call is added to the crash handling machinery; I've pushed a change to do that.)