Skip to content

Commit 82090d2

Browse files
committed
---
yaml --- r: 152617 b: refs/heads/try2 c: d6736a1 h: refs/heads/master i: 152615: e9e56e8 v: v3
1 parent c039453 commit 82090d2

39 files changed

+507
-418
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: 3744d828513092d1ed64c4c6f8cd2536f7a5ff0d
8+
refs/heads/try2: d6736a1440d42f6af967a8a20ab8d73522112b72
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
@@ -1888,8 +1888,6 @@ type int8_t = i8;
18881888

18891889
### Static-only attributes
18901890

1891-
- `address_insignificant` - references to this static may alias with
1892-
references to other statics, potentially of unrelated type.
18931891
- `thread_local` - on a `static mut`, this signals that the value of this
18941892
static may change depending on the current thread. The exact consequences of
18951893
this are implementation-defined.
@@ -2200,13 +2198,22 @@ These types help drive the compiler's analysis
22002198
### Inline attributes
22012199

22022200
The inline attribute is used to suggest to the compiler to perform an inline
2203-
expansion and place a copy of the function in the caller rather than generating
2204-
code to call the function where it is defined.
2201+
expansion and place a copy of the function or static in the caller rather than
2202+
generating code to call the function or access the static where it is defined.
22052203

22062204
The compiler automatically inlines functions based on internal heuristics.
22072205
Incorrectly inlining functions can actually making the program slower, so it
22082206
should be used with care.
22092207

2208+
Immutable statics are always considered inlineable
2209+
unless marked with `#[inline(never)]`.
2210+
It is undefined
2211+
whether two different inlineable statics
2212+
have the same memory address.
2213+
In other words,
2214+
the compiler is free
2215+
to collapse duplicate inlineable statics together.
2216+
22102217
`#[inline]` and `#[inline(always)]` always causes the function to be serialized
22112218
into crate metadata to allow cross-crate inlining.
22122219

branches/try2/src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,9 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
346346
assert_eq!(next(st), '[');
347347
let def = parse_def(st, NominalType, |x,y| conv(x,y));
348348
let substs = parse_substs(st, |x,y| conv(x,y));
349-
let store = parse_trait_store(st, |x,y| conv(x,y));
350349
let bounds = parse_bounds(st, |x,y| conv(x,y));
351350
assert_eq!(next(st), ']');
352-
return ty::mk_trait(st.tcx, def, substs, store, bounds.builtin_bounds);
351+
return ty::mk_trait(st.tcx, def, substs, bounds.builtin_bounds);
353352
}
354353
'p' => {
355354
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));

branches/try2/src/librustc/metadata/tyencode.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
232232
ty::ty_trait(box ty::TyTrait {
233233
def_id,
234234
ref substs,
235-
store,
236235
bounds
237236
}) => {
238237
mywrite!(w, "x[{}|", (cx.ds)(def_id));
239238
enc_substs(w, cx, substs);
240-
enc_trait_store(w, cx, store);
241239
let bounds = ty::ParamBounds {builtin_bounds: bounds,
242240
trait_bounds: Vec::new()};
243241
enc_bounds(w, cx, &bounds);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,12 @@ fn check_bounds_on_type_parameters(cx: &mut Context, e: &Expr) {
361361
fn check_trait_cast(cx: &mut Context, source_ty: ty::t, target_ty: ty::t, span: Span) {
362362
check_cast_for_escaping_regions(cx, source_ty, target_ty, span);
363363
match ty::get(target_ty).sty {
364-
ty::ty_trait(box ty::TyTrait { bounds, .. }) => {
365-
check_trait_cast_bounds(cx, span, source_ty, bounds);
366-
}
364+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ ty, .. }) => match ty::get(ty).sty {
365+
ty::ty_trait(box ty::TyTrait { bounds, .. }) => {
366+
check_trait_cast_bounds(cx, span, source_ty, bounds);
367+
}
368+
_ => {}
369+
},
367370
_ => {}
368371
}
369372
}
@@ -530,9 +533,8 @@ pub fn check_cast_for_escaping_regions(
530533
{
531534
// Determine what type we are casting to; if it is not a trait, then no
532535
// worries.
533-
match ty::get(target_ty).sty {
534-
ty::ty_trait(..) => {}
535-
_ => { return; }
536+
if !ty::type_is_trait(target_ty) {
537+
return;
536538
}
537539

538540
// Collect up the regions that appear in the target type. We want to

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,6 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
981981
n_box += 1;
982982
}
983983
ty::ty_uniq(_) |
984-
ty::ty_trait(box ty::TyTrait {
985-
store: ty::UniqTraitStore, ..
986-
}) |
987984
ty::ty_closure(box ty::ClosureTy {
988985
store: ty::UniqTraitStore,
989986
..
@@ -1088,7 +1085,6 @@ fn check_unused_attribute(cx: &Context, attr: &ast::Attribute) {
10881085

10891086
// FIXME: #14406 these are processed in trans, which happens after the
10901087
// lint pass
1091-
"address_insignificant",
10921088
"cold",
10931089
"inline",
10941090
"link",

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ pub enum deref_kind {
174174
pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
175175
match ty::get(t).sty {
176176
ty::ty_uniq(_) |
177-
ty::ty_trait(box ty::TyTrait { store: ty::UniqTraitStore, .. }) |
178177
ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
179178
Some(deref_ptr(OwnedPtr))
180179
}
@@ -183,13 +182,6 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
183182
let kind = ty::BorrowKind::from_mutbl(mt.mutbl);
184183
Some(deref_ptr(BorrowedPtr(kind, r)))
185184
}
186-
ty::ty_trait(box ty::TyTrait {
187-
store: ty::RegionTraitStore(r, mutbl),
188-
..
189-
}) => {
190-
let kind = ty::BorrowKind::from_mutbl(mutbl);
191-
Some(deref_ptr(BorrowedPtr(kind, r)))
192-
}
193185

194186
ty::ty_closure(box ty::ClosureTy {
195187
store: ty::RegionTraitStore(r, _),

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/adt.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,11 @@ impl Case {
292292
fn find_ptr(&self) -> Option<uint> {
293293
self.tys.iter().position(|&ty| {
294294
match ty::get(ty).sty {
295-
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
296-
ty::ty_vec(_, None) | ty::ty_str => false,
295+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
296+
ty::ty_vec(_, None) | ty::ty_str| ty::ty_trait(..) => false,
297297
_ => true,
298298
},
299-
ty::ty_uniq(..) | ty::ty_box(..) |
300-
ty::ty_bare_fn(..) => true,
299+
ty::ty_box(..) | ty::ty_bare_fn(..) => true,
301300
// Is that everything? Would closures or slices qualify?
302301
_ => false
303302
}

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,9 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
17941794
match ty::get(ret_ty).sty {
17951795
// `~` pointer return values never alias because ownership
17961796
// is transferred
1797+
ty::ty_uniq(it) if match ty::get(it).sty {
1798+
ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false
1799+
} => {}
17971800
ty::ty_uniq(_) => {
17981801
attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NoAliasAttribute as u64));
17991802
}
@@ -1803,9 +1806,9 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
18031806
// We can also mark the return value as `nonnull` in certain cases
18041807
match ty::get(ret_ty).sty {
18051808
// These are not really pointers but pairs, (pointer, len)
1806-
ty::ty_rptr(_, ty::mt { ty: it, .. }) |
1809+
ty::ty_uniq(it) |
18071810
ty::ty_rptr(_, ty::mt { ty: it, .. }) if match ty::get(it).sty {
1808-
ty::ty_str | ty::ty_vec(..) => true, _ => false
1811+
ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false
18091812
} => {}
18101813
ty::ty_uniq(_) | ty::ty_rptr(_, _) => {
18111814
attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NonNullAttribute as u64));
@@ -1994,7 +1997,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
19941997
let sym = exported_name(ccx, id, ty, i.attrs.as_slice());
19951998

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

20302033
// Apply the `unnamed_addr` attribute if
20312034
// requested
2032-
if attr::contains_name(i.attrs.as_slice(),
2033-
"address_insignificant") {
2034-
if ccx.reachable.contains(&id) {
2035-
ccx.sess().span_bug(i.span,
2036-
"insignificant static is reachable");
2037-
}
2035+
if !ast_util::static_has_significant_address(
2036+
mutbl,
2037+
i.attrs.as_slice()) {
20382038
lib::llvm::SetUnnamedAddr(g, true);
20392039

20402040
// This is a curious case where we must make
20412041
// all of these statics inlineable. If a
2042-
// global is tagged as
2043-
// address_insignificant, then LLVM won't
2044-
// coalesce globals unless they have an
2045-
// 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
20462045
// external crates cannot use this global.
20472046
// This is a problem for things like inner
20482047
// statics in generic functions, because the
20492048
// function will be inlined into another
20502049
// crate and then attempt to link to the
20512050
// static in the original crate, only to
20522051
// find that it's not there. On the other
2053-
// side of inlininig, the crates knows to
2052+
// side of inlining, the crates knows to
20542053
// not declare this static as
20552054
// available_externally (because it isn't)
20562055
inlineable = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
6767
ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) ||
6868
type_is_newtype_immediate(ccx, ty) || ty::type_is_bot(ty) ||
6969
ty::type_is_simd(tcx, ty);
70-
if simple {
70+
if simple && !ty::type_is_trait(ty) {
7171
return true;
7272
}
7373
match ty::get(ty).sty {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
144144
let dv = match ty::get(t).sty {
145145
ty::ty_ptr(mt) | ty::ty_rptr(_, mt) => {
146146
match ty::get(mt.ty).sty {
147-
ty::ty_vec(_, None) | ty::ty_str => cx.sess().bug("unexpected slice"),
147+
ty::ty_vec(_, None) | ty::ty_str | ty::ty_trait(..) => {
148+
cx.sess().bug("unexpected unsized type")
149+
}
148150
_ => const_deref_ptr(cx, v),
149151
}
150152
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ pub fn appropriate_rvalue_mode(ccx: &CrateContext, ty: ty::t) -> RvalueMode {
157157
* on whether type is immediate or not.
158158
*/
159159

160-
if type_is_zero_size(ccx, ty) {
161-
ByValue
162-
} else if type_is_immediate(ccx, ty) {
160+
if type_is_immediate(ccx, ty) {
163161
ByValue
164162
} else {
165163
ByRef

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ impl TypeMap {
285285
// unique ptr (~) -> {~ :pointee-uid:}
286286
// @-ptr (@) -> {@ :pointee-uid:}
287287
// sized vec ([T, ..x]) -> {[:size:] :element-uid:}
288-
// vec slice (&[T]) -> {&<mut> [] :element-uid:}
289-
// trait (~ | &[mut] T) -> {:sigil: trait_:svh: / :node-id:_<(:param-uid:),*> }
288+
// unsized vec ([T]) -> {[] :element-uid:}
289+
// trait (T) -> {trait_:svh: / :node-id:_<(:param-uid:),*> }
290290
// closure -> {<unsafe_> <once_> :store-sigil: |(:param-uid:),* <,_...>| -> \
291291
// :return-type-uid: : (:bounds:)*}
292292
// function -> {<unsafe_> <abi_> fn( (:param-uid:)* <,_...> ) -> \
@@ -361,18 +361,12 @@ impl TypeMap {
361361
let inner_type_id = self.get_unique_type_id_as_string(inner_type_id);
362362
unique_type_id.push_str(inner_type_id.as_slice());
363363
},
364-
ty::ty_vec(ty::mt { ty: inner_type, mutbl }, optional_length) => {
364+
ty::ty_vec(ty::mt { ty: inner_type, .. }, optional_length) => {
365365
match optional_length {
366366
Some(len) => {
367367
unique_type_id.push_str(format!("[{}]", len).as_slice());
368368
}
369369
None => {
370-
unique_type_id.push_char('&');
371-
372-
if mutbl == ast::MutMutable {
373-
unique_type_id.push_str("mut");
374-
}
375-
376370
unique_type_id.push_str("[]");
377371
}
378372
};
@@ -382,12 +376,6 @@ impl TypeMap {
382376
unique_type_id.push_str(inner_type_id.as_slice());
383377
},
384378
ty::ty_trait(ref trait_data) => {
385-
match trait_data.store {
386-
ty::UniqTraitStore => unique_type_id.push_char('~'),
387-
ty::RegionTraitStore(_, ast::MutMutable) => unique_type_id.push_str("&mut"),
388-
ty::RegionTraitStore(_, ast::MutImmutable) => unique_type_id.push_char('&'),
389-
};
390-
391379
unique_type_id.push_str("trait ");
392380

393381
from_def_id_and_substs(self,
@@ -2901,6 +2889,16 @@ fn type_metadata(cx: &CrateContext,
29012889
let i8_t = ty::mk_i8();
29022890
heap_vec_metadata(cx, pointee_type, i8_t, unique_type_id, usage_site_span)
29032891
}
2892+
ty::ty_trait(box ty::TyTrait {
2893+
def_id,
2894+
ref substs,
2895+
ref bounds
2896+
}) => {
2897+
MetadataCreationResult::new(
2898+
trait_metadata(cx, def_id, t, substs, ty::UniqTraitStore,
2899+
bounds, unique_type_id),
2900+
false)
2901+
}
29042902
_ => {
29052903
let pointee_metadata = type_metadata(cx, pointee_type, usage_site_span);
29062904
return_if_created_in_meantime!();
@@ -2917,6 +2915,17 @@ fn type_metadata(cx: &CrateContext,
29172915
ty::ty_str => {
29182916
vec_slice_metadata(cx, t, ty::mk_i8(), unique_type_id, usage_site_span)
29192917
}
2918+
ty::ty_trait(box ty::TyTrait {
2919+
def_id,
2920+
ref substs,
2921+
ref bounds
2922+
}) => {
2923+
MetadataCreationResult::new(
2924+
trait_metadata(cx, def_id, t, substs,
2925+
ty::RegionTraitStore(ty::ReStatic, mt.mutbl),
2926+
bounds, unique_type_id),
2927+
false)
2928+
}
29202929
_ => {
29212930
let pointee = type_metadata(cx, mt.ty, usage_site_span);
29222931
return_if_created_in_meantime!();
@@ -2930,16 +2939,6 @@ fn type_metadata(cx: &CrateContext,
29302939
ty::ty_closure(ref closurety) => {
29312940
subroutine_type_metadata(cx, unique_type_id, &closurety.sig, usage_site_span)
29322941
}
2933-
ty::ty_trait(box ty::TyTrait {
2934-
def_id,
2935-
ref substs,
2936-
store,
2937-
ref bounds
2938-
}) => {
2939-
MetadataCreationResult::new(
2940-
trait_metadata(cx, def_id, t, substs, store, bounds, unique_type_id),
2941-
false)
2942-
}
29432942
ty::ty_struct(def_id, ref substs) => {
29442943
prepare_struct_metadata(cx,
29452944
t,

0 commit comments

Comments
 (0)