Skip to content

Commit c94db78

Browse files
committed
---
yaml --- r: 214184 b: refs/heads/auto c: d8952e7 h: refs/heads/master v: v3
1 parent d536b3e commit c94db78

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 6061707348ada3245de306c9d38d07250293e58e
11+
refs/heads/auto: d8952e7932823a3f3aa9d4af0ab9fa6f08b18cef
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#![feature(ref_slice)]
5252
#![feature(rustc_diagnostic_macros)]
5353
#![feature(rustc_private)]
54+
#![feature(scoped_tls)]
5455
#![feature(slice_bytes)]
5556
#![feature(slice_extras)]
5657
#![feature(slice_patterns)]

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,29 @@ impl<'tcx> ctxt<'tcx> {
804804
}
805805
}
806806

807+
pub mod tls {
808+
use middle::ty;
809+
use session::Session;
810+
811+
/// Marker type used for the scoped TLS slot.
812+
/// The type context cannot be used directly because the scoped TLS
813+
/// in libstd doesn't allow types generic over lifetimes.
814+
struct ThreadLocalTyCx;
815+
816+
scoped_thread_local!(static TLS_TCX: ThreadLocalTyCx);
817+
818+
pub fn enter<'tcx, F: FnOnce(&ty::ctxt<'tcx>) -> R, R>(tcx: ty::ctxt<'tcx>, f: F)
819+
-> (Session, R) {
820+
let tls_ptr = &tcx as *const _ as *const ThreadLocalTyCx;
821+
let result = TLS_TCX.set(unsafe { &*tls_ptr }, || f(&tcx));
822+
(tcx.sess, result)
823+
}
824+
825+
pub fn with<F: FnOnce(&ty::ctxt) -> R, R>(f: F) -> R {
826+
TLS_TCX.with(|tcx| f(unsafe { &*(tcx as *const _ as *const ty::ctxt) }))
827+
}
828+
}
829+
807830
// Flags that we track on types. These flags are propagated upwards
808831
// through the type during type construction, so that we can quickly
809832
// check whether the type has various kinds of types in it without
@@ -2824,7 +2847,7 @@ pub fn with_ctxt<'tcx, F, R>(s: Session,
28242847
let mut interner = FnvHashMap();
28252848
let common_types = CommonTypes::new(&arenas.type_, &mut interner);
28262849

2827-
let tcx = ctxt {
2850+
tls::enter(ctxt {
28282851
arenas: arenas,
28292852
interner: RefCell::new(interner),
28302853
substs_interner: RefCell::new(FnvHashMap()),
@@ -2886,9 +2909,7 @@ pub fn with_ctxt<'tcx, F, R>(s: Session,
28862909
const_qualif_map: RefCell::new(NodeMap()),
28872910
custom_coerce_unsized_kinds: RefCell::new(DefIdMap()),
28882911
cast_kinds: RefCell::new(NodeMap()),
2889-
};
2890-
let result = f(&tcx);
2891-
(tcx.sess, result)
2912+
}, f)
28922913
}
28932914

28942915
// Type constructors

0 commit comments

Comments
 (0)