From c5c2df2f87d8ba874d6326a36a8e1548c0ce73f0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 8 Nov 2018 16:46:39 +0300 Subject: [PATCH] document the interaction between macros and nameres "The name resolution is a separate pass" is a wishful thinking :( --- src/name-resolution.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/name-resolution.md b/src/name-resolution.md index bba3142f..3117217e 100644 --- a/src/name-resolution.md +++ b/src/name-resolution.md @@ -1,12 +1,17 @@ # Name resolution -The name resolution is a separate pass in the compiler. Its input is the syntax -tree, produced by parsing input files. It produces links from all the names in -the source to relevant places where the name was introduced. It also generates +The name resolution is a two-phase process. In the first phase, which runs +during macro expansion, we build a tree of modules and resolve imports. Macro +expansion and name resolution communicate with each other via the `Resolver` +trait, defined in `libsyntax`. + +The input to the second phase is the syntax tree, produced by parsing input +files and expanding macros. This phase produces links from all the names in the +source to relevant places where the name was introduced. It also generates helpful error messages, like typo suggestions, traits to import or lints about unused items. -A successful run of the name resolution (`Resolver::resolve_crate`) creates kind +A successful run of the second phase (`Resolver::resolve_crate`) creates kind of an index the rest of the compilation may use to ask about the present names (through the `hir::lowering::Resolver` interface).