diff options
author | Florian Diebold <[email protected]> | 2021-03-13 13:44:51 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-03-13 15:17:15 +0000 |
commit | 6c32bbf3ca5980fb33c1ea28dd1c5a1524ce81cb (patch) | |
tree | f81c7438f67de3c292a233887e56c7e99bcc0a01 /crates/hir_ty/src/lower.rs | |
parent | 7accf6bc37c059a83a58c82f463f02a02ed2226f (diff) |
Separate `Ty` and `TyKind` like in Chalk
Currently `Ty` just wraps `TyKind`, but this allows us to change most
places to already use `intern` / `interned`.
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r-- | crates/hir_ty/src/lower.rs | 122 |
1 files changed, 71 insertions, 51 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index d84ec9b7a..9fe7e3dce 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -34,7 +34,7 @@ use crate::{ | |||
34 | }, | 34 | }, |
35 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, | 35 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, |
36 | OpaqueTy, OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, | 36 | OpaqueTy, OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, |
37 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, | 37 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, |
38 | }; | 38 | }; |
39 | 39 | ||
40 | #[derive(Debug)] | 40 | #[derive(Debug)] |
@@ -146,10 +146,10 @@ impl Ty { | |||
146 | pub fn from_hir_ext(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> (Self, Option<TypeNs>) { | 146 | pub fn from_hir_ext(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> (Self, Option<TypeNs>) { |
147 | let mut res = None; | 147 | let mut res = None; |
148 | let ty = match type_ref { | 148 | let ty = match type_ref { |
149 | TypeRef::Never => Ty::Never, | 149 | TypeRef::Never => TyKind::Never.intern(&Interner), |
150 | TypeRef::Tuple(inner) => { | 150 | TypeRef::Tuple(inner) => { |
151 | let inner_tys: Arc<[Ty]> = inner.iter().map(|tr| Ty::from_hir(ctx, tr)).collect(); | 151 | let inner_tys: Arc<[Ty]> = inner.iter().map(|tr| Ty::from_hir(ctx, tr)).collect(); |
152 | Ty::Tuple(inner_tys.len(), Substs(inner_tys)) | 152 | TyKind::Tuple(inner_tys.len(), Substs(inner_tys)).intern(&Interner) |
153 | } | 153 | } |
154 | TypeRef::Path(path) => { | 154 | TypeRef::Path(path) => { |
155 | let (ty, res_) = Ty::from_hir_path(ctx, path); | 155 | let (ty, res_) = Ty::from_hir_path(ctx, path); |
@@ -158,38 +158,42 @@ impl Ty { | |||
158 | } | 158 | } |
159 | TypeRef::RawPtr(inner, mutability) => { | 159 | TypeRef::RawPtr(inner, mutability) => { |
160 | let inner_ty = Ty::from_hir(ctx, inner); | 160 | let inner_ty = Ty::from_hir(ctx, inner); |
161 | Ty::Raw(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) | 161 | TyKind::Raw(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) |
162 | .intern(&Interner) | ||
162 | } | 163 | } |
163 | TypeRef::Array(inner) => { | 164 | TypeRef::Array(inner) => { |
164 | let inner_ty = Ty::from_hir(ctx, inner); | 165 | let inner_ty = Ty::from_hir(ctx, inner); |
165 | Ty::Array(Substs::single(inner_ty)) | 166 | TyKind::Array(Substs::single(inner_ty)).intern(&Interner) |
166 | } | 167 | } |
167 | TypeRef::Slice(inner) => { | 168 | TypeRef::Slice(inner) => { |
168 | let inner_ty = Ty::from_hir(ctx, inner); | 169 | let inner_ty = Ty::from_hir(ctx, inner); |
169 | Ty::Slice(Substs::single(inner_ty)) | 170 | TyKind::Slice(Substs::single(inner_ty)).intern(&Interner) |
170 | } | 171 | } |
171 | TypeRef::Reference(inner, _, mutability) => { | 172 | TypeRef::Reference(inner, _, mutability) => { |
172 | let inner_ty = Ty::from_hir(ctx, inner); | 173 | let inner_ty = Ty::from_hir(ctx, inner); |
173 | Ty::Ref(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) | 174 | TyKind::Ref(lower_to_chalk_mutability(*mutability), Substs::single(inner_ty)) |
175 | .intern(&Interner) | ||
174 | } | 176 | } |
175 | TypeRef::Placeholder => Ty::Unknown, | 177 | TypeRef::Placeholder => TyKind::Unknown.intern(&Interner), |
176 | TypeRef::Fn(params, is_varargs) => { | 178 | TypeRef::Fn(params, is_varargs) => { |
177 | let substs = Substs(params.iter().map(|tr| Ty::from_hir(ctx, tr)).collect()); | 179 | let substs = Substs(params.iter().map(|tr| Ty::from_hir(ctx, tr)).collect()); |
178 | Ty::Function(FnPointer { | 180 | TyKind::Function(FnPointer { |
179 | num_args: substs.len() - 1, | 181 | num_args: substs.len() - 1, |
180 | sig: FnSig { variadic: *is_varargs }, | 182 | sig: FnSig { variadic: *is_varargs }, |
181 | substs, | 183 | substs, |
182 | }) | 184 | }) |
185 | .intern(&Interner) | ||
183 | } | 186 | } |
184 | TypeRef::DynTrait(bounds) => { | 187 | TypeRef::DynTrait(bounds) => { |
185 | let self_ty = Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)); | 188 | let self_ty = |
189 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner); | ||
186 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { | 190 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { |
187 | bounds | 191 | bounds |
188 | .iter() | 192 | .iter() |
189 | .flat_map(|b| GenericPredicate::from_type_bound(ctx, b, self_ty.clone())) | 193 | .flat_map(|b| GenericPredicate::from_type_bound(ctx, b, self_ty.clone())) |
190 | .collect() | 194 | .collect() |
191 | }); | 195 | }); |
192 | Ty::Dyn(predicates) | 196 | TyKind::Dyn(predicates).intern(&Interner) |
193 | } | 197 | } |
194 | TypeRef::ImplTrait(bounds) => { | 198 | TypeRef::ImplTrait(bounds) => { |
195 | match ctx.impl_trait_mode { | 199 | match ctx.impl_trait_mode { |
@@ -226,10 +230,11 @@ impl Ty { | |||
226 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); | 230 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); |
227 | let generics = generics(ctx.db.upcast(), func.into()); | 231 | let generics = generics(ctx.db.upcast(), func.into()); |
228 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); | 232 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); |
229 | Ty::Alias(AliasTy::Opaque(OpaqueTy { | 233 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { |
230 | opaque_ty_id: impl_trait_id, | 234 | opaque_ty_id: impl_trait_id, |
231 | parameters, | 235 | parameters, |
232 | })) | 236 | })) |
237 | .intern(&Interner) | ||
233 | } | 238 | } |
234 | ImplTraitLoweringMode::Param => { | 239 | ImplTraitLoweringMode::Param => { |
235 | let idx = ctx.impl_trait_counter.get(); | 240 | let idx = ctx.impl_trait_counter.get(); |
@@ -243,10 +248,10 @@ impl Ty { | |||
243 | data.provenance == TypeParamProvenance::ArgumentImplTrait | 248 | data.provenance == TypeParamProvenance::ArgumentImplTrait |
244 | }) | 249 | }) |
245 | .nth(idx as usize) | 250 | .nth(idx as usize) |
246 | .map_or(Ty::Unknown, |(id, _)| Ty::Placeholder(id)); | 251 | .map_or(TyKind::Unknown, |(id, _)| TyKind::Placeholder(id)); |
247 | param | 252 | param.intern(&Interner) |
248 | } else { | 253 | } else { |
249 | Ty::Unknown | 254 | TyKind::Unknown.intern(&Interner) |
250 | } | 255 | } |
251 | } | 256 | } |
252 | ImplTraitLoweringMode::Variable => { | 257 | ImplTraitLoweringMode::Variable => { |
@@ -260,18 +265,19 @@ impl Ty { | |||
260 | } else { | 265 | } else { |
261 | (0, 0, 0, 0) | 266 | (0, 0, 0, 0) |
262 | }; | 267 | }; |
263 | Ty::BoundVar(BoundVar::new( | 268 | TyKind::BoundVar(BoundVar::new( |
264 | ctx.in_binders, | 269 | ctx.in_binders, |
265 | idx as usize + parent_params + self_params + list_params, | 270 | idx as usize + parent_params + self_params + list_params, |
266 | )) | 271 | )) |
272 | .intern(&Interner) | ||
267 | } | 273 | } |
268 | ImplTraitLoweringMode::Disallowed => { | 274 | ImplTraitLoweringMode::Disallowed => { |
269 | // FIXME: report error | 275 | // FIXME: report error |
270 | Ty::Unknown | 276 | TyKind::Unknown.intern(&Interner) |
271 | } | 277 | } |
272 | } | 278 | } |
273 | } | 279 | } |
274 | TypeRef::Error => Ty::Unknown, | 280 | TypeRef::Error => TyKind::Unknown.intern(&Interner), |
275 | }; | 281 | }; |
276 | (ty, res) | 282 | (ty, res) |
277 | } | 283 | } |
@@ -315,7 +321,7 @@ impl Ty { | |||
315 | (Ty::select_associated_type(ctx, res, segment), None) | 321 | (Ty::select_associated_type(ctx, res, segment), None) |
316 | } else if remaining_segments.len() > 1 { | 322 | } else if remaining_segments.len() > 1 { |
317 | // FIXME report error (ambiguous associated type) | 323 | // FIXME report error (ambiguous associated type) |
318 | (Ty::Unknown, None) | 324 | (TyKind::Unknown.intern(&Interner), None) |
319 | } else { | 325 | } else { |
320 | (ty, res) | 326 | (ty, res) |
321 | } | 327 | } |
@@ -332,7 +338,10 @@ impl Ty { | |||
332 | TypeNs::TraitId(trait_) => { | 338 | TypeNs::TraitId(trait_) => { |
333 | // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there | 339 | // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there |
334 | let self_ty = if remaining_segments.len() == 0 { | 340 | let self_ty = if remaining_segments.len() == 0 { |
335 | Some(Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))) | 341 | Some( |
342 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) | ||
343 | .intern(&Interner), | ||
344 | ) | ||
336 | } else { | 345 | } else { |
337 | None | 346 | None |
338 | }; | 347 | }; |
@@ -348,21 +357,23 @@ impl Ty { | |||
348 | match found { | 357 | match found { |
349 | Some((super_trait_ref, associated_ty)) => { | 358 | Some((super_trait_ref, associated_ty)) => { |
350 | // FIXME handle type parameters on the segment | 359 | // FIXME handle type parameters on the segment |
351 | Ty::Alias(AliasTy::Projection(ProjectionTy { | 360 | TyKind::Alias(AliasTy::Projection(ProjectionTy { |
352 | associated_ty, | 361 | associated_ty, |
353 | parameters: super_trait_ref.substs, | 362 | parameters: super_trait_ref.substs, |
354 | })) | 363 | })) |
364 | .intern(&Interner) | ||
355 | } | 365 | } |
356 | None => { | 366 | None => { |
357 | // FIXME: report error (associated type not found) | 367 | // FIXME: report error (associated type not found) |
358 | Ty::Unknown | 368 | TyKind::Unknown.intern(&Interner) |
359 | } | 369 | } |
360 | } | 370 | } |
361 | } else if remaining_segments.len() > 1 { | 371 | } else if remaining_segments.len() > 1 { |
362 | // FIXME report error (ambiguous associated type) | 372 | // FIXME report error (ambiguous associated type) |
363 | Ty::Unknown | 373 | TyKind::Unknown.intern(&Interner) |
364 | } else { | 374 | } else { |
365 | Ty::Dyn(Arc::new([GenericPredicate::Implemented(trait_ref)])) | 375 | TyKind::Dyn(Arc::new([GenericPredicate::Implemented(trait_ref)])) |
376 | .intern(&Interner) | ||
366 | }; | 377 | }; |
367 | return (ty, None); | 378 | return (ty, None); |
368 | } | 379 | } |
@@ -372,12 +383,13 @@ impl Ty { | |||
372 | ctx.resolver.generic_def().expect("generics in scope"), | 383 | ctx.resolver.generic_def().expect("generics in scope"), |
373 | ); | 384 | ); |
374 | match ctx.type_param_mode { | 385 | match ctx.type_param_mode { |
375 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 386 | TypeParamLoweringMode::Placeholder => TyKind::Placeholder(param_id), |
376 | TypeParamLoweringMode::Variable => { | 387 | TypeParamLoweringMode::Variable => { |
377 | let idx = generics.param_idx(param_id).expect("matching generics"); | 388 | let idx = generics.param_idx(param_id).expect("matching generics"); |
378 | Ty::BoundVar(BoundVar::new(ctx.in_binders, idx)) | 389 | TyKind::BoundVar(BoundVar::new(ctx.in_binders, idx)) |
379 | } | 390 | } |
380 | } | 391 | } |
392 | .intern(&Interner) | ||
381 | } | 393 | } |
382 | TypeNs::SelfType(impl_id) => { | 394 | TypeNs::SelfType(impl_id) => { |
383 | let generics = generics(ctx.db.upcast(), impl_id.into()); | 395 | let generics = generics(ctx.db.upcast(), impl_id.into()); |
@@ -414,7 +426,7 @@ impl Ty { | |||
414 | Ty::from_hir_path_inner(ctx, resolved_segment, it.into(), infer_args) | 426 | Ty::from_hir_path_inner(ctx, resolved_segment, it.into(), infer_args) |
415 | } | 427 | } |
416 | // FIXME: report error | 428 | // FIXME: report error |
417 | TypeNs::EnumVariantId(_) => return (Ty::Unknown, None), | 429 | TypeNs::EnumVariantId(_) => return (TyKind::Unknown.intern(&Interner), None), |
418 | }; | 430 | }; |
419 | Ty::from_type_relative_path(ctx, ty, Some(resolution), remaining_segments) | 431 | Ty::from_type_relative_path(ctx, ty, Some(resolution), remaining_segments) |
420 | } | 432 | } |
@@ -428,7 +440,7 @@ impl Ty { | |||
428 | let (resolution, remaining_index) = | 440 | let (resolution, remaining_index) = |
429 | match ctx.resolver.resolve_path_in_type_ns(ctx.db.upcast(), path.mod_path()) { | 441 | match ctx.resolver.resolve_path_in_type_ns(ctx.db.upcast(), path.mod_path()) { |
430 | Some(it) => it, | 442 | Some(it) => it, |
431 | None => return (Ty::Unknown, None), | 443 | None => return (TyKind::Unknown.intern(&Interner), None), |
432 | }; | 444 | }; |
433 | let (resolved_segment, remaining_segments) = match remaining_index { | 445 | let (resolved_segment, remaining_segments) = match remaining_index { |
434 | None => ( | 446 | None => ( |
@@ -473,18 +485,21 @@ impl Ty { | |||
473 | // associated_type_shorthand_candidates does not do that | 485 | // associated_type_shorthand_candidates does not do that |
474 | let substs = substs.shift_bound_vars(ctx.in_binders); | 486 | let substs = substs.shift_bound_vars(ctx.in_binders); |
475 | // FIXME handle type parameters on the segment | 487 | // FIXME handle type parameters on the segment |
476 | return Some(Ty::Alias(AliasTy::Projection(ProjectionTy { | 488 | return Some( |
477 | associated_ty, | 489 | TyKind::Alias(AliasTy::Projection(ProjectionTy { |
478 | parameters: substs, | 490 | associated_ty, |
479 | }))); | 491 | parameters: substs, |
492 | })) | ||
493 | .intern(&Interner), | ||
494 | ); | ||
480 | } | 495 | } |
481 | 496 | ||
482 | None | 497 | None |
483 | }); | 498 | }); |
484 | 499 | ||
485 | ty.unwrap_or(Ty::Unknown) | 500 | ty.unwrap_or(TyKind::Unknown.intern(&Interner)) |
486 | } else { | 501 | } else { |
487 | Ty::Unknown | 502 | TyKind::Unknown.intern(&Interner) |
488 | } | 503 | } |
489 | } | 504 | } |
490 | 505 | ||
@@ -553,13 +568,13 @@ fn substs_from_path_segment( | |||
553 | def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); | 568 | def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); |
554 | let total_len = parent_params + self_params + type_params + impl_trait_params; | 569 | let total_len = parent_params + self_params + type_params + impl_trait_params; |
555 | 570 | ||
556 | substs.extend(iter::repeat(Ty::Unknown).take(parent_params)); | 571 | substs.extend(iter::repeat(TyKind::Unknown.intern(&Interner)).take(parent_params)); |
557 | 572 | ||
558 | let mut had_explicit_type_args = false; | 573 | let mut had_explicit_type_args = false; |
559 | 574 | ||
560 | if let Some(generic_args) = &segment.args_and_bindings { | 575 | if let Some(generic_args) = &segment.args_and_bindings { |
561 | if !generic_args.has_self_type { | 576 | if !generic_args.has_self_type { |
562 | substs.extend(iter::repeat(Ty::Unknown).take(self_params)); | 577 | substs.extend(iter::repeat(TyKind::Unknown.intern(&Interner)).take(self_params)); |
563 | } | 578 | } |
564 | let expected_num = | 579 | let expected_num = |
565 | if generic_args.has_self_type { self_params + type_params } else { type_params }; | 580 | if generic_args.has_self_type { self_params + type_params } else { type_params }; |
@@ -602,7 +617,7 @@ fn substs_from_path_segment( | |||
602 | // add placeholders for args that were not provided | 617 | // add placeholders for args that were not provided |
603 | // FIXME: emit diagnostics in contexts where this is not allowed | 618 | // FIXME: emit diagnostics in contexts where this is not allowed |
604 | for _ in substs.len()..total_len { | 619 | for _ in substs.len()..total_len { |
605 | substs.push(Ty::Unknown); | 620 | substs.push(TyKind::Unknown.intern(&Interner)); |
606 | } | 621 | } |
607 | assert_eq!(substs.len(), total_len); | 622 | assert_eq!(substs.len(), total_len); |
608 | 623 | ||
@@ -674,12 +689,13 @@ impl GenericPredicate { | |||
674 | let param_id = | 689 | let param_id = |
675 | hir_def::TypeParamId { parent: generic_def, local_id: *param_id }; | 690 | hir_def::TypeParamId { parent: generic_def, local_id: *param_id }; |
676 | match ctx.type_param_mode { | 691 | match ctx.type_param_mode { |
677 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 692 | TypeParamLoweringMode::Placeholder => TyKind::Placeholder(param_id), |
678 | TypeParamLoweringMode::Variable => { | 693 | TypeParamLoweringMode::Variable => { |
679 | let idx = generics.param_idx(param_id).expect("matching generics"); | 694 | let idx = generics.param_idx(param_id).expect("matching generics"); |
680 | Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx)) | 695 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx)) |
681 | } | 696 | } |
682 | } | 697 | } |
698 | .intern(&Interner) | ||
683 | } | 699 | } |
684 | }; | 700 | }; |
685 | GenericPredicate::from_type_bound(ctx, bound, self_ty) | 701 | GenericPredicate::from_type_bound(ctx, bound, self_ty) |
@@ -751,7 +767,7 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
751 | preds.extend(GenericPredicate::from_type_bound( | 767 | preds.extend(GenericPredicate::from_type_bound( |
752 | ctx, | 768 | ctx, |
753 | bound, | 769 | bound, |
754 | Ty::Alias(AliasTy::Projection(projection_ty.clone())), | 770 | TyKind::Alias(AliasTy::Projection(projection_ty.clone())).intern(&Interner), |
755 | )); | 771 | )); |
756 | } | 772 | } |
757 | preds | 773 | preds |
@@ -761,7 +777,8 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
761 | impl ReturnTypeImplTrait { | 777 | impl ReturnTypeImplTrait { |
762 | fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { | 778 | fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { |
763 | cov_mark::hit!(lower_rpit); | 779 | cov_mark::hit!(lower_rpit); |
764 | let self_ty = Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)); | 780 | let self_ty = |
781 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner); | ||
765 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { | 782 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { |
766 | bounds | 783 | bounds |
767 | .iter() | 784 | .iter() |
@@ -994,17 +1011,20 @@ pub(crate) fn generic_defaults_query( | |||
994 | .iter() | 1011 | .iter() |
995 | .enumerate() | 1012 | .enumerate() |
996 | .map(|(idx, (_, p))| { | 1013 | .map(|(idx, (_, p))| { |
997 | let mut ty = p.default.as_ref().map_or(Ty::Unknown, |t| Ty::from_hir(&ctx, t)); | 1014 | let mut ty = p |
1015 | .default | ||
1016 | .as_ref() | ||
1017 | .map_or(TyKind::Unknown.intern(&Interner), |t| Ty::from_hir(&ctx, t)); | ||
998 | 1018 | ||
999 | // Each default can only refer to previous parameters. | 1019 | // Each default can only refer to previous parameters. |
1000 | ty.walk_mut_binders( | 1020 | ty.walk_mut_binders( |
1001 | &mut |ty, binders| match ty { | 1021 | &mut |ty, binders| match &mut ty.0 { |
1002 | Ty::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => { | 1022 | TyKind::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => { |
1003 | if *index >= idx { | 1023 | if *index >= idx { |
1004 | // type variable default referring to parameter coming | 1024 | // type variable default referring to parameter coming |
1005 | // after it. This is forbidden (FIXME: report | 1025 | // after it. This is forbidden (FIXME: report |
1006 | // diagnostic) | 1026 | // diagnostic) |
1007 | *ty = Ty::Unknown; | 1027 | *ty = TyKind::Unknown.intern(&Interner); |
1008 | } | 1028 | } |
1009 | } | 1029 | } |
1010 | _ => {} | 1030 | _ => {} |
@@ -1040,7 +1060,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { | |||
1040 | fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> { | 1060 | fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> { |
1041 | let generics = generics(db.upcast(), def.into()); | 1061 | let generics = generics(db.upcast(), def.into()); |
1042 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1062 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1043 | Binders::new(substs.len(), Ty::FnDef(def.into(), substs)) | 1063 | Binders::new(substs.len(), TyKind::FnDef(def.into(), substs).intern(&Interner)) |
1044 | } | 1064 | } |
1045 | 1065 | ||
1046 | /// Build the declared type of a const. | 1066 | /// Build the declared type of a const. |
@@ -1083,7 +1103,7 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders<T | |||
1083 | } | 1103 | } |
1084 | let generics = generics(db.upcast(), def.into()); | 1104 | let generics = generics(db.upcast(), def.into()); |
1085 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1105 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1086 | Binders::new(substs.len(), Ty::FnDef(def.into(), substs)) | 1106 | Binders::new(substs.len(), TyKind::FnDef(def.into(), substs).intern(&Interner)) |
1087 | } | 1107 | } |
1088 | 1108 | ||
1089 | fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig { | 1109 | fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig { |
@@ -1108,7 +1128,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) - | |||
1108 | } | 1128 | } |
1109 | let generics = generics(db.upcast(), def.parent.into()); | 1129 | let generics = generics(db.upcast(), def.parent.into()); |
1110 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1130 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1111 | Binders::new(substs.len(), Ty::FnDef(def.into(), substs)) | 1131 | Binders::new(substs.len(), TyKind::FnDef(def.into(), substs).intern(&Interner)) |
1112 | } | 1132 | } |
1113 | 1133 | ||
1114 | fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { | 1134 | fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { |
@@ -1123,7 +1143,7 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> { | |||
1123 | let ctx = | 1143 | let ctx = |
1124 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 1144 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
1125 | if db.type_alias_data(t).is_extern { | 1145 | if db.type_alias_data(t).is_extern { |
1126 | Binders::new(0, Ty::ForeignType(t)) | 1146 | Binders::new(0, TyKind::ForeignType(t).intern(&Interner)) |
1127 | } else { | 1147 | } else { |
1128 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1148 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1129 | let type_ref = &db.type_alias_data(t).type_ref; | 1149 | let type_ref = &db.type_alias_data(t).type_ref; |
@@ -1199,7 +1219,7 @@ pub(crate) fn ty_recover(db: &dyn HirDatabase, _cycle: &[String], def: &TyDefId) | |||
1199 | TyDefId::AdtId(it) => generics(db.upcast(), it.into()).len(), | 1219 | TyDefId::AdtId(it) => generics(db.upcast(), it.into()).len(), |
1200 | TyDefId::TypeAliasId(it) => generics(db.upcast(), it.into()).len(), | 1220 | TyDefId::TypeAliasId(it) => generics(db.upcast(), it.into()).len(), |
1201 | }; | 1221 | }; |
1202 | Binders::new(num_binders, Ty::Unknown) | 1222 | Binders::new(num_binders, TyKind::Unknown.intern(&Interner)) |
1203 | } | 1223 | } |
1204 | 1224 | ||
1205 | pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Binders<Ty> { | 1225 | pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Binders<Ty> { |
@@ -1237,7 +1257,7 @@ pub(crate) fn impl_self_ty_recover( | |||
1237 | impl_id: &ImplId, | 1257 | impl_id: &ImplId, |
1238 | ) -> Binders<Ty> { | 1258 | ) -> Binders<Ty> { |
1239 | let generics = generics(db.upcast(), (*impl_id).into()); | 1259 | let generics = generics(db.upcast(), (*impl_id).into()); |
1240 | Binders::new(generics.len(), Ty::Unknown) | 1260 | Binders::new(generics.len(), TyKind::Unknown.intern(&Interner)) |
1241 | } | 1261 | } |
1242 | 1262 | ||
1243 | pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<Binders<TraitRef>> { | 1263 | pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<Binders<TraitRef>> { |