Skip to content

Commit f89feb9

Browse files
committed
more implementations moved across
1 parent 83171d0 commit f89feb9

7 files changed

Lines changed: 353 additions & 168 deletions

File tree

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,30 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
803803
) -> Ty<'tcx> {
804804
self.struct_tail_raw(ty, cause, normalize, f)
805805
}
806+
807+
fn get_ty_var(self, id: usize) -> Option<&Ty<'tcx>> {
808+
self.types.ty_vars.get(id)
809+
}
810+
811+
fn get_fresh_ty(self, id: usize) -> Option<&Ty<'tcx>> {
812+
self.types.fresh_tys.get(id)
813+
}
814+
815+
fn get_fresh_ty_int(self, id: usize) -> Option<&Ty<'tcx>> {
816+
self.types.fresh_int_tys.get(id)
817+
}
818+
819+
fn get_fresh_ty_float(self, id: usize) -> Option<&Ty<'tcx>> {
820+
self.types.fresh_float_tys.get(id)
821+
}
822+
823+
fn get_anon_bound_ty(self, id: usize) -> Option<&Vec<Ty<'tcx>>> {
824+
self.types.anon_bound_tys.get(id)
825+
}
826+
827+
fn get_anon_canonical_bound_ty(self, id: usize) -> Option<&Ty<'tcx>> {
828+
self.types.anon_canonical_bound_tys.get(var.as_usize())
829+
}
806830
}
807831

808832
/// Defines trivial conversion functions between the main [`LangItem`] enum,
@@ -841,6 +865,7 @@ bidirectional_lang_item_map! {
841865
FieldBase,
842866
FieldType,
843867
FutureOutput,
868+
GlobalAlloc,
844869
Metadata,
845870
// tidy-alphabetical-end
846871
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 114 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_hir::def_id::DefId;
1515
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, extension};
1616
use rustc_span::{DUMMY_SP, Span, Symbol, kw, sym};
1717
use rustc_type_ir::TyKind::*;
18-
use rustc_type_ir::inherent::{AdtDef, IntoKind};
18+
use rustc_type_ir::inherent::IntoKind;
1919
use rustc_type_ir::solve::SizedTraitKind;
2020
use rustc_type_ir::walk::TypeWalker;
2121
use rustc_type_ir::{self as ir, BoundVar, CollectAndApply, TypeVisitableExt, elaborate};
@@ -363,123 +363,123 @@ impl ParamConst {
363363

364364
/// Constructors for `Ty`
365365
impl<'tcx> Ty<'tcx> {
366-
#[inline]
367-
pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferTy) -> Ty<'tcx> {
368-
Ty::new(tcx, TyKind::Infer(infer))
369-
}
370-
371-
#[inline]
372-
pub fn new_var(tcx: TyCtxt<'tcx>, v: ty::TyVid) -> Ty<'tcx> {
373-
// Use a pre-interned one when possible.
374-
tcx.types
375-
.ty_vars
376-
.get(v.as_usize())
377-
.copied()
378-
.unwrap_or_else(|| Ty::new(tcx, Infer(TyVar(v))))
379-
}
380-
381-
#[inline]
382-
pub fn new_int_var(tcx: TyCtxt<'tcx>, v: ty::IntVid) -> Ty<'tcx> {
383-
Ty::new_infer(tcx, IntVar(v))
384-
}
366+
// #[inline]
367+
// pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferTy) -> Ty<'tcx> {
368+
// Ty::new(tcx, TyKind::Infer(infer))
369+
// }
385370

386-
#[inline]
387-
pub fn new_float_var(tcx: TyCtxt<'tcx>, v: ty::FloatVid) -> Ty<'tcx> {
388-
Ty::new_infer(tcx, FloatVar(v))
389-
}
371+
// #[inline]
372+
// pub fn new_var(tcx: TyCtxt<'tcx>, v: ty::TyVid) -> Ty<'tcx> {
373+
// // Use a pre-interned one when possible.
374+
// tcx.types
375+
// .ty_vars
376+
// .get(v.as_usize())
377+
// .copied()
378+
// .unwrap_or_else(|| Ty::new(tcx, Infer(TyVar(v))))
379+
// }
380+
381+
// #[inline]
382+
// pub fn new_int_var(tcx: TyCtxt<'tcx>, v: ty::IntVid) -> Ty<'tcx> {
383+
// Ty::new_infer(tcx, IntVar(v))
384+
// }
385+
386+
// #[inline]
387+
// pub fn new_float_var(tcx: TyCtxt<'tcx>, v: ty::FloatVid) -> Ty<'tcx> {
388+
// Ty::new_infer(tcx, FloatVar(v))
389+
// }
390390

391-
#[inline]
392-
pub fn new_fresh(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
393-
// Use a pre-interned one when possible.
394-
tcx.types
395-
.fresh_tys
396-
.get(n as usize)
397-
.copied()
398-
.unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshTy(n)))
399-
}
391+
// #[inline]
392+
// pub fn new_fresh(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
393+
// // Use a pre-interned one when possible.
394+
// tcx.types
395+
// .fresh_tys
396+
// .get(n as usize)
397+
// .copied()
398+
// .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshTy(n)))
399+
// }
400400

401-
#[inline]
402-
pub fn new_fresh_int(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
403-
// Use a pre-interned one when possible.
404-
tcx.types
405-
.fresh_int_tys
406-
.get(n as usize)
407-
.copied()
408-
.unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshIntTy(n)))
409-
}
401+
// #[inline]
402+
// pub fn new_fresh_int(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
403+
// // Use a pre-interned one when possible.
404+
// tcx.types
405+
// .fresh_int_tys
406+
// .get(n as usize)
407+
// .copied()
408+
// .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshIntTy(n)))
409+
// }
410410

411-
#[inline]
412-
pub fn new_fresh_float(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
413-
// Use a pre-interned one when possible.
414-
tcx.types
415-
.fresh_float_tys
416-
.get(n as usize)
417-
.copied()
418-
.unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshFloatTy(n)))
419-
}
411+
// #[inline]
412+
// pub fn new_fresh_float(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
413+
// // Use a pre-interned one when possible.
414+
// tcx.types
415+
// .fresh_float_tys
416+
// .get(n as usize)
417+
// .copied()
418+
// .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshFloatTy(n)))
419+
// }
420420

421-
#[inline]
422-
pub fn new_param(tcx: TyCtxt<'tcx>, index: u32, name: Symbol) -> Ty<'tcx> {
423-
Ty::new(tcx, Param(ParamTy { index, name }))
424-
}
421+
// #[inline]
422+
// pub fn new_param(tcx: TyCtxt<'tcx>, index: u32, name: Symbol) -> Ty<'tcx> {
423+
// Ty::new(tcx, Param(ParamTy { index, name }))
424+
// }
425425

426-
#[inline]
427-
pub fn new_bound(
428-
tcx: TyCtxt<'tcx>,
429-
index: ty::DebruijnIndex,
430-
bound_ty: ty::BoundTy<'tcx>,
431-
) -> Ty<'tcx> {
432-
// Use a pre-interned one when possible.
433-
if let ty::BoundTy { var, kind: ty::BoundTyKind::Anon } = bound_ty
434-
&& let Some(inner) = tcx.types.anon_bound_tys.get(index.as_usize())
435-
&& let Some(ty) = inner.get(var.as_usize()).copied()
436-
{
437-
ty
438-
} else {
439-
Ty::new(tcx, Bound(ty::BoundVarIndexKind::Bound(index), bound_ty))
440-
}
441-
}
426+
// #[inline]
427+
// pub fn new_bound(
428+
// tcx: TyCtxt<'tcx>,
429+
// index: ty::DebruijnIndex,
430+
// bound_ty: ty::BoundTy<'tcx>,
431+
// ) -> Ty<'tcx> {
432+
// // Use a pre-interned one when possible.
433+
// if let ty::BoundTy { var, kind: ty::BoundTyKind::Anon } = bound_ty
434+
// && let Some(inner) = tcx.types.anon_bound_tys.get(index.as_usize())
435+
// && let Some(ty) = inner.get(var.as_usize()).copied()
436+
// {
437+
// ty
438+
// } else {
439+
// Ty::new(tcx, Bound(ty::BoundVarIndexKind::Bound(index), bound_ty))
440+
// }
441+
// }
442442

443-
#[inline]
444-
pub fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: BoundVar) -> Ty<'tcx> {
445-
// Use a pre-interned one when possible.
446-
if let Some(ty) = tcx.types.anon_canonical_bound_tys.get(var.as_usize()).copied() {
447-
ty
448-
} else {
449-
Ty::new(
450-
tcx,
451-
Bound(
452-
ty::BoundVarIndexKind::Canonical,
453-
ty::BoundTy { var, kind: ty::BoundTyKind::Anon },
454-
),
455-
)
456-
}
457-
}
443+
// #[inline]
444+
// pub fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: BoundVar) -> Ty<'tcx> {
445+
// // Use a pre-interned one when possible.
446+
// if let Some(ty) = tcx.types.anon_canonical_bound_tys.get(var.as_usize()).copied() {
447+
// ty
448+
// } else {
449+
// Ty::new(
450+
// tcx,
451+
// Bound(
452+
// ty::BoundVarIndexKind::Canonical,
453+
// ty::BoundTy { var, kind: ty::BoundTyKind::Anon },
454+
// ),
455+
// )
456+
// }
457+
// }
458458

459-
#[inline]
460-
pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Ty<'tcx> {
461-
Ty::new(tcx, Placeholder(placeholder))
462-
}
459+
// #[inline]
460+
// pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Ty<'tcx> {
461+
// Ty::new(tcx, Placeholder(placeholder))
462+
// }
463463

464-
#[inline]
465-
pub fn new_alias(
466-
tcx: TyCtxt<'tcx>,
467-
kind: ty::AliasTyKind,
468-
alias_ty: ty::AliasTy<'tcx>,
469-
) -> Ty<'tcx> {
470-
debug_assert_matches!(
471-
(kind, tcx.def_kind(alias_ty.def_id)),
472-
(ty::Opaque, DefKind::OpaqueTy)
473-
| (ty::Projection | ty::Inherent, DefKind::AssocTy)
474-
| (ty::Free, DefKind::TyAlias)
475-
);
476-
Ty::new(tcx, Alias(kind, alias_ty))
477-
}
464+
// #[inline]
465+
// pub fn new_alias(
466+
// tcx: TyCtxt<'tcx>,
467+
// kind: ty::AliasTyKind,
468+
// alias_ty: ty::AliasTy<'tcx>,
469+
// ) -> Ty<'tcx> {
470+
// debug_assert_matches!(
471+
// (kind, tcx.def_kind(alias_ty.def_id)),
472+
// (ty::Opaque, DefKind::OpaqueTy)
473+
// | (ty::Projection | ty::Inherent, DefKind::AssocTy)
474+
// | (ty::Free, DefKind::TyAlias)
475+
// );
476+
// Ty::new(tcx, Alias(kind, alias_ty))
477+
// }
478478

479-
#[inline]
480-
pub fn new_pat(tcx: TyCtxt<'tcx>, base: Ty<'tcx>, pat: ty::Pattern<'tcx>) -> Ty<'tcx> {
481-
Ty::new(tcx, Pat(base, pat))
482-
}
479+
// #[inline]
480+
// pub fn new_pat(tcx: TyCtxt<'tcx>, base: Ty<'tcx>, pat: ty::Pattern<'tcx>) -> Ty<'tcx> {
481+
// Ty::new(tcx, Pat(base, pat))
482+
// }
483483

484484
#[inline]
485485
pub fn new_field_representing_type(
@@ -516,6 +516,12 @@ impl<'tcx> Ty<'tcx> {
516516
Ty::new_alias(tcx, ty::Opaque, AliasTy::new_from_args(tcx, def_id, args))
517517
}
518518

519+
// #[inline]
520+
// #[instrument(level = "debug", skip(tcx))]
521+
// pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
522+
// Ty::new_alias(tcx, ty::Opaque, AliasTy::new_from_args(tcx, def_id, args))
523+
// }
524+
519525
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
520526
// pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Ty<'tcx> {
521527
// Ty::new(tcx, Error(guar))

0 commit comments

Comments
 (0)