Skip to content

Commit

Permalink
internal: Fetch toolchain and datalayout for DetachedFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Feb 20, 2024
1 parent 2223b4f commit d93096e
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 80 deletions.
4 changes: 2 additions & 2 deletions crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use itertools::Itertools;

use crate::{
hir::{
Array, BindingAnnotation, BindingId, CaptureBy, ClosureKind, Literal, LiteralOrConst,
Movability, Statement,
Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst, Movability,
Statement,
},
pretty::{print_generic_args, print_path, print_type_ref},
type_ref::TypeRef,
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{fmt, hash::BuildHasherDefault};

use base_db::CrateId;
use fst::{self, raw::IndexedValue, Automaton, Streamer};
use fst::{raw::IndexedValue, Automaton, Streamer};
use hir_expand::name::Name;
use indexmap::IndexMap;
use itertools::Itertools;
Expand Down Expand Up @@ -477,7 +477,7 @@ mod tests {
use expect_test::{expect, Expect};
use test_fixture::WithFixture;

use crate::{db::DefDatabase, test_db::TestDB, ItemContainerId, Lookup};
use crate::{test_db::TestDB, ItemContainerId, Lookup};

use super::*;

Expand Down
6 changes: 3 additions & 3 deletions crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ use std::{
ops::{Index, Range},
};

use ast::{AstNode, HasName, StructKind};
use ast::{AstNode, StructKind};
use base_db::CrateId;
use either::Either;
use hir_expand::{
ast_id_map::{AstIdNode, FileAstId},
attrs::RawAttrs,
name::{name, AsName, Name},
name::Name,
ExpandTo, HirFileId, InFile,
};
use intern::Interned;
Expand All @@ -67,7 +67,7 @@ use crate::{
attr::Attrs,
db::DefDatabase,
generics::{GenericParams, LifetimeParamData, TypeOrConstParamData},
path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind},
path::{GenericArgs, ImportAlias, ModPath, Path, PathKind},
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
visibility::{RawVisibility, VisibilityExplicitness},
BlockId, Lookup,
Expand Down
26 changes: 21 additions & 5 deletions crates/hir-def/src/item_tree/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@

use std::collections::hash_map::Entry;

use hir_expand::{ast_id_map::AstIdMap, span_map::SpanMapRef, HirFileId};
use syntax::ast::{self, HasModuleItem, HasTypeBounds, IsString};
use hir_expand::{
ast_id_map::AstIdMap, mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId,
};
use la_arena::Arena;
use syntax::{
ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString},
AstNode,
};
use triomphe::Arc;

use crate::{
db::DefDatabase,
generics::{GenericParams, GenericParamsCollector, TypeParamData, TypeParamProvenance},
type_ref::{LifetimeRef, TraitBoundModifier, TraitRef},
item_tree::{
AssocItem, AttrOwner, Const, Either, Enum, ExternBlock, ExternCrate, Field, FieldAstId,
Fields, FileItemTreeId, FnFlags, Function, GenericArgs, Idx, IdxRange, Impl, ImportAlias,
Interned, ItemTree, ItemTreeData, ItemTreeNode, Macro2, MacroCall, MacroRules, Mod,
ModItem, ModKind, ModPath, Mutability, Name, Param, ParamAstId, Path, Range, RawAttrs,
RawIdx, RawVisibilityId, Static, Struct, StructKind, Trait, TraitAlias, TypeAlias, Union,
Use, UseTree, UseTreeKind, Variant,
},
path::AssociatedTypeBinding,
type_ref::{LifetimeRef, TraitBoundModifier, TraitRef, TypeBound, TypeRef},
visibility::RawVisibility,
LocalLifetimeParamId, LocalTypeOrConstParamId,
};

use super::*;

fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
FileItemTreeId(index)
}
Expand Down
9 changes: 7 additions & 2 deletions crates/hir-def/src/item_tree/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ use span::ErasedFileAstId;

use crate::{
generics::{TypeOrConstParamData, WherePredicate, WherePredicateTypeTarget},
item_tree::{
AttrOwner, Const, DefDatabase, Enum, ExternBlock, ExternCrate, Field, FieldAstId, Fields,
FileItemTreeId, FnFlags, Function, GenericParams, Impl, Interned, ItemTree, Macro2,
MacroCall, MacroRules, Mod, ModItem, ModKind, Param, ParamAstId, Path, RawAttrs,
RawVisibilityId, Static, Struct, Trait, TraitAlias, TypeAlias, TypeBound, TypeRef, Union,
Use, UseTree, UseTreeKind, Variant,
},
pretty::{print_path, print_type_bounds, print_type_ref},
visibility::RawVisibility,
};

use super::*;

pub(super) fn print_item_tree(db: &dyn DefDatabase, tree: &ItemTree) -> String {
let mut p = Printer { db, tree, buf: String::new(), indent_level: 0, needs_indent: true };

Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod proc_macro;
#[cfg(test)]
mod tests;

use std::{cmp::Ord, ops::Deref};
use std::ops::Deref;

use base_db::{CrateId, Edition, FileId};
use hir_expand::{
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,7 @@ mod tests {
use base_db::SourceDatabase;
use test_fixture::WithFixture;

use crate::{db::DefDatabase, test_db::TestDB};
use crate::test_db::TestDB;

use super::*;

Expand Down
3 changes: 0 additions & 3 deletions crates/hir-def/src/nameres/tests/macros.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use expect_test::expect;
use test_fixture::WithFixture;

use itertools::Itertools;

use crate::nameres::tests::check;

use super::*;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/diagnostics/match_check/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Originates from `rustc_hir::pat_util`

use std::iter::{Enumerate, ExactSizeIterator};
use std::iter::Enumerate;

pub(crate) struct EnumerateAndAdjust<I> {
enumerate: Enumerate<I>,
Expand Down
8 changes: 6 additions & 2 deletions crates/hir-ty/src/mir/eval/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ use hir_def::{
builtin_type::{BuiltinInt, BuiltinUint},
resolver::HasResolver,
};
use hir_expand::mod_path::ModPath;

use super::*;
use crate::mir::eval::{
name, pad16, static_lifetime, Address, AdtId, Arc, BuiltinType, Evaluator, FunctionId,
HasModule, HirDisplay, Interned, InternedClosure, Interner, Interval, IntervalAndTy,
IntervalOrOwned, ItemContainerId, LangItem, Layout, Locals, Lookup, MirEvalError, MirSpan,
ModPath, Mutability, Result, Substitution, Ty, TyBuilder, TyExt,
};

mod simd;

Expand Down
1 change: 1 addition & 0 deletions crates/hir-ty/src/mir/eval/shim/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::cmp::Ordering;

use crate::consteval::try_const_usize;
use crate::TyKind;

use super::*;
Expand Down
10 changes: 8 additions & 2 deletions crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ use crate::{
inhabitedness::is_ty_uninhabited_from,
layout::LayoutError,
mapping::ToChalk,
mir::{
intern_const_scalar, return_slot, AggregateKind, Arena, BasicBlock, BasicBlockId, BinOp,
BorrowKind, CastKind, ClosureId, ConstScalar, Either, Expr, FieldId, Idx, InferenceResult,
Interner, Local, LocalId, MemoryMap, MirBody, MirSpan, Mutability, Operand, Place,
PlaceElem, PointerCast, ProjectionElem, ProjectionStore, RawIdx, Rvalue, Statement,
StatementKind, Substitution, SwitchTargets, Terminator, TerminatorKind, TupleFieldId, Ty,
UnOp, VariantId,
},
static_lifetime,
traits::FnTrait,
utils::{generics, ClosureSubst},
Adjust, Adjustment, AutoBorrow, CallableDefId, TyBuilder, TyExt,
};

use super::*;

mod as_place;
mod pattern_matching;

Expand Down
13 changes: 10 additions & 3 deletions crates/hir-ty/src/mir/lower/pattern_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

use hir_def::{hir::LiteralOrConst, resolver::HasResolver, AssocItemId};

use crate::BindingMode;

use super::*;
use crate::{
mir::lower::{
BasicBlockId, BinOp, BindingId, BorrowKind, Either, Expr, FieldId, Idx, Interner,
MemoryMap, MirLowerCtx, MirLowerError, MirSpan, Mutability, Operand, Pat, PatId, Place,
PlaceElem, ProjectionElem, RecordFieldPat, ResolveValueResult, Result, Rvalue,
Substitution, SwitchTargets, TerminatorKind, TupleFieldId, TupleId, TyBuilder, TyKind,
ValueNs, VariantData, VariantId,
},
BindingMode,
};

macro_rules! not_supported {
($x: expr) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hir::{self, HasCrate, HasVisibility};
use hir::{HasCrate, HasVisibility};
use ide_db::{path_transform::PathTransform, FxHashSet};
use syntax::{
ast::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//! }
//! ```

use hir::{self, HasAttrs};
use hir::HasAttrs;
use ide_db::{
documentation::HasDocs, path_transform::PathTransform,
syntax_helpers::insert_whitespace_into_node, traits::get_missing_assoc_items, SymbolKind,
Expand Down
1 change: 0 additions & 1 deletion crates/ide-db/src/imports/insert_use/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use hir::PrefixKind;
use stdx::trim_indent;
use test_fixture::WithFixture;
use test_utils::{assert_eq_text, CURSOR_MARKER};
Expand Down
3 changes: 1 addition & 2 deletions crates/ide-db/src/symbol_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use base_db::{
salsa::{self, ParallelDatabase},
SourceDatabaseExt, SourceRootId, Upcast,
};
use fst::{self, raw::IndexedValue, Automaton, Streamer};
use fst::{raw::IndexedValue, Automaton, Streamer};
use hir::{
db::HirDatabase,
import_map::{AssocSearchMode, SearchMode},
Expand Down Expand Up @@ -394,7 +394,6 @@ impl Query {
mod tests {

use expect_test::expect_file;
use hir::symbols::SymbolCollector;
use test_fixture::WithFixture;

use super::*;
Expand Down
1 change: 0 additions & 1 deletion crates/ide/src/join_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {

#[cfg(test)]
mod tests {
use syntax::SourceFile;
use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};

use super::*;
Expand Down
15 changes: 7 additions & 8 deletions crates/load-cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ fn load_crate_graph(
vfs: &mut vfs::Vfs,
receiver: &Receiver<vfs::loader::Message>,
) -> AnalysisHost {
let (ProjectWorkspace::Cargo { toolchain, target_layout, .. }
| ProjectWorkspace::Json { toolchain, target_layout, .. }
| ProjectWorkspace::DetachedFiles { toolchain, target_layout, .. }) = ws;

let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok());
let mut host = AnalysisHost::new(lru_cap);
let mut analysis_change = Change::new();
Expand Down Expand Up @@ -344,14 +348,9 @@ fn load_crate_graph(
let num_crates = crate_graph.len();
analysis_change.set_crate_graph(crate_graph);
analysis_change.set_proc_macros(proc_macros);
if let ProjectWorkspace::Cargo { toolchain, target_layout, .. }
| ProjectWorkspace::Json { toolchain, target_layout, .. } = ws
{
analysis_change.set_target_data_layouts(
iter::repeat(target_layout.clone()).take(num_crates).collect(),
);
analysis_change.set_toolchains(iter::repeat(toolchain.clone()).take(num_crates).collect());
}
analysis_change
.set_target_data_layouts(iter::repeat(target_layout.clone()).take(num_crates).collect());
analysis_change.set_toolchains(iter::repeat(toolchain.clone()).take(num_crates).collect());

host.apply_change(analysis_change);
host
Expand Down
Loading

0 comments on commit d93096e

Please sign in to comment.