Skip to content

Commit dc340f1

Browse files
bors[bot]matklad
andauthored
Merge #4772
4772: Document certain invariants r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents d4a92b4 + 81ffe97 commit dc340f1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/dev/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,27 @@ use crate::{}
184184
use super::{} // but prefer `use crate::`
185185
```
186186

187+
## Import Style
188+
189+
Items from `hir` and `ast` should be used qualified:
190+
191+
```rust
192+
// Good
193+
use ra_syntax::ast;
194+
195+
fn frobnicate(func: hir::Function, strukt: ast::StructDef) {}
196+
197+
// Not as good
198+
use hir::Function;
199+
use ra_syntax::ast::StructDef;
200+
201+
fn frobnicate(func: Function, strukt: StructDef) {}
202+
```
203+
204+
Avoid local `use MyEnum::*` imports.
205+
206+
Prefer `use crate::foo::bar` to `use super::bar`.
207+
187208
## Order of Items
188209

189210
Optimize for the reader who sees the file for the first time, and wants to get the general idea about what's going on.
@@ -220,6 +241,33 @@ struct Foo {
220241
For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines.
221242
If the line is too long, you want to split the sentence in two :-)
222243

244+
# Architecture Invariants
245+
246+
This section tries to document high-level design constraints, which are not
247+
always obvious from the low-level code.
248+
249+
## Incomplete syntax trees
250+
251+
Syntax trees are by design incomplete and do not enforce well-formedness.
252+
If ast method returns an `Option`, it *can* be `None` at runtime, even if this is forbidden by the grammar.
253+
254+
## LSP indenpendence
255+
256+
rust-analyzer is independent from LSP.
257+
It provides features for a hypothetical perfect Rust-specific IDE client.
258+
Internal representations are lowered to LSP in the `rust-analyzer` crate (the only crate which is allowed to use LSP types).
259+
260+
## IDE/Compiler split
261+
262+
There's a semi-hard split between "compiler" and "IDE", at the `ra_hir` crate.
263+
Compiler derives new facts about source code.
264+
It explicitly acknowledges that not all info is available (ie, you can't look at types during name resolution).
265+
266+
IDE assumes that all information is available at all times.
267+
268+
IDE should use only types from `ra_hir`, and should not depend on the underling compiler types.
269+
`ra_hir` is a facade.
270+
223271
# Logging
224272

225273
Logging is done by both rust-analyzer and VS Code, so it might be tricky to

0 commit comments

Comments
 (0)