Stream: t-compiler/help

Topic: Generating ExprKind:Err from AST lowering

Amanieu (May 26 2020 at 08:15, on Zulip):

In librustc_ast_lowering I turn ast::ExprKind::InlineAsm to hir::ExprKind::Err if the current target doesn't support inline asm or if an invalid register is used for an operand. Unfortunately this seems to lead to crashes later on (#72570) since the expressions used in the asm operands aren't lowered to HIR and are therefore missing HirIds.

Amanieu (May 26 2020 at 08:17, on Zulip):

Is it valid to lower something to hir:ExprKind::Err? If not then I guess I have to make up some semi-valid HIR to keep the compiler happy. Until what point do I need to keep this HIR valid?

marmeladema (May 26 2020 at 08:53, on Zulip):

I've encountered the same issue, let me find the PR

marmeladema (May 26 2020 at 08:54, on Zulip):

marmeladema (May 26 2020 at 08:56, on Zulip):

So i did not properly fix the lowering per say, but i ended up to the same conclusion, being that generating hir:ExprKind::Err nodes make the HIR invalid and it breaks/crash later on

oli (May 26 2020 at 09:29, on Zulip):

I think you need to eagerly lower all expressions even if you are throwing them away later

oli (May 26 2020 at 09:30, on Zulip):

but we may be able to come up with a better scheme

oli (May 26 2020 at 09:30, on Zulip):

where are the HirIds to the asm operands? Maybe we need to ensure these ids are never stored anywhere?

Amanieu (May 26 2020 at 09:40, on Zulip):

I haven't managed to get a proper backtrace from the crash yet.

Amanieu (May 26 2020 at 09:41, on Zulip):

Building rustc with debuginfo takes forever :/

oli (May 26 2020 at 09:45, on Zulip):


oli (May 26 2020 at 09:47, on Zulip):

I don't remember it taking any additional time

oli (May 26 2020 at 09:47, on Zulip):

did you leave optimizations enabled?

Amanieu (May 26 2020 at 09:49, on Zulip):

Yes, the LTO at the end is the part that takes a while.

Amanieu (May 26 2020 at 09:51, on Zulip):

I'm currently trying to eagerly lower all sub-expressions as you suggest.

Amanieu (May 26 2020 at 09:54, on Zulip):

OK that seems to have solved the issue, thanks!

Amanieu (May 26 2020 at 09:55, on Zulip):

I had some early exit logic on error which I removed. I still emit hir::ExprKind::Err but I now call lower_expr_mut on all sub-expressions.

oli (May 26 2020 at 10:09, on Zulip):

:+1: if you have the time please open an issue about this (with the ICE message about the missing HirId, so that people can find it when they hit the same problem). Mentioning the solution and asking for something allowing us to make it simpler to eagerly bail out early.

Last update: Sep 28 2020 at 14:00UTC