Skip to content

Commit 8fd4500

Browse files
committed
wip
1 parent d580377 commit 8fd4500

File tree

10 files changed

+228
-146
lines changed

10 files changed

+228
-146
lines changed

src/Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/job.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ pub unsafe fn setup(build: &mut Build) {
126126
// during startup or terminating abnormally). This is important for running tests,
127127
// since some of them use abnormal termination by design.
128128
// This mode is inherited by all child processes.
129-
let mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
130-
SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
129+
//let mode = SetErrorMode(SEM_NOGPFAULTERRORBOX); // read inherited flags
130+
SetErrorMode(0);
131131

132132
// Create a new job object for us to use
133133
let job = CreateJobObjectW(0 as *mut _, 0 as *const _);

src/librustc/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ graphviz = { path = "../libgraphviz" }
1616
jobserver = "0.1"
1717
log = "0.3"
1818
rayon = { git = "https://github.com/Zoxc/rayon.git", branch = "fiber" }
19-
rayon-core = { git = "https://github.com/Zoxc/rayon.git", branch = "fiber" }
19+
rayon-core = { git = "https://github.com/Zoxc/rayon.git", branch = "fiber", features=["debug"] }
2020
scoped-tls = { git = "https://github.com/Zoxc/scoped-tls.git", features=["nightly"] }
2121
owning_ref = { git = "https://github.com/Zoxc/owning-ref-rs.git" }
2222
rustc_back = { path = "../librustc_back" }
@@ -26,6 +26,7 @@ rustc_errors = { path = "../librustc_errors" }
2626
serialize = { path = "../libserialize" }
2727
syntax = { path = "../libsyntax" }
2828
syntax_pos = { path = "../libsyntax_pos" }
29+
lazy_static = "1.0.0"
2930

3031
# Note that these dependencies are a lie, they're just here to get linkage to
3132
# work.

src/librustc/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
435435
ref fresh_tables,
436436
} = *self;
437437
let in_progress_tables = fresh_tables.as_ref();
438-
global_tcx.enter_local(arena, |tcx| f(InferCtxt {
438+
global_tcx.enter_local(arena, global_tcx.query(), |tcx| f(InferCtxt {
439439
tcx,
440440
in_progress_tables,
441441
projection_cache: RefCell::new(traits::ProjectionCache::new()),

src/librustc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#![feature(i128_type)]
5252
#![feature(inclusive_range)]
5353
#![feature(inclusive_range_syntax)]
54+
#![feature(iterator_step_by)]
5455
#![cfg_attr(windows, feature(libc))]
5556
#![feature(macro_vis_matcher)]
5657
#![feature(match_default_bindings)]
@@ -79,6 +80,7 @@ extern crate libc;
7980
extern crate owning_ref;
8081
extern crate rustc_back;
8182
#[macro_use] extern crate rustc_data_structures;
83+
#[macro_use] extern crate lazy_static;
8284
extern crate serialize;
8385
extern crate rustc_const_math;
8486
extern crate rustc_errors as errors;

src/librustc/ty/context.rs

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@ impl<'tcx> CommonTypes<'tcx> {
778778
#[derive(Copy, Clone)]
779779
pub struct TyCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
780780
gcx: &'a GlobalCtxt<'gcx>,
781-
interners: &'a CtxtInterners<'tcx>
781+
interners: &'a CtxtInterners<'tcx>,
782+
query: &'a maps::QueryJob<'gcx>,
782783
}
783784

784785
impl<'a, 'gcx, 'tcx> Deref for TyCtxt<'a, 'gcx, 'tcx> {
@@ -881,18 +882,32 @@ pub struct GlobalCtxt<'tcx> {
881882
output_filenames: Arc<OutputFilenames>,
882883
}
883884

884-
impl<'tcx> GlobalCtxt<'tcx> {
885-
/// Get the global TyCtxt.
886-
pub fn global_tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
885+
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
886+
pub fn query(self) -> &'a maps::QueryJob<'gcx> {
887+
self.query
888+
}
889+
890+
pub fn with_query<'b>(self,
891+
query: &'b maps::QueryJob<'gcx>)
892+
-> TyCtxt<'b, 'gcx, 'tcx>
893+
where 'a: 'b
894+
{
887895
TyCtxt {
888-
gcx: self,
889-
interners: &self.global_interners
896+
gcx: self.gcx,
897+
interners: self.interners,
898+
query,
890899
}
891900
}
892-
}
893901

902+
/// Get the global TyCtxt.
903+
pub fn global_tcx(self) -> TyCtxt<'a, 'gcx, 'gcx> {
904+
TyCtxt {
905+
gcx: self.gcx,
906+
interners: &self.gcx.global_interners,
907+
query: self.query,
908+
}
909+
}
894910

895-
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
896911
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
897912
self.global_arenas.generics.alloc(generics)
898913
}
@@ -1342,11 +1357,14 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
13421357

13431358
impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
13441359
/// Call the closure with a local `TyCtxt` using the given arena.
1345-
pub fn enter_local<F, R>(&self, arena: &'tcx DroplessArena, f: F) -> R
1360+
pub fn enter_local<F, R>(&self,
1361+
arena: &'tcx DroplessArena,
1362+
query: &maps::QueryJob<'gcx>,
1363+
f: F) -> R
13461364
where F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
13471365
{
13481366
let interners = CtxtInterners::new(arena);
1349-
tls::enter(self, &interners, f)
1367+
tls::enter(self, &interners, query, f)
13501368
}
13511369
}
13521370

@@ -1498,16 +1516,20 @@ pub mod tls {
14981516
use std::cell::Cell;
14991517
use std::fmt;
15001518
use syntax_pos;
1519+
use ty::maps;
1520+
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
15011521

15021522
/// Marker types used for the scoped TLS slot.
15031523
/// The type context cannot be used directly because the scoped TLS
15041524
/// in libstd doesn't allow types generic over lifetimes.
15051525
enum ThreadLocalGlobalCtxt {}
15061526
enum ThreadLocalInterners {}
1527+
enum ThreadLocalQuery {}
15071528

15081529
thread_local! {
15091530
static TLS_TCX: Cell<Option<(*const ThreadLocalGlobalCtxt,
1510-
*const ThreadLocalInterners)>> = Cell::new(None)
1531+
*const ThreadLocalInterners,
1532+
*const ThreadLocalQuery)>> = Cell::new(None)
15111533
}
15121534

15131535
fn span_debug(span: syntax_pos::Span, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1516,31 +1538,53 @@ pub mod tls {
15161538
})
15171539
}
15181540

1541+
fn track_diagnostic(diagnostic: &Diagnostic) {
1542+
with(|tcx| {
1543+
if tcx.query.track_diagnostics {
1544+
tcx.query.diagnostics.lock().push(diagnostic.clone());
1545+
}
1546+
})
1547+
}
1548+
15191549
pub fn enter_global<'gcx, F, R>(gcx: &GlobalCtxt<'gcx>, f: F) -> R
15201550
where F: for<'a> FnOnce(TyCtxt<'a, 'gcx, 'gcx>) -> R
15211551
{
15221552
syntax_pos::SPAN_DEBUG.with(|span_dbg| {
15231553
let original_span_debug = span_dbg.get();
15241554
span_dbg.set(span_debug);
1525-
let result = enter(&gcx, &gcx.global_interners, f);
1555+
1556+
let result = TRACK_DIAGNOSTICS.with(|current| {
1557+
let original = current.get();
1558+
current.set(track_diagnostic);
1559+
1560+
let global_query = maps::QueryJob::new(Vec::new(), false, false);
1561+
let result = enter(&gcx, &gcx.global_interners, &global_query, f);
1562+
current.set(original);
1563+
result
1564+
});
1565+
15261566
span_dbg.set(original_span_debug);
15271567
result
15281568
})
15291569
}
15301570

15311571
pub fn enter<'a, 'gcx: 'tcx, 'tcx, F, R>(gcx: &'a GlobalCtxt<'gcx>,
15321572
interners: &'a CtxtInterners<'tcx>,
1573+
query: &'a maps::QueryJob<'gcx>,
15331574
f: F) -> R
15341575
where F: FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
15351576
{
1577+
let tls_query = maps::QueryJob::new(Vec::new(), false, true);
15361578
let gcx_ptr = gcx as *const _ as *const ThreadLocalGlobalCtxt;
15371579
let interners_ptr = interners as *const _ as *const ThreadLocalInterners;
1580+
let query_ptr = &tls_query as *const _ as *const ThreadLocalQuery;
15381581
TLS_TCX.with(|tls| {
15391582
let prev = tls.get();
1540-
tls.set(Some((gcx_ptr, interners_ptr)));
1583+
tls.set(Some((gcx_ptr, interners_ptr, query_ptr)));
15411584
let ret = f(TyCtxt {
15421585
gcx,
15431586
interners,
1587+
query,
15441588
});
15451589
tls.set(prev);
15461590
ret
@@ -1551,12 +1595,14 @@ pub mod tls {
15511595
where F: for<'a, 'gcx, 'tcx> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> R
15521596
{
15531597
TLS_TCX.with(|tcx| {
1554-
let (gcx, interners) = tcx.get().unwrap();
1598+
let (gcx, interners, query) = tcx.get().unwrap();
15551599
let gcx = unsafe { &*(gcx as *const GlobalCtxt) };
15561600
let interners = unsafe { &*(interners as *const CtxtInterners) };
1601+
let query = unsafe { &*(query as *const maps::QueryJob) };
15571602
f(TyCtxt {
15581603
gcx,
15591604
interners,
1605+
query,
15601606
})
15611607
})
15621608
}

src/librustc/ty/maps/job.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,33 @@ use rustc_data_structures::sync::{Lock, LockGuard, Lrc};
1717
use rayon_core::registry::{self, Registry};
1818
use rayon_core::fiber::WaiterLatch;
1919
use rayon_core::latch::Latch;
20+
use syntax_pos::Span;
21+
use ty::maps::Query;
22+
use errors::Diagnostic;
2023

21-
pub(super) struct QueryJob {
22-
latch: WaiterLatch,
24+
pub struct QueryJob<'tcx> {
25+
pub latch: WaiterLatch,
26+
pub stack: Vec<(Span, Query<'tcx>)>,
27+
pub track_diagnostics: bool,
28+
pub tls: bool,
29+
pub diagnostics: Lock<Vec<Diagnostic>>,
2330
}
2431

25-
impl QueryJob {
26-
pub fn new() -> Self {
32+
impl<'tcx> QueryJob<'tcx> {
33+
pub fn new(stack: Vec<(Span, Query<'tcx>)>, track_diagnostics: bool, tls: bool) -> Self {
2734
QueryJob {
2835
latch: WaiterLatch::new(),
36+
track_diagnostics,
37+
diagnostics: Lock::new(Vec::new()),
38+
stack,
39+
tls,
2940
}
3041
}
3142

43+
pub fn start(&self) {
44+
self.latch.start()
45+
}
46+
3247
pub fn await(&self) {
3348
#[cfg(parallel_queries)]
3449
registry::in_worker(|worker, _| {
@@ -47,7 +62,7 @@ impl QueryJob {
4762
}
4863
}
4964

50-
pub(super) enum QueryResult<T> {
51-
Started(Lrc<QueryJob>),
65+
pub(super) enum QueryResult<'tcx, T> {
66+
Started(Lrc<QueryJob<'tcx>>),
5267
Complete(T),
5368
}

src/librustc/ty/maps/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use self::plumbing::*;
6060
pub use self::plumbing::force_from_dep_node;
6161

6262
mod job;
63+
pub use self::job::QueryJob;
6364
use self::job::QueryResult;
6465

6566
mod keys;

0 commit comments

Comments
 (0)