@@ -16,11 +16,13 @@ use middle::privacy::AccessLevels;
16
16
use mir;
17
17
use session:: CompileResult ;
18
18
use ty:: { self , CrateInherentImpls , Ty , TyCtxt } ;
19
+ use ty:: item_path;
19
20
use ty:: subst:: Substs ;
20
21
use util:: nodemap:: NodeSet ;
21
22
22
23
use rustc_data_structures:: indexed_vec:: IndexVec ;
23
24
use std:: cell:: { RefCell , RefMut } ;
25
+ use std:: mem;
24
26
use std:: ops:: Deref ;
25
27
use std:: rc:: Rc ;
26
28
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -122,24 +124,36 @@ pub struct CycleError<'a, 'tcx: 'a> {
122
124
123
125
impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
124
126
pub fn report_cycle ( self , CycleError { span, cycle } : CycleError ) {
125
- assert ! ( !cycle. is_empty( ) ) ;
126
-
127
- let mut err = struct_span_err ! ( self . sess, span, E0391 ,
128
- "unsupported cyclic reference between types/traits detected" ) ;
129
- err. span_label ( span, & format ! ( "cyclic reference" ) ) ;
130
-
131
- err. span_note ( cycle[ 0 ] . 0 , & format ! ( "the cycle begins when {}..." ,
132
- cycle[ 0 ] . 1 . describe( self ) ) ) ;
133
-
134
- for & ( span, ref query) in & cycle[ 1 ..] {
135
- err. span_note ( span, & format ! ( "...which then requires {}..." ,
136
- query. describe( self ) ) ) ;
137
- }
127
+ // Subtle: release the refcell lock before invoking `describe()`
128
+ // below by dropping `cycle`.
129
+ let stack = cycle. to_vec ( ) ;
130
+ mem:: drop ( cycle) ;
131
+
132
+ assert ! ( !stack. is_empty( ) ) ;
133
+
134
+ // Disable naming impls with types in this path, since that
135
+ // sometimes cycles itself, leading to extra cycle errors.
136
+ // (And cycle errors around impls tend to occur during the
137
+ // collect/coherence phases anyhow.)
138
+ item_path:: with_forced_impl_filename_line ( || {
139
+ let mut err =
140
+ struct_span_err ! ( self . sess, span, E0391 ,
141
+ "unsupported cyclic reference between types/traits detected" ) ;
142
+ err. span_label ( span, & format ! ( "cyclic reference" ) ) ;
143
+
144
+ err. span_note ( stack[ 0 ] . 0 , & format ! ( "the cycle begins when {}..." ,
145
+ stack[ 0 ] . 1 . describe( self ) ) ) ;
146
+
147
+ for & ( span, ref query) in & stack[ 1 ..] {
148
+ err. span_note ( span, & format ! ( "...which then requires {}..." ,
149
+ query. describe( self ) ) ) ;
150
+ }
138
151
139
- err. note ( & format ! ( "...which then again requires {}, completing the cycle." ,
140
- cycle [ 0 ] . 1 . describe( self ) ) ) ;
152
+ err. note ( & format ! ( "...which then again requires {}, completing the cycle." ,
153
+ stack [ 0 ] . 1 . describe( self ) ) ) ;
141
154
142
- err. emit ( ) ;
155
+ err. emit ( ) ;
156
+ } ) ;
143
157
}
144
158
145
159
fn cycle_check < F , R > ( self , span : Span , query : Query < ' gcx > , compute : F )
@@ -245,11 +259,11 @@ impl<'tcx> QueryDescription for queries::const_eval<'tcx> {
245
259
macro_rules! define_maps {
246
260
( <$tcx: tt>
247
261
$( $( #[ $attr: meta] ) *
248
- pub $name: ident: $node: ident( $K: ty) -> $V: ty) ,* ) => {
262
+ [ $ ( $ pub: tt ) * ] $name: ident: $node: ident( $K: ty) -> $V: ty) ,* ) => {
249
263
pub struct Maps <$tcx> {
250
264
providers: IndexVec <CrateNum , Providers <$tcx>>,
251
265
query_stack: RefCell <Vec <( Span , Query <$tcx>) >>,
252
- $( $( #[ $attr] ) * pub $name: RefCell <DepTrackingMap <queries:: $name<$tcx>>>) ,*
266
+ $( $( #[ $attr] ) * $ ( $ pub) * $name: RefCell <DepTrackingMap <queries:: $name<$tcx>>>) ,*
253
267
}
254
268
255
269
impl <$tcx> Maps <$tcx> {
@@ -306,6 +320,11 @@ macro_rules! define_maps {
306
320
-> Result <R , CycleError <' a, $tcx>>
307
321
where F : FnOnce ( & $V) -> R
308
322
{
323
+ debug!( "ty::queries::{}::try_get_with(key={:?}, span={:?})" ,
324
+ stringify!( $name) ,
325
+ key,
326
+ span) ;
327
+
309
328
if let Some ( result) = tcx. maps. $name. borrow( ) . get( & key) {
310
329
return Ok ( f( result) ) ;
311
330
}
@@ -412,52 +431,52 @@ macro_rules! define_maps {
412
431
// the driver creates (using several `rustc_*` crates).
413
432
define_maps ! { <' tcx>
414
433
/// Records the type of every item.
415
- pub type_of: ItemSignature ( DefId ) -> Ty <' tcx>,
434
+ [ ] type_of: ItemSignature ( DefId ) -> Ty <' tcx>,
416
435
417
436
/// Maps from the def-id of an item (trait/struct/enum/fn) to its
418
437
/// associated generics and predicates.
419
- pub generics_of: ItemSignature ( DefId ) -> & ' tcx ty:: Generics ,
420
- pub predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
438
+ [ ] generics_of: ItemSignature ( DefId ) -> & ' tcx ty:: Generics ,
439
+ [ ] predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
421
440
422
441
/// Maps from the def-id of a trait to the list of
423
442
/// super-predicates. This is a subset of the full list of
424
443
/// predicates. We store these in a separate map because we must
425
444
/// evaluate them even during type conversion, often before the
426
445
/// full predicates are available (note that supertraits have
427
446
/// additional acyclicity requirements).
428
- pub super_predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
447
+ [ ] super_predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
429
448
430
449
/// To avoid cycles within the predicates of a single item we compute
431
450
/// per-type-parameter predicates for resolving `T::AssocTy`.
432
- pub type_param_predicates: TypeParamPredicates ( ( DefId , DefId ) )
451
+ [ ] type_param_predicates: TypeParamPredicates ( ( DefId , DefId ) )
433
452
-> ty:: GenericPredicates <' tcx>,
434
453
435
- pub trait_def: ItemSignature ( DefId ) -> & ' tcx ty:: TraitDef ,
436
- pub adt_def: ItemSignature ( DefId ) -> & ' tcx ty:: AdtDef ,
437
- pub adt_destructor: AdtDestructor ( DefId ) -> Option <ty:: Destructor >,
438
- pub adt_sized_constraint: SizedConstraint ( DefId ) -> & ' tcx [ Ty <' tcx>] ,
439
- pub adt_dtorck_constraint: DtorckConstraint ( DefId ) -> ty:: DtorckConstraint <' tcx>,
454
+ [ ] trait_def: ItemSignature ( DefId ) -> & ' tcx ty:: TraitDef ,
455
+ [ ] adt_def: ItemSignature ( DefId ) -> & ' tcx ty:: AdtDef ,
456
+ [ ] adt_destructor: AdtDestructor ( DefId ) -> Option <ty:: Destructor >,
457
+ [ ] adt_sized_constraint: SizedConstraint ( DefId ) -> & ' tcx [ Ty <' tcx>] ,
458
+ [ ] adt_dtorck_constraint: DtorckConstraint ( DefId ) -> ty:: DtorckConstraint <' tcx>,
440
459
441
460
/// True if this is a foreign item (i.e., linked via `extern { ... }`).
442
- pub is_foreign_item: IsForeignItem ( DefId ) -> bool ,
461
+ [ ] is_foreign_item: IsForeignItem ( DefId ) -> bool ,
443
462
444
463
/// Maps from def-id of a type or region parameter to its
445
464
/// (inferred) variance.
446
- pub variances_of: ItemSignature ( DefId ) -> Rc <Vec <ty:: Variance >>,
465
+ [ pub ] variances_of: ItemSignature ( DefId ) -> Rc <Vec <ty:: Variance >>,
447
466
448
467
/// Maps from an impl/trait def-id to a list of the def-ids of its items
449
- pub associated_item_def_ids: AssociatedItemDefIds ( DefId ) -> Rc <Vec <DefId >>,
468
+ [ ] associated_item_def_ids: AssociatedItemDefIds ( DefId ) -> Rc <Vec <DefId >>,
450
469
451
470
/// Maps from a trait item to the trait item "descriptor"
452
- pub associated_item: AssociatedItems ( DefId ) -> ty:: AssociatedItem ,
471
+ [ ] associated_item: AssociatedItems ( DefId ) -> ty:: AssociatedItem ,
453
472
454
- pub impl_trait_ref: ItemSignature ( DefId ) -> Option <ty:: TraitRef <' tcx>>,
455
- pub impl_polarity: ItemSignature ( DefId ) -> hir:: ImplPolarity ,
473
+ [ ] impl_trait_ref: ItemSignature ( DefId ) -> Option <ty:: TraitRef <' tcx>>,
474
+ [ ] impl_polarity: ItemSignature ( DefId ) -> hir:: ImplPolarity ,
456
475
457
476
/// Maps a DefId of a type to a list of its inherent impls.
458
477
/// Contains implementations of methods that are inherent to a type.
459
478
/// Methods in these implementations don't need to be exported.
460
- pub inherent_impls: InherentImpls ( DefId ) -> Rc <Vec <DefId >>,
479
+ [ ] inherent_impls: InherentImpls ( DefId ) -> Rc <Vec <DefId >>,
461
480
462
481
/// Maps from the def-id of a function/method or const/static
463
482
/// to its MIR. Mutation is done at an item granularity to
@@ -466,54 +485,54 @@ define_maps! { <'tcx>
466
485
///
467
486
/// Note that cross-crate MIR appears to be always borrowed
468
487
/// (in the `RefCell` sense) to prevent accidental mutation.
469
- pub mir: Mir ( DefId ) -> & ' tcx RefCell <mir:: Mir <' tcx>>,
488
+ [ pub ] mir: Mir ( DefId ) -> & ' tcx RefCell <mir:: Mir <' tcx>>,
470
489
471
490
/// Maps DefId's that have an associated Mir to the result
472
491
/// of the MIR qualify_consts pass. The actual meaning of
473
492
/// the value isn't known except to the pass itself.
474
- pub mir_const_qualif: Mir ( DefId ) -> u8 ,
493
+ [ ] mir_const_qualif: Mir ( DefId ) -> u8 ,
475
494
476
495
/// Records the type of each closure. The def ID is the ID of the
477
496
/// expression defining the closure.
478
- pub closure_kind: ItemSignature ( DefId ) -> ty:: ClosureKind ,
497
+ [ ] closure_kind: ItemSignature ( DefId ) -> ty:: ClosureKind ,
479
498
480
499
/// Records the type of each closure. The def ID is the ID of the
481
500
/// expression defining the closure.
482
- pub closure_type: ItemSignature ( DefId ) -> ty:: PolyFnSig <' tcx>,
501
+ [ ] closure_type: ItemSignature ( DefId ) -> ty:: PolyFnSig <' tcx>,
483
502
484
503
/// Caches CoerceUnsized kinds for impls on custom types.
485
- pub coerce_unsized_info: ItemSignature ( DefId )
504
+ [ ] coerce_unsized_info: ItemSignature ( DefId )
486
505
-> ty:: adjustment:: CoerceUnsizedInfo ,
487
506
488
- pub typeck_item_bodies: typeck_item_bodies_dep_node( CrateNum ) -> CompileResult ,
507
+ [ ] typeck_item_bodies: typeck_item_bodies_dep_node( CrateNum ) -> CompileResult ,
489
508
490
- pub typeck_tables_of: TypeckTables ( DefId ) -> & ' tcx ty:: TypeckTables <' tcx>,
509
+ [ ] typeck_tables_of: TypeckTables ( DefId ) -> & ' tcx ty:: TypeckTables <' tcx>,
491
510
492
- pub coherent_trait: coherent_trait_dep_node( ( CrateNum , DefId ) ) -> ( ) ,
511
+ [ ] coherent_trait: coherent_trait_dep_node( ( CrateNum , DefId ) ) -> ( ) ,
493
512
494
- pub borrowck: BorrowCheck ( DefId ) -> ( ) ,
513
+ [ ] borrowck: BorrowCheck ( DefId ) -> ( ) ,
495
514
496
515
/// Gets a complete map from all types to their inherent impls.
497
516
/// Not meant to be used directly outside of coherence.
498
517
/// (Defined only for LOCAL_CRATE)
499
- pub crate_inherent_impls: crate_inherent_impls_dep_node( CrateNum ) -> CrateInherentImpls ,
518
+ [ ] crate_inherent_impls: crate_inherent_impls_dep_node( CrateNum ) -> CrateInherentImpls ,
500
519
501
520
/// Checks all types in the krate for overlap in their inherent impls. Reports errors.
502
521
/// Not meant to be used directly outside of coherence.
503
522
/// (Defined only for LOCAL_CRATE)
504
- pub crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node( CrateNum ) -> ( ) ,
523
+ [ ] crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node( CrateNum ) -> ( ) ,
505
524
506
525
/// Results of evaluating const items or constants embedded in
507
526
/// other items (such as enum variant explicit discriminants).
508
- pub const_eval: const_eval_dep_node( ( DefId , & ' tcx Substs <' tcx>) )
527
+ [ ] const_eval: const_eval_dep_node( ( DefId , & ' tcx Substs <' tcx>) )
509
528
-> const_val:: EvalResult <' tcx>,
510
529
511
530
/// Performs the privacy check and computes "access levels".
512
- pub privacy_access_levels: PrivacyAccessLevels ( CrateNum ) -> Rc <AccessLevels >,
531
+ [ ] privacy_access_levels: PrivacyAccessLevels ( CrateNum ) -> Rc <AccessLevels >,
513
532
514
- pub reachable_set: reachability_dep_node( CrateNum ) -> Rc <NodeSet >,
533
+ [ ] reachable_set: reachability_dep_node( CrateNum ) -> Rc <NodeSet >,
515
534
516
- pub mir_shims: mir_shim_dep_node( ty:: InstanceDef <' tcx>) -> & ' tcx RefCell <mir:: Mir <' tcx>>
535
+ [ ] mir_shims: mir_shim_dep_node( ty:: InstanceDef <' tcx>) -> & ' tcx RefCell <mir:: Mir <' tcx>>
517
536
}
518
537
519
538
fn coherent_trait_dep_node ( ( _, def_id) : ( CrateNum , DefId ) ) -> DepNode < DefId > {
0 commit comments