Stream: t-compiler/rust-analyzer

Topic: Hygiene Frames Information


Edwin Cheng (Jan 03 2021 at 05:12, on Zulip):

In PR 7133, I introduced HygineneFrames to store the hygiene information for given HirFileId, but turn out it slowing down a lot. This information is needed because hygiene information is per span, the previous implementation only store the single macro information , which is wrong.

Edwin Cheng (Jan 03 2021 at 05:22, on Zulip):

Some background information:

For examples, how '$crate' expanded depends on which 'root' crate is located :

//! in crate foo
macro_rules m! {
   () => { vec![$crate::local!()]
}

The expansion order in here is : foo::m! => std::vec! => $crate::local.
Note that $crate should be expanded respect to foo , but not std. But in previous implementation, we only stored std hygiene frame information but not foo one. To fix this problem. We have to have some mechanisms to get the whole expansion chain information on the fly.

Edwin Cheng (Jan 03 2021 at 05:26, on Zulip):

Another road-block is how lowering path works:

/// Converts an `ast::Path` to `Path`. Works with use trees.
/// It correctly handles `$crate` based path from macro call.
pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>

Note that we don't have AstDatabase here so all salsa magic don't work inside lower_path.

Jonas Schievink [he/him] (Jan 03 2021 at 10:47, on Zulip):

(going to revert the slow PR for now, to make sure it doesn't end up in the release tomorrow)

Edwin Cheng (Jan 04 2021 at 03:12, on Zulip):

I submitted another draft #7145 to due with some problems.

Last update: Jul 29 2021 at 08:45UTC