adding HasParamEnv trait

This commit is contained in:
Saleem Jaffer 2019-05-04 15:02:22 +05:30
parent 8802dc037e
commit 18679cdc54
8 changed files with 49 additions and 22 deletions

View file

@ -1662,9 +1662,20 @@ impl ty::query::TyCtxtAt<'a, 'tcx, '_> {
}
}
pub trait HasParamEnv<'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx>;
}
impl<'tcx, C> HasParamEnv<'tcx> for LayoutCx<'tcx, C> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}
}
impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
where C: LayoutOf<Ty = Ty<'tcx>> + HasTyCtxt<'tcx>,
C::TyLayout: MaybeResult<TyLayout<'tcx>>
C::TyLayout: MaybeResult<TyLayout<'tcx>>,
C: HasParamEnv<'tcx>
{
type ParamEnv = ty::ParamEnv<'tcx>;
@ -1960,15 +1971,6 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
}
}
}
fn is_freeze(
this: TyLayout<'tcx>,
cx: &C,
param_env: Self::ParamEnv,
)-> bool {
this.ty.is_freeze(cx.tcx(), param_env, DUMMY_SP)
}
}
struct Niche {

View file

@ -66,6 +66,12 @@ impl ty::layout::HasTyCtxt<'tcx> for Builder<'_, '_, 'tcx> {
}
}
impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.cx.param_env()
}
}
impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
type Ty = Ty<'tcx>;
type TyLayout = TyLayout<'tcx>;

View file

@ -15,7 +15,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
use rustc::mir::mono::Stats;
use rustc::session::config::{self, DebugInfo};
use rustc::session::Session;
use rustc::ty::layout::{LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx};
use rustc::ty::layout::{LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx, HasParamEnv};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::util::nodemap::FxHashMap;
use rustc_target::spec::{HasTargetSpec, Target};
@ -861,3 +861,9 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> {
})
}
}
impl<'tcx, 'll> HasParamEnv<'tcx> for CodegenCx<'ll, 'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
panic!("asd")
}
}

View file

@ -10,7 +10,7 @@ use crate::mir::operand::OperandRef;
use crate::mir::place::PlaceRef;
use crate::MemFlags;
use rustc::ty::Ty;
use rustc::ty::layout::{Align, Size};
use rustc::ty::layout::{Align, Size, HasParamEnv};
use std::ops::Range;
use std::iter::TrustedLen;
@ -29,6 +29,8 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
+ IntrinsicCallMethods<'tcx>
+ AsmBuilderMethods<'tcx>
+ StaticBuilderMethods<'tcx>
+ HasParamEnv<'tcx>
{
fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
fn with_cx(cx: &'a Self::CodegenCx) -> Self;

View file

@ -41,6 +41,8 @@ pub use self::type_::{
ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
};
pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
use rustc::ty::layout::{HasParamEnv};
use std::fmt;
@ -58,6 +60,7 @@ pub trait CodegenMethods<'tcx>:
+ DeclareMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>
+ HasParamEnv<'tcx>
{
}
@ -72,6 +75,7 @@ impl<'tcx, T> CodegenMethods<'tcx> for T where
+ DeclareMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>
+ HasParamEnv<'tcx>
{
}
@ -85,5 +89,6 @@ pub trait HasCodegen<'tcx>:
Type = Self::Type,
Funclet = Self::Funclet,
DIScope = Self::DIScope,
>;
>
+ HasParamEnv<'tcx>;
}

View file

@ -175,6 +175,14 @@ impl<'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for InterpretCx<'a, 'mir, 'tcx,
}
}
impl<'a, 'mir, 'tcx, M> layout::HasParamEnv<'tcx> for InterpretCx<'a, 'mir, 'tcx, M>
where M: Machine<'a, 'mir, 'tcx>
{
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}
}
impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf
for InterpretCx<'a, 'mir, 'tcx, M>
{

View file

@ -7,6 +7,7 @@ use rustc::ty::layout::HasTyCtxt;
use rustc::ty::layout::LayoutOf;
use rustc::ty::layout::TargetDataLayout;
use rustc::ty::layout::TyLayout;
use rustc::ty::layout::HasParamEnv;
use rustc::ty::ParamEnv;
use rustc::ty::Ty;
use rustc::ty::TyCtxt;
@ -122,6 +123,12 @@ impl<'me, 'tcx> HasTyCtxt<'tcx> for UnwrapLayoutCx<'me, 'tcx> {
}
}
impl<'me, 'tcx> HasParamEnv<'tcx> for UnwrapLayoutCx<'me, 'tcx> {
fn param_env(&self) -> ParamEnv<'tcx> {
self.param_env
}
}
impl<'me, 'tcx> HasDataLayout for UnwrapLayoutCx<'me, 'tcx> {
fn data_layout(&self) -> &TargetDataLayout {
self.tcx.data_layout()

View file

@ -947,11 +947,6 @@ pub trait TyLayoutMethods<'a, C: LayoutOf<Ty = Self>>: Sized {
offset: Size,
param_env: Self::ParamEnv,
) -> Option<PointeeInfo>;
fn is_freeze(
this: TyLayout<'a, Self>,
cx: &C,
param_env: Self::ParamEnv,
)-> bool;
}
impl<'a, Ty> TyLayout<'a, Ty> {
@ -969,10 +964,6 @@ impl<'a, Ty> TyLayout<'a, Ty> {
where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> {
Ty::pointee_info_at(self, cx, offset, param_env)
}
pub fn is_freeze<C>(self, cx: &C, param_env: Ty::ParamEnv) -> bool
where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> {
Ty::is_freeze(self, cx, param_env)
}
}
impl<'a, Ty> TyLayout<'a, Ty> {