@@ -17,11 +17,13 @@ use middle::privacy::AccessLevels;
17
17
use mir;
18
18
use session:: CompileResult ;
19
19
use ty:: { self , CrateInherentImpls , Ty , TyCtxt } ;
20
+ use ty:: item_path;
20
21
use ty:: subst:: Substs ;
21
22
use util:: nodemap:: NodeSet ;
22
23
23
24
use rustc_data_structures:: indexed_vec:: IndexVec ;
24
25
use std:: cell:: { RefCell , RefMut } ;
26
+ use std:: mem;
25
27
use std:: ops:: Deref ;
26
28
use std:: rc:: Rc ;
27
29
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -139,24 +141,36 @@ pub struct CycleError<'a, 'tcx: 'a> {
139
141
140
142
impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
141
143
pub fn report_cycle ( self , CycleError { span, cycle } : CycleError ) {
142
- assert ! ( !cycle. is_empty( ) ) ;
143
-
144
- let mut err = struct_span_err ! ( self . sess, span, E0391 ,
145
- "unsupported cyclic reference between types/traits detected" ) ;
146
- err. span_label ( span, & format ! ( "cyclic reference" ) ) ;
147
-
148
- err. span_note ( cycle[ 0 ] . 0 , & format ! ( "the cycle begins when {}..." ,
149
- cycle[ 0 ] . 1 . describe( self ) ) ) ;
150
-
151
- for & ( span, ref query) in & cycle[ 1 ..] {
152
- err. span_note ( span, & format ! ( "...which then requires {}..." ,
153
- query. describe( self ) ) ) ;
154
- }
144
+ // Subtle: release the refcell lock before invoking `describe()`
145
+ // below by dropping `cycle`.
146
+ let stack = cycle. to_vec ( ) ;
147
+ mem:: drop ( cycle) ;
148
+
149
+ assert ! ( !stack. is_empty( ) ) ;
150
+
151
+ // Disable naming impls with types in this path, since that
152
+ // sometimes cycles itself, leading to extra cycle errors.
153
+ // (And cycle errors around impls tend to occur during the
154
+ // collect/coherence phases anyhow.)
155
+ item_path:: with_forced_impl_filename_line ( || {
156
+ let mut err =
157
+ struct_span_err ! ( self . sess, span, E0391 ,
158
+ "unsupported cyclic reference between types/traits detected" ) ;
159
+ err. span_label ( span, & format ! ( "cyclic reference" ) ) ;
160
+
161
+ err. span_note ( stack[ 0 ] . 0 , & format ! ( "the cycle begins when {}..." ,
162
+ stack[ 0 ] . 1 . describe( self ) ) ) ;
163
+
164
+ for & ( span, ref query) in & stack[ 1 ..] {
165
+ err. span_note ( span, & format ! ( "...which then requires {}..." ,
166
+ query. describe( self ) ) ) ;
167
+ }
155
168
156
- err. note ( & format ! ( "...which then again requires {}, completing the cycle." ,
157
- cycle [ 0 ] . 1 . describe( self ) ) ) ;
169
+ err. note ( & format ! ( "...which then again requires {}, completing the cycle." ,
170
+ stack [ 0 ] . 1 . describe( self ) ) ) ;
158
171
159
- err. emit ( ) ;
172
+ err. emit ( ) ;
173
+ } ) ;
160
174
}
161
175
162
176
fn cycle_check < F , R > ( self , span : Span , query : Query < ' gcx > , compute : F )
@@ -274,11 +288,11 @@ impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
274
288
macro_rules! define_maps {
275
289
( <$tcx: tt>
276
290
$( $( #[ $attr: meta] ) *
277
- pub $name: ident: $node: ident( $K: ty) -> $V: ty) ,* ) => {
291
+ [ $ ( $ pub: tt ) * ] $name: ident: $node: ident( $K: ty) -> $V: ty) ,* ) => {
278
292
pub struct Maps <$tcx> {
279
293
providers: IndexVec <CrateNum , Providers <$tcx>>,
280
294
query_stack: RefCell <Vec <( Span , Query <$tcx>) >>,
281
- $( $( #[ $attr] ) * pub $name: RefCell <DepTrackingMap <queries:: $name<$tcx>>>) ,*
295
+ $( $( #[ $attr] ) * $ ( $ pub) * $name: RefCell <DepTrackingMap <queries:: $name<$tcx>>>) ,*
282
296
}
283
297
284
298
impl <$tcx> Maps <$tcx> {
@@ -335,6 +349,11 @@ macro_rules! define_maps {
335
349
-> Result <R , CycleError <' a, $tcx>>
336
350
where F : FnOnce ( & $V) -> R
337
351
{
352
+ debug!( "ty::queries::{}::try_get_with(key={:?}, span={:?})" ,
353
+ stringify!( $name) ,
354
+ key,
355
+ span) ;
356
+
338
357
if let Some ( result) = tcx. maps. $name. borrow( ) . get( & key) {
339
358
return Ok ( f( result) ) ;
340
359
}
@@ -441,52 +460,52 @@ macro_rules! define_maps {
441
460
// the driver creates (using several `rustc_*` crates).
442
461
define_maps ! { <' tcx>
443
462
/// Records the type of every item.
444
- pub type_of: ItemSignature ( DefId ) -> Ty <' tcx>,
463
+ [ ] type_of: ItemSignature ( DefId ) -> Ty <' tcx>,
445
464
446
465
/// Maps from the def-id of an item (trait/struct/enum/fn) to its
447
466
/// associated generics and predicates.
448
- pub generics_of: ItemSignature ( DefId ) -> & ' tcx ty:: Generics ,
449
- pub predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
467
+ [ ] generics_of: ItemSignature ( DefId ) -> & ' tcx ty:: Generics ,
468
+ [ ] predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
450
469
451
470
/// Maps from the def-id of a trait to the list of
452
471
/// super-predicates. This is a subset of the full list of
453
472
/// predicates. We store these in a separate map because we must
454
473
/// evaluate them even during type conversion, often before the
455
474
/// full predicates are available (note that supertraits have
456
475
/// additional acyclicity requirements).
457
- pub super_predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
476
+ [ ] super_predicates_of: ItemSignature ( DefId ) -> ty:: GenericPredicates <' tcx>,
458
477
459
478
/// To avoid cycles within the predicates of a single item we compute
460
479
/// per-type-parameter predicates for resolving `T::AssocTy`.
461
- pub type_param_predicates: TypeParamPredicates ( ( DefId , DefId ) )
480
+ [ ] type_param_predicates: TypeParamPredicates ( ( DefId , DefId ) )
462
481
-> ty:: GenericPredicates <' tcx>,
463
482
464
- pub trait_def: ItemSignature ( DefId ) -> & ' tcx ty:: TraitDef ,
465
- pub adt_def: ItemSignature ( DefId ) -> & ' tcx ty:: AdtDef ,
466
- pub adt_destructor: AdtDestructor ( DefId ) -> Option <ty:: Destructor >,
467
- pub adt_sized_constraint: SizedConstraint ( DefId ) -> & ' tcx [ Ty <' tcx>] ,
468
- pub adt_dtorck_constraint: DtorckConstraint ( DefId ) -> ty:: DtorckConstraint <' tcx>,
483
+ [ ] trait_def: ItemSignature ( DefId ) -> & ' tcx ty:: TraitDef ,
484
+ [ ] adt_def: ItemSignature ( DefId ) -> & ' tcx ty:: AdtDef ,
485
+ [ ] adt_destructor: AdtDestructor ( DefId ) -> Option <ty:: Destructor >,
486
+ [ ] adt_sized_constraint: SizedConstraint ( DefId ) -> & ' tcx [ Ty <' tcx>] ,
487
+ [ ] adt_dtorck_constraint: DtorckConstraint ( DefId ) -> ty:: DtorckConstraint <' tcx>,
469
488
470
489
/// True if this is a foreign item (i.e., linked via `extern { ... }`).
471
- pub is_foreign_item: IsForeignItem ( DefId ) -> bool ,
490
+ [ ] is_foreign_item: IsForeignItem ( DefId ) -> bool ,
472
491
473
492
/// Maps from def-id of a type or region parameter to its
474
493
/// (inferred) variance.
475
- pub variances_of: ItemSignature ( DefId ) -> Rc <Vec <ty:: Variance >>,
494
+ [ pub ] variances_of: ItemSignature ( DefId ) -> Rc <Vec <ty:: Variance >>,
476
495
477
496
/// Maps from an impl/trait def-id to a list of the def-ids of its items
478
- pub associated_item_def_ids: AssociatedItemDefIds ( DefId ) -> Rc <Vec <DefId >>,
497
+ [ ] associated_item_def_ids: AssociatedItemDefIds ( DefId ) -> Rc <Vec <DefId >>,
479
498
480
499
/// Maps from a trait item to the trait item "descriptor"
481
- pub associated_item: AssociatedItems ( DefId ) -> ty:: AssociatedItem ,
500
+ [ ] associated_item: AssociatedItems ( DefId ) -> ty:: AssociatedItem ,
482
501
483
- pub impl_trait_ref: ItemSignature ( DefId ) -> Option <ty:: TraitRef <' tcx>>,
484
- pub impl_polarity: ItemSignature ( DefId ) -> hir:: ImplPolarity ,
502
+ [ ] impl_trait_ref: ItemSignature ( DefId ) -> Option <ty:: TraitRef <' tcx>>,
503
+ [ ] impl_polarity: ItemSignature ( DefId ) -> hir:: ImplPolarity ,
485
504
486
505
/// Maps a DefId of a type to a list of its inherent impls.
487
506
/// Contains implementations of methods that are inherent to a type.
488
507
/// Methods in these implementations don't need to be exported.
489
- pub inherent_impls: InherentImpls ( DefId ) -> Rc <Vec <DefId >>,
508
+ [ ] inherent_impls: InherentImpls ( DefId ) -> Rc <Vec <DefId >>,
490
509
491
510
/// Maps from the def-id of a function/method or const/static
492
511
/// to its MIR. Mutation is done at an item granularity to
@@ -495,59 +514,61 @@ define_maps! { <'tcx>
495
514
///
496
515
/// Note that cross-crate MIR appears to be always borrowed
497
516
/// (in the `RefCell` sense) to prevent accidental mutation.
498
- pub mir: Mir ( DefId ) -> & ' tcx RefCell <mir:: Mir <' tcx>>,
517
+ [ pub ] mir: Mir ( DefId ) -> & ' tcx RefCell <mir:: Mir <' tcx>>,
499
518
500
519
/// Maps DefId's that have an associated Mir to the result
501
520
/// of the MIR qualify_consts pass. The actual meaning of
502
521
/// the value isn't known except to the pass itself.
503
- pub mir_const_qualif: Mir ( DefId ) -> u8 ,
522
+ [ ] mir_const_qualif: Mir ( DefId ) -> u8 ,
504
523
505
524
/// Records the type of each closure. The def ID is the ID of the
506
525
/// expression defining the closure.
507
- pub closure_kind: ItemSignature ( DefId ) -> ty:: ClosureKind ,
526
+ [ ] closure_kind: ItemSignature ( DefId ) -> ty:: ClosureKind ,
508
527
509
528
/// Records the type of each closure. The def ID is the ID of the
510
529
/// expression defining the closure.
511
- pub closure_type: ItemSignature ( DefId ) -> ty:: PolyFnSig <' tcx>,
530
+ [ ] closure_type: ItemSignature ( DefId ) -> ty:: PolyFnSig <' tcx>,
512
531
513
532
/// Caches CoerceUnsized kinds for impls on custom types.
514
- pub coerce_unsized_info: ItemSignature ( DefId )
533
+ [ ] coerce_unsized_info: ItemSignature ( DefId )
515
534
-> ty:: adjustment:: CoerceUnsizedInfo ,
516
535
517
- pub typeck_item_bodies: typeck_item_bodies_dep_node( CrateNum ) -> CompileResult ,
536
+ [ ] typeck_item_bodies: typeck_item_bodies_dep_node( CrateNum ) -> CompileResult ,
518
537
519
- pub typeck_tables_of: TypeckTables ( DefId ) -> & ' tcx ty:: TypeckTables <' tcx>,
538
+ [ ] typeck_tables_of: TypeckTables ( DefId ) -> & ' tcx ty:: TypeckTables <' tcx>,
520
539
521
- pub coherent_trait : coherent_trait_dep_node ( ( CrateNum , DefId ) ) -> ( ) ,
540
+ [ ] has_typeck_tables : TypeckTables ( DefId ) -> bool ,
522
541
523
- pub borrowck: BorrowCheck ( DefId ) -> ( ) ,
542
+ [ ] coherent_trait: coherent_trait_dep_node( ( CrateNum , DefId ) ) -> ( ) ,
543
+
544
+ [ ] borrowck: BorrowCheck ( DefId ) -> ( ) ,
524
545
525
546
/// Gets a complete map from all types to their inherent impls.
526
547
/// Not meant to be used directly outside of coherence.
527
548
/// (Defined only for LOCAL_CRATE)
528
- pub crate_inherent_impls: crate_inherent_impls_dep_node( CrateNum ) -> CrateInherentImpls ,
549
+ [ ] crate_inherent_impls: crate_inherent_impls_dep_node( CrateNum ) -> CrateInherentImpls ,
529
550
530
551
/// Checks all types in the krate for overlap in their inherent impls. Reports errors.
531
552
/// Not meant to be used directly outside of coherence.
532
553
/// (Defined only for LOCAL_CRATE)
533
- pub crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node( CrateNum ) -> ( ) ,
554
+ [ ] crate_inherent_impls_overlap_check: crate_inherent_impls_dep_node( CrateNum ) -> ( ) ,
534
555
535
556
/// Results of evaluating const items or constants embedded in
536
557
/// other items (such as enum variant explicit discriminants).
537
- pub const_eval: const_eval_dep_node( ( DefId , & ' tcx Substs <' tcx>) )
558
+ [ ] const_eval: const_eval_dep_node( ( DefId , & ' tcx Substs <' tcx>) )
538
559
-> const_val:: EvalResult <' tcx>,
539
560
540
561
/// Performs the privacy check and computes "access levels".
541
- pub privacy_access_levels: PrivacyAccessLevels ( CrateNum ) -> Rc <AccessLevels >,
562
+ [ ] privacy_access_levels: PrivacyAccessLevels ( CrateNum ) -> Rc <AccessLevels >,
542
563
543
- pub reachable_set: reachability_dep_node( CrateNum ) -> Rc <NodeSet >,
564
+ [ ] reachable_set: reachability_dep_node( CrateNum ) -> Rc <NodeSet >,
544
565
545
- pub mir_shims: mir_shim_dep_node( ty:: InstanceDef <' tcx>) -> & ' tcx RefCell <mir:: Mir <' tcx>>,
566
+ [ ] mir_shims: mir_shim_dep_node( ty:: InstanceDef <' tcx>) -> & ' tcx RefCell <mir:: Mir <' tcx>>,
546
567
547
- pub def_symbol_name: SymbolName ( DefId ) -> ty:: SymbolName ,
548
- pub symbol_name: symbol_name_dep_node( ty:: Instance <' tcx>) -> ty:: SymbolName ,
568
+ [ ] def_symbol_name: SymbolName ( DefId ) -> ty:: SymbolName ,
569
+ [ ] symbol_name: symbol_name_dep_node( ty:: Instance <' tcx>) -> ty:: SymbolName ,
549
570
550
- pub describe_def: meta_data_node( DefId ) -> Option <Def >
571
+ [ ] describe_def: meta_data_node( DefId ) -> Option <Def >
551
572
}
552
573
553
574
fn coherent_trait_dep_node ( ( _, def_id) : ( CrateNum , DefId ) ) -> DepNode < DefId > {
@@ -582,4 +603,4 @@ fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
582
603
583
604
fn meta_data_node ( def_id : DefId ) -> DepNode < DefId > {
584
605
DepNode :: MetaData ( def_id)
585
- }
606
+ }
0 commit comments