Skip to content

Commit 554fe71

Browse files
committed
Auto merge of #47906 - Zoxc:nocycle, r=nikomatsakis
Add a `fatal_cycle` attribute for queries which indicates that they will cause a fatal error on query cycles This moves us towards the goal of having cycle errors be non-fatal by not relying on the default implementation of `ty::maps::values::Value` which aborts on errors. r? @nikomatsakis
2 parents 58a8e0c + e236994 commit 554fe71

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/librustc/ty/maps/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ pub use self::on_disk_cache::OnDiskCache;
7878
// a way that memoizes and does dep-graph tracking,
7979
// wrapping around the actual chain of providers that
8080
// the driver creates (using several `rustc_*` crates).
81+
//
82+
// The result of query must implement Clone. They must also implement ty::maps::values::Value
83+
// which produces an appropiate error value if the query resulted in a query cycle.
84+
// Queries marked with `fatal_cycle` do not need that implementation
85+
// as they will raise an fatal error on query cycles instead.
8186
define_maps! { <'tcx>
8287
/// Records the type of every item.
8388
[] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>,
@@ -267,13 +272,13 @@ define_maps! { <'tcx>
267272
[] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
268273
-> Rc<Vec<(CrateNum, LinkagePreference)>>,
269274

270-
[] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
271-
[] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
272-
[] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
273-
[] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
274-
[] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
275-
[] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
276-
[] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
275+
[fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
276+
[fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
277+
[fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
278+
[fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
279+
[fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
280+
[fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,
281+
[fatal_cycle] fn is_no_builtins: IsNoBuiltins(CrateNum) -> bool,
277282

278283
[] fn extern_crate: ExternCrate(DefId) -> Rc<Option<ExternCrate>>,
279284

src/librustc/ty/maps/plumbing.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,19 @@ macro_rules! profq_key {
183183
}
184184
}
185185

186+
macro_rules! handle_cycle_error {
187+
([][$this: expr]) => {{
188+
Value::from_cycle_error($this.global_tcx())
189+
}};
190+
([fatal_cycle$(, $modifiers:ident)*][$this:expr]) => {{
191+
$this.tcx.sess.abort_if_errors();
192+
unreachable!();
193+
}};
194+
([$other:ident$(, $modifiers:ident)*][$($args:tt)*]) => {
195+
handle_cycle_error!([$($modifiers),*][$($args)*])
196+
};
197+
}
198+
186199
macro_rules! define_maps {
187200
(<$tcx:tt>
188201
$($(#[$attr:meta])*
@@ -564,7 +577,7 @@ macro_rules! define_maps {
564577
pub fn $name(self, key: $K) -> $V {
565578
queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|mut e| {
566579
e.emit();
567-
Value::from_cycle_error(self.global_tcx())
580+
handle_cycle_error!([$($modifiers)*][self])
568581
})
569582
})*
570583
}
@@ -583,7 +596,7 @@ macro_rules! define_maps {
583596

584597
macro_rules! define_map_struct {
585598
(tcx: $tcx:tt,
586-
input: ($(([$(modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
599+
input: ($(([$($modifiers:tt)*] [$($attr:tt)*] [$name:ident]))*)) => {
587600
pub struct Maps<$tcx> {
588601
providers: IndexVec<CrateNum, Providers<$tcx>>,
589602
query_stack: RefCell<Vec<(Span, Query<$tcx>)>>,

0 commit comments

Comments
 (0)