Skip to content

Commit 52017d9

Browse files
committed
---
yaml --- r: 191797 b: refs/heads/snap-stage3 c: c109189 h: refs/heads/master i: 191795: 2223f41 v: v3
1 parent 1fb04dd commit 52017d9

File tree

24 files changed

+350
-579
lines changed

24 files changed

+350
-579
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 809a554fca2d0ebc2ba50077016fe282a4064752
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 0947f4076ddbf5c0db63d60c19f28b6b79023638
4+
refs/heads/snap-stage3: c10918905fda1344e78bc16e6e73294d096ee97d
55
refs/heads/try: ce76bff75603a754d092456285ff455eb871633d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libarena/lib.rs

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

4343
use std::cell::{Cell, RefCell};
4444
use std::cmp;
45-
use std::intrinsics::{TyDesc, get_tydesc};
4645
use std::intrinsics;
46+
#[cfg(stage0)] // SNAP 270a677
47+
use std::intrinsics::{get_tydesc, TyDesc};
4748
use std::marker;
4849
use std::mem;
4950
#[cfg(stage0)]
@@ -186,6 +187,27 @@ fn un_bitpack_tydesc_ptr(p: usize) -> (*const TyDesc, bool) {
186187
((p & !1) as *const TyDesc, p & 1 == 1)
187188
}
188189

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+
189211
impl<'longer_than_self> Arena<'longer_than_self> {
190212
fn chunk_size(&self) -> usize {
191213
self.copy_head.borrow().capacity()

branches/snap-stage3/src/libcore/intrinsics.rs

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

4545
use marker::Sized;
4646

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

4950
#[lang="ty_desc"]
5051
#[derive(Copy)]
52+
#[cfg(stage0)] // SNAP 270a677
5153
pub struct TyDesc {
5254
// sizeof(T)
5355
pub size: usize,
@@ -197,8 +199,13 @@ extern "rust-intrinsic" {
197199
pub fn pref_align_of<T>() -> usize;
198200

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

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+
202209
/// Gets an identifier which is globally unique to the specified type. This
203210
/// function will return the same value for a type regardless of whichever
204211
/// crate it is invoked in.

branches/snap-stage3/src/librustc/middle/lang_items.rs

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

317317
StartFnLangItem, "start", start_fn;
318318

319-
TyDescStructLangItem, "ty_desc", ty_desc;
320-
OpaqueStructLangItem, "opaque", opaque;
321-
322319
EhPersonalityLangItem, "eh_personality", eh_personality;
323320

324321
ExchangeHeapLangItem, "exchange_heap", exchange_heap;

branches/snap-stage3/src/librustc/middle/ty.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ 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};
51-
use middle::lang_items::{FnOnceTraitLangItem, TyDescStructLangItem};
50+
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
5251
use middle::mem_categorization as mc;
5352
use middle::region;
5453
use middle::resolve_lifetime;
@@ -724,7 +723,6 @@ pub struct ctxt<'tcx> {
724723
pub object_cast_map: ObjectCastMap<'tcx>,
725724

726725
pub map: ast_map::Map<'tcx>,
727-
pub intrinsic_defs: RefCell<DefIdMap<Ty<'tcx>>>,
728726
pub freevars: RefCell<FreevarMap>,
729727
pub tcache: RefCell<DefIdMap<TypeScheme<'tcx>>>,
730728
pub rcache: RefCell<FnvHashMap<creader_cache_key, Ty<'tcx>>>,
@@ -2576,7 +2574,6 @@ pub fn mk_ctxt<'tcx>(s: Session,
25762574
super_predicates: RefCell::new(DefIdMap()),
25772575
object_cast_map: RefCell::new(NodeMap()),
25782576
map: map,
2579-
intrinsic_defs: RefCell::new(DefIdMap()),
25802577
freevars: freevars,
25812578
tcache: RefCell::new(DefIdMap()),
25822579
rcache: RefCell::new(FnvHashMap()),
@@ -5975,13 +5972,6 @@ pub fn required_region_bounds<'tcx>(tcx: &ctxt<'tcx>,
59755972
.collect()
59765973
}
59775974

5978-
pub fn get_tydesc_ty<'tcx>(tcx: &ctxt<'tcx>) -> Result<Ty<'tcx>, String> {
5979-
tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
5980-
tcx.intrinsic_defs.borrow().get(&tydesc_lang_item).cloned()
5981-
.expect("Failed to resolve TyDesc")
5982-
})
5983-
}
5984-
59855975
pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
59865976
lookup_locally_or_in_crate_store(
59875977
"item_variance_map", item_id, &mut *tcx.item_variance_map.borrow_mut(),

branches/snap-stage3/src/librustc/util/ppaux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,10 +1053,11 @@ 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: {}, fty: {}, \
1056+
format!("method(name: {}, generics: {}, predicates: {}, fty: {}, \
10571057
explicit_self: {}, vis: {}, def_id: {})",
10581058
self.name.repr(tcx),
10591059
self.generics.repr(tcx),
1060+
self.predicates.repr(tcx),
10601061
self.fty.repr(tcx),
10611062
self.explicit_self.repr(tcx),
10621063
self.vis.repr(tcx),

branches/snap-stage3/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 vt = tvec::vec_types(bcx, ty::sequence_element_type(bcx.tcx(), ty::type_content(vec_ty)));
663+
let unit_ty = 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: vt.unit_ty, mutbl: ast::MutImmutable});
672+
ty::mt {ty: 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/snap-stage3/src/librustc_trans/trans/base.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ 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::{tydesc_info, type_is_immediate};
61-
use trans::common::{type_is_zero_size, val_ty};
60+
use trans::common::{type_is_immediate, type_is_zero_size, val_ty};
6261
use trans::common;
6362
use trans::consts;
6463
use trans::context::SharedCrateContext;
@@ -90,7 +89,6 @@ use std::ffi::{CStr, CString};
9089
use std::cell::{Cell, RefCell};
9190
use std::collections::HashSet;
9291
use std::mem;
93-
use std::rc::Rc;
9492
use std::str;
9593
use std::{i8, i16, i32, i64};
9694
use syntax::abi::{Rust, RustCall, RustIntrinsic, Abi};
@@ -392,22 +390,6 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
392390
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
393391
}
394392

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-
411393
#[allow(dead_code)] // useful
412394
pub fn set_optimize_for_size(f: ValueRef) {
413395
llvm::SetFunctionAttribute(f, llvm::OptimizeForSizeAttribute)
@@ -702,6 +684,10 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
702684
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
703685
cx = tvec::iter_vec_raw(cx, base, unit_ty, len, f);
704686
}
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+
}
705691
ty::ty_tup(ref args) => {
706692
let repr = adt::represent_type(cx.ccx(), t);
707693
for (i, arg) in args.iter().enumerate() {
@@ -3133,7 +3119,6 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
31333119
}
31343120

31353121
for ccx in shared_ccx.iter() {
3136-
glue::emit_tydescs(&ccx);
31373122
if ccx.sess().opts.debuginfo != NoDebugInfo {
31383123
debuginfo::finalize(&ccx);
31393124
}
@@ -3145,7 +3130,6 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
31453130
if shared_ccx.sess().trans_stats() {
31463131
let stats = shared_ccx.stats();
31473132
println!("--- trans stats ---");
3148-
println!("n_static_tydescs: {}", stats.n_static_tydescs.get());
31493133
println!("n_glues_created: {}", stats.n_glues_created.get());
31503134
println!("n_null_glues: {}", stats.n_null_glues.get());
31513135
println!("n_real_glues: {}", stats.n_real_glues.get());

branches/snap-stage3/src/librustc_trans/trans/common.rs

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use arena::TypedArena;
4646
use libc::{c_uint, c_char};
4747
use std::ffi::CString;
4848
use std::cell::{Cell, RefCell};
49+
use std::result::Result as StdResult;
4950
use std::vec::Vec;
5051
use syntax::ast::Ident;
5152
use syntax::ast;
@@ -316,15 +317,6 @@ pub fn gensym_name(name: &str) -> PathElem {
316317
PathName(token::gensym(&format!("{}:{}", name, num)))
317318
}
318319

319-
#[derive(Copy)]
320-
pub struct tydesc_info<'tcx> {
321-
pub ty: Ty<'tcx>,
322-
pub tydesc: ValueRef,
323-
pub size: ValueRef,
324-
pub align: ValueRef,
325-
pub name: ValueRef,
326-
}
327-
328320
/*
329321
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
330322
*
@@ -1006,9 +998,9 @@ pub fn expr_ty_adjusted<'blk, 'tcx>(bcx: &BlockS<'blk, 'tcx>, ex: &ast::Expr) ->
1006998
/// do not (necessarily) resolve all nested obligations on the impl. Note that type check should
1007999
/// guarantee to us that all nested obligations *could be* resolved if we wanted to.
10081000
pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1009-
span: Span,
1010-
trait_ref: ty::PolyTraitRef<'tcx>)
1011-
-> traits::Vtable<'tcx, ()>
1001+
span: Span,
1002+
trait_ref: ty::PolyTraitRef<'tcx>)
1003+
-> traits::Vtable<'tcx, ()>
10121004
{
10131005
let tcx = ccx.tcx();
10141006

@@ -1067,7 +1059,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
10671059
let vtable = selection.map_move_nested(|predicate| {
10681060
fulfill_cx.register_predicate_obligation(&infcx, predicate);
10691061
});
1070-
let vtable = drain_fulfillment_cx(span, &infcx, &mut fulfill_cx, &vtable);
1062+
let vtable = drain_fulfillment_cx_or_panic(span, &infcx, &mut fulfill_cx, &vtable);
10711063

10721064
info!("Cache miss: {}", trait_ref.repr(ccx.tcx()));
10731065
ccx.trait_cache().borrow_mut().insert(trait_ref,
@@ -1076,6 +1068,22 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
10761068
vtable
10771069
}
10781070

1071+
pub fn predicates_hold<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1072+
predicates: Vec<ty::Predicate<'tcx>>)
1073+
-> bool
1074+
{
1075+
debug!("predicates_hold(predicates={})",
1076+
predicates.repr(ccx.tcx()));
1077+
1078+
let infcx = infer::new_infer_ctxt(ccx.tcx());
1079+
let mut fulfill_cx = traits::FulfillmentContext::new();
1080+
for predicate in predicates {
1081+
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(), predicate);
1082+
fulfill_cx.register_predicate_obligation(&infcx, obligation);
1083+
}
1084+
drain_fulfillment_cx(DUMMY_SP, &infcx, &mut fulfill_cx, &()).is_ok()
1085+
}
1086+
10791087
pub struct NormalizingClosureTyper<'a,'tcx:'a> {
10801088
param_env: ty::ParameterEnvironment<'a, 'tcx>
10811089
}
@@ -1123,11 +1131,36 @@ impl<'a,'tcx> ty::ClosureTyper<'tcx> for NormalizingClosureTyper<'a,'tcx> {
11231131
}
11241132
}
11251133

1134+
pub fn drain_fulfillment_cx_or_panic<'a,'tcx,T>(span: Span,
1135+
infcx: &infer::InferCtxt<'a,'tcx>,
1136+
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
1137+
result: &T)
1138+
-> T
1139+
where T : TypeFoldable<'tcx> + Repr<'tcx>
1140+
{
1141+
match drain_fulfillment_cx(span, infcx, fulfill_cx, result) {
1142+
Ok(v) => v,
1143+
Err(errors) => {
1144+
infcx.tcx.sess.span_bug(
1145+
span,
1146+
&format!("Encountered errors `{}` fulfilling during trans",
1147+
errors.repr(infcx.tcx)));
1148+
}
1149+
}
1150+
}
1151+
1152+
/// Finishes processes any obligations that remain in the fulfillment
1153+
/// context, and then "freshens" and returns `result`. This is
1154+
/// primarily used during normalization and other cases where
1155+
/// processing the obligations in `fulfill_cx` may cause type
1156+
/// inference variables that appear in `result` to be unified, and
1157+
/// hence we need to process those obligations to get the complete
1158+
/// picture of the type.
11261159
pub fn drain_fulfillment_cx<'a,'tcx,T>(span: Span,
1127-
infcx: &infer::InferCtxt<'a,'tcx>,
1128-
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
1129-
result: &T)
1130-
-> T
1160+
infcx: &infer::InferCtxt<'a,'tcx>,
1161+
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
1162+
result: &T)
1163+
-> StdResult<T,Vec<traits::FulfillmentError<'tcx>>>
11311164
where T : TypeFoldable<'tcx> + Repr<'tcx>
11321165
{
11331166
debug!("drain_fulfillment_cx(result={})",
@@ -1140,16 +1173,13 @@ pub fn drain_fulfillment_cx<'a,'tcx,T>(span: Span,
11401173
match fulfill_cx.select_all_or_error(infcx, &typer) {
11411174
Ok(()) => { }
11421175
Err(errors) => {
1176+
// We always want to surface any overflow errors, no matter what.
11431177
if errors.iter().all(|e| e.is_overflow()) {
1144-
// See Ok(None) case above.
11451178
infcx.tcx.sess.span_fatal(
11461179
span,
11471180
"reached the recursion limit during monomorphization");
11481181
} else {
1149-
infcx.tcx.sess.span_bug(
1150-
span,
1151-
&format!("Encountered errors `{}` fulfilling during trans",
1152-
errors.repr(infcx.tcx)));
1182+
return Err(errors);
11531183
}
11541184
}
11551185
}
@@ -1159,7 +1189,7 @@ pub fn drain_fulfillment_cx<'a,'tcx,T>(span: Span,
11591189
// sort of overkill because we do not expect there to be any
11601190
// unbound type variables, hence no `TyFresh` types should ever be
11611191
// inserted.
1162-
result.fold_with(&mut infcx.freshener())
1192+
Ok(result.fold_with(&mut infcx.freshener()))
11631193
}
11641194

11651195
// Key used to lookup values supplied for type parameters in an expr.

branches/snap-stage3/src/librustc_trans/trans/consts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
317317
let info =
318318
expr::unsized_info(
319319
cx, k, e.id, ty, param_substs,
320-
|t| ty::mk_imm_rptr(cx.tcx(), cx.tcx().mk_region(ty::ReStatic), t),
321320
|| const_get_elt(cx, llconst, &[abi::FAT_PTR_EXTRA as u32]));
322321

323322
let unsized_ty = ty::unsize_ty(cx.tcx(), ty, k, e.span);

0 commit comments

Comments
 (0)