]> git.lizzy.rs Git - rust.git/commitdiff
adding HasParamEnv trait
authorSaleem Jaffer <ssaleem1992@gmail.com>
Sat, 4 May 2019 09:32:22 +0000 (15:02 +0530)
committerSaleem Jaffer <ssaleem1992@gmail.com>
Sat, 4 May 2019 09:49:59 +0000 (15:19 +0530)
src/librustc/ty/layout.rs
src/librustc_codegen_llvm/builder.rs
src/librustc_codegen_llvm/context.rs
src/librustc_codegen_ssa/traits/builder.rs
src/librustc_codegen_ssa/traits/mod.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_passes/layout_test.rs
src/librustc_target/abi/mod.rs

index e4f80838d84f8997998ffad9e9488fbc757c4afc..d4b93ed4785025cd5284aa7a9b6bc2731876ad77 100644 (file)
@@ -1662,9 +1662,20 @@ pub fn layout_of(self, param_env_and_ty: ty::ParamEnvAnd<'tcx, Ty<'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 @@ fn pointee_info_at(
             }
         }
     }
-
-    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 {
index 123fda1e215ff9ca5890919fb34f08288d79a767..bc2bb97a19e5471f5a8e6e5739eca5d200f8fe8f 100644 (file)
@@ -66,6 +66,12 @@ fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, '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>;
index 7cf78a41feb7202dc56616b2947a6da5d0b26b87..a225a11e94db049ea6469ce93e67ebdf2a9d7e72 100644 (file)
@@ -15,7 +15,7 @@
 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 @@ fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
             })
     }
 }
+
+impl<'tcx, 'll> HasParamEnv<'tcx> for CodegenCx<'ll, 'tcx> {
+    fn param_env(&self) -> ty::ParamEnv<'tcx> {
+        panic!("asd")
+    }
+}
index 48142fc9fa9f4e328d681a4d310e68c1efa9704d..a3f99cd869e28f5851aebc854d63d57dc9c175da 100644 (file)
@@ -10,7 +10,7 @@
 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;
index 8fe8b7ecd47091f56c1138eeef2ff59bb714837e..8c336b11a5d0abf00fb165326d287d63b3a1a784 100644 (file)
@@ -41,6 +41,8 @@
     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>;
 }
index ad4bc6a91f5a179d9aba993ca1171c45853c0d41..db827afdb94f4481096d600aa8db0cd5ec599e9d 100644 (file)
@@ -175,6 +175,14 @@ fn tcx<'d>(&'d self) -> TyCtxt<'d, 'tcx, '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>
 {
index 6940f8f442ee94a5789dc4f5a54c830244037be6..7041a5593abbfe861d664f081f1fd74be0cdd81c 100644 (file)
@@ -7,6 +7,7 @@
 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 @@ fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, '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()
index 087d98d70318e0118d3c4e58a1e81a311b27c3b5..d69b4b6d2bdcaad0ae372ca9402ca3d2a59bce67 100644 (file)
@@ -947,11 +947,6 @@ fn pointee_info_at(
         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 @@ pub fn pointee_info_at<C>(
     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> {