@@ -4,7 +4,6 @@ use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace};
44use rustc_serialize:: opaque:: Encoder ;
55use std:: marker:: PhantomData ;
66use std:: num:: NonZeroUsize ;
7- use std:: u32;
87use log:: debug;
98
109/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
@@ -73,7 +72,7 @@ impl FixedSizeEncoding for u32 {
7372/// of each DefIndex. It is not required that all definitions appear
7473/// in the metadata, nor that they are serialized in order, and
7574/// therefore we first allocate the vector here and fill it with
76- /// `u32::MAX `. Whenever an index is visited, we fill in the
75+ /// `0 `. Whenever an index is visited, we fill in the
7776/// appropriate spot by calling `record_position`. We should never
7877/// visit the same index twice.
7978pub struct Index < ' tcx > {
@@ -84,8 +83,8 @@ pub struct Index<'tcx> {
8483impl Index < ' tcx > {
8584 pub fn new ( ( max_index_lo, max_index_hi) : ( usize , usize ) ) -> Self {
8685 Index {
87- positions : [ vec ! [ 0xff ; max_index_lo * 4 ] ,
88- vec ! [ 0xff ; max_index_hi * 4 ] ] ,
86+ positions : [ vec ! [ 0 ; max_index_lo * 4 ] ,
87+ vec ! [ 0 ; max_index_hi * 4 ] ] ,
8988 _marker : PhantomData ,
9089 }
9190 }
@@ -96,13 +95,13 @@ impl Index<'tcx> {
9695 }
9796
9897 pub fn record_index ( & mut self , item : DefIndex , entry : Lazy < Entry < ' tcx > > ) {
99- assert ! ( entry. position. get( ) < ( u32 :: MAX as usize ) ) ;
10098 let position = entry. position . get ( ) as u32 ;
99+ assert_eq ! ( position as usize , entry. position. get( ) ) ;
101100 let space_index = item. address_space ( ) . index ( ) ;
102101 let array_index = item. as_array_index ( ) ;
103102
104103 let positions = & mut self . positions [ space_index] ;
105- assert ! ( u32 :: read_from_bytes_at( positions, array_index) == u32 :: MAX ,
104+ assert ! ( u32 :: read_from_bytes_at( positions, array_index) == 0 ,
106105 "recorded position for item {:?} twice, first at {:?} and now at {:?}" ,
107106 item,
108107 u32 :: read_from_bytes_at( positions, array_index) ,
@@ -147,12 +146,7 @@ impl Lazy<[Index<'tcx>]> {
147146 } ;
148147
149148 let position = u32:: read_from_bytes_at ( bytes, 1 + i) ;
150- if position == u32:: MAX {
151- debug ! ( "Index::lookup: position=u32::MAX" ) ;
152- None
153- } else {
154- debug ! ( "Index::lookup: position={:?}" , position) ;
155- Some ( Lazy :: from_position ( NonZeroUsize :: new ( position as usize ) . unwrap ( ) ) )
156- }
149+ debug ! ( "Index::lookup: position={:?}" , position) ;
150+ NonZeroUsize :: new ( position as usize ) . map ( Lazy :: from_position)
157151 }
158152}
0 commit comments