Skip to content

Commit 120b239

Browse files
committed
---
yaml --- r: 152040 b: refs/heads/try2 c: 0c51149 h: refs/heads/master v: v3
1 parent 993354a commit 120b239

File tree

7 files changed

+107
-272
lines changed

7 files changed

+107
-272
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ba77c602707fe7adba2c631db87ba7ad7f4dc812
8+
refs/heads/try2: 0c51149ac97b818a31749d85bcb3b3f2332b94fb
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/lint.rs

Lines changed: 54 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use syntax::parse::token;
7272
use syntax::visit::Visitor;
7373
use syntax::{ast, ast_util, visit};
7474

75-
#[deriving(Clone, Show, Eq, Ord, TotalEq, TotalOrd, Hash)]
75+
#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd)]
7676
pub enum Lint {
7777
CTypes,
7878
UnusedImports,
@@ -94,7 +94,6 @@ pub enum Lint {
9494
UnknownFeatures,
9595
UnknownCrateType,
9696
UnsignedNegate,
97-
VariantSizeDifference,
9897

9998
ManagedHeapMemory,
10099
OwnedHeapMemory,
@@ -148,9 +147,8 @@ pub struct LintSpec {
148147

149148
pub type LintDict = HashMap<&'static str, LintSpec>;
150149

151-
// this is public for the lints that run in trans
152150
#[deriving(Eq)]
153-
pub enum LintSource {
151+
enum LintSource {
154152
Node(Span),
155153
Default,
156154
CommandLine
@@ -409,13 +407,6 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
409407
default: Warn
410408
}),
411409

412-
("variant_size_difference",
413-
LintSpec {
414-
lint: VariantSizeDifference,
415-
desc: "detects enums with widely varying variant sizes",
416-
default: Allow,
417-
}),
418-
419410
("unused_must_use",
420411
LintSpec {
421412
lint: UnusedMustUse,
@@ -454,78 +445,30 @@ pub fn get_lint_dict() -> LintDict {
454445
}
455446

456447
struct Context<'a> {
457-
/// All known lint modes (string versions)
448+
// All known lint modes (string versions)
458449
dict: LintDict,
459-
/// Current levels of each lint warning
450+
// Current levels of each lint warning
460451
cur: SmallIntMap<(Level, LintSource)>,
461-
/// Context we're checking in (used to access fields like sess)
452+
// context we're checking in (used to access fields like sess)
462453
tcx: &'a ty::ctxt,
463-
/// Items exported by the crate; used by the missing_doc lint.
454+
// Items exported by the crate; used by the missing_doc lint.
464455
exported_items: &'a privacy::ExportedItems,
465-
/// The id of the current `ast::StructDef` being walked.
456+
// The id of the current `ast::StructDef` being walked.
466457
cur_struct_def_id: ast::NodeId,
467-
/// Whether some ancestor of the current node was marked
468-
/// #[doc(hidden)].
458+
// Whether some ancestor of the current node was marked
459+
// #[doc(hidden)].
469460
is_doc_hidden: bool,
470461

471-
/// When recursing into an attributed node of the ast which modifies lint
472-
/// levels, this stack keeps track of the previous lint levels of whatever
473-
/// was modified.
462+
// When recursing into an attributed node of the ast which modifies lint
463+
// levels, this stack keeps track of the previous lint levels of whatever
464+
// was modified.
474465
lint_stack: Vec<(Lint, Level, LintSource)>,
475466

476-
/// Id of the last visited negated expression
467+
// id of the last visited negated expression
477468
negated_expr_id: ast::NodeId,
478469

479-
/// Ids of structs/enums which have been checked for raw_pointer_deriving
470+
// ids of structs/enums which have been checked for raw_pointer_deriving
480471
checked_raw_pointers: NodeSet,
481-
482-
/// Level of lints for certain NodeIds, stored here because the body of
483-
/// the lint needs to run in trans.
484-
node_levels: HashMap<(ast::NodeId, Lint), (Level, LintSource)>,
485-
}
486-
487-
pub fn emit_lint(level: Level, src: LintSource, msg: &str, span: Span,
488-
lint_str: &str, tcx: &ty::ctxt) {
489-
if level == Allow { return }
490-
491-
let mut note = None;
492-
let msg = match src {
493-
Default => {
494-
format!("{}, \\#[{}({})] on by default", msg,
495-
level_to_str(level), lint_str)
496-
},
497-
CommandLine => {
498-
format!("{} [-{} {}]", msg,
499-
match level {
500-
Warn => 'W', Deny => 'D', Forbid => 'F',
501-
Allow => fail!()
502-
}, lint_str.replace("_", "-"))
503-
},
504-
Node(src) => {
505-
note = Some(src);
506-
msg.to_str()
507-
}
508-
};
509-
510-
match level {
511-
Warn => { tcx.sess.span_warn(span, msg.as_slice()); }
512-
Deny | Forbid => { tcx.sess.span_err(span, msg.as_slice()); }
513-
Allow => fail!(),
514-
}
515-
516-
for &span in note.iter() {
517-
tcx.sess.span_note(span, "lint level defined here");
518-
}
519-
}
520-
521-
pub fn lint_to_str(lint: Lint) -> &'static str {
522-
for &(name, lspec) in lint_table.iter() {
523-
if lspec.lint == lint {
524-
return name;
525-
}
526-
}
527-
528-
fail!("unrecognized lint: {}", lint);
529472
}
530473

531474
impl<'a> Context<'a> {
@@ -557,7 +500,7 @@ impl<'a> Context<'a> {
557500
return *k;
558501
}
559502
}
560-
fail!("unregistered lint {}", lint);
503+
fail!("unregistered lint {:?}", lint);
561504
}
562505

563506
fn span_lint(&self, lint: Lint, span: Span, msg: &str) {
@@ -566,8 +509,37 @@ impl<'a> Context<'a> {
566509
Some(&(Warn, src)) => (self.get_level(Warnings), src),
567510
Some(&pair) => pair,
568511
};
512+
if level == Allow { return }
513+
514+
let mut note = None;
515+
let msg = match src {
516+
Default => {
517+
format_strbuf!("{}, \\#[{}({})] on by default",
518+
msg,
519+
level_to_str(level),
520+
self.lint_to_str(lint))
521+
},
522+
CommandLine => {
523+
format!("{} [-{} {}]", msg,
524+
match level {
525+
Warn => 'W', Deny => 'D', Forbid => 'F',
526+
Allow => fail!()
527+
}, self.lint_to_str(lint).replace("_", "-"))
528+
},
529+
Node(src) => {
530+
note = Some(src);
531+
msg.to_str()
532+
}
533+
};
534+
match level {
535+
Warn => self.tcx.sess.span_warn(span, msg.as_slice()),
536+
Deny | Forbid => self.tcx.sess.span_err(span, msg.as_slice()),
537+
Allow => fail!(),
538+
}
569539

570-
emit_lint(level, src, msg, span, self.lint_to_str(lint), self.tcx);
540+
for &span in note.iter() {
541+
self.tcx.sess.span_note(span, "lint level defined here");
542+
}
571543
}
572544

573545
/**
@@ -646,8 +618,8 @@ impl<'a> Context<'a> {
646618
}
647619
}
648620

649-
/// Check that every lint from the list of attributes satisfies `f`.
650-
/// Return true if that's the case. Otherwise return false.
621+
// Check that every lint from the list of attributes satisfies `f`.
622+
// Return true if that's the case. Otherwise return false.
651623
pub fn each_lint(sess: &session::Session,
652624
attrs: &[ast::Attribute],
653625
f: |@ast::MetaItem, Level, InternedString| -> bool)
@@ -681,8 +653,8 @@ pub fn each_lint(sess: &session::Session,
681653
true
682654
}
683655

684-
/// Check from a list of attributes if it contains the appropriate
685-
/// `#[level(lintname)]` attribute (e.g. `#[allow(dead_code)]).
656+
// Check from a list of attributes if it contains the appropriate
657+
// `#[level(lintname)]` attribute (e.g. `#[allow(dead_code)]).
686658
pub fn contains_lint(attrs: &[ast::Attribute],
687659
level: Level,
688660
lintname: &'static str)
@@ -1767,24 +1739,9 @@ fn check_stability(cx: &Context, e: &ast::Expr) {
17671739
cx.span_lint(lint, e.span, msg.as_slice());
17681740
}
17691741

1770-
fn check_enum_variant_sizes(cx: &mut Context, it: &ast::Item) {
1771-
match it.node {
1772-
ast::ItemEnum(..) => {
1773-
match cx.cur.find(&(VariantSizeDifference as uint)) {
1774-
Some(&(lvl, src)) if lvl != Allow => {
1775-
cx.node_levels.insert((it.id, VariantSizeDifference), (lvl, src));
1776-
},
1777-
_ => { }
1778-
}
1779-
},
1780-
_ => { }
1781-
}
1782-
}
1783-
17841742
impl<'a> Visitor<()> for Context<'a> {
17851743
fn visit_item(&mut self, it: &ast::Item, _: ()) {
17861744
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
1787-
check_enum_variant_sizes(cx, it);
17881745
check_item_ctypes(cx, it);
17891746
check_item_non_camel_case_types(cx, it);
17901747
check_item_non_uppercase_statics(cx, it);
@@ -1976,7 +1933,6 @@ pub fn check_crate(tcx: &ty::ctxt,
19761933
lint_stack: Vec::new(),
19771934
negated_expr_id: -1,
19781935
checked_raw_pointers: NodeSet::new(),
1979-
node_levels: HashMap::new(),
19801936
};
19811937

19821938
// Install default lint levels, followed by the command line levels, and
@@ -2013,11 +1969,13 @@ pub fn check_crate(tcx: &ty::ctxt,
20131969
// in the iteration code.
20141970
for (id, v) in tcx.sess.lints.borrow().iter() {
20151971
for &(lint, span, ref msg) in v.iter() {
2016-
tcx.sess.span_bug(span, format!("unprocessed lint {} at {}: {}",
2017-
lint, tcx.map.node_to_str(*id), *msg).as_slice())
1972+
tcx.sess.span_bug(span,
1973+
format!("unprocessed lint {:?} at {}: {}",
1974+
lint,
1975+
tcx.map.node_to_str(*id),
1976+
*msg).as_slice())
20181977
}
20191978
}
20201979

20211980
tcx.sess.abort_if_errors();
2022-
*tcx.node_lint_levels.borrow_mut() = cx.node_levels;
20231981
}

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use lib::llvm::{ModuleRef, ValueRef, BasicBlockRef};
3636
use lib::llvm::{llvm, Vector};
3737
use lib;
3838
use metadata::{csearch, encoder};
39-
use middle::lint;
4039
use middle::astencode;
4140
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
4241
use middle::weak_lang_items;
@@ -58,7 +57,7 @@ use middle::trans::foreign;
5857
use middle::trans::glue;
5958
use middle::trans::inline;
6059
use middle::trans::machine;
61-
use middle::trans::machine::{llalign_of_min, llsize_of, llsize_of_real};
60+
use middle::trans::machine::{llalign_of_min, llsize_of};
6261
use middle::trans::meth;
6362
use middle::trans::monomorphize;
6463
use middle::trans::tvec;
@@ -1490,7 +1489,7 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
14901489
}
14911490

14921491
fn trans_enum_def(ccx: &CrateContext, enum_definition: &ast::EnumDef,
1493-
sp: Span, id: ast::NodeId, vi: &[Rc<ty::VariantInfo>],
1492+
id: ast::NodeId, vi: &[Rc<ty::VariantInfo>],
14941493
i: &mut uint) {
14951494
for &variant in enum_definition.variants.iter() {
14961495
let disr_val = vi[*i].disr_val;
@@ -1510,57 +1509,6 @@ fn trans_enum_def(ccx: &CrateContext, enum_definition: &ast::EnumDef,
15101509
}
15111510
}
15121511
}
1513-
1514-
enum_variant_size_lint(ccx, enum_definition, sp, id);
1515-
}
1516-
1517-
fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span, id: ast::NodeId) {
1518-
let mut sizes = Vec::new(); // does no allocation if no pushes, thankfully
1519-
1520-
let (lvl, src) = ccx.tcx.node_lint_levels.borrow()
1521-
.find(&(id, lint::VariantSizeDifference))
1522-
.map_or((lint::Allow, lint::Default), |&(lvl,src)| (lvl, src));
1523-
1524-
if lvl != lint::Allow {
1525-
let avar = adt::represent_type(ccx, ty::node_id_to_type(ccx.tcx(), id));
1526-
match *avar {
1527-
adt::General(_, ref variants) => {
1528-
for var in variants.iter() {
1529-
let mut size = 0;
1530-
for field in var.fields.iter().skip(1) {
1531-
// skip the dicriminant
1532-
size += llsize_of_real(ccx, sizing_type_of(ccx, *field));
1533-
}
1534-
sizes.push(size);
1535-
}
1536-
},
1537-
_ => { /* its size is either constant or unimportant */ }
1538-
}
1539-
1540-
let (largest, slargest, largest_index) = sizes.iter().enumerate().fold((0, 0, 0),
1541-
|(l, s, li), (idx, &size)|
1542-
if size > l {
1543-
(size, l, idx)
1544-
} else if size > s {
1545-
(l, size, li)
1546-
} else {
1547-
(l, s, li)
1548-
}
1549-
);
1550-
1551-
// we only warn if the largest variant is at least thrice as large as
1552-
// the second-largest.
1553-
if largest > slargest * 3 && slargest > 0 {
1554-
lint::emit_lint(lvl, src,
1555-
format!("enum variant is more than three times larger \
1556-
({} bytes) than the next largest (ignoring padding)",
1557-
largest).as_slice(),
1558-
sp, lint::lint_to_str(lint::VariantSizeDifference), ccx.tcx());
1559-
1560-
ccx.sess().span_note(enum_def.variants.get(largest_index).span,
1561-
"this variant is the largest");
1562-
}
1563-
}
15641512
}
15651513

15661514
pub struct TransItemVisitor<'a> {
@@ -1607,7 +1555,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
16071555
if !generics.is_type_parameterized() {
16081556
let vi = ty::enum_variants(ccx.tcx(), local_def(item.id));
16091557
let mut i = 0;
1610-
trans_enum_def(ccx, enum_definition, item.span, item.id, vi.as_slice(), &mut i);
1558+
trans_enum_def(ccx, enum_definition, item.id, vi.as_slice(), &mut i);
16111559
}
16121560
}
16131561
ast::ItemStatic(_, m, expr) => {
@@ -1818,6 +1766,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
18181766
if !type_is_immediate(ccx, t) {
18191767
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
18201768
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
1769+
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
18211770
}
18221771
}
18231772
}

0 commit comments

Comments
 (0)