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