about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-11-13 13:03:09 +0800
committerkennytm <kennytm@gmail.com>2018-11-13 19:20:28 +0800
commit98bc7d63fbc78643532853db3cb289bacc86167c (patch)
tree5c83d9eb185c22820484d44ece754200a29eb882
parentd811f844a5e992f8a2533fc440421a4b3cf7056f (diff)
parent2bd4d5b1a0b05827401970f0cfbe17e6b6f32d0d (diff)
downloadrust-98bc7d63fbc78643532853db3cb289bacc86167c.tar.gz
rust-98bc7d63fbc78643532853db3cb289bacc86167c.zip
Rollup merge of #55805 - nnethercote:mv-static_assert, r=Mark-Simulacrum
Move `static_assert!` into librustc_data_structures
-rw-r--r--src/librustc/macros.rs10
-rw-r--r--src/librustc/mir/mod.rs8
-rw-r--r--src/librustc/ty/context.rs6
-rw-r--r--src/librustc/ty/mod.rs4
-rw-r--r--src/librustc/ty/sty.rs4
-rw-r--r--src/librustc_data_structures/lib.rs1
-rw-r--r--src/librustc_data_structures/macros.rs21
-rw-r--r--src/libsyntax/ast.rs6
8 files changed, 40 insertions, 20 deletions
diff --git a/src/librustc/macros.rs b/src/librustc/macros.rs
index f21f949c9f5..781a0fa3f66 100644
--- a/src/librustc/macros.rs
+++ b/src/librustc/macros.rs
@@ -63,16 +63,6 @@ macro_rules! span_bug {
 }
 
 #[macro_export]
-macro_rules! static_assert {
-    ($name:ident: $test:expr) => {
-        // Use the bool to access an array such that if the bool is false, the access
-        // is out-of-bounds.
-        #[allow(dead_code)]
-        static $name: () = [()][!$test as usize];
-    }
-}
-
-#[macro_export]
 macro_rules! __impl_stable_hash_field {
     ($field:ident, $ctx:expr, $hasher:expr) => ($field.hash_stable($ctx, $hasher));
     ($field:ident, $ctx:expr, $hasher:expr, _) => ({ let _ = $field; });
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index 8a32e8f46c2..46b61d8ffe6 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -1719,14 +1719,14 @@ pub struct Statement<'tcx> {
     pub kind: StatementKind<'tcx>,
 }
 
+// `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
+#[cfg(target_arch = "x86_64")]
+static_assert!(MEM_SIZE_OF_STATEMENT: mem::size_of::<Statement<'_>>() == 56);
+
 impl<'tcx> Statement<'tcx> {
     /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
     /// invalidating statement indices in `Location`s.
     pub fn make_nop(&mut self) {
-        // `Statement` contributes significantly to peak memory usage. Make
-        // sure it doesn't get bigger.
-        static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56);
-
         self.kind = StatementKind::Nop
     }
 
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 82095a2f5b0..f78fad9f7aa 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -823,12 +823,6 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
 
 impl<'tcx> CommonTypes<'tcx> {
     fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
-        // Ensure our type representation does not grow
-        #[cfg(target_pointer_width = "64")]
-        static_assert!(ASSERT_TY_KIND: ::std::mem::size_of::<ty::TyKind<'_>>() <= 24);
-        #[cfg(target_pointer_width = "64")]
-        static_assert!(ASSERT_TYS: ::std::mem::size_of::<ty::TyS<'_>>() <= 32);
-
         let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
         let mk_region = |r| {
             if let Some(r) = interners.region.borrow().get(&r) {
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 9a63bb374c6..979cc9b115b 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -514,6 +514,10 @@ pub struct TyS<'tcx> {
     outer_exclusive_binder: ty::DebruijnIndex,
 }
 
+// `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
+#[cfg(target_arch = "x86_64")]
+static_assert!(MEM_SIZE_OF_TY_S: ::std::mem::size_of::<TyS<'_>>() == 32);
+
 impl<'tcx> Ord for TyS<'tcx> {
     fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
         self.sty.cmp(&other.sty)
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index a4130bf15cb..bd3a34cae90 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -211,6 +211,10 @@ pub enum TyKind<'tcx> {
     Error,
 }
 
+// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.
+#[cfg(target_arch = "x86_64")]
+static_assert!(MEM_SIZE_OF_TY_KIND: ::std::mem::size_of::<TyKind<'_>>() == 24);
+
 /// A closure can be modeled as a struct that looks like:
 ///
 ///     struct Closure<'l0...'li, T0...Tj, CK, CS, U0...Uk> {
diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs
index 07e5548216f..135abebdacb 100644
--- a/src/librustc_data_structures/lib.rs
+++ b/src/librustc_data_structures/lib.rs
@@ -57,6 +57,7 @@ extern crate rustc_cratesio_shim;
 
 pub use rustc_serialize::hex::ToHex;
 
+pub mod macros;
 pub mod svh;
 pub mod base_n;
 pub mod bit_set;
diff --git a/src/librustc_data_structures/macros.rs b/src/librustc_data_structures/macros.rs
new file mode 100644
index 00000000000..3cc91b0e93f
--- /dev/null
+++ b/src/librustc_data_structures/macros.rs
@@ -0,0 +1,21 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+/// A simple static assertion macro. The first argument should be a unique
+/// ALL_CAPS identifier that describes the condition.
+#[macro_export]
+macro_rules! static_assert {
+    ($name:ident: $test:expr) => {
+        // Use the bool to access an array such that if the bool is false, the access
+        // is out-of-bounds.
+        #[allow(dead_code)]
+        static $name: () = [()][!$test as usize];
+    }
+}
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 2f17bc0548c..808e19d6f12 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -20,6 +20,8 @@ use print::pprust;
 use ptr::P;
 use rustc_data_structures::indexed_vec;
 use rustc_data_structures::indexed_vec::Idx;
+#[cfg(target_arch = "x86_64")]
+use rustc_data_structures::static_assert;
 use rustc_target::spec::abi::Abi;
 use source_map::{dummy_spanned, respan, Spanned};
 use symbol::{keywords, Symbol};
@@ -924,6 +926,10 @@ pub struct Expr {
     pub attrs: ThinVec<Attribute>,
 }
 
+// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
+#[cfg(target_arch = "x86_64")]
+static_assert!(MEM_SIZE_OF_EXPR: std::mem::size_of::<Expr>() == 88);
+
 impl Expr {
     /// Whether this expression would be valid somewhere that expects a value, for example, an `if`
     /// condition.