Skip to content

Commit 5d0ec82

Browse files
committed
---
yaml --- r: 152609 b: refs/heads/try2 c: 5c81a18 h: refs/heads/master i: 152607: d404430 v: v3
1 parent 866f98b commit 5d0ec82

File tree

13 files changed

+108
-55
lines changed

13 files changed

+108
-55
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: 8e7213f65b4348e1b54d8baeeb291267581227d2
8+
refs/heads/try2: 5c81a186e9d835ca66865bd9807524b805a06d8d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/rust.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,8 +1829,6 @@ type int8_t = i8;
18291829

18301830
### Static-only attributes
18311831

1832-
- `address_insignificant` - references to this static may alias with
1833-
references to other statics, potentially of unrelated type.
18341832
- `thread_local` - on a `static mut`, this signals that the value of this
18351833
static may change depending on the current thread. The exact consequences of
18361834
this are implementation-defined.
@@ -2141,13 +2139,22 @@ These types help drive the compiler's analysis
21412139
### Inline attributes
21422140

21432141
The inline attribute is used to suggest to the compiler to perform an inline
2144-
expansion and place a copy of the function in the caller rather than generating
2145-
code to call the function where it is defined.
2142+
expansion and place a copy of the function or static in the caller rather than
2143+
generating code to call the function or access the static where it is defined.
21462144

21472145
The compiler automatically inlines functions based on internal heuristics.
21482146
Incorrectly inlining functions can actually making the program slower, so it
21492147
should be used with care.
21502148

2149+
Immutable statics are always considered inlineable
2150+
unless marked with `#[inline(never)]`.
2151+
It is undefined
2152+
whether two different inlineable statics
2153+
have the same memory address.
2154+
In other words,
2155+
the compiler is free
2156+
to collapse duplicate inlineable statics together.
2157+
21512158
`#[inline]` and `#[inline(always)]` always causes the function to be serialized
21522159
into crate metadata to allow cross-crate inlining.
21532160

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,6 @@ fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
10841084

10851085
// FIXME: #14406 these are processed in trans, which happens after the
10861086
// lint pass
1087-
"address_insignificant",
10881087
"cold",
10891088
"inline",
10901089
"link",

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ use std::collections::HashSet;
2626
use syntax::abi;
2727
use syntax::ast;
2828
use syntax::ast_map;
29-
use syntax::ast_util::{is_local};
29+
use syntax::ast_util::is_local;
30+
use syntax::ast_util;
31+
use syntax::attr::{InlineAlways, InlineHint, InlineNever, InlineNone};
3032
use syntax::attr;
3133
use syntax::visit::Visitor;
3234
use syntax::visit;
3335

3436
// Returns true if the given set of attributes contains the `#[inline]`
3537
// attribute.
3638
fn attributes_specify_inlining(attrs: &[ast::Attribute]) -> bool {
37-
attr::contains_name(attrs, "inline")
39+
match attr::find_inline_attr(attrs) {
40+
InlineNone | InlineNever => false,
41+
InlineAlways | InlineHint => true,
42+
}
3843
}
3944

4045
// Returns true if the given set of generics implies that the item it's
@@ -118,8 +123,8 @@ impl<'a> Visitor<()> for ReachableContext<'a> {
118123
match def {
119124
// If this path leads to a static, then we may have
120125
// to do some work to figure out whether the static
121-
// is indeed reachable (address_insignificant
122-
// statics are *never* reachable).
126+
// is indeed reachable. (Inlineable statics are
127+
// never reachable.)
123128
def::DefStatic(..) => {
124129
self.worklist.push(def_id.node);
125130
}
@@ -281,9 +286,10 @@ impl<'a> ReachableContext<'a> {
281286

282287
// Statics with insignificant addresses are not reachable
283288
// because they're inlined specially into all other crates.
284-
ast::ItemStatic(_, _, ref init) => {
285-
if attr::contains_name(item.attrs.as_slice(),
286-
"address_insignificant") {
289+
ast::ItemStatic(_, mutbl, ref init) => {
290+
if !ast_util::static_has_significant_address(
291+
mutbl,
292+
item.attrs.as_slice()) {
287293
self.reachable_symbols.remove(&search_item);
288294
}
289295
visit::walk_expr(self, &**init, ());

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
19971997
let sym = exported_name(ccx, id, ty, i.attrs.as_slice());
19981998

19991999
let v = match i.node {
2000-
ast::ItemStatic(_, _, ref expr) => {
2000+
ast::ItemStatic(_, mutbl, ref expr) => {
20012001
// If this static came from an external crate, then
20022002
// we need to get the symbol from csearch instead of
20032003
// using the current crate's name/version
@@ -2032,28 +2032,24 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
20322032

20332033
// Apply the `unnamed_addr` attribute if
20342034
// requested
2035-
if attr::contains_name(i.attrs.as_slice(),
2036-
"address_insignificant") {
2037-
if ccx.reachable.contains(&id) {
2038-
ccx.sess().span_bug(i.span,
2039-
"insignificant static is reachable");
2040-
}
2035+
if !ast_util::static_has_significant_address(
2036+
mutbl,
2037+
i.attrs.as_slice()) {
20412038
lib::llvm::SetUnnamedAddr(g, true);
20422039

20432040
// This is a curious case where we must make
20442041
// all of these statics inlineable. If a
2045-
// global is tagged as
2046-
// address_insignificant, then LLVM won't
2047-
// coalesce globals unless they have an
2048-
// internal linkage type. This means that
2042+
// global is not tagged as `#[inline(never)]`,
2043+
// then LLVM won't coalesce globals unless they
2044+
// have an internal linkage type. This means that
20492045
// external crates cannot use this global.
20502046
// This is a problem for things like inner
20512047
// statics in generic functions, because the
20522048
// function will be inlined into another
20532049
// crate and then attempt to link to the
20542050
// static in the original crate, only to
20552051
// find that it's not there. On the other
2056-
// side of inlininig, the crates knows to
2052+
// side of inlining, the crates knows to
20572053
// not declare this static as
20582054
// available_externally (because it isn't)
20592055
inlineable = true;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use middle::ty;
1717

1818
use syntax::ast;
1919
use syntax::ast_util::local_def;
20-
use syntax::attr;
20+
use syntax::ast_util;
2121

2222
pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
2323
-> ast::DefId {
@@ -62,12 +62,13 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
6262
// however, so we use the available_externally linkage which llvm
6363
// provides
6464
match item.node {
65-
ast::ItemStatic(..) => {
65+
ast::ItemStatic(_, mutbl, _) => {
6666
let g = get_item_val(ccx, item.id);
6767
// see the comment in get_item_val() as to why this check is
6868
// performed here.
69-
if !attr::contains_name(item.attrs.as_slice(),
70-
"address_insignificant") {
69+
if ast_util::static_has_significant_address(
70+
mutbl,
71+
item.attrs.as_slice()) {
7172
SetLinkage(g, AvailableExternallyLinkage);
7273
}
7374
}

branches/try2/src/librustc/middle/typeck/check/regionck.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
443443

444444
match expr.node {
445445
ast::ExprCall(ref callee, ref args) => {
446-
if !has_method_map {
446+
if has_method_map {
447+
constrain_call(rcx, None, expr, Some(*callee),
448+
args.as_slice(), false);
449+
} else {
447450
constrain_callee(rcx, callee.id, expr, &**callee);
448451
constrain_call(rcx,
449452
Some(callee.id),

branches/try2/src/libsyntax/ast_util.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use ast::*;
1212
use ast;
1313
use ast_util;
14+
use attr::{InlineNever, InlineNone};
15+
use attr;
1416
use codemap;
1517
use codemap::Span;
1618
use owned_slice::OwnedSlice;
@@ -742,6 +744,17 @@ pub fn get_inner_tys(ty: P<Ty>) -> Vec<P<Ty>> {
742744
}
743745
}
744746

747+
/// Returns true if the static with the given mutability and attributes
748+
/// has a significant address and false otherwise.
749+
pub fn static_has_significant_address(mutbl: ast::Mutability,
750+
attrs: &[ast::Attribute])
751+
-> bool {
752+
if mutbl == ast::MutMutable {
753+
return true
754+
}
755+
let inline = attr::find_inline_attr(attrs);
756+
inline == InlineNever || inline == InlineNone
757+
}
745758

746759
#[cfg(test)]
747760
mod test {

branches/try2/src/libsyntax/attr.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,6 @@ pub fn sort_meta_items(items: &[Gc<MetaItem>]) -> Vec<Gc<MetaItem>> {
271271
}).collect()
272272
}
273273

274-
/**
275-
* From a list of crate attributes get only the meta_items that affect crate
276-
* linkage
277-
*/
278-
pub fn find_linkage_metas(attrs: &[Attribute]) -> Vec<Gc<MetaItem>> {
279-
let mut result = Vec::new();
280-
for attr in attrs.iter().filter(|at| at.check_name("link")) {
281-
match attr.meta().node {
282-
MetaList(_, ref items) => result.push_all(items.as_slice()),
283-
_ => ()
284-
}
285-
}
286-
result
287-
}
288-
289274
pub fn find_crateid(attrs: &[Attribute]) -> Option<CrateId> {
290275
match first_attr_value_str_by_name(attrs, "crate_id") {
291276
None => None,

branches/try2/src/libsyntax/ext/format.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,14 @@ impl<'a, 'b> Context<'a, 'b> {
312312
/// These attributes are applied to all statics that this syntax extension
313313
/// will generate.
314314
fn static_attrs(&self) -> Vec<ast::Attribute> {
315-
// Flag statics as `address_insignificant` so LLVM can merge duplicate
316-
// globals as much as possible (which we're generating a whole lot of).
317-
let unnamed = self.ecx
318-
.meta_word(self.fmtsp,
319-
InternedString::new(
320-
"address_insignificant"));
321-
let unnamed = self.ecx.attribute(self.fmtsp, unnamed);
322-
323315
// Do not warn format string as dead code
324316
let dead_code = self.ecx.meta_word(self.fmtsp,
325317
InternedString::new("dead_code"));
326318
let allow_dead_code = self.ecx.meta_list(self.fmtsp,
327319
InternedString::new("allow"),
328320
vec!(dead_code));
329321
let allow_dead_code = self.ecx.attribute(self.fmtsp, allow_dead_code);
330-
return vec!(unnamed, allow_dead_code);
322+
return vec!(allow_dead_code);
331323
}
332324

333325
fn rtpath(&self, s: &str) -> Vec<ast::Ident> {

branches/try2/src/test/auxiliary/xcrate_address_insignificant.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
pub fn foo<T>() -> int {
12-
#[address_insignificant]
1312
static a: int = 3;
1413
a
1514
}

branches/try2/src/test/auxiliary/xcrate_static_addresses.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[inline(never)]
1112
pub static global: int = 3;
1213

14+
#[inline(never)]
1315
static global0: int = 4;
16+
17+
#[inline(never)]
1418
pub static global2: &'static int = &global0;
1519

1620
pub fn verify_same(a: &'static int) {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2014 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+
#![feature(overloaded_calls)]
12+
13+
use std::ops::Fn;
14+
15+
trait Response {}
16+
trait Request {}
17+
trait Ingot<R, S> {
18+
fn enter(&mut self, _: &mut R, _: &mut S, a: &mut Alloy) -> Status;
19+
}
20+
21+
#[allow(dead_code)]
22+
struct HelloWorld;
23+
24+
struct SendFile<'a>;
25+
struct Alloy;
26+
enum Status {
27+
Continue
28+
}
29+
30+
impl Alloy {
31+
fn find<T>(&self) -> Option<T> {
32+
None
33+
}
34+
}
35+
36+
impl<'a, 'b> Fn<(&'b mut Response,),()> for SendFile<'a> {
37+
fn call(&self, (_res,): (&'b mut Response,)) {}
38+
}
39+
40+
impl<Rq: Request, Rs: Response> Ingot<Rq, Rs> for HelloWorld {
41+
fn enter(&mut self, _req: &mut Rq, res: &mut Rs, alloy: &mut Alloy) -> Status {
42+
let send_file = alloy.find::<SendFile>().unwrap();
43+
send_file(res);
44+
Continue
45+
}
46+
}
47+
48+
fn main() {}

0 commit comments

Comments
 (0)