Rollup merge of #72689 - lcnr:common_str, r=estebank

add str to common types

I already expected this to be the case and it may slightly improve perf.

Afaict if we ever want to change str into a lang item this would have to get reverted.
As that would be fairly simple I don't believe this to cause any problems in the future.
This commit is contained in:
Manish Goregaokar 2020-06-19 19:42:47 -07:00 committed by GitHub
commit 218b90f643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 8 deletions

View File

@ -206,7 +206,7 @@ fn const_str(&self, s: Symbol) -> (&'ll Value, &'ll Value) {
let len = s.as_str().len();
let cs = consts::ptrcast(
self.const_cstr(s, false),
self.type_ptr_to(self.layout_of(self.tcx.mk_str()).llvm_type(self)),
self.type_ptr_to(self.layout_of(self.tcx.types.str_).llvm_type(self)),
);
(cs, self.const_usize(len as u64))
}

View File

@ -143,6 +143,7 @@ pub struct CommonTypes<'tcx> {
pub u128: Ty<'tcx>,
pub f32: Ty<'tcx>,
pub f64: Ty<'tcx>,
pub str_: Ty<'tcx>,
pub never: Ty<'tcx>,
pub self_param: Ty<'tcx>,
@ -816,6 +817,7 @@ fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
u128: mk(Uint(ast::UintTy::U128)),
f32: mk(Float(ast::FloatTy::F32)),
f64: mk(Float(ast::FloatTy::F64)),
str_: mk(Str),
self_param: mk(ty::Param(ty::ParamTy { index: 0, name: kw::SelfUpper })),
trait_object_dummy_self: mk(Infer(ty::FreshTy(0))),
@ -2149,14 +2151,9 @@ pub fn mk_mach_float(self, tm: ast::FloatTy) -> Ty<'tcx> {
}
}
#[inline]
pub fn mk_str(self) -> Ty<'tcx> {
self.mk_ty(Str)
}
#[inline]
pub fn mk_static_str(self) -> Ty<'tcx> {
self.mk_imm_ref(self.lifetimes.re_static, self.mk_str())
self.mk_imm_ref(self.lifetimes.re_static, self.types.str_)
}
#[inline]

View File

@ -2787,7 +2787,7 @@ pub fn res_to_ty(
hir::PrimTy::Int(it) => tcx.mk_mach_int(it),
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(uit),
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ft),
hir::PrimTy::Str => tcx.mk_str(),
hir::PrimTy::Str => tcx.types.str_,
}
}
Res::Err => {