Skip to content

Commit 2bd06ea

Browse files
authored
Merge pull request #545 from nathanwhit/chalk-ir-function-cleanup
Cleanup function names in `chalk-ir`
2 parents 87564e4 + 98df959 commit 2bd06ea

File tree

19 files changed

+60
-56
lines changed

19 files changed

+60
-56
lines changed

chalk-integration/src/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl RustIrDatabase<ChalkIr> for Program {
385385
<[_] as CouldMatch<[_]>>::could_match(
386386
&parameters,
387387
interner,
388-
&trait_ref.substitution.parameters(interner),
388+
&trait_ref.substitution.as_slice(interner),
389389
)
390390
}
391391
})

chalk-ir/src/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ where
205205
fn cast_to(self, interner: &I) -> ProgramClause<I> {
206206
let implication = ProgramClauseImplication {
207207
consequence: self.cast(interner),
208-
conditions: Goals::new(interner),
208+
conditions: Goals::empty(interner),
209209
priority: ClausePriority::High,
210210
};
211211

@@ -222,7 +222,7 @@ where
222222
fn cast_to(self, interner: &I) -> ProgramClause<I> {
223223
ProgramClauseData(self.map(|bound| ProgramClauseImplication {
224224
consequence: bound.cast(interner),
225-
conditions: Goals::new(interner),
225+
conditions: Goals::empty(interner),
226226
priority: ClausePriority::High,
227227
}))
228228
.intern(interner)

chalk-ir/src/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<'a, 'me, I: Interner> Debug for SeparatorTraitRefDebug<'a, 'me, I> {
544544
let parameters = separator_trait_ref
545545
.trait_ref
546546
.substitution
547-
.parameters(interner);
547+
.as_slice(interner);
548548
write!(
549549
fmt,
550550
"{:?}{}{:?}{:?}",
@@ -856,7 +856,7 @@ impl<I: Interner> Substitution<I> {
856856
/// Displays the substitution in the form `< P0, .. Pn >`, or (if
857857
/// the substitution is empty) as an empty string.
858858
pub fn with_angle(&self, interner: &I) -> Angle<'_, GenericArg<I>> {
859-
Angle(self.parameters(interner))
859+
Angle(self.as_slice(interner))
860860
}
861861
}
862862

chalk-ir/src/lib.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::fold::shift::Shift;
1111
use crate::fold::{Fold, Folder, Subst, SuperFold};
1212
use crate::visit::{SuperVisit, Visit, VisitExt, VisitResult, Visitor};
1313
use chalk_derive::{Fold, HasInterner, SuperVisit, Visit, Zip};
14-
use std::iter;
1514
use std::marker::PhantomData;
1615

1716
pub use crate::debug::SeparatorTraitRef;
@@ -77,7 +76,7 @@ impl<I: Interner> Environment<I> {
7776
/// Creates a new environment.
7877
pub fn new(interner: &I) -> Self {
7978
Environment {
80-
clauses: ProgramClauses::new(interner),
79+
clauses: ProgramClauses::empty(interner),
8180
}
8281
}
8382

@@ -1804,7 +1803,7 @@ impl<T: HasInterner> Binders<T> {
18041803
/// (value)`. Since our deBruijn indices count binders, not variables, this
18051804
/// is sometimes useful.
18061805
pub fn empty(interner: &T::Interner, value: T) -> Self {
1807-
let binders = VariableKinds::new(interner);
1806+
let binders = VariableKinds::empty(interner);
18081807
Self { binders, value }
18091808
}
18101809

@@ -1895,7 +1894,7 @@ impl<T: HasInterner> Binders<T> {
18951894
// The new variable is at the front and everything afterwards is shifted up by 1
18961895
let new_var = TyData::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(interner);
18971896
let value = op(new_var);
1898-
let binders = VariableKinds::from(interner, iter::once(VariableKind::Ty(TyKind::General)));
1897+
let binders = VariableKinds::from1(interner, VariableKind::Ty(TyKind::General));
18991898
Binders { binders, value }
19001899
}
19011900

@@ -2105,7 +2104,7 @@ pub struct ProgramClauses<I: Interner> {
21052104

21062105
impl<I: Interner> ProgramClauses<I> {
21072106
/// Creates an empty list of program clauses.
2108-
pub fn new(interner: &I) -> Self {
2107+
pub fn empty(interner: &I) -> Self {
21092108
Self::from(interner, None::<ProgramClause<I>>)
21102109
}
21112110

@@ -2167,8 +2166,8 @@ pub struct VariableKinds<I: Interner> {
21672166
}
21682167

21692168
impl<I: Interner> VariableKinds<I> {
2170-
/// Creates an empty list of canonical variable kinds.
2171-
pub fn new(interner: &I) -> Self {
2169+
/// Creates an empty list of variable kinds.
2170+
pub fn empty(interner: &I) -> Self {
21722171
Self::from(interner, None::<VariableKind<I>>)
21732172
}
21742173

@@ -2198,6 +2197,11 @@ impl<I: Interner> VariableKinds<I> {
21982197
})
21992198
}
22002199

2200+
/// Creates a list of variable kinds from a single variable kind.
2201+
pub fn from1(interner: &I, variable_kind: VariableKind<I>) -> Self {
2202+
Self::from(interner, Some(variable_kind))
2203+
}
2204+
22012205
/// Get an iterator over the list of variable kinds.
22022206
pub fn iter(&self, interner: &I) -> std::slice::Iter<'_, VariableKind<I>> {
22032207
self.as_slice(interner).iter()
@@ -2227,7 +2231,7 @@ pub struct CanonicalVarKinds<I: Interner> {
22272231

22282232
impl<I: Interner> CanonicalVarKinds<I> {
22292233
/// Creates an empty list of canonical variable kinds.
2230-
pub fn new(interner: &I) -> Self {
2234+
pub fn empty(interner: &I) -> Self {
22312235
Self::from(interner, None::<CanonicalVarKind<I>>)
22322236
}
22332237

@@ -2260,6 +2264,11 @@ impl<I: Interner> CanonicalVarKinds<I> {
22602264
})
22612265
}
22622266

2267+
/// Creates a list of canonical variable kinds from a single canonical variable kind.
2268+
pub fn from1(interner: &I, variable_kind: CanonicalVarKind<I>) -> Self {
2269+
Self::from(interner, Some(variable_kind))
2270+
}
2271+
22632272
/// Get an iterator over the list of canonical variable kinds.
22642273
pub fn iter(&self, interner: &I) -> std::slice::Iter<'_, CanonicalVarKind<I>> {
22652274
self.as_slice(interner).iter()
@@ -2325,7 +2334,7 @@ impl<T: HasInterner> UCanonical<T> {
23252334
let subst = &canonical_subst.value.subst;
23262335
assert_eq!(
23272336
self.canonical.binders.len(interner),
2328-
subst.parameters(interner).len()
2337+
subst.as_slice(interner).len()
23292338
);
23302339
subst.is_identity_subst(interner)
23312340
}
@@ -2372,7 +2381,7 @@ pub struct Goals<I: Interner> {
23722381

23732382
impl<I: Interner> Goals<I> {
23742383
/// Creates an empty list of goals.
2375-
pub fn new(interner: &I) -> Self {
2384+
pub fn empty(interner: &I) -> Self {
23762385
Self::from(interner, None::<Goal<I>>)
23772386
}
23782387

@@ -2521,7 +2530,7 @@ where
25212530
}
25222531
} else {
25232532
// No goals to prove, always true
2524-
GoalData::All(Goals::new(interner)).intern(interner)
2533+
GoalData::All(Goals::empty(interner)).intern(interner)
25252534
}
25262535
}
25272536
}
@@ -2662,7 +2671,7 @@ impl<I: Interner> Substitution<I> {
26622671

26632672
/// Index into the list of parameters.
26642673
pub fn at(&self, interner: &I, index: usize) -> &GenericArg<I> {
2665-
&self.parameters(interner)[index]
2674+
&self.as_slice(interner)[index]
26662675
}
26672676

26682677
/// Create a substitution from a single parameter.
@@ -2677,22 +2686,22 @@ impl<I: Interner> Substitution<I> {
26772686

26782687
/// Check whether this is an empty substitution.
26792688
pub fn is_empty(&self, interner: &I) -> bool {
2680-
self.parameters(interner).is_empty()
2689+
self.as_slice(interner).is_empty()
26812690
}
26822691

26832692
/// Get an iterator over the parameters of the substitution.
26842693
pub fn iter(&self, interner: &I) -> std::slice::Iter<'_, GenericArg<I>> {
2685-
self.parameters(interner).iter()
2694+
self.as_slice(interner).iter()
26862695
}
26872696

2688-
/// Get the parameters associated with a substitution.
2689-
pub fn parameters(&self, interner: &I) -> &[GenericArg<I>] {
2697+
/// Returns a slice containing the parameters associated with the substitution.
2698+
pub fn as_slice(&self, interner: &I) -> &[GenericArg<I>] {
26902699
interner.substitution_data(&self.interned)
26912700
}
26922701

26932702
/// Get the length of the substitution (number of parameters).
26942703
pub fn len(&self, interner: &I) -> usize {
2695-
self.parameters(interner).len()
2704+
self.as_slice(interner).len()
26962705
}
26972706

26982707
/// A substitution is an **identity substitution** if it looks
@@ -2753,7 +2762,7 @@ impl<I: Interner> SubstFolder<'_, I> {
27532762
/// Index into the list of parameters.
27542763
pub fn at(&self, index: usize) -> &GenericArg<I> {
27552764
let interner = self.interner;
2756-
&self.subst.parameters(interner)[index]
2765+
&self.subst.as_slice(interner)[index]
27572766
}
27582767
}
27592768

@@ -2766,7 +2775,7 @@ pub trait AsParameters<I: Interner> {
27662775
impl<I: Interner> AsParameters<I> for Substitution<I> {
27672776
#[allow(unreachable_code, unused_variables)]
27682777
fn as_parameters(&self, interner: &I) -> &[GenericArg<I>] {
2769-
self.parameters(interner)
2778+
self.as_slice(interner)
27702779
}
27712780
}
27722781

chalk-ir/src/visit/binder_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<I: Interner> Visit<I> for Fn<I> {
1717
{
1818
let interner = visitor.interner();
1919
self.substitution
20-
.parameters(interner)
20+
.as_slice(interner)
2121
.visit_with(visitor, outer_binder.shifted_in())
2222
}
2323
}

chalk-ir/src/zip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<I: Interner> Zip<I> for Substitution<I> {
287287
I: 'i,
288288
{
289289
let interner = zipper.interner();
290-
Zip::zip_with(zipper, a.parameters(interner), b.parameters(interner))
290+
Zip::zip_with(zipper, a.as_slice(interner), b.as_slice(interner))
291291
}
292292
}
293293

chalk-solve/src/clauses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn program_clauses_that_could_match<I: Interner>(
235235

236236
for impl_id in db.impls_for_trait(
237237
trait_ref.trait_id,
238-
trait_ref.substitution.parameters(interner),
238+
trait_ref.substitution.as_slice(interner),
239239
) {
240240
db.impl_datum(impl_id).to_program_clauses(builder);
241241
}

chalk-solve/src/clauses/builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::iter;
21
use std::marker::PhantomData;
32

43
use crate::cast::{Cast, CastTo};
@@ -156,7 +155,7 @@ impl<'me, I: Interner> ClauseBuilder<'me, I> {
156155
pub fn push_bound_ty(&mut self, op: impl FnOnce(&mut Self, Ty<I>)) {
157156
let interner = self.interner();
158157
let binders = Binders::new(
159-
VariableKinds::from(interner, iter::once(VariableKind::Ty(TyKind::General))),
158+
VariableKinds::from1(interner, VariableKind::Ty(TyKind::General)),
160159
PhantomData::<I>,
161160
);
162161
self.push_binders(&binders, |this, PhantomData| {

chalk-solve/src/clauses/builtin_traits/fn_family.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub fn add_fn_trait_program_clauses<I: Interner>(
144144
builder.push_binders(&bound_ref, |builder, orig_sub| {
145145
// The last parameter represents the function return type
146146
let (arg_sub, fn_output_ty) = orig_sub
147-
.parameters(interner)
147+
.as_slice(interner)
148148
.split_at(orig_sub.len(interner) - 1);
149149
let arg_sub = Substitution::from(interner, arg_sub);
150150
let output_ty = fn_output_ty[0].assert_ty_ref(interner).clone();

chalk-solve/src/clauses/builtin_traits/unsize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ pub fn add_unsize_program_clauses<I: Interner>(
387387
return;
388388
}
389389

390-
let parameters_a = substitution_a.parameters(interner);
391-
let parameters_b = substitution_b.parameters(interner);
390+
let parameters_a = substitution_a.as_slice(interner);
391+
let parameters_b = substitution_b.as_slice(interner);
392392
// Check that the source adt with the target's
393393
// unsizing parameters is equal to the target.
394394
// We construct a new substitution where if a parameter is used in the

chalk-solve/src/coherence/solve.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ impl<I: Interner> CoherenceSolver<'_, I> {
9393
let lhs_params = lhs_bound
9494
.trait_ref
9595
.substitution
96-
.parameters(interner)
96+
.as_slice(interner)
9797
.iter()
9898
.cloned();
9999
let rhs_params = rhs_bound
100100
.trait_ref
101101
.substitution
102-
.parameters(interner)
102+
.as_slice(interner)
103103
.iter()
104104
.map(|param| param.shifted_in(interner));
105105

@@ -223,14 +223,14 @@ impl<I: Interner> CoherenceSolver<'_, I> {
223223
// T0 = U0, ..., Tm = Um
224224
let params_goals = more_special_trait_ref
225225
.substitution
226-
.parameters(interner)
226+
.as_slice(interner)
227227
.iter()
228228
.cloned()
229229
.zip(
230230
less_special_impl
231231
.trait_ref
232232
.substitution
233-
.parameters(interner)
233+
.as_slice(interner)
234234
.iter()
235235
.cloned(),
236236
)

chalk-solve/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn display_self_where_clauses_as_bounds<'a, I: Interner>(
137137
WhereClause::Implemented(trait_ref) => display_type_with_generics(
138138
s,
139139
trait_ref.trait_id,
140-
&trait_ref.substitution.parameters(interner)[1..],
140+
&trait_ref.substitution.as_slice(interner)[1..],
141141
)
142142
.fmt(f),
143143
WhereClause::AliasEq(alias_eq) => match &alias_eq.alias {

chalk-solve/src/display/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<I: Interner> RenderAsRust<I> for TraitRef<I> {
107107
display_type_with_generics(
108108
s,
109109
self.trait_id,
110-
&self.substitution.parameters(interner)[1..]
110+
&self.substitution.as_slice(interner)[1..]
111111
)
112112
)
113113
}

chalk-solve/src/display/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<I: Interner> RenderAsRust<I> for ImplDatum<I> {
234234
s,
235235
trait_ref.trait_id,
236236
// Ignore automatically added Self parameter by skipping first parameter
237-
&trait_ref.substitution.parameters(interner)[1..],
237+
&trait_ref.substitution.as_slice(interner)[1..],
238238
);
239239
write!(
240240
f,

chalk-solve/src/display/stub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<I: Interner, DB: RustIrDatabase<I>> RustIrDatabase<I> for StubWrapper<'_, D
108108
v.bound = Binders::new(
109109
v.bound.binders,
110110
OpaqueTyDatumBound {
111-
bounds: Binders::new(VariableKinds::new(self.db.interner()), Vec::new()),
111+
bounds: Binders::new(VariableKinds::empty(self.db.interner()), Vec::new()),
112112
},
113113
);
114114
Arc::new(v)

0 commit comments

Comments
 (0)