From 504a54b222553a096c8eaa0cd9efca33d916c275 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 7 Feb 2021 12:31:33 +0800 Subject: [PATCH] Update architecture.md for mbe and proc-macro --- docs/dev/architecture.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md index a6bb024a86..1c892e13ab 100644 --- a/docs/dev/architecture.md +++ b/docs/dev/architecture.md @@ -254,6 +254,17 @@ A single `rust-analyzer` process can serve many projects, so it is important tha These crates implement macros as token tree -> token tree transforms. They are independent from the rest of the code. +`tt` crate defined `TokenTree`, a single token or a delimited sequence of token trees. +`mbe` crate contains tools for transforming between syntax trees and token tree. +And it also handles the actual parsing and expansion of declarative macro (a-la "Macros By Example" or mbe). + +For proc macros, we pass the token trees by loading the corresponding dynamic library (which built by `cargo`). +That's why the client (`proc_macro_api`) and server (`proc_macro_srv`) model are used to run proc-macro in separate process in background. + + **Architecture Invariant:** +Bad proc macros may panic or segfault accidentally. So we run it in another process and recover it from fatal error. +And they may be non-deterministic which conflict how `salsa` works, so special attention is required. + ### `crates/cfg` This crate is responsible for parsing, evaluation and general definition of `cfg` attributes.