diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-06 17:55:13 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-06 17:55:13 +0000 |
| commit | dc340f12a39e7cd8b495b84c009052c4d441d867 (patch) | |
| tree | a36b249c79f1f944793ff21ed5a739fe26f5ddf4 /docs/dev | |
| parent | d4a92b4fefecbd63d8c7c82a5553cd209c068144 (diff) | |
| parent | 81ffe973ac265507419024048c166bbeef9aa275 (diff) | |
| download | rust-dc340f12a39e7cd8b495b84c009052c4d441d867.tar.gz rust-dc340f12a39e7cd8b495b84c009052c4d441d867.zip | |
Merge #4772
4772: Document certain invariants r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Diffstat (limited to 'docs/dev')
| -rw-r--r-- | docs/dev/README.md | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md index 194a40e15c4..903cb4055a8 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md @@ -184,6 +184,27 @@ use crate::{} use super::{} // but prefer `use crate::` ``` +## Import Style + +Items from `hir` and `ast` should be used qualified: + +```rust +// Good +use ra_syntax::ast; + +fn frobnicate(func: hir::Function, strukt: ast::StructDef) {} + +// Not as good +use hir::Function; +use ra_syntax::ast::StructDef; + +fn frobnicate(func: Function, strukt: StructDef) {} +``` + +Avoid local `use MyEnum::*` imports. + +Prefer `use crate::foo::bar` to `use super::bar`. + ## Order of Items 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 { For `.md` and `.adoc` files, prefer a sentence-per-line format, don't wrap lines. If the line is too long, you want to split the sentence in two :-) +# Architecture Invariants + +This section tries to document high-level design constraints, which are not +always obvious from the low-level code. + +## Incomplete syntax trees + +Syntax trees are by design incomplete and do not enforce well-formedness. +If ast method returns an `Option`, it *can* be `None` at runtime, even if this is forbidden by the grammar. + +## LSP indenpendence + +rust-analyzer is independent from LSP. +It provides features for a hypothetical perfect Rust-specific IDE client. +Internal representations are lowered to LSP in the `rust-analyzer` crate (the only crate which is allowed to use LSP types). + +## IDE/Compiler split + +There's a semi-hard split between "compiler" and "IDE", at the `ra_hir` crate. +Compiler derives new facts about source code. +It explicitly acknowledges that not all info is available (ie, you can't look at types during name resolution). + +IDE assumes that all information is available at all times. + +IDE should use only types from `ra_hir`, and should not depend on the underling compiler types. +`ra_hir` is a facade. + # Logging Logging is done by both rust-analyzer and VS Code, so it might be tricky to |
