Skip to content

Commit c0a28c9

Browse files
committed
---
yaml --- r: 225990 b: refs/heads/stable c: d8952e7 h: refs/heads/master v: v3
1 parent f5e7e56 commit c0a28c9

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
@@ -29,6 +29,6 @@ refs/heads/tmp: e5d90d98402475b6e154ce216f9efcb80da1a747
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 1fe32ca12c51afcd761d9962f51a74ff0d07a591
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 6061707348ada3245de306c9d38d07250293e58e
32+
refs/heads/stable: d8952e7932823a3f3aa9d4af0ab9fa6f08b18cef
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b

branches/stable/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/stable/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)