Skip to content

Commit 35614c7

Browse files
Merge #8328
8328: Move things in hir_ty into submodules r=flodiebold a=flodiebold - all the types that will be replaced by Chalk go to `types` - `TypeWalk` impls go to `walk` - also fix signature of `Substitution::interned` Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2 parents 0924888 + 645a9c3 commit 35614c7

File tree

17 files changed

+855
-814
lines changed

17 files changed

+855
-814
lines changed

crates/hir/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ use hir_ty::{
5555
autoderef, could_unify,
5656
method_resolution::{self, TyFingerprint},
5757
primitive::UintTy,
58-
traits::{FnTrait, Solution, SolutionVariables},
58+
traits::FnTrait,
5959
AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast,
60-
DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Substitution,
61-
TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind, TyVariableKind, WhereClause,
60+
DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution,
61+
SolutionVariables, Substitution, TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind,
62+
TyVariableKind, WhereClause,
6263
};
6364
use itertools::Itertools;
6465
use rustc_hash::FxHashSet;
@@ -1822,7 +1823,7 @@ impl Type {
18221823
match db.trait_solve(self.krate, goal)? {
18231824
Solution::Unique(SolutionVariables(subst)) => subst
18241825
.value
1825-
.interned(&Interner)
1826+
.interned()
18261827
.first()
18271828
.map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())),
18281829
Solution::Ambig(_) => None,

crates/hir_ty/src/autoderef.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ use hir_expand::name::name;
1212
use log::{info, warn};
1313

1414
use crate::{
15-
db::HirDatabase,
16-
traits::{InEnvironment, Solution},
17-
AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex, Interner, Ty,
18-
TyBuilder, TyKind,
15+
db::HirDatabase, AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex,
16+
InEnvironment, Interner, Solution, Ty, TyBuilder, TyKind,
1917
};
2018

2119
const AUTODEREF_RECURSION_LIMIT: usize = 10;

crates/hir_ty/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<D> TyBuilder<D> {
3333
fn build_internal(self) -> (D, Substitution) {
3434
assert_eq!(self.vec.len(), self.param_count);
3535
// FIXME: would be good to have a way to construct a chalk_ir::Substitution from the interned form
36-
let subst = Substitution(self.vec);
36+
let subst = Substitution::intern(self.vec);
3737
(self.data, subst)
3838
}
3939

@@ -138,7 +138,7 @@ impl TyBuilder<hir_def::AdtId> {
138138
self.vec.push(fallback().cast(&Interner));
139139
} else {
140140
// each default can depend on the previous parameters
141-
let subst_so_far = Substitution(self.vec.clone());
141+
let subst_so_far = Substitution::intern(self.vec.clone());
142142
self.vec.push(default_ty.clone().subst(&subst_so_far).cast(&Interner));
143143
}
144144
}

crates/hir_ty/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
123123
&self,
124124
krate: CrateId,
125125
goal: crate::Canonical<crate::InEnvironment<crate::DomainGoal>>,
126-
) -> Option<crate::traits::Solution>;
126+
) -> Option<crate::Solution>;
127127

128128
#[salsa::invoke(crate::traits::chalk::program_clauses_for_chalk_env_query)]
129129
fn program_clauses_for_chalk_env(

crates/hir_ty/src/display.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl HirDisplay for ProjectionTy {
260260
write!(f, "<{} as {}", first_parameter, trait_.name)?;
261261
if self.substitution.len(&Interner) > 1 {
262262
write!(f, "<")?;
263-
f.write_joined(&self.substitution.interned(&Interner)[1..], ", ")?;
263+
f.write_joined(&self.substitution.interned()[1..], ", ")?;
264264
write!(f, ">")?;
265265
}
266266
write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?;
@@ -387,7 +387,7 @@ impl HirDisplay for Ty {
387387
write!(f, ",)")?;
388388
} else {
389389
write!(f, "(")?;
390-
f.write_joined(&*substs.0, ", ")?;
390+
f.write_joined(&*substs.interned(), ", ")?;
391391
write!(f, ")")?;
392392
}
393393
}
@@ -415,7 +415,7 @@ impl HirDisplay for Ty {
415415
// We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
416416
if total_len > 0 {
417417
write!(f, "<")?;
418-
f.write_joined(&parameters.0[..total_len], ", ")?;
418+
f.write_joined(&parameters.interned()[..total_len], ", ")?;
419419
write!(f, ">")?;
420420
}
421421
}
@@ -468,7 +468,7 @@ impl HirDisplay for Ty {
468468
.map(|generic_def_id| f.db.generic_defaults(generic_def_id))
469469
.filter(|defaults| !defaults.is_empty())
470470
{
471-
None => parameters.0.as_ref(),
471+
None => parameters.interned().as_ref(),
472472
Some(default_parameters) => {
473473
let mut default_from = 0;
474474
for (i, parameter) in parameters.iter(&Interner).enumerate() {
@@ -490,11 +490,11 @@ impl HirDisplay for Ty {
490490
}
491491
}
492492
}
493-
&parameters.0[0..default_from]
493+
&parameters.interned()[0..default_from]
494494
}
495495
}
496496
} else {
497-
parameters.0.as_ref()
497+
parameters.interned().as_ref()
498498
};
499499
if !parameters_to_write.is_empty() {
500500
write!(f, "<")?;
@@ -517,7 +517,7 @@ impl HirDisplay for Ty {
517517
write!(f, "{}::{}", trait_.name, type_alias_data.name)?;
518518
if parameters.len(&Interner) > 0 {
519519
write!(f, "<")?;
520-
f.write_joined(&*parameters.0, ", ")?;
520+
f.write_joined(&*parameters.interned(), ", ")?;
521521
write!(f, ">")?;
522522
}
523523
} else {
@@ -727,13 +727,13 @@ fn write_bounds_like_dyn_trait(
727727
// existential) here, which is the only thing that's
728728
// possible in actual Rust, and hence don't print it
729729
write!(f, "{}", f.db.trait_data(trait_).name)?;
730-
if let [_, params @ ..] = &*trait_ref.substitution.0 {
730+
if let [_, params @ ..] = &*trait_ref.substitution.interned() {
731731
if is_fn_trait {
732732
if let Some(args) =
733733
params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple())
734734
{
735735
write!(f, "(")?;
736-
f.write_joined(&*args.0, ", ")?;
736+
f.write_joined(&*args.interned(), ", ")?;
737737
write!(f, ")")?;
738738
}
739739
} else if !params.is_empty() {
@@ -789,7 +789,7 @@ impl TraitRef {
789789
write!(f, "{}", f.db.trait_data(self.hir_trait_id()).name)?;
790790
if self.substitution.len(&Interner) > 1 {
791791
write!(f, "<")?;
792-
f.write_joined(&self.substitution.interned(&Interner)[1..], ", ")?;
792+
f.write_joined(&self.substitution.interned()[1..], ", ")?;
793793
write!(f, ">")?;
794794
}
795795
Ok(())

crates/hir_ty/src/infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use stdx::impl_from;
3737
use syntax::SmolStr;
3838

3939
use super::{
40-
traits::{DomainGoal, Guidance, Solution},
41-
InEnvironment, ProjectionTy, TraitEnvironment, TraitRef, Ty, TypeWalk,
40+
DomainGoal, Guidance, InEnvironment, ProjectionTy, Solution, TraitEnvironment, TraitRef, Ty,
41+
TypeWalk,
4242
};
4343
use crate::{
4444
db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode,

crates/hir_ty/src/infer/coerce.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use chalk_ir::{cast::Cast, Mutability, TyVariableKind};
88
use hir_def::lang_item::LangItemTarget;
99

10-
use crate::{autoderef, traits::Solution, Interner, Ty, TyBuilder, TyKind};
10+
use crate::{autoderef, Interner, Solution, Ty, TyBuilder, TyKind};
1111

1212
use super::{InEnvironment, InferenceContext};
1313

crates/hir_ty/src/infer/expr.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use crate::{
2020
method_resolution, op,
2121
primitive::{self, UintTy},
2222
to_chalk_trait_id,
23-
traits::{chalk::from_chalk, FnTrait, InEnvironment},
23+
traits::{chalk::from_chalk, FnTrait},
2424
utils::{generics, variant_data, Generics},
25-
AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Rawness, Scalar, Substitution,
26-
TraitRef, Ty, TyBuilder, TyKind,
25+
AdtId, Binders, CallableDefId, FnPointer, FnSig, InEnvironment, Interner, Rawness, Scalar,
26+
Substitution, TraitRef, Ty, TyBuilder, TyKind,
2727
};
2828

2929
use super::{
@@ -452,11 +452,7 @@ impl<'a> InferenceContext<'a> {
452452
};
453453
match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) {
454454
TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| {
455-
substs
456-
.interned(&Interner)
457-
.get(idx)
458-
.map(|a| a.assert_ty_ref(&Interner))
459-
.cloned()
455+
substs.interned().get(idx).map(|a| a.assert_ty_ref(&Interner)).cloned()
460456
}),
461457
TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => {
462458
let local_id = self.db.struct_data(*s).variant_data.field(name)?;

crates/hir_ty/src/infer/pat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a> InferenceContext<'a> {
123123
let ty = match &body[pat] {
124124
&Pat::Tuple { ref args, ellipsis } => {
125125
let expectations = match expected.as_tuple() {
126-
Some(parameters) => &*parameters.0,
126+
Some(parameters) => &*parameters.interned(),
127127
_ => &[],
128128
};
129129

@@ -239,7 +239,7 @@ impl<'a> InferenceContext<'a> {
239239
let (inner_ty, alloc_ty) = match expected.as_adt() {
240240
Some((adt, subst)) if adt == box_adt => (
241241
subst.at(&Interner, 0).assert_ty_ref(&Interner).clone(),
242-
subst.interned(&Interner).get(1).and_then(|a| a.ty(&Interner).cloned()),
242+
subst.interned().get(1).and_then(|a| a.ty(&Interner).cloned()),
243243
),
244244
_ => (self.result.standard_types.unknown.clone(), None),
245245
};

crates/hir_ty/src/infer/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a> InferenceContext<'a> {
9898
let substs = ctx.substs_from_path(path, typable, true);
9999
let ty = TyBuilder::value_ty(self.db, typable)
100100
.use_parent_substs(&parent_substs)
101-
.fill(substs.interned(&Interner)[parent_substs.len(&Interner)..].iter().cloned())
101+
.fill(substs.interned()[parent_substs.len(&Interner)..].iter().cloned())
102102
.build();
103103
Some(ty)
104104
}

0 commit comments

Comments
 (0)