From ae71a631fd657368e8593feb5e025d23147afe60 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 16:36:55 +0200 Subject: [PATCH] Rename ra_hir -> hir --- Cargo.lock | 46 +++++++++---------- crates/{ra_hir => hir}/Cargo.toml | 9 ++-- crates/{ra_hir => hir}/src/code_model.rs | 0 crates/{ra_hir => hir}/src/db.rs | 0 crates/{ra_hir => hir}/src/diagnostics.rs | 0 crates/{ra_hir => hir}/src/from_id.rs | 0 crates/{ra_hir => hir}/src/has_source.rs | 0 crates/{ra_hir => hir}/src/lib.rs | 4 +- crates/{ra_hir => hir}/src/semantics.rs | 0 .../src/semantics/source_to_def.rs | 0 crates/{ra_hir => hir}/src/source_analyzer.rs | 0 crates/ra_assists/Cargo.toml | 2 +- crates/ra_ide/Cargo.toml | 2 +- crates/ra_ide/src/lib.rs | 2 +- crates/ra_ide_db/Cargo.toml | 2 +- crates/ra_ssr/Cargo.toml | 2 +- crates/rust-analyzer/Cargo.toml | 2 +- docs/dev/README.md | 6 +-- docs/dev/architecture.md | 6 +-- docs/dev/guide.md | 38 +++++++-------- xtask/tests/tidy.rs | 2 +- 21 files changed, 61 insertions(+), 62 deletions(-) rename crates/{ra_hir => hir}/Cargo.toml (92%) rename crates/{ra_hir => hir}/src/code_model.rs (100%) rename crates/{ra_hir => hir}/src/db.rs (100%) rename crates/{ra_hir => hir}/src/diagnostics.rs (100%) rename crates/{ra_hir => hir}/src/from_id.rs (100%) rename crates/{ra_hir => hir}/src/has_source.rs (100%) rename crates/{ra_hir => hir}/src/lib.rs (92%) rename crates/{ra_hir => hir}/src/semantics.rs (100%) rename crates/{ra_hir => hir}/src/semantics/source_to_def.rs (100%) rename crates/{ra_hir => hir}/src/source_analyzer.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 6ecea36470e..ae71ea9fdbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -463,6 +463,24 @@ dependencies = [ "libc", ] +[[package]] +name = "hir" +version = "0.0.0" +dependencies = [ + "arrayvec", + "base_db", + "either", + "hir_def", + "hir_expand", + "hir_ty", + "itertools", + "log", + "profile", + "rustc-hash", + "stdx", + "syntax", +] + [[package]] name = "hir_def" version = "0.0.0" @@ -1071,9 +1089,9 @@ version = "0.1.0" dependencies = [ "base_db", "either", + "hir", "itertools", "profile", - "ra_hir", "ra_ide_db", "rustc-hash", "stdx", @@ -1082,24 +1100,6 @@ dependencies = [ "text_edit", ] -[[package]] -name = "ra_hir" -version = "0.1.0" -dependencies = [ - "arrayvec", - "base_db", - "either", - "hir_def", - "hir_expand", - "hir_ty", - "itertools", - "log", - "profile", - "rustc-hash", - "stdx", - "syntax", -] - [[package]] name = "ra_ide" version = "0.1.0" @@ -1108,13 +1108,13 @@ dependencies = [ "cfg", "either", "expect", + "hir", "indexmap", "itertools", "log", "oorandom", "profile", "ra_assists", - "ra_hir", "ra_ide_db", "ra_ssr", "rustc-hash", @@ -1131,10 +1131,10 @@ dependencies = [ "base_db", "either", "fst", + "hir", "log", "once_cell", "profile", - "ra_hir", "rayon", "rustc-hash", "stdx", @@ -1149,7 +1149,7 @@ version = "0.1.0" dependencies = [ "base_db", "expect", - "ra_hir", + "hir", "ra_ide_db", "rustc-hash", "syntax", @@ -1236,6 +1236,7 @@ dependencies = [ "env_logger", "expect", "flycheck", + "hir", "hir_def", "hir_ty", "itertools", @@ -1251,7 +1252,6 @@ dependencies = [ "proc_macro_srv", "profile", "project_model", - "ra_hir", "ra_ide", "ra_ide_db", "ra_ssr", diff --git a/crates/ra_hir/Cargo.toml b/crates/hir/Cargo.toml similarity index 92% rename from crates/ra_hir/Cargo.toml rename to crates/hir/Cargo.toml index 61cc099ac71..dbb2986b600 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/hir/Cargo.toml @@ -1,9 +1,9 @@ [package] -edition = "2018" -name = "ra_hir" -version = "0.1.0" -authors = ["rust-analyzer developers"] +name = "hir" +version = "0.0.0" license = "MIT OR Apache-2.0" +authors = ["rust-analyzer developers"] +edition = "2018" [lib] doctest = false @@ -13,7 +13,6 @@ log = "0.4.8" rustc-hash = "1.1.0" either = "1.5.3" arrayvec = "0.5.1" - itertools = "0.9.0" stdx = { path = "../stdx" } diff --git a/crates/ra_hir/src/code_model.rs b/crates/hir/src/code_model.rs similarity index 100% rename from crates/ra_hir/src/code_model.rs rename to crates/hir/src/code_model.rs diff --git a/crates/ra_hir/src/db.rs b/crates/hir/src/db.rs similarity index 100% rename from crates/ra_hir/src/db.rs rename to crates/hir/src/db.rs diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs similarity index 100% rename from crates/ra_hir/src/diagnostics.rs rename to crates/hir/src/diagnostics.rs diff --git a/crates/ra_hir/src/from_id.rs b/crates/hir/src/from_id.rs similarity index 100% rename from crates/ra_hir/src/from_id.rs rename to crates/hir/src/from_id.rs diff --git a/crates/ra_hir/src/has_source.rs b/crates/hir/src/has_source.rs similarity index 100% rename from crates/ra_hir/src/has_source.rs rename to crates/hir/src/has_source.rs diff --git a/crates/ra_hir/src/lib.rs b/crates/hir/src/lib.rs similarity index 92% rename from crates/ra_hir/src/lib.rs rename to crates/hir/src/lib.rs index 34b02c5365f..24a0f6b4b18 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -9,11 +9,11 @@ //! It is written in "OO" style. Each type is self contained (as in, it knows it's //! parents and full context). It should be "clean code". //! -//! `ra_hir_*` crates are the implementation of the compiler logic. +//! `hir_*` crates are the implementation of the compiler logic. //! They are written in "ECS" style, with relatively little abstractions. //! Many types are not self-contained, and explicitly use local indexes, arenas, etc. //! -//! `ra_hir` is what insulates the "we don't know how to actually write an incremental compiler" +//! `hir` is what insulates the "we don't know how to actually write an incremental compiler" //! from the ide with completions, hovers, etc. It is a (soft, internal) boundary: //! https://www.tedinski.com/2018/02/06/system-boundaries.html. diff --git a/crates/ra_hir/src/semantics.rs b/crates/hir/src/semantics.rs similarity index 100% rename from crates/ra_hir/src/semantics.rs rename to crates/hir/src/semantics.rs diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs similarity index 100% rename from crates/ra_hir/src/semantics/source_to_def.rs rename to crates/hir/src/semantics/source_to_def.rs diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs similarity index 100% rename from crates/ra_hir/src/source_analyzer.rs rename to crates/hir/src/source_analyzer.rs diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index ebac09be626..cacc063da2b 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml @@ -20,5 +20,5 @@ text_edit = { path = "../text_edit" } profile = { path = "../profile" } base_db = { path = "../base_db" } ra_ide_db = { path = "../ra_ide_db" } -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } test_utils = { path = "../test_utils" } diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 1af51f3ae8f..a701cdf1d50 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml @@ -33,7 +33,7 @@ ra_ssr = { path = "../ra_ssr" } # ra_ide should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } [dev-dependencies] expect = { path = "../expect" } diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 789fbdaf232..0d14c823aef 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -3,7 +3,7 @@ //! Strings, suitable for displaying to the human. //! //! What powers this API are the `RootDatabase` struct, which defines a `salsa` -//! database, and the `ra_hir` crate, where majority of the analysis happens. +//! database, and the `hir` crate, where majority of the analysis happens. //! However, IDE specific bits of the analysis (most notably completion) happen //! in this crate. diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml index 0cda7090d3f..eda257a3a8b 100644 --- a/crates/ra_ide_db/Cargo.toml +++ b/crates/ra_ide_db/Cargo.toml @@ -29,4 +29,4 @@ test_utils = { path = "../test_utils" } # ra_ide should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } diff --git a/crates/ra_ssr/Cargo.toml b/crates/ra_ssr/Cargo.toml index f290939cfbd..bed4bbdf19c 100644 --- a/crates/ra_ssr/Cargo.toml +++ b/crates/ra_ssr/Cargo.toml @@ -15,7 +15,7 @@ text_edit = { path = "../text_edit" } syntax = { path = "../syntax" } base_db = { path = "../base_db" } ra_ide_db = { path = "../ra_ide_db" } -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } rustc-hash = "1.1.0" test_utils = { path = "../test_utils" } diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index e17fe47daeb..c0257e9c897 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -49,7 +49,7 @@ toolchain = { path = "../toolchain" } base_db = { path = "../base_db" } ra_ide_db = { path = "../ra_ide_db" } ra_ssr = { path = "../ra_ssr" } -hir = { path = "../ra_hir", package = "ra_hir" } +hir = { path = "../hir" } hir_def = { path = "../hir_def" } hir_ty = { path = "../hir_ty" } proc_macro_srv = { path = "../proc_macro_srv" } diff --git a/docs/dev/README.md b/docs/dev/README.md index 4aab6e2b86a..04bebbfca5c 100644 --- a/docs/dev/README.md +++ b/docs/dev/README.md @@ -148,14 +148,14 @@ Internal representations are lowered to LSP in the `rust-analyzer` crate (the on ## IDE/Compiler split -There's a semi-hard split between "compiler" and "IDE", at the `ra_hir` crate. +There's a semi-hard split between "compiler" and "IDE", at the `hir` crate. Compiler derives new facts about source code. It explicitly acknowledges that not all info is available (i.e. 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. +IDE should use only types from `hir`, and should not depend on the underling compiler types. +`hir` is a facade. ## IDE API diff --git a/docs/dev/architecture.md b/docs/dev/architecture.md index 746d41f83ce..0ffe61026ac 100644 --- a/docs/dev/architecture.md +++ b/docs/dev/architecture.md @@ -102,7 +102,7 @@ defines most of the "input" queries: facts supplied by the client of the analyzer. Reading the docs of the `base_db::input` module should be useful: everything else is strictly derived from those inputs. -### `crates/ra_hir*` crates +### `crates/hir*` crates HIR provides high-level "object oriented" access to Rust code. @@ -113,10 +113,10 @@ is responsible for guessing a HIR for a particular source position. Underneath, HIR works on top of salsa, using a `HirDatabase` trait. -`ra_hir_xxx` crates have a strong ECS flavor, in that they work with raw ids and +`hir_xxx` crates have a strong ECS flavor, in that they work with raw ids and directly query the database. -The top-level `ra_hir` façade crate wraps ids into a more OO-flavored API. +The top-level `hir` façade crate wraps ids into a more OO-flavored API. ### `crates/ra_ide` diff --git a/docs/dev/guide.md b/docs/dev/guide.md index d14143226b1..29d84bf3f6a 100644 --- a/docs/dev/guide.md +++ b/docs/dev/guide.md @@ -275,7 +275,7 @@ several times, with different sets of `cfg`s enabled. The IDE-specific task of mapping source code position into a semantic model is inherently imprecise for this reason, and is handled by the [`source_binder`]. -[`source_binder`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/source_binder.rs +[`source_binder`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/source_binder.rs The semantic interface is declared in the [`code_model_api`] module. Each entity is identified by an integer ID and has a bunch of methods which take a salsa database @@ -283,8 +283,8 @@ as an argument and returns other entities (which are also IDs). Internally, thes methods invoke various queries on the database to build the model on demand. Here's [the list of queries]. -[`code_model_api`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/code_model_api.rs -[the list of queries]: https://github.com/rust-analyzer/rust-analyzer/blob/7e84440e25e19529e4ff8a66e521d1b06349c6ec/crates/ra_hir/src/db.rs#L20-L106 +[`code_model_api`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/code_model_api.rs +[the list of queries]: https://github.com/rust-analyzer/rust-analyzer/blob/7e84440e25e19529e4ff8a66e521d1b06349c6ec/crates/hir/src/db.rs#L20-L106 The first step of building the model is parsing the source code. @@ -341,7 +341,7 @@ The algorithm for building a tree of modules is to start with a crate root declarations and recursively process child modules. This is handled by the [`module_tree_query`], with two slight variations. -[`module_tree_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L116-L123 +[`module_tree_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/module_tree.rs#L116-L123 First, rust-analyzer builds a module tree for all crates in a source root simultaneously. The main reason for this is historical (`module_tree` predates @@ -364,7 +364,7 @@ the same, we don't have to re-execute [`module_tree_query`]. In fact, we only need to re-execute it when we add/remove new files or when we change mod declarations. -[`submodules_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/module_tree.rs#L41 +[`submodules_query`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/module_tree.rs#L41 We store the resulting modules in a `Vec`-based indexed arena. The indices in the arena becomes module IDs. And this brings us to the next topic: @@ -393,7 +393,7 @@ database we use includes a couple of [interners]. How to "garbage collect" unused locations is an open question. [`LocationInterner`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/base_db/src/loc2id.rs#L65-L71 -[interners]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/db.rs#L22-L23 +[interners]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/db.rs#L22-L23 For example, we use `LocationInterner` to assign IDs to definitions of functions, structs, enums, etc. The location, [`DefLoc`] contains two bits of information: @@ -407,7 +407,7 @@ using offsets, text ranges or syntax trees as keys and values for queries. What we do instead is we store "index" of the item among all of the items of a file (so, a positional based ID, but localized to a single file). -[`DefLoc`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/ids.rs#L127-L139 +[`DefLoc`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/ids.rs#L127-L139 One thing we've glossed over for the time being is support for macros. We have only proof of concept handling of macros at the moment, but they are extremely @@ -440,7 +440,7 @@ terms of `HirFileId`! This does not recur infinitely though: any chain of `HirFileId`s bottoms out in `HirFileId::FileId`, that is, some source file actually written by the user. -[`HirFileId`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/ids.rs#L18-L125 +[`HirFileId`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/ids.rs#L18-L125 Now that we understand how to identify a definition, in a source or in a macro-generated file, we can discuss name resolution a bit. @@ -454,14 +454,14 @@ each module into a position-independent representation which does not change if we modify bodies of the items. After that we [loop] resolving all imports until we've reached a fixed point. -[lower]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L113-L117 -[loop]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres.rs#L186-L196 +[lower]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L113-L117 +[loop]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres.rs#L186-L196 And, given all our preparation with IDs and a position-independent representation, it is satisfying to [test] that typing inside function body does not invalidate name resolution results. -[test]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/tests.rs#L376 +[test]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/tests.rs#L376 An interesting fact about name resolution is that it "erases" all of the intermediate paths from the imports: in the end, we know which items are defined @@ -496,10 +496,10 @@ there's an intermediate [projection query] which returns only the first position-independent part of the lowering. The result of this query is stable. Naturally, name resolution [uses] this stable projection query. -[imports]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L52-L59 -[`SourceMap`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L52-L59 -[projection query]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L97-L103 -[uses]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/query_definitions.rs#L49 +[imports]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L52-L59 +[`SourceMap`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L52-L59 +[projection query]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L97-L103 +[uses]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/query_definitions.rs#L49 ## Type inference @@ -521,10 +521,10 @@ construct a mapping from `ExprId`s to types. [@flodiebold]: https://github.com/flodiebold [#327]: https://github.com/rust-analyzer/rust-analyzer/pull/327 -[lower the AST]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/expr.rs -[positional ID]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/expr.rs#L13-L15 -[a source map]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/expr.rs#L41-L44 -[type inference]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/ty.rs#L1208-L1223 +[lower the AST]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/expr.rs +[positional ID]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/expr.rs#L13-L15 +[a source map]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/expr.rs#L41-L44 +[type inference]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/ty.rs#L1208-L1223 ## Tying it all together: completion diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs index 5a5bd4a3ee3..97a11a01eeb 100644 --- a/xtask/tests/tidy.rs +++ b/xtask/tests/tidy.rs @@ -192,7 +192,7 @@ impl TidyDocs { } let poorly_documented = [ - "ra_hir", + "hir", "hir_expand", "ra_ide", "mbe",