diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-21 18:51:53 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-21 18:51:53 +0100 |
commit | edbde25ca2f13ffacfd006ada7b38618d36d97c6 (patch) | |
tree | b1c5208c74ce56a36c8a9c454b9c479a3312ee94 /crates/hir_ty/src/interner.rs | |
parent | de403b10448e23f232804596538de92fc57203d6 (diff) | |
parent | ef558c97d09b0be8639c92f490e5ad380aa04288 (diff) |
Merge #8856
8856: Use Chalk for unification r=flodiebold a=flodiebold
- use Chalk's unification, get rid of our own `unify`
- rewrite coercion to not use unification internals and to be more analogous to rustc
- fix various coercion bugs
- rewrite handling of obligations, since the old hacky optimization where we noted when an inference variable changes wasn't possible anymore
- stop trying to deeply resolve types all the time during inference, instead only do it shallowly where necessary
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/interner.rs')
-rw-r--r-- | crates/hir_ty/src/interner.rs | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/crates/hir_ty/src/interner.rs b/crates/hir_ty/src/interner.rs index 7b4119747..29ffdd9b7 100644 --- a/crates/hir_ty/src/interner.rs +++ b/crates/hir_ty/src/interner.rs | |||
@@ -15,9 +15,15 @@ use std::{fmt, sync::Arc}; | |||
15 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] | 15 | #[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)] |
16 | pub struct Interner; | 16 | pub struct Interner; |
17 | 17 | ||
18 | #[derive(PartialEq, Eq, Hash, Debug)] | 18 | #[derive(PartialEq, Eq, Hash)] |
19 | pub struct InternedWrapper<T>(T); | 19 | pub struct InternedWrapper<T>(T); |
20 | 20 | ||
21 | impl<T: fmt::Debug> fmt::Debug for InternedWrapper<T> { | ||
22 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
23 | fmt::Debug::fmt(&self.0, f) | ||
24 | } | ||
25 | } | ||
26 | |||
21 | impl<T> std::ops::Deref for InternedWrapper<T> { | 27 | impl<T> std::ops::Deref for InternedWrapper<T> { |
22 | type Target = T; | 28 | type Target = T; |
23 | 29 | ||
@@ -101,66 +107,65 @@ impl chalk_ir::interner::Interner for Interner { | |||
101 | opaque_ty: &chalk_ir::OpaqueTy<Interner>, | 107 | opaque_ty: &chalk_ir::OpaqueTy<Interner>, |
102 | fmt: &mut fmt::Formatter<'_>, | 108 | fmt: &mut fmt::Formatter<'_>, |
103 | ) -> Option<fmt::Result> { | 109 | ) -> Option<fmt::Result> { |
104 | tls::with_current_program(|prog| Some(prog?.debug_opaque_ty(opaque_ty, fmt))) | 110 | Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id)) |
105 | } | 111 | } |
106 | 112 | ||
107 | fn debug_opaque_ty_id( | 113 | fn debug_opaque_ty_id( |
108 | opaque_ty_id: chalk_ir::OpaqueTyId<Self>, | 114 | opaque_ty_id: chalk_ir::OpaqueTyId<Self>, |
109 | fmt: &mut fmt::Formatter<'_>, | 115 | fmt: &mut fmt::Formatter<'_>, |
110 | ) -> Option<fmt::Result> { | 116 | ) -> Option<fmt::Result> { |
111 | 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()) |
112 | } | 118 | } |
113 | 119 | ||
114 | 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> { |
115 | tls::with_current_program(|prog| Some(prog?.debug_ty(ty, fmt))) | 121 | Some(write!(fmt, "{:?}", ty.data(&Interner))) |
116 | } | 122 | } |
117 | 123 | ||
118 | fn debug_lifetime( | 124 | fn debug_lifetime( |
119 | lifetime: &chalk_ir::Lifetime<Interner>, | 125 | lifetime: &chalk_ir::Lifetime<Interner>, |
120 | fmt: &mut fmt::Formatter<'_>, | 126 | fmt: &mut fmt::Formatter<'_>, |
121 | ) -> Option<fmt::Result> { | 127 | ) -> Option<fmt::Result> { |
122 | tls::with_current_program(|prog| Some(prog?.debug_lifetime(lifetime, fmt))) | 128 | Some(write!(fmt, "{:?}", lifetime.data(&Interner))) |
123 | } | 129 | } |
124 | 130 | ||
125 | fn debug_generic_arg( | 131 | fn debug_generic_arg( |
126 | parameter: &GenericArg, | 132 | parameter: &GenericArg, |
127 | fmt: &mut fmt::Formatter<'_>, | 133 | fmt: &mut fmt::Formatter<'_>, |
128 | ) -> Option<fmt::Result> { | 134 | ) -> Option<fmt::Result> { |
129 | tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) | 135 | Some(write!(fmt, "{:?}", parameter.data(&Interner).inner_debug())) |
130 | } | 136 | } |
131 | 137 | ||
132 | 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> { |
133 | tls::with_current_program(|prog| Some(prog?.debug_goal(goal, fmt))) | 139 | let goal_data = goal.data(&Interner); |
140 | Some(write!(fmt, "{:?}", goal_data)) | ||
134 | } | 141 | } |
135 | 142 | ||
136 | fn debug_goals( | 143 | fn debug_goals( |
137 | goals: &chalk_ir::Goals<Interner>, | 144 | goals: &chalk_ir::Goals<Interner>, |
138 | fmt: &mut fmt::Formatter<'_>, | 145 | fmt: &mut fmt::Formatter<'_>, |
139 | ) -> Option<fmt::Result> { | 146 | ) -> Option<fmt::Result> { |
140 | tls::with_current_program(|prog| Some(prog?.debug_goals(goals, fmt))) | 147 | Some(write!(fmt, "{:?}", goals.debug(&Interner))) |
141 | } | 148 | } |
142 | 149 | ||
143 | fn debug_program_clause_implication( | 150 | fn debug_program_clause_implication( |
144 | pci: &chalk_ir::ProgramClauseImplication<Interner>, | 151 | pci: &chalk_ir::ProgramClauseImplication<Interner>, |
145 | fmt: &mut fmt::Formatter<'_>, | 152 | fmt: &mut fmt::Formatter<'_>, |
146 | ) -> Option<fmt::Result> { | 153 | ) -> Option<fmt::Result> { |
147 | tls::with_current_program(|prog| Some(prog?.debug_program_clause_implication(pci, fmt))) | 154 | Some(write!(fmt, "{:?}", pci.debug(&Interner))) |
148 | } | 155 | } |
149 | 156 | ||
150 | fn debug_substitution( | 157 | fn debug_substitution( |
151 | substitution: &chalk_ir::Substitution<Interner>, | 158 | substitution: &chalk_ir::Substitution<Interner>, |
152 | fmt: &mut fmt::Formatter<'_>, | 159 | fmt: &mut fmt::Formatter<'_>, |
153 | ) -> Option<fmt::Result> { | 160 | ) -> Option<fmt::Result> { |
154 | tls::with_current_program(|prog| Some(prog?.debug_substitution(substitution, fmt))) | 161 | Some(write!(fmt, "{:?}", substitution.debug(&Interner))) |
155 | } | 162 | } |
156 | 163 | ||
157 | fn debug_separator_trait_ref( | 164 | fn debug_separator_trait_ref( |
158 | separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>, | 165 | separator_trait_ref: &chalk_ir::SeparatorTraitRef<Interner>, |
159 | fmt: &mut fmt::Formatter<'_>, | 166 | fmt: &mut fmt::Formatter<'_>, |
160 | ) -> Option<fmt::Result> { | 167 | ) -> Option<fmt::Result> { |
161 | tls::with_current_program(|prog| { | 168 | Some(write!(fmt, "{:?}", separator_trait_ref.debug(&Interner))) |
162 | Some(prog?.debug_separator_trait_ref(separator_trait_ref, fmt)) | ||
163 | }) | ||
164 | } | 169 | } |
165 | 170 | ||
166 | fn debug_fn_def_id( | 171 | fn debug_fn_def_id( |
@@ -173,47 +178,43 @@ impl chalk_ir::interner::Interner for Interner { | |||
173 | constant: &chalk_ir::Const<Self>, | 178 | constant: &chalk_ir::Const<Self>, |
174 | fmt: &mut fmt::Formatter<'_>, | 179 | fmt: &mut fmt::Formatter<'_>, |
175 | ) -> Option<fmt::Result> { | 180 | ) -> Option<fmt::Result> { |
176 | tls::with_current_program(|prog| Some(prog?.debug_const(constant, fmt))) | 181 | Some(write!(fmt, "{:?}", constant.data(&Interner))) |
177 | } | 182 | } |
178 | fn debug_variable_kinds( | 183 | fn debug_variable_kinds( |
179 | variable_kinds: &chalk_ir::VariableKinds<Self>, | 184 | variable_kinds: &chalk_ir::VariableKinds<Self>, |
180 | fmt: &mut fmt::Formatter<'_>, | 185 | fmt: &mut fmt::Formatter<'_>, |
181 | ) -> Option<fmt::Result> { | 186 | ) -> Option<fmt::Result> { |
182 | tls::with_current_program(|prog| Some(prog?.debug_variable_kinds(variable_kinds, fmt))) | 187 | Some(write!(fmt, "{:?}", variable_kinds.as_slice(&Interner))) |
183 | } | 188 | } |
184 | fn debug_variable_kinds_with_angles( | 189 | fn debug_variable_kinds_with_angles( |
185 | variable_kinds: &chalk_ir::VariableKinds<Self>, | 190 | variable_kinds: &chalk_ir::VariableKinds<Self>, |
186 | fmt: &mut fmt::Formatter<'_>, | 191 | fmt: &mut fmt::Formatter<'_>, |
187 | ) -> Option<fmt::Result> { | 192 | ) -> Option<fmt::Result> { |
188 | tls::with_current_program(|prog| { | 193 | Some(write!(fmt, "{:?}", variable_kinds.inner_debug(&Interner))) |
189 | Some(prog?.debug_variable_kinds_with_angles(variable_kinds, fmt)) | ||
190 | }) | ||
191 | } | 194 | } |
192 | fn debug_canonical_var_kinds( | 195 | fn debug_canonical_var_kinds( |
193 | canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>, | 196 | canonical_var_kinds: &chalk_ir::CanonicalVarKinds<Self>, |
194 | fmt: &mut fmt::Formatter<'_>, | 197 | fmt: &mut fmt::Formatter<'_>, |
195 | ) -> Option<fmt::Result> { | 198 | ) -> Option<fmt::Result> { |
196 | tls::with_current_program(|prog| { | 199 | Some(write!(fmt, "{:?}", canonical_var_kinds.as_slice(&Interner))) |
197 | Some(prog?.debug_canonical_var_kinds(canonical_var_kinds, fmt)) | ||
198 | }) | ||
199 | } | 200 | } |
200 | fn debug_program_clause( | 201 | fn debug_program_clause( |
201 | clause: &chalk_ir::ProgramClause<Self>, | 202 | clause: &chalk_ir::ProgramClause<Self>, |
202 | fmt: &mut fmt::Formatter<'_>, | 203 | fmt: &mut fmt::Formatter<'_>, |
203 | ) -> Option<fmt::Result> { | 204 | ) -> Option<fmt::Result> { |
204 | tls::with_current_program(|prog| Some(prog?.debug_program_clause(clause, fmt))) | 205 | Some(write!(fmt, "{:?}", clause.data(&Interner))) |
205 | } | 206 | } |
206 | fn debug_program_clauses( | 207 | fn debug_program_clauses( |
207 | clauses: &chalk_ir::ProgramClauses<Self>, | 208 | clauses: &chalk_ir::ProgramClauses<Self>, |
208 | fmt: &mut fmt::Formatter<'_>, | 209 | fmt: &mut fmt::Formatter<'_>, |
209 | ) -> Option<fmt::Result> { | 210 | ) -> Option<fmt::Result> { |
210 | tls::with_current_program(|prog| Some(prog?.debug_program_clauses(clauses, fmt))) | 211 | Some(write!(fmt, "{:?}", clauses.as_slice(&Interner))) |
211 | } | 212 | } |
212 | fn debug_quantified_where_clauses( | 213 | fn debug_quantified_where_clauses( |
213 | clauses: &chalk_ir::QuantifiedWhereClauses<Self>, | 214 | clauses: &chalk_ir::QuantifiedWhereClauses<Self>, |
214 | fmt: &mut fmt::Formatter<'_>, | 215 | fmt: &mut fmt::Formatter<'_>, |
215 | ) -> Option<fmt::Result> { | 216 | ) -> Option<fmt::Result> { |
216 | tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) | 217 | Some(write!(fmt, "{:?}", clauses.as_slice(&Interner))) |
217 | } | 218 | } |
218 | 219 | ||
219 | fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType { | 220 | fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType { |