Skip to content

Commit 508a1ec

Browse files
committed
Move things in hir_ty into submodules
- all the types that will be replaced by Chalk go to `types` - `TypeWalk` impls go to `walk`
1 parent bc8b278 commit 508a1ec

File tree

11 files changed

+751
-707
lines changed

11 files changed

+751
-707
lines changed

crates/hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ impl Type {
18221822
match db.trait_solve(self.krate, goal)? {
18231823
Solution::Unique(SolutionVariables(subst)) => subst
18241824
.value
1825-
.interned(&Interner)
1825+
.interned()
18261826
.first()
18271827
.map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())),
18281828
Solution::Ambig(_) => None,

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/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/expr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

crates/hir_ty/src/infer/unify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl InferenceTable {
284284
substs2: &Substitution,
285285
depth: usize,
286286
) -> bool {
287-
substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| {
287+
substs1.iter(&Interner).zip(substs2.iter(&Interner)).all(|(t1, t2)| {
288288
self.unify_inner(t1.assert_ty_ref(&Interner), t2.assert_ty_ref(&Interner), depth)
289289
})
290290
}

0 commit comments

Comments
 (0)