Skip to content

Qualify constness in rvalue expressions for promotion to globals. #21744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librand/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ pub trait Reseeder<R> {
/// Reseed an RNG using a `Default` instance. This reseeds by
/// replacing the RNG with the result of a `Default::default` call.
#[derive(Copy)]
pub struct ReseedWithDefault;
pub struct ReseedWithDefault { __hack: [u8; 0] }
// FIXME(#21721) used to be an unit struct but that can cause
// certain LLVM versions to abort during optimizations.
#[allow(non_upper_case_globals)]
pub const ReseedWithDefault: ReseedWithDefault = ReseedWithDefault { __hack: [] };

impl<R: Rng + Default> Reseeder<R> for ReseedWithDefault {
fn reseed(&mut self, rng: &mut R) {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ register_diagnostics! {
E0010,
E0011,
E0012,
E0013,
E0014,
E0015,
E0016,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub mod middle {
pub mod check_loop;
pub mod check_match;
pub mod check_rvalues;
pub mod check_static;
pub mod const_eval;
pub mod dataflow;
pub mod dead;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl LintPass for TypeLimits {
if let ast::LitInt(shift, _) = lit.node { shift >= bits }
else { false }
} else {
match eval_const_expr_partial(cx.tcx, &**r) {
match eval_const_expr_partial(cx.tcx, &**r, Some(cx.tcx.types.uint)) {
Ok(const_int(shift)) => { shift as u64 >= bits },
Ok(const_uint(shift)) => { shift >= bits },
_ => { false }
Expand Down
15 changes: 2 additions & 13 deletions src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

pub use self::astencode_tag::*;

use std::mem;
use back::svh::Svh;

// EBML enum definitions and utils shared by the encoder and decoder
Expand Down Expand Up @@ -113,7 +112,7 @@ pub const tag_items_data_item_reexport_def_id: uint = 0x39;
pub const tag_items_data_item_reexport_name: uint = 0x3a;

// used to encode crate_ctxt side tables
#[derive(Copy, PartialEq)]
#[derive(Copy, PartialEq, FromPrimitive)]
#[repr(uint)]
pub enum astencode_tag { // Reserves 0x40 -- 0x5f
tag_ast = 0x40,
Expand Down Expand Up @@ -144,17 +143,7 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
tag_table_upvar_capture_map = 0x56,
tag_table_capture_modes = 0x57,
tag_table_object_cast_map = 0x58,
}

static first_astencode_tag: uint = tag_ast as uint;
static last_astencode_tag: uint = tag_table_object_cast_map as uint;
impl astencode_tag {
pub fn from_uint(value : uint) -> Option<astencode_tag> {
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
if !is_a_tag { None } else {
Some(unsafe { mem::transmute::<uint, astencode_tag>(value) })
}
}
tag_table_const_qualif = 0x59,
}

pub const tag_item_trait_item_sort: uint = 0x60;
Expand Down
19 changes: 17 additions & 2 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use metadata::tydecode;
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
use metadata::tydecode::{RegionParameter, ClosureSource};
use metadata::tyencode;
use middle::check_const::ConstQualif;
use middle::mem_categorization::Typer;
use middle::subst;
use middle::subst::VecPerParamSpace;
Expand All @@ -38,6 +39,7 @@ use syntax::ptr::P;
use syntax;

use std::old_io::Seek;
use std::num::FromPrimitive;
use std::rc::Rc;

use rbml::io::SeekableMemWriter;
Expand Down Expand Up @@ -1305,6 +1307,15 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
})
})
}

for &qualif in tcx.const_qualif_map.borrow().get(&id).iter() {
rbml_w.tag(c::tag_table_const_qualif, |rbml_w| {
rbml_w.id(id);
rbml_w.tag(c::tag_table_val, |rbml_w| {
qualif.encode(rbml_w).unwrap()
})
})
}
}

trait doc_decoder_helpers {
Expand Down Expand Up @@ -1836,8 +1847,8 @@ fn decode_side_tables(dcx: &DecodeContext,
debug!(">> Side table document with tag 0x{:x} \
found for id {} (orig {})",
tag, id, id0);

match c::astencode_tag::from_uint(tag) {
let decoded_tag: Option<c::astencode_tag> = FromPrimitive::from_uint(tag);
match decoded_tag {
None => {
dcx.tcx.sess.bug(
&format!("unknown tag found in side tables: {:x}",
Expand Down Expand Up @@ -1919,6 +1930,10 @@ fn decode_side_tables(dcx: &DecodeContext,
dcx.tcx.closure_kinds.borrow_mut().insert(ast_util::local_def(id),
closure_kind);
}
c::tag_table_const_qualif => {
let qualif: ConstQualif = Decodable::decode(val_dsr).unwrap();
dcx.tcx.const_qualif_map.borrow_mut().insert(id, qualif);
}
_ => {
dcx.tcx.sess.bug(
&format!("unknown tag found in side tables: {:x}",
Expand Down
Loading