@@ -16,11 +16,13 @@ use middle::privacy::AccessLevels;
1616use mir;
1717use session:: CompileResult ;
1818use ty:: { self , CrateInherentImpls , Ty , TyCtxt } ;
19+ use ty:: item_path;
1920use ty:: subst:: Substs ;
2021use util:: nodemap:: NodeSet ;
2122
2223use rustc_data_structures:: indexed_vec:: IndexVec ;
2324use std:: cell:: { RefCell , RefMut } ;
25+ use std:: mem;
2426use std:: ops:: Deref ;
2527use std:: rc:: Rc ;
2628use syntax_pos:: { Span , DUMMY_SP } ;
@@ -122,24 +124,36 @@ pub struct CycleError<'a, 'tcx: 'a> {
122124
123125impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
124126 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+ }
138151
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 ) ) ) ;
141154
142- err. emit ( ) ;
155+ err. emit ( ) ;
156+ } ) ;
143157 }
144158
145159 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> {
245259macro_rules! define_maps {
246260 ( <$tcx: tt>
247261 $( $( #[ $attr: meta] ) *
248- pub $name: ident: $node: ident( $K: ty) -> $V: ty) ,* ) => {
262+ [ $ ( $ pub: tt ) * ] $name: ident: $node: ident( $K: ty) -> $V: ty) ,* ) => {
249263 pub struct Maps <$tcx> {
250264 providers: IndexVec <CrateNum , Providers <$tcx>>,
251265 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>>>) ,*
253267 }
254268
255269 impl <$tcx> Maps <$tcx> {
@@ -306,6 +320,11 @@ macro_rules! define_maps {
306320 -> Result <R , CycleError <' a, $tcx>>
307321 where F : FnOnce ( & $V) -> R
308322 {
323+ debug!( "ty::queries::{}::try_get_with(key={:?}, span={:?})" ,
324+ stringify!( $name) ,
325+ key,
326+ span) ;
327+
309328 if let Some ( result) = tcx. maps. $name. borrow( ) . get( & key) {
310329 return Ok ( f( result) ) ;
311330 }
@@ -412,52 +431,52 @@ macro_rules! define_maps {
412431// the driver creates (using several `rustc_*` crates).
413432define_maps ! { <' tcx>
414433 /// Records the type of every item.
415- pub type_of: ItemSignature ( DefId ) -> Ty <' tcx>,
434+ [ ] type_of: ItemSignature ( DefId ) -> Ty <' tcx>,
416435
417436 /// Maps from the def-id of an item (trait/struct/enum/fn) to its
418437 /// 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>,
421440
422441 /// Maps from the def-id of a trait to the list of
423442 /// super-predicates. This is a subset of the full list of
424443 /// predicates. We store these in a separate map because we must
425444 /// evaluate them even during type conversion, often before the
426445 /// full predicates are available (note that supertraits have
427446 /// additional acyclicity requirements).
428- pub super_predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
447+ [ ] super_predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
429448
430449 /// To avoid cycles within the predicates of a single item we compute
431450 /// per-type-parameter predicates for resolving `T::AssocTy`.
432- pub type_param_predicates: TypeParamPredicates ( ( DefId , DefId ) )
451+ [ ] type_param_predicates: TypeParamPredicates ( ( DefId , DefId ) )
433452 -> ty:: GenericPredicates <' tcx>,
434453
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>,
440459
441460 /// 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 ,
443462
444463 /// Maps from def-id of a type or region parameter to its
445464 /// (inferred) variance.
446- pub variances_of: ItemSignature ( DefId ) -> Rc <Vec <ty:: Variance >>,
465+ [ pub ] variances_of: ItemSignature ( DefId ) -> Rc <Vec <ty:: Variance >>,
447466
448467 /// 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 >>,
450469
451470 /// 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 ,
453472
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 ,
456475
457476 /// Maps a DefId of a type to a list of its inherent impls.
458477 /// Contains implementations of methods that are inherent to a type.
459478 /// 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 >>,
461480
462481 /// Maps from the def-id of a function/method or const/static
463482 /// to its MIR. Mutation is done at an item granularity to
@@ -466,54 +485,54 @@ define_maps! { <'tcx>
466485 ///
467486 /// Note that cross-crate MIR appears to be always borrowed
468487 /// (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>>,
470489
471490 /// Maps DefId's that have an associated Mir to the result
472491 /// of the MIR qualify_consts pass. The actual meaning of
473492 /// 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 ,
475494
476495 /// Records the type of each closure. The def ID is the ID of the
477496 /// expression defining the closure.
478- pub closure_kind: ItemSignature ( DefId ) -> ty:: ClosureKind ,
497+ [ ] closure_kind: ItemSignature ( DefId ) -> ty:: ClosureKind ,
479498
480499 /// Records the type of each closure. The def ID is the ID of the
481500 /// expression defining the closure.
482- pub closure_type: ItemSignature ( DefId ) -> ty:: PolyFnSig <' tcx>,
501+ [ ] closure_type: ItemSignature ( DefId ) -> ty:: PolyFnSig <' tcx>,
483502
484503 /// Caches CoerceUnsized kinds for impls on custom types.
485- pub coerce_unsized_info: ItemSignature ( DefId )
504+ [ ] coerce_unsized_info: ItemSignature ( DefId )
486505 -> ty:: adjustment:: CoerceUnsizedInfo ,
487506
488- pub typeck_item_bodies: typeck_item_bodies_dep_node( CrateNum ) -> CompileResult ,
507+ [ ] typeck_item_bodies: typeck_item_bodies_dep_node( CrateNum ) -> CompileResult ,
489508
490- pub typeck_tables_of: TypeckTables ( DefId ) -> & ' tcx ty:: TypeckTables <' tcx>,
509+ [ ] typeck_tables_of: TypeckTables ( DefId ) -> & ' tcx ty:: TypeckTables <' tcx>,
491510
492- pub coherent_trait: coherent_trait_dep_node( ( CrateNum , DefId ) ) -> ( ) ,
511+ [ ] coherent_trait: coherent_trait_dep_node( ( CrateNum , DefId ) ) -> ( ) ,
493512
494- pub borrowck: BorrowCheck ( DefId ) -> ( ) ,
513+ [ ] borrowck: BorrowCheck ( DefId ) -> ( ) ,
495514
496515 /// Gets a complete map from all types to their inherent impls.
497516 /// Not meant to be used directly outside of coherence.
498517 /// (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 ,
500519
501520 /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
502521 /// Not meant to be used directly outside of coherence.
503522 /// (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 ) -> ( ) ,
505524
506525 /// Results of evaluating const items or constants embedded in
507526 /// 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>) )
509528 -> const_val:: EvalResult <' tcx>,
510529
511530 /// 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 >,
513532
514- pub reachable_set: reachability_dep_node( CrateNum ) -> Rc <NodeSet >,
533+ [ ] reachable_set: reachability_dep_node( CrateNum ) -> Rc <NodeSet >,
515534
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>>
517536}
518537
519538fn coherent_trait_dep_node ( ( _, def_id) : ( CrateNum , DefId ) ) -> DepNode < DefId > {
0 commit comments