Skip to content

Commit e46bf62

Browse files
committed
---
yaml --- r: 193895 b: refs/heads/beta c: 1b0f0ad h: refs/heads/master i: 193893: 619e3e8 193891: a62def6 193887: 213897c v: v3
1 parent debf877 commit e46bf62

File tree

30 files changed

+597
-450
lines changed

30 files changed

+597
-450
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: 1ae32decb87e3275ce955383a5c71e5c784a0216
34+
refs/heads/beta: 1b0f0ad28070c072f68ea0ab10bbae61b52706a8
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: de8a23bbc3a7b9cbd7574b5b91a34af59bf030e6

branches/beta/src/libarena/lib.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ extern crate alloc;
4242

4343
use std::cell::{Cell, RefCell};
4444
use std::cmp;
45+
use std::intrinsics::{TyDesc, get_tydesc};
4546
use std::intrinsics;
46-
#[cfg(stage0)] // SNAP 270a677
47-
use std::intrinsics::{get_tydesc, TyDesc};
4847
use std::marker;
4948
use std::mem;
5049
#[cfg(stage0)]
@@ -187,27 +186,6 @@ fn un_bitpack_tydesc_ptr(p: usize) -> (*const TyDesc, bool) {
187186
((p & !1) as *const TyDesc, p & 1 == 1)
188187
}
189188

190-
// HACK(eddyb) TyDesc replacement using a trait object vtable.
191-
// This could be replaced in the future with a custom DST layout,
192-
// or `&'static (drop_glue, size, align)` created by a `const fn`.
193-
#[cfg(not(stage0))] // SNAP 270a677
194-
struct TyDesc {
195-
drop_glue: fn(*const i8),
196-
size: usize,
197-
align: usize
198-
}
199-
200-
#[cfg(not(stage0))] // SNAP 270a677
201-
unsafe fn get_tydesc<T>() -> *const TyDesc {
202-
use std::raw::TraitObject;
203-
204-
let ptr = &*(1 as *const T);
205-
206-
// Can use any trait that is implemented for all types.
207-
let obj = mem::transmute::<&marker::MarkerTrait, TraitObject>(ptr);
208-
obj.vtable as *const TyDesc
209-
}
210-
211189
impl<'longer_than_self> Arena<'longer_than_self> {
212190
fn chunk_size(&self) -> usize {
213191
self.copy_head.borrow().capacity()

branches/beta/src/libcore/intrinsics.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@
4444

4545
use marker::Sized;
4646

47-
#[cfg(stage0)] // SNAP 270a677
4847
pub type GlueFn = extern "Rust" fn(*const i8);
4948

5049
#[lang="ty_desc"]
5150
#[derive(Copy)]
52-
#[cfg(stage0)] // SNAP 270a677
5351
pub struct TyDesc {
5452
// sizeof(T)
5553
pub size: usize,
@@ -199,13 +197,8 @@ extern "rust-intrinsic" {
199197
pub fn pref_align_of<T>() -> usize;
200198

201199
/// Get a static pointer to a type descriptor.
202-
#[cfg(stage0)] // SNAP 270a677
203200
pub fn get_tydesc<T: ?Sized>() -> *const TyDesc;
204201

205-
/// Gets a static string slice containing the name of a type.
206-
#[cfg(not(stage0))] // SNAP 270a677
207-
pub fn type_name<T: ?Sized>() -> &'static str;
208-
209202
/// Gets an identifier which is globally unique to the specified type. This
210203
/// function will return the same value for a type regardless of whichever
211204
/// crate it is invoked in.

branches/beta/src/librustc/middle/infer/bivariate.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@ impl<'f, 'tcx> Combine<'tcx> for Bivariate<'f, 'tcx> {
7474
Ok(a)
7575
}
7676

77-
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
78-
debug!("mts({} <: {})",
79-
a.repr(self.fields.infcx.tcx),
80-
b.repr(self.fields.infcx.tcx));
81-
82-
if a.mutbl != b.mutbl { return Err(ty::terr_mutability); }
83-
let t = try!(self.tys(a.ty, b.ty));
84-
Ok(ty::mt { mutbl: a.mutbl, ty: t })
85-
}
86-
8777
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
8878
if a != b {
8979
Err(ty::terr_unsafety_mismatch(expected_found(self, a, b)))

branches/beta/src/librustc/middle/infer/combine.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,24 @@ pub trait Combine<'tcx> : Sized {
7474
fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields().clone()) }
7575
fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields().clone()) }
7676

77-
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>>;
77+
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
78+
debug!("{}.mts({}, {})",
79+
self.tag(),
80+
a.repr(self.tcx()),
81+
b.repr(self.tcx()));
82+
83+
if a.mutbl != b.mutbl {
84+
Err(ty::terr_mutability)
85+
} else {
86+
let mutbl = a.mutbl;
87+
let variance = match mutbl {
88+
ast::MutImmutable => ty::Covariant,
89+
ast::MutMutable => ty::Invariant,
90+
};
91+
let ty = try!(self.tys_with_variance(variance, a.ty, b.ty));
92+
Ok(ty::mt {ty: ty, mutbl: mutbl})
93+
}
94+
}
7895

7996
fn tys_with_variance(&self, variance: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
8097
-> cres<'tcx, Ty<'tcx>>;

branches/beta/src/librustc/middle/infer/equate.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> {
5454
Ok(a)
5555
}
5656

57-
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
58-
debug!("mts({} <: {})",
59-
a.repr(self.fields.infcx.tcx),
60-
b.repr(self.fields.infcx.tcx));
61-
62-
if a.mutbl != b.mutbl { return Err(ty::terr_mutability); }
63-
let t = try!(self.tys(a.ty, b.ty));
64-
Ok(ty::mt { mutbl: a.mutbl, ty: t })
65-
}
6657

6758
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
6859
if a != b {

branches/beta/src/librustc/middle/infer/glb.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,6 @@ impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> {
5555
}
5656
}
5757

58-
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
59-
let tcx = self.fields.infcx.tcx;
60-
61-
debug!("{}.mts({}, {})",
62-
self.tag(),
63-
mt_to_string(tcx, a),
64-
mt_to_string(tcx, b));
65-
66-
match (a.mutbl, b.mutbl) {
67-
// If one side or both is mut, then the GLB must use
68-
// the precise type from the mut side.
69-
(MutMutable, MutMutable) => {
70-
let t = try!(self.equate().tys(a.ty, b.ty));
71-
Ok(ty::mt {ty: t, mutbl: MutMutable})
72-
}
73-
74-
// If one side or both is immutable, we can use the GLB of
75-
// both sides but mutbl must be `MutImmutable`.
76-
(MutImmutable, MutImmutable) => {
77-
let t = try!(self.tys(a.ty, b.ty));
78-
Ok(ty::mt {ty: t, mutbl: MutImmutable})
79-
}
80-
81-
// There is no mutual subtype of these combinations.
82-
(MutMutable, MutImmutable) |
83-
(MutImmutable, MutMutable) => {
84-
Err(ty::terr_mutability)
85-
}
86-
}
87-
}
8858

8959
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
9060
match (a, b) {

branches/beta/src/librustc/middle/infer/lub.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,6 @@ impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> {
5555
}
5656
}
5757

58-
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
59-
let tcx = self.tcx();
60-
61-
debug!("{}.mts({}, {})",
62-
self.tag(),
63-
mt_to_string(tcx, a),
64-
mt_to_string(tcx, b));
65-
66-
if a.mutbl != b.mutbl {
67-
return Err(ty::terr_mutability)
68-
}
69-
70-
let m = a.mutbl;
71-
match m {
72-
MutImmutable => {
73-
let t = try!(self.tys(a.ty, b.ty));
74-
Ok(ty::mt {ty: t, mutbl: m})
75-
}
76-
77-
MutMutable => {
78-
let t = try!(self.equate().tys(a.ty, b.ty));
79-
Ok(ty::mt {ty: t, mutbl: m})
80-
}
81-
}
82-
}
83-
8458
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
8559
match (a, b) {
8660
(Unsafety::Unsafe, _) | (_, Unsafety::Unsafe) => Ok(Unsafety::Unsafe),

branches/beta/src/librustc/middle/infer/sub.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,6 @@ impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> {
6666
Ok(a)
6767
}
6868

69-
fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
70-
debug!("mts({} <: {})",
71-
a.repr(self.tcx()),
72-
b.repr(self.tcx()));
73-
74-
if a.mutbl != b.mutbl {
75-
return Err(ty::terr_mutability);
76-
}
77-
78-
match b.mutbl {
79-
MutMutable => {
80-
// If supertype is mut, subtype must match exactly
81-
// (i.e., invariant if mut):
82-
try!(self.equate().tys(a.ty, b.ty));
83-
}
84-
MutImmutable => {
85-
// Otherwise we can be covariant:
86-
try!(self.tys(a.ty, b.ty));
87-
}
88-
}
89-
90-
Ok(*a) // return is meaningless in sub, just return *a
91-
}
92-
9369
fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
9470
self.lub().unsafeties(a, b).compare(b, || {
9571
ty::terr_unsafety_mismatch(expected_found(self, a, b))

branches/beta/src/librustc/middle/lang_items.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ lets_do_this! {
316316

317317
StartFnLangItem, "start", start_fn;
318318

319+
TyDescStructLangItem, "ty_desc", ty_desc;
320+
OpaqueStructLangItem, "opaque", opaque;
321+
319322
EhPersonalityLangItem, "eh_personality", eh_personality;
320323

321324
ExchangeHeapLangItem, "exchange_heap", exchange_heap;

branches/beta/src/librustc/middle/ty.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ use middle::check_const;
4747
use middle::const_eval;
4848
use middle::def::{self, DefMap, ExportMap};
4949
use middle::dependency_format;
50-
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
50+
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem};
51+
use middle::lang_items::{FnOnceTraitLangItem, TyDescStructLangItem};
5152
use middle::mem_categorization as mc;
5253
use middle::region;
5354
use middle::resolve_lifetime;
@@ -722,6 +723,7 @@ pub struct ctxt<'tcx> {
722723
pub object_cast_map: ObjectCastMap<'tcx>,
723724

724725
pub map: ast_map::Map<'tcx>,
726+
pub intrinsic_defs: RefCell<DefIdMap<Ty<'tcx>>>,
725727
pub freevars: RefCell<FreevarMap>,
726728
pub tcache: RefCell<DefIdMap<TypeScheme<'tcx>>>,
727729
pub rcache: RefCell<FnvHashMap<creader_cache_key, Ty<'tcx>>>,
@@ -2573,6 +2575,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
25732575
super_predicates: RefCell::new(DefIdMap()),
25742576
object_cast_map: RefCell::new(NodeMap()),
25752577
map: map,
2578+
intrinsic_defs: RefCell::new(DefIdMap()),
25762579
freevars: freevars,
25772580
tcache: RefCell::new(DefIdMap()),
25782581
rcache: RefCell::new(FnvHashMap()),
@@ -5948,6 +5951,13 @@ pub fn required_region_bounds<'tcx>(tcx: &ctxt<'tcx>,
59485951
.collect()
59495952
}
59505953

5954+
pub fn get_tydesc_ty<'tcx>(tcx: &ctxt<'tcx>) -> Result<Ty<'tcx>, String> {
5955+
tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
5956+
tcx.intrinsic_defs.borrow().get(&tydesc_lang_item).cloned()
5957+
.expect("Failed to resolve TyDesc")
5958+
})
5959+
}
5960+
59515961
pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
59525962
lookup_locally_or_in_crate_store(
59535963
"item_variance_map", item_id, &mut *tcx.item_variance_map.borrow_mut(),

branches/beta/src/librustc/util/ppaux.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,10 @@ impl<'tcx> Repr<'tcx> for ty::Variance {
10531053

10541054
impl<'tcx> Repr<'tcx> for ty::Method<'tcx> {
10551055
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
1056-
format!("method(name: {}, generics: {}, predicates: {}, fty: {}, \
1056+
format!("method(name: {}, generics: {}, fty: {}, \
10571057
explicit_self: {}, vis: {}, def_id: {})",
10581058
self.name.repr(tcx),
10591059
self.generics.repr(tcx),
1060-
self.predicates.repr(tcx),
10611060
self.fty.repr(tcx),
10621061
self.explicit_self.repr(tcx),
10631062
self.vis.repr(tcx),

branches/beta/src/librustc_trans/trans/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ fn bind_subslice_pat(bcx: Block,
660660
offset_right: uint) -> ValueRef {
661661
let _icx = push_ctxt("match::bind_subslice_pat");
662662
let vec_ty = node_id_type(bcx, pat_id);
663-
let unit_ty = ty::sequence_element_type(bcx.tcx(), ty::type_content(vec_ty));
663+
let vt = tvec::vec_types(bcx, ty::sequence_element_type(bcx.tcx(), ty::type_content(vec_ty)));
664664
let vec_datum = match_datum(val, vec_ty);
665665
let (base, len) = vec_datum.get_vec_base_and_len(bcx);
666666

@@ -669,7 +669,7 @@ fn bind_subslice_pat(bcx: Block,
669669
let slice_len = Sub(bcx, len, slice_len_offset, DebugLoc::None);
670670
let slice_ty = ty::mk_slice(bcx.tcx(),
671671
bcx.tcx().mk_region(ty::ReStatic),
672-
ty::mt {ty: unit_ty, mutbl: ast::MutImmutable});
672+
ty::mt {ty: vt.unit_ty, mutbl: ast::MutImmutable});
673673
let scratch = rvalue_scratch_datum(bcx, slice_ty, "");
674674
Store(bcx, slice_begin,
675675
GEPi(bcx, scratch.val, &[0, abi::FAT_PTR_ADDR]));

branches/beta/src/librustc_trans/trans/base.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ use trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_undef};
5757
use trans::common::{CrateContext, ExternMap, FunctionContext};
5858
use trans::common::{Result, NodeIdAndSpan};
5959
use trans::common::{node_id_type, return_type_is_void};
60-
use trans::common::{type_is_immediate, type_is_zero_size, val_ty};
60+
use trans::common::{tydesc_info, type_is_immediate};
61+
use trans::common::{type_is_zero_size, val_ty};
6162
use trans::common;
6263
use trans::consts;
6364
use trans::context::SharedCrateContext;
@@ -89,6 +90,7 @@ use std::ffi::{CStr, CString};
8990
use std::cell::{Cell, RefCell};
9091
use std::collections::HashSet;
9192
use std::mem;
93+
use std::rc::Rc;
9294
use std::str;
9395
use std::{i8, i16, i32, i64};
9496
use syntax::abi::{Rust, RustCall, RustIntrinsic, Abi};
@@ -390,6 +392,22 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
390392
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
391393
}
392394

395+
// Type descriptor and type glue stuff
396+
397+
pub fn get_tydesc<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
398+
t: Ty<'tcx>) -> Rc<tydesc_info<'tcx>> {
399+
match ccx.tydescs().borrow().get(&t) {
400+
Some(inf) => return inf.clone(),
401+
_ => { }
402+
}
403+
404+
ccx.stats().n_static_tydescs.set(ccx.stats().n_static_tydescs.get() + 1);
405+
let inf = Rc::new(glue::declare_tydesc(ccx, t));
406+
407+
ccx.tydescs().borrow_mut().insert(t, inf.clone());
408+
inf
409+
}
410+
393411
#[allow(dead_code)] // useful
394412
pub fn set_optimize_for_size(f: ValueRef) {
395413
llvm::SetFunctionAttribute(f, llvm::OptimizeForSizeAttribute)
@@ -684,10 +702,6 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
684702
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
685703
cx = tvec::iter_vec_raw(cx, base, unit_ty, len, f);
686704
}
687-
ty::ty_vec(_, None) | ty::ty_str => {
688-
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
689-
cx = tvec::iter_vec_raw(cx, data_ptr, unit_ty, info.unwrap(), f);
690-
}
691705
ty::ty_tup(ref args) => {
692706
let repr = adt::represent_type(cx.ccx(), t);
693707
for (i, arg) in args.iter().enumerate() {
@@ -3119,6 +3133,7 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
31193133
}
31203134

31213135
for ccx in shared_ccx.iter() {
3136+
glue::emit_tydescs(&ccx);
31223137
if ccx.sess().opts.debuginfo != NoDebugInfo {
31233138
debuginfo::finalize(&ccx);
31243139
}
@@ -3130,6 +3145,7 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
31303145
if shared_ccx.sess().trans_stats() {
31313146
let stats = shared_ccx.stats();
31323147
println!("--- trans stats ---");
3148+
println!("n_static_tydescs: {}", stats.n_static_tydescs.get());
31333149
println!("n_glues_created: {}", stats.n_glues_created.get());
31343150
println!("n_null_glues: {}", stats.n_null_glues.get());
31353151
println!("n_real_glues: {}", stats.n_real_glues.get());

0 commit comments

Comments
 (0)