mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 03:54:42 +00:00 
			
		
		
		
	Salsify the crate graph
I.e. make it not one giant input but multiple, for incrementality and decreased memory usage for Salsa 3 reasons.
This commit is contained in:
		
							parent
							
								
									44f18c3d05
								
							
						
					
					
						commit
						c94e9efbef
					
				
					 108 changed files with 3630 additions and 2512 deletions
				
			
		|  | @ -86,7 +86,6 @@ impl Body { | |||
|                         let item_tree = f.id.item_tree(db); | ||||
|                         let func = &item_tree[f.id.value]; | ||||
|                         let krate = f.container.module(db).krate; | ||||
|                         let crate_graph = db.crate_graph(); | ||||
|                         ( | ||||
|                             param_list, | ||||
|                             (0..func.params.len()).map(move |idx| { | ||||
|  | @ -99,7 +98,7 @@ impl Body { | |||
|                                             Idx::from_raw(RawIdx::from(idx as u32)), | ||||
|                                         ), | ||||
|                                     ) | ||||
|                                     .is_cfg_enabled(&crate_graph[krate].cfg_options) | ||||
|                                     .is_cfg_enabled(krate.cfg_options(db)) | ||||
|                             }), | ||||
|                         ) | ||||
|                     }); | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ mod asm; | |||
| 
 | ||||
| use std::mem; | ||||
| 
 | ||||
| use base_db::CrateId; | ||||
| use base_db::Crate; | ||||
| use either::Either; | ||||
| use hir_expand::{ | ||||
|     mod_path::tool_path, | ||||
|  | @ -50,7 +50,7 @@ use crate::{ | |||
|     item_scope::BuiltinShadowMode, | ||||
|     lang_item::LangItem, | ||||
|     lower::LowerCtx, | ||||
|     nameres::{DefMap, MacroSubNs}, | ||||
|     nameres::{DefMap, LocalDefMap, MacroSubNs}, | ||||
|     path::{GenericArgs, Path}, | ||||
|     type_ref::{Mutability, Rawness, TypeRef}, | ||||
|     AdtId, BlockId, BlockLoc, ConstBlockLoc, DefWithBodyId, MacroId, ModuleDefId, UnresolvedMacro, | ||||
|  | @ -64,7 +64,7 @@ pub(super) fn lower_body( | |||
|     expander: Expander, | ||||
|     parameters: Option<(ast::ParamList, impl Iterator<Item = bool>)>, | ||||
|     body: Option<ast::Expr>, | ||||
|     krate: CrateId, | ||||
|     krate: Crate, | ||||
|     is_async_fn: bool, | ||||
| ) -> (Body, BodySourceMap) { | ||||
|     // We cannot leave the root span map empty and let any identifier from it be treated as root,
 | ||||
|  | @ -189,7 +189,7 @@ pub(super) fn lower( | |||
|     owner: ExprStoreOwnerId, | ||||
|     expander: Expander, | ||||
|     body: Option<ast::Expr>, | ||||
|     krate: CrateId, | ||||
|     krate: Crate, | ||||
| ) -> (ExpressionStore, ExpressionStoreSourceMap) { | ||||
|     // We cannot leave the root span map empty and let any identifier from it be treated as root,
 | ||||
|     // because when inside nested macros `SyntaxContextId`s from the outer macro will be interleaved
 | ||||
|  | @ -214,8 +214,9 @@ struct ExprCollector<'a> { | |||
|     expander: Expander, | ||||
|     owner: ExprStoreOwnerId, | ||||
|     def_map: Arc<DefMap>, | ||||
|     local_def_map: Arc<LocalDefMap>, | ||||
|     ast_id_map: Arc<AstIdMap>, | ||||
|     krate: CrateId, | ||||
|     krate: Crate, | ||||
|     store: ExpressionStoreBuilder, | ||||
|     source_map: ExpressionStoreSourceMap, | ||||
| 
 | ||||
|  | @ -327,14 +328,16 @@ impl ExprCollector<'_> { | |||
|         db: &dyn DefDatabase, | ||||
|         owner: ExprStoreOwnerId, | ||||
|         expander: Expander, | ||||
|         krate: CrateId, | ||||
|         krate: Crate, | ||||
|         span_map: Option<Arc<ExpansionSpanMap>>, | ||||
|     ) -> ExprCollector<'_> { | ||||
|         let (def_map, local_def_map) = expander.module.local_def_map(db); | ||||
|         ExprCollector { | ||||
|             db, | ||||
|             owner, | ||||
|             krate, | ||||
|             def_map: expander.module.def_map(db), | ||||
|             def_map, | ||||
|             local_def_map, | ||||
|             source_map: ExpressionStoreSourceMap::default(), | ||||
|             ast_id_map: db.ast_id_map(expander.current_file_id()), | ||||
|             store: ExpressionStoreBuilder::default(), | ||||
|  | @ -1306,6 +1309,7 @@ impl ExprCollector<'_> { | |||
|             None => self.expander.enter_expand(self.db, mcall, |path| { | ||||
|                 self.def_map | ||||
|                     .resolve_path( | ||||
|                         &self.local_def_map, | ||||
|                         self.db, | ||||
|                         module, | ||||
|                         path, | ||||
|  | @ -1608,6 +1612,7 @@ impl ExprCollector<'_> { | |||
|                     // This could also be a single-segment path pattern. To
 | ||||
|                     // decide that, we need to try resolving the name.
 | ||||
|                     let (resolved, _) = self.def_map.resolve_path( | ||||
|                         &self.local_def_map, | ||||
|                         self.db, | ||||
|                         self.expander.module.local_id, | ||||
|                         &name.clone().into(), | ||||
|  |  | |||
|  | @ -293,7 +293,7 @@ impl SsrError { | |||
|     assert_eq!(db.body_with_source_map(def).1.diagnostics(), &[]); | ||||
|     expect Chayim Refael Friedman
						Chayim Refael Friedman