Skip to content

Commit 985a785

Browse files
authored
Rollup merge of rust-lang#55805 - nnethercote:mv-static_assert, r=Mark-Simulacrum
Move `static_assert!` into librustc_data_structures
2 parents ed39b93 + e01e0b0 commit 985a785

File tree

8 files changed

+39
-20
lines changed

8 files changed

+39
-20
lines changed

src/librustc/macros.rs

-10
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ macro_rules! span_bug {
6262
})
6363
}
6464

65-
#[macro_export]
66-
macro_rules! static_assert {
67-
($name:ident: $test:expr) => {
68-
// Use the bool to access an array such that if the bool is false, the access
69-
// is out-of-bounds.
70-
#[allow(dead_code)]
71-
static $name: () = [()][!$test as usize];
72-
}
73-
}
74-
7565
#[macro_export]
7666
macro_rules! __impl_stable_hash_field {
7767
($field:ident, $ctx:expr, $hasher:expr) => ($field.hash_stable($ctx, $hasher));

src/librustc/mir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1719,14 +1719,14 @@ pub struct Statement<'tcx> {
17191719
pub kind: StatementKind<'tcx>,
17201720
}
17211721

1722+
// `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
1723+
#[cfg(target_arch = "x86_64")]
1724+
static_assert!(MEM_SIZE_OF_STATEMENT: mem::size_of::<Statement<'_>>() == 56);
1725+
17221726
impl<'tcx> Statement<'tcx> {
17231727
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
17241728
/// invalidating statement indices in `Location`s.
17251729
pub fn make_nop(&mut self) {
1726-
// `Statement` contributes significantly to peak memory usage. Make
1727-
// sure it doesn't get bigger.
1728-
static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56);
1729-
17301730
self.kind = StatementKind::Nop
17311731
}
17321732

src/librustc/ty/context.rs

-6
Original file line numberDiff line numberDiff line change
@@ -823,12 +823,6 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
823823

824824
impl<'tcx> CommonTypes<'tcx> {
825825
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
826-
// Ensure our type representation does not grow
827-
#[cfg(target_pointer_width = "64")]
828-
static_assert!(ASSERT_TY_KIND: ::std::mem::size_of::<ty::TyKind<'_>>() <= 24);
829-
#[cfg(target_pointer_width = "64")]
830-
static_assert!(ASSERT_TYS: ::std::mem::size_of::<ty::TyS<'_>>() <= 32);
831-
832826
let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
833827
let mk_region = |r| {
834828
if let Some(r) = interners.region.borrow().get(&r) {

src/librustc/ty/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ pub struct TyS<'tcx> {
514514
outer_exclusive_binder: ty::DebruijnIndex,
515515
}
516516

517+
// `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
518+
#[cfg(target_arch = "x86_64")]
519+
static_assert!(MEM_SIZE_OF_TY_S: ::std::mem::size_of::<TyS<'_>>() == 32);
520+
517521
impl<'tcx> Ord for TyS<'tcx> {
518522
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
519523
self.sty.cmp(&other.sty)

src/librustc/ty/sty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ pub enum TyKind<'tcx> {
211211
Error,
212212
}
213213

214+
// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.
215+
#[cfg(target_arch = "x86_64")]
216+
static_assert!(MEM_SIZE_OF_TY_KIND: ::std::mem::size_of::<TyKind<'_>>() == 24);
217+
214218
/// A closure can be modeled as a struct that looks like:
215219
///
216220
/// struct Closure<'l0...'li, T0...Tj, CK, CS, U0...Uk> {

src/librustc_data_structures/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extern crate rustc_cratesio_shim;
5757

5858
pub use rustc_serialize::hex::ToHex;
5959

60+
pub mod macros;
6061
pub mod svh;
6162
pub mod base_n;
6263
pub mod bit_set;
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
/// A simple static assertion macro. The first argument should be a unique
12+
/// ALL_CAPS identifier that describes the condition.
13+
#[macro_export]
14+
macro_rules! static_assert {
15+
($name:ident: $test:expr) => {
16+
// Use the bool to access an array such that if the bool is false, the access
17+
// is out-of-bounds.
18+
#[allow(dead_code)]
19+
static $name: () = [()][!$test as usize];
20+
}
21+
}

src/libsyntax/ast.rs

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use print::pprust;
2020
use ptr::P;
2121
use rustc_data_structures::indexed_vec;
2222
use rustc_data_structures::indexed_vec::Idx;
23+
use rustc_data_structures::static_assert;
2324
use rustc_target::spec::abi::Abi;
2425
use source_map::{dummy_spanned, respan, Spanned};
2526
use symbol::{keywords, Symbol};
@@ -924,6 +925,10 @@ pub struct Expr {
924925
pub attrs: ThinVec<Attribute>,
925926
}
926927

928+
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
929+
#[cfg(target_arch = "x86_64")]
930+
static_assert!(MEM_SIZE_OF_EXPR: std::mem::size_of::<Expr>() == 88);
931+
927932
impl Expr {
928933
/// Whether this expression would be valid somewhere that expects a value, for example, an `if`
929934
/// condition.

0 commit comments

Comments
 (0)