Skip to content

Commit e3f8228

Browse files
authored
Merge pull request #366 from jackh726/debug
Use fallback debug impls instead of unimplemented
2 parents a8bf437 + 93aef02 commit e3f8228

File tree

7 files changed

+101
-45
lines changed

7 files changed

+101
-45
lines changed

chalk-ir/src/debug.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,78 +23,63 @@ impl<I: Interner> Debug for AssocTypeId<I> {
2323

2424
impl<I: Interner> Debug for Ty<I> {
2525
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
26-
I::debug_ty(self, fmt)
27-
.unwrap_or_else(|| unimplemented!("cannot format Ty without setting Program in tls"))
26+
I::debug_ty(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned))
2827
}
2928
}
3029

3130
impl<I: Interner> Debug for Lifetime<I> {
3231
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
33-
I::debug_lifetime(self, fmt).unwrap_or_else(|| {
34-
unimplemented!("cannot format Lifetime without setting Program in tls")
35-
})
32+
I::debug_lifetime(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned))
3633
}
3734
}
3835

3936
impl<I: Interner> Debug for Parameter<I> {
4037
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
41-
I::debug_parameter(self, fmt).unwrap_or_else(|| {
42-
unimplemented!("cannot format Parameter without setting Program in tls")
43-
})
38+
I::debug_parameter(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.0))
4439
}
4540
}
4641

4742
impl<I: Interner> Debug for Goal<I> {
4843
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
49-
I::debug_goal(self, fmt)
50-
.unwrap_or_else(|| unimplemented!("cannot format Goal without setting Program in tls"))
44+
I::debug_goal(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned))
5145
}
5246
}
5347

5448
impl<I: Interner> Debug for Goals<I> {
5549
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
56-
I::debug_goals(self, fmt)
57-
.unwrap_or_else(|| unimplemented!("cannot format Goals without setting Program in tls"))
50+
I::debug_goals(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.goals))
5851
}
5952
}
6053

6154
impl<I: Interner> Debug for ProgramClauseImplication<I> {
6255
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
63-
I::debug_program_clause_implication(self, fmt).unwrap_or_else(|| {
64-
unimplemented!("cannot format ProgramClauseImplication without setting Program in tls")
65-
})
56+
I::debug_program_clause_implication(self, fmt)
57+
.unwrap_or_else(|| write!(fmt, "ProgramClauseImplication(?)"))
6658
}
6759
}
6860

6961
impl<I: Interner> Debug for ApplicationTy<I> {
7062
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
71-
I::debug_application_ty(self, fmt).unwrap_or_else(|| {
72-
unimplemented!("cannot format ApplicationTy without setting Program in tls")
73-
})
63+
I::debug_application_ty(self, fmt).unwrap_or_else(|| write!(fmt, "ApplicationTy(?)"))
7464
}
7565
}
7666

7767
impl<I: Interner> Debug for SeparatorTraitRef<'_, I> {
7868
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
79-
I::debug_separator_trait_ref(self, fmt).unwrap_or_else(|| {
80-
unimplemented!("cannot format Substitution without setting Program in tls")
81-
})
69+
I::debug_separator_trait_ref(self, fmt)
70+
.unwrap_or_else(|| write!(fmt, "SeparatorTraitRef(?)"))
8271
}
8372
}
8473

8574
impl<I: Interner> Debug for AliasTy<I> {
8675
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
87-
I::debug_alias(self, fmt).unwrap_or_else(|| {
88-
unimplemented!("cannot format AliasTy without setting Program in tls")
89-
})
76+
I::debug_alias(self, fmt).unwrap_or_else(|| write!(fmt, "AliasTy(?)"))
9077
}
9178
}
9279

9380
impl<I: Interner> Display for Substitution<I> {
9481
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
95-
I::debug_substitution(self, fmt).unwrap_or_else(|| {
96-
unimplemented!("cannot format Substitution without setting Program in tls")
97-
})
82+
I::debug_substitution(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.parameters))
9883
}
9984
}
10085

chalk-ir/src/interner.rs

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
106106
///
107107
/// Returns `None` to fallback to the default debug output (e.g.,
108108
/// if no info about current program is available from TLS).
109+
#[allow(unused_variables)]
109110
fn debug_struct_id(
110111
struct_id: StructId<Self>,
111112
fmt: &mut fmt::Formatter<'_>,
112-
) -> Option<fmt::Result>;
113+
) -> Option<fmt::Result> {
114+
None
115+
}
113116

114117
/// Prints the debug representation of a type-kind-id. To get good
115118
/// results, this requires inspecting TLS, and is difficult to
@@ -118,17 +121,25 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
118121
///
119122
/// Returns `None` to fallback to the default debug output (e.g.,
120123
/// if no info about current program is available from TLS).
121-
fn debug_trait_id(trait_id: TraitId<Self>, fmt: &mut fmt::Formatter<'_>)
122-
-> Option<fmt::Result>;
124+
#[allow(unused_variables)]
125+
fn debug_trait_id(
126+
trait_id: TraitId<Self>,
127+
fmt: &mut fmt::Formatter<'_>,
128+
) -> Option<fmt::Result> {
129+
None
130+
}
123131

124132
/// Prints the debug representation of a type-kind-id. To get good
125133
/// results, this requires inspecting TLS, and is difficult to
126134
/// code without reference to a specific interner (and hence
127135
/// fully known types).
136+
#[allow(unused_variables)]
128137
fn debug_assoc_type_id(
129138
type_id: AssocTypeId<Self>,
130139
fmt: &mut fmt::Formatter<'_>,
131-
) -> Option<fmt::Result>;
140+
) -> Option<fmt::Result> {
141+
None
142+
}
132143

133144
/// Prints the debug representation of an alias. To get good
134145
/// results, this requires inspecting TLS, and is difficult to
@@ -137,7 +148,10 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
137148
///
138149
/// Returns `None` to fallback to the default debug output (e.g.,
139150
/// if no info about current program is available from TLS).
140-
fn debug_alias(alias: &AliasTy<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>;
151+
#[allow(unused_variables)]
152+
fn debug_alias(alias: &AliasTy<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
153+
None
154+
}
141155

142156
/// Prints the debug representation of an type. To get good
143157
/// results, this requires inspecting TLS, and is difficult to
@@ -146,7 +160,10 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
146160
///
147161
/// Returns `None` to fallback to the default debug output (e.g.,
148162
/// if no info about current program is available from TLS).
149-
fn debug_ty(ty: &Ty<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>;
163+
#[allow(unused_variables)]
164+
fn debug_ty(ty: &Ty<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
165+
None
166+
}
150167

151168
/// Prints the debug representation of an lifetime. To get good
152169
/// results, this requires inspecting TLS, and is difficult to
@@ -155,10 +172,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
155172
///
156173
/// Returns `None` to fallback to the default debug output (e.g.,
157174
/// if no info about current program is available from TLS).
175+
#[allow(unused_variables)]
158176
fn debug_lifetime(
159177
lifetime: &Lifetime<Self>,
160178
fmt: &mut fmt::Formatter<'_>,
161-
) -> Option<fmt::Result>;
179+
) -> Option<fmt::Result> {
180+
None
181+
}
162182

163183
/// Prints the debug representation of an parameter. To get good
164184
/// results, this requires inspecting TLS, and is difficult to
@@ -167,10 +187,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
167187
///
168188
/// Returns `None` to fallback to the default debug output (e.g.,
169189
/// if no info about current program is available from TLS).
190+
#[allow(unused_variables)]
170191
fn debug_parameter(
171192
parameter: &Parameter<Self>,
172193
fmt: &mut fmt::Formatter<'_>,
173-
) -> Option<fmt::Result>;
194+
) -> Option<fmt::Result> {
195+
None
196+
}
174197

175198
/// Prints the debug representation of an goal. To get good
176199
/// results, this requires inspecting TLS, and is difficult to
@@ -179,7 +202,10 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
179202
///
180203
/// Returns `None` to fallback to the default debug output (e.g.,
181204
/// if no info about current program is available from TLS).
182-
fn debug_goal(goal: &Goal<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>;
205+
#[allow(unused_variables)]
206+
fn debug_goal(goal: &Goal<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
207+
None
208+
}
183209

184210
/// Prints the debug representation of a list of goals. To get good
185211
/// results, this requires inspecting TLS, and is difficult to
@@ -188,7 +214,10 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
188214
///
189215
/// Returns `None` to fallback to the default debug output (e.g.,
190216
/// if no info about current program is available from TLS).
191-
fn debug_goals(goals: &Goals<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>;
217+
#[allow(unused_variables)]
218+
fn debug_goals(goals: &Goals<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
219+
None
220+
}
192221

193222
/// Prints the debug representation of a ProgramClauseImplication. To get good
194223
/// results, this requires inspecting TLS, and is difficult to
@@ -197,10 +226,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
197226
///
198227
/// Returns `None` to fallback to the default debug output (e.g.,
199228
/// if no info about current program is available from TLS).
229+
#[allow(unused_variables)]
200230
fn debug_program_clause_implication(
201231
pci: &ProgramClauseImplication<Self>,
202232
fmt: &mut fmt::Formatter<'_>,
203-
) -> Option<fmt::Result>;
233+
) -> Option<fmt::Result> {
234+
None
235+
}
204236

205237
/// Prints the debug representation of an ApplicationTy. To get good
206238
/// results, this requires inspecting TLS, and is difficult to
@@ -209,10 +241,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
209241
///
210242
/// Returns `None` to fallback to the default debug output (e.g.,
211243
/// if no info about current program is available from TLS).
244+
#[allow(unused_variables)]
212245
fn debug_application_ty(
213246
application_ty: &ApplicationTy<Self>,
214247
fmt: &mut fmt::Formatter<'_>,
215-
) -> Option<fmt::Result>;
248+
) -> Option<fmt::Result> {
249+
None
250+
}
216251

217252
/// Prints the debug representation of a Substitution. To get good
218253
/// results, this requires inspecting TLS, and is difficult to
@@ -221,10 +256,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
221256
///
222257
/// Returns `None` to fallback to the default debug output (e.g.,
223258
/// if no info about current program is available from TLS).
259+
#[allow(unused_variables)]
224260
fn debug_substitution(
225261
substitution: &Substitution<Self>,
226262
fmt: &mut fmt::Formatter<'_>,
227-
) -> Option<fmt::Result>;
263+
) -> Option<fmt::Result> {
264+
None
265+
}
228266

229267
/// Prints the debug representation of a SeparatorTraitRef. To get good
230268
/// results, this requires inspecting TLS, and is difficult to
@@ -233,10 +271,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
233271
///
234272
/// Returns `None` to fallback to the default debug output (e.g.,
235273
/// if no info about current program is available from TLS).
274+
#[allow(unused_variables)]
236275
fn debug_separator_trait_ref(
237-
separator_trait_ref: &SeparatorTraitRef<Self>,
276+
separator_trait_ref: &SeparatorTraitRef<'_, Self>,
238277
fmt: &mut fmt::Formatter<'_>,
239-
) -> Option<fmt::Result>;
278+
) -> Option<fmt::Result> {
279+
None
280+
}
240281

241282
/// Create an "interned" type from `ty`. This is not normally
242283
/// invoked directly; instead, you invoke `TyData::intern` (which
@@ -433,7 +474,7 @@ mod default {
433474
}
434475

435476
fn debug_separator_trait_ref(
436-
separator_trait_ref: &SeparatorTraitRef<ChalkIr>,
477+
separator_trait_ref: &SeparatorTraitRef<'_, ChalkIr>,
437478
fmt: &mut fmt::Formatter<'_>,
438479
) -> Option<fmt::Result> {
439480
tls::with_current_program(|prog| {

chalk-ir/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
use crate::cast::{Cast, CastTo};
24
use crate::fold::shift::Shift;
35
use crate::fold::{Fold, Folder, Subst, SuperFold};
@@ -178,6 +180,10 @@ impl<I: Interner> Ty<I> {
178180
}
179181
}
180182

183+
pub fn interned(&self) -> &I::InternedType {
184+
&self.interned
185+
}
186+
181187
pub fn data(&self, interner: &I) -> &TyData<I> {
182188
I::ty_data(interner, &self.interned)
183189
}
@@ -577,6 +583,10 @@ impl<I: Interner> Lifetime<I> {
577583
}
578584
}
579585

586+
pub fn interned(&self) -> &I::InternedLifetime {
587+
&self.interned
588+
}
589+
580590
pub fn data(&self, interner: &I) -> &LifetimeData<I> {
581591
I::lifetime_data(interner, &self.interned)
582592
}
@@ -749,6 +759,10 @@ impl<I: Interner> Parameter<I> {
749759
Parameter(interned)
750760
}
751761

762+
pub fn interned(&self) -> &I::InternedParameter {
763+
&self.0
764+
}
765+
752766
pub fn data(&self, interner: &I) -> &ParameterData<I> {
753767
I::parameter_data(interner, &self.0)
754768
}
@@ -1277,6 +1291,10 @@ impl<I: Interner> Goals<I> {
12771291
Self::from(interner, None::<Goal<I>>)
12781292
}
12791293

1294+
pub fn interned(&self) -> &I::InternedGoals {
1295+
&self.goals
1296+
}
1297+
12801298
pub fn from(interner: &I, goals: impl IntoIterator<Item = impl CastTo<Goal<I>>>) -> Self {
12811299
use crate::cast::Caster;
12821300
Goals {
@@ -1325,6 +1343,10 @@ impl<I: Interner> Goal<I> {
13251343
Self { interned }
13261344
}
13271345

1346+
pub fn interned(&self) -> &I::InternedGoal {
1347+
&self.interned
1348+
}
1349+
13281350
pub fn data(&self, interner: &I) -> &GoalData<I> {
13291351
interner.goal_data(&self.interned)
13301352
}
@@ -1497,6 +1519,10 @@ impl<I: Interner> Substitution<I> {
14971519
})
14981520
}
14991521

1522+
pub fn interned(&self) -> &I::InternedSubstitution {
1523+
&self.parameters
1524+
}
1525+
15001526
/// Index into the list of parameters
15011527
pub fn at(&self, interner: &I, index: usize) -> &Parameter<I> {
15021528
&self.parameters(interner)[index]

chalk-ir/src/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub trait DebugContext {
8282

8383
fn debug_separator_trait_ref(
8484
&self,
85-
separator_trait_ref: &SeparatorTraitRef<ChalkIr>,
85+
separator_trait_ref: &SeparatorTraitRef<'_, ChalkIr>,
8686
fmt: &mut fmt::Formatter<'_>,
8787
) -> Result<(), fmt::Error>;
8888
}

chalk-rust-ir/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
//! Contains the definition for the "Rust IR" -- this is basically a "lowered"
24
//! version of the AST, roughly corresponding to [the HIR] in the Rust
35
//! compiler.

chalk-solve/src/clauses/builtin_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{TraitRef, WellKnownTrait};
77
pub fn add_builtin_program_clauses<I: Interner>(
88
well_known: WellKnownTrait,
99
_trait_ref: &TraitRef<I>,
10-
_builder: &mut ClauseBuilder<I>,
10+
_builder: &mut ClauseBuilder<'_, I>,
1111
) {
1212
match well_known {
1313
WellKnownTrait::SizedTrait => { /* TODO */ }

chalk-solve/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rust_2018_idioms)]
2+
13
use chalk_ir::interner::Interner;
24
use chalk_ir::*;
35
use chalk_rust_ir::*;

0 commit comments

Comments
 (0)