Stream: t-compiler/wg-incr-comp

Topic: Moving AST information out of the HIR tree


view this post on Zulip cjgillot (Dec 05 2020 at 23:49):

Hi @wg-incr-comp

Earlier this year, I submitted MCP https://github.com/rust-lang/compiler-team/issues/294, which proposes removing Span information out of the HIR tree, and into a side table. This turns to be a larger change than initially thought, so I need some design help.

I submitted #79519 last week, doing essentially the same thing with [Attribute] leaves. It is an opportunity to evaluate the basic idea on a smaller problem. It shows a reduction in the HIR invalidation for incremental tests. Perf is pending.

Completing the initial plan of removing Spans additionally requires to remove Idents from the HIR. However, this is a much more risky operation, since Idents are used for hygienic comparisons and pretty-printing. One possibility would be to introduce a new hir::Ident struct with carefully chosen content. What do you recommend?

Last point: it is not possible to measure perf gains before having completely removed Ident and Span from HIR, so design iterations discussions are difficult.

view this post on Zulip Jonas Schievink [he/him] (Dec 09 2020 at 23:37):

This is now also somewhat relevant for rust-analyzer, which currently mostly ignores spans and associated data like hygiene, $crate, and the edition.

The fact that we ignore $crate (and instead implement resolution of $crate paths with an approximation) is now causing incorrect diagnostics that are hard/impossible to fix without reimplementing this properly.

Maybe it would make sense to try out different approaches there? The code base is quite a lot easier to work with than rustc.

view this post on Zulip cjgillot (Dec 14 2020 at 22:58):

If I understand correctly, the resolution in rustc runs on the AST, not on the HIR. The HIR is already resolved, and is dedicated to typechecking and other checks and lints, before turning into MIR.

view this post on Zulip cjgillot (Dec 14 2020 at 23:04):

The only exception is the distinction between hygienic vs non-hygienic names. I need to wrap my head around this before I touch that code.

view this post on Zulip cjgillot (Dec 14 2020 at 23:07):

I should be able to remove the position part of the Span (ie where in the file), but I will need to preserve expansion info for idents.

view this post on Zulip cjgillot (Dec 14 2020 at 23:07):

Does that seem correct ?

view this post on Zulip cjgillot (Dec 15 2020 at 18:09):

Does that seem correct ?

view this post on Zulip Wesley Wiser (Dec 15 2020 at 18:40):

cjgillot said:

If I understand correctly, the resolution in rustc runs on the AST, not on the HIR. The HIR is already resolved, and is dedicated to typechecking and other checks and lints, before turning into MIR.

This is definitely correct

view this post on Zulip Wesley Wiser (Dec 15 2020 at 18:41):

cjgillot said:

The only exception is the distinction between hygienic vs non-hygienic names. I need to wrap my head around this before I touch that code.

This part I don't know about. I don't think I've ever touched expansion/proc_macros in the compiler.

view this post on Zulip Wesley Wiser (Dec 15 2020 at 18:42):

cjgillot said:

I should be able to remove the position part of the Span (ie where in the file), but I will need to preserve expansion info for idents.

This _sounds_ correct to me but as I said, I don't know the details in that part of the compiler.

view this post on Zulip Wesley Wiser (Dec 15 2020 at 18:47):

This reminds me of #54725 which tracks some unstable proc_macro apis that give access to span information. We may still need to get access to span information for a idents somehow to support these apis.

view this post on Zulip cjgillot (Dec 15 2020 at 19:08):

(I did not mean to double post, sorry for the noise.)
Thanks anyway for the answer :)

view this post on Zulip Wesley Wiser (Dec 15 2020 at 19:09):

No worries! Sorry I couldn't answer more definitively :)

view this post on Zulip Vadim Petrochenkov (Dec 15 2020 at 19:51):

cjgillot said:

If I understand correctly, the resolution in rustc runs on the AST, not on the HIR. The HIR is already resolved, and is dedicated to typechecking and other checks and lints, before turning into MIR.

Module-relative name resolution is performed on AST, type-relative name resolution is performed on HIR, both use same span-based approach to hygiene.


Last updated: Oct 21 2021 at 21:46 UTC