aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-05-15 21:26:55 +0100
committerFlorian Diebold <[email protected]>2021-05-21 16:48:34 +0100
commit29266ada0469440d69fd3f3532121a7e8ff5379d (patch)
tree7ad65e64269aa2ed99e89d2ccd038fdd2873ddb2 /crates
parent7c423f5b88f40da4f3682602bf17a9b6848f5411 (diff)
Improve debug printing without TLS
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/interner.rs41
-rw-r--r--crates/hir_ty/src/tls.rs138
2 files changed, 21 insertions, 158 deletions
diff --git a/crates/hir_ty/src/interner.rs b/crates/hir_ty/src/interner.rs
index 8e77378ab..29ffdd9b7 100644
--- a/crates/hir_ty/src/interner.rs
+++ b/crates/hir_ty/src/interner.rs
@@ -107,66 +107,65 @@ impl chalk_ir::interner::Interner for Interner {
107 opaque_ty: &chalk_ir::OpaqueTy<Interner>, 107 opaque_ty: &chalk_ir::OpaqueTy<Interner>,
108 fmt: &mut fmt::Formatter<'_>, 108 fmt: &mut fmt::Formatter<'_>,
109 ) -> Option<fmt::Result> { 109 ) -> Option<fmt::Result> {
110 tls::with_current_program(|prog| Some(prog?.debug_opaque_ty(opaque_ty, fmt))) 110 Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id))
111 } 111 }
112 112
113 fn debug_opaque_ty_id( 113 fn debug_opaque_ty_id(
114 opaque_ty_id: chalk_ir::OpaqueTyId<Self>, 114 opaque_ty_id: chalk_ir::OpaqueTyId<Self>,
115 fmt: &mut fmt::Formatter<'_>, 115 fmt: &mut fmt::Formatter<'_>,
116 ) -> Option<fmt::Result> { 116 ) -> Option<fmt::Result> {
117 tls::with_current_program(|prog| Some(prog?.debug_opaque_ty_id(opaque_ty_id, fmt))) 117 Some(fmt.debug_struct("OpaqueTyId").field("index", &opaque_ty_id.0).finish())
118 } 118 }
119 119
120 fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 120 fn debug_ty(ty: &chalk_ir::Ty<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
121 tls::with_current_program(|prog| Some(prog?.debug_ty(ty, fmt))) 121 Some(write!(fmt, "{:?}", ty.data(&Interner)))
122 } 122 }
123 123
124 fn debug_lifetime( 124 fn debug_lifetime(
125 lifetime: &chalk_ir::Lifetime<Interner>, 125 lifetime: &chalk_ir::Lifetime<Interner>,
126 fmt: &mut fmt::Formatter<'_>, 126 fmt: &mut fmt::Formatter<'_>,
127 ) -> Option<fmt::Result> { 127 ) -> Option<fmt::Result> {
128 tls::with_current_program(|prog| Some(prog?.debug_lifetime(lifetime, fmt))) 128 Some(write!(fmt, "{:?}", lifetime.data(&Interner)))
129 } 129 }
130 130
131 fn debug_generic_arg( 131 fn debug_generic_arg(
132 parameter: &GenericArg, 132 parameter: &GenericArg,
133 fmt: &mut fmt::Formatter<'_>, 133 fmt: &mut fmt::Formatter<'_>,
134 ) -> Option<fmt::Result> { 134 ) -> Option<fmt::Result> {
135 tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) 135 Some(write!(fmt, "{:?}", parameter.data(&Interner).inner_debug()))
136 } 136 }
137 137
138 fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> { 138 fn debug_goal(goal: &Goal<Interner>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
139 tls::with_current_program(|prog| Some(prog?.debug_goal(goal, fmt))) 139 let goal_data = goal.data(&Interner);
140 Some(write!(fmt, "{:?}", goal_data))
140 } 141 }
141 142
142 fn debug_goals( 143 fn debug_goals(
143 goals: &chalk_ir::Goals<Interner>, 144 goals: &chalk_ir::Goals<Interner>,
144 fmt: &mut fmt::Formatter<'_>, 145 fmt: &mut fmt::Formatter<'_>,
145 ) -> Option<fmt::Result> { 146 ) -> Option<fmt::Result> {
146 tls::with_current_program(|prog| Some(prog?.debug_goals(goals, fmt))) 147 Some(write!(fmt, "{:?}", goals.debug(&Interner)))
147 } 148 }
148 149
149 fn debug_program_clause_implication( 150 fn debug_program_clause_implication(
150 pci: &chalk_ir::ProgramClauseImplication<Interner>, 151 pci: &chalk_ir::ProgramClauseImplication<Interner>,
151 fmt: &mut fmt::Formatter<'_>, 152 fmt: &mut fmt::Formatter<'_>,
152 ) -> Option<fmt::Result> { 153 ) -> Option<fmt::Result> {
153 tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt))) 154 Some(write!(fmt, "{:?}", pci.debug(&Interner)))
154 } 155 }
155 156
156 fn debug_substitution( 157 fn debug_substitution(
157 substitution: &chalk_ir::Substitution<Interner>, 158 substitution: &chalk_ir::Substitution<Interner>,
158 fmt: &mut fmt::Formatter<'_>, 159 fmt: &mut fmt::Formatter<'_>,
159 ) -> Option<fmt::Result> { 160 ) -> Option<fmt::Result> {
160 tls::with_current_program(|prog| Some(prog?.debug_substitution(substitution, fmt))) 161 Some(write!(fmt, "{:?}", substitution.debug(&Interner)))
161 } 162 }
162 163
163 fn debug_separator_trait_ref( 164 fn debug_separator_trait_ref(
164 separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>, 165 separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>,
165 fmt: &mut fmt::Formatter<'_>, 166 fmt: &mut fmt::Formatter<'_>,
166 ) -> Option<fmt::Result> { 167 ) -> Option<fmt::Result> {
167 tls::with_current_program(|prog| { 168 Some(write!(fmt, "{:?}", separator_trait_ref.debug(&Interner)))
168 Some(prog?.debug_separator_trait_ref(separator_trait_ref, fmt))
169 })
170 } 169 }
171 170
172 fn debug_fn_def_id( 171 fn debug_fn_def_id(
@@ -179,47 +178,43 @@ impl chalk_ir::interner::Interner for Interner {
179 constant: &chalk_ir::Const<Self>, 178 constant: &chalk_ir::Const<Self>,
180 fmt: &mut fmt::Formatter<'_>, 179 fmt: &mut fmt::Formatter<'_>,
181 ) -> Option<fmt::Result> { 180 ) -> Option<fmt::Result> {
182 tls::with_current_program(|prog| Some(prog?.debug_const(constant, fmt))) 181 Some(write!(fmt, "{:?}", constant.data(&Interner)))
183 } 182 }
184 fn debug_variable_kinds( 183 fn debug_variable_kinds(
185 variable_kinds: &chalk_ir::VariableKinds<Self>, 184 variable_kinds: &chalk_ir::VariableKinds<Self>,
186 fmt: &mut fmt::Formatter<'_>, 185 fmt: &mut fmt::Formatter<'_>,
187 ) -> Option<fmt::Result> { 186 ) -> Option<fmt::Result> {
188 tls::with_current_program(|prog| Some(prog?.debug_variable_kinds(variable_kinds, fmt))) 187 Some(write!(fmt, "{:?}", variable_kinds.as_slice(&Interner)))
189 } 188 }
190 fn debug_variable_kinds_with_angles( 189 fn debug_variable_kinds_with_angles(
191 variable_kinds: &chalk_ir::VariableKinds<Self>, 190 variable_kinds: &chalk_ir::VariableKinds<Self>,
192 fmt: &mut fmt::Formatter<'_>, 191 fmt: &mut fmt::Formatter<'_>,
193 ) -> Option<fmt::Result> { 192 ) -> Option<fmt::Result> {
194 tls::with_current_program(|prog| { 193 Some(write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner)))
195 Some(prog?.debug_variable_kinds_with_angles(variable_kinds, fmt))
196 })
197 } 194 }
198 fn debug_canonical_var_kinds( 195 fn debug_canonical_var_kinds(
199 canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>, 196 canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>,
200 fmt: &mut fmt::Formatter<'_>, 197 fmt: &mut fmt::Formatter<'_>,
201 ) -> Option<fmt::Result> { 198 ) -> Option<fmt::Result> {
202 tls::with_current_program(|prog| { 199 Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner)))
203 Some(prog?.debug_canonical_var_kinds(canonical_var_kinds, fmt))
204 })
205 } 200 }
206 fn debug_program_clause( 201 fn debug_program_clause(
207 clause: &chalk_ir::ProgramClause<Self>, 202 clause: &chalk_ir::ProgramClause<Self>,
208 fmt: &mut fmt::Formatter<'_>, 203 fmt: &mut fmt::Formatter<'_>,
209 ) -> Option<fmt::Result> { 204 ) -> Option<fmt::Result> {
210 tls::with_current_program(|prog| Some(prog?.debug_program_clause(clause, fmt))) 205 Some(write!(fmt, "{:?}", clause.data(&Interner)))
211 } 206 }
212 fn debug_program_clauses( 207 fn debug_program_clauses(
213 clauses: &chalk_ir::ProgramClauses<Self>, 208 clauses: &chalk_ir::ProgramClauses<Self>,
214 fmt: &mut fmt::Formatter<'_>, 209 fmt: &mut fmt::Formatter<'_>,
215 ) -> Option<fmt::Result> { 210 ) -> Option<fmt::Result> {
216 tls::with_current_program(|prog| Some(prog?.debug_program_clauses(clauses, fmt))) 211 Some(write!(fmt, "{:?}", clauses.as_slice(&Interner)))
217 } 212 }
218 fn debug_quantified_where_clauses( 213 fn debug_quantified_where_clauses(
219 clauses: &chalk_ir::QuantifiedWhereClauses<Self>, 214 clauses: &chalk_ir::QuantifiedWhereClauses<Self>,
220 fmt: &mut fmt::Formatter<'_>, 215 fmt: &mut fmt::Formatter<'_>,
221 ) -> Option<fmt::Result> { 216 ) -> Option<fmt::Result> {
222 tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) 217 Some(write!(fmt, "{:?}", clauses.as_slice(&Interner)))
223 } 218 }
224 219
225 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType { 220 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
diff --git a/crates/hir_ty/src/tls.rs b/crates/hir_ty/src/tls.rs
index 87c671a42..708797c47 100644
--- a/crates/hir_ty/src/tls.rs
+++ b/crates/hir_ty/src/tls.rs
@@ -1,7 +1,7 @@
1//! Implementation of Chalk debug helper functions using TLS. 1//! Implementation of Chalk debug helper functions using TLS.
2use std::fmt; 2use std::fmt::{self, Debug};
3 3
4use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication}; 4use chalk_ir::AliasTy;
5use itertools::Itertools; 5use itertools::Itertools;
6 6
7use crate::{ 7use crate::{
@@ -53,14 +53,6 @@ impl DebugContext<'_> {
53 write!(fmt, "{}::{}", trait_data.name, type_alias_data.name) 53 write!(fmt, "{}::{}", trait_data.name, type_alias_data.name)
54 } 54 }
55 55
56 pub(crate) fn debug_opaque_ty_id(
57 &self,
58 opaque_ty_id: chalk_ir::OpaqueTyId<Interner>,
59 fmt: &mut fmt::Formatter<'_>,
60 ) -> Result<(), fmt::Error> {
61 fmt.debug_struct("OpaqueTyId").field("index", &opaque_ty_id.0).finish()
62 }
63
64 pub(crate) fn debug_alias( 56 pub(crate) fn debug_alias(
65 &self, 57 &self,
66 alias_ty: &AliasTy<Interner>, 58 alias_ty: &AliasTy<Interner>,
@@ -68,7 +60,7 @@ impl DebugContext<'_> {
68 ) -> Result<(), fmt::Error> { 60 ) -> Result<(), fmt::Error> {
69 match alias_ty { 61 match alias_ty {
70 AliasTy::Projection(projection_ty) => self.debug_projection_ty(projection_ty, fmt), 62 AliasTy::Projection(projection_ty) => self.debug_projection_ty(projection_ty, fmt),
71 AliasTy::Opaque(opaque_ty) => self.debug_opaque_ty(opaque_ty, fmt), 63 AliasTy::Opaque(opaque_ty) => opaque_ty.fmt(fmt),
72 } 64 }
73 } 65 }
74 66
@@ -96,79 +88,6 @@ impl DebugContext<'_> {
96 write!(fmt, ">::{}", type_alias_data.name) 88 write!(fmt, ">::{}", type_alias_data.name)
97 } 89 }
98 90
99 pub(crate) fn debug_opaque_ty(
100 &self,
101 opaque_ty: &chalk_ir::OpaqueTy<Interner>,
102 fmt: &mut fmt::Formatter<'_>,
103 ) -> Result<(), fmt::Error> {
104 write!(fmt, "{:?}", opaque_ty.opaque_ty_id)
105 }
106
107 pub(crate) fn debug_ty(
108 &self,
109 ty: &chalk_ir::Ty<Interner>,
110 fmt: &mut fmt::Formatter<'_>,
111 ) -> Result<(), fmt::Error> {
112 write!(fmt, "{:?}", ty.data(&Interner))
113 }
114
115 pub(crate) fn debug_lifetime(
116 &self,
117 lifetime: &Lifetime<Interner>,
118 fmt: &mut fmt::Formatter<'_>,
119 ) -> Result<(), fmt::Error> {
120 write!(fmt, "{:?}", lifetime.data(&Interner))
121 }
122
123 pub(crate) fn debug_generic_arg(
124 &self,
125 parameter: &GenericArg<Interner>,
126 fmt: &mut fmt::Formatter<'_>,
127 ) -> Result<(), fmt::Error> {
128 write!(fmt, "{:?}", parameter.data(&Interner).inner_debug())
129 }
130
131 pub(crate) fn debug_goal(
132 &self,
133 goal: &Goal<Interner>,
134 fmt: &mut fmt::Formatter<'_>,
135 ) -> Result<(), fmt::Error> {
136 let goal_data = goal.data(&Interner);
137 write!(fmt, "{:?}", goal_data)
138 }
139
140 pub(crate) fn debug_goals(
141 &self,
142 goals: &Goals<Interner>,
143 fmt: &mut fmt::Formatter<'_>,
144 ) -> Result<(), fmt::Error> {
145 write!(fmt, "{:?}", goals.debug(&Interner))
146 }
147
148 pub(crate) fn debug_program_clause_implication(
149 &self,
150 pci: &ProgramClauseImplication<Interner>,
151 fmt: &mut fmt::Formatter<'_>,
152 ) -> Result<(), fmt::Error> {
153 write!(fmt, "{:?}", pci.debug(&Interner))
154 }
155
156 pub(crate) fn debug_substitution(
157 &self,
158 substitution: &chalk_ir::Substitution<Interner>,
159 fmt: &mut fmt::Formatter<'_>,
160 ) -> Result<(), fmt::Error> {
161 write!(fmt, "{:?}", substitution.debug(&Interner))
162 }
163
164 pub(crate) fn debug_separator_trait_ref(
165 &self,
166 separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>,
167 fmt: &mut fmt::Formatter<'_>,
168 ) -> Result<(), fmt::Error> {
169 write!(fmt, "{:?}", separator_trait_ref.debug(&Interner))
170 }
171
172 pub(crate) fn debug_fn_def_id( 91 pub(crate) fn debug_fn_def_id(
173 &self, 92 &self,
174 fn_def_id: chalk_ir::FnDefId<Interner>, 93 fn_def_id: chalk_ir::FnDefId<Interner>,
@@ -190,57 +109,6 @@ impl DebugContext<'_> {
190 } 109 }
191 } 110 }
192 } 111 }
193
194 pub(crate) fn debug_const(
195 &self,
196 _constant: &chalk_ir::Const<Interner>,
197 fmt: &mut fmt::Formatter<'_>,
198 ) -> fmt::Result {
199 write!(fmt, "const")
200 }
201
202 pub(crate) fn debug_variable_kinds(
203 &self,
204 variable_kinds: &chalk_ir::VariableKinds<Interner>,
205 fmt: &mut fmt::Formatter<'_>,
206 ) -> fmt::Result {
207 write!(fmt, "{:?}", variable_kinds.as_slice(&Interner))
208 }
209 pub(crate) fn debug_variable_kinds_with_angles(
210 &self,
211 variable_kinds: &chalk_ir::VariableKinds<Interner>,
212 fmt: &mut fmt::Formatter<'_>,
213 ) -> fmt::Result {
214 write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner))
215 }
216 pub(crate) fn debug_canonical_var_kinds(
217 &self,
218 canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Interner>,
219 fmt: &mut fmt::Formatter<'_>,
220 ) -> fmt::Result {
221 write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner))
222 }
223 pub(crate) fn debug_program_clause(
224 &self,
225 clause: &chalk_ir::ProgramClause<Interner>,
226 fmt: &mut fmt::Formatter<'_>,
227 ) -> fmt::Result {
228 write!(fmt, "{:?}", clause.data(&Interner))
229 }
230 pub(crate) fn debug_program_clauses(
231 &self,
232 clauses: &chalk_ir::ProgramClauses<Interner>,
233 fmt: &mut fmt::Formatter<'_>,
234 ) -> fmt::Result {
235 write!(fmt, "{:?}", clauses.as_slice(&Interner))
236 }
237 pub(crate) fn debug_quantified_where_clauses(
238 &self,
239 clauses: &chalk_ir::QuantifiedWhereClauses<Interner>,
240 fmt: &mut fmt::Formatter<'_>,
241 ) -> fmt::Result {
242 write!(fmt, "{:?}", clauses.as_slice(&Interner))
243 }
244} 112}
245 113
246mod unsafe_tls { 114mod unsafe_tls {