diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 3df18098a07..5e4c1284e24 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -10,6 +10,7 @@ #![feature(macro_metavar_expr)] #![feature(min_specialization)] #![feature(slice_as_chunks)] +#![feature(trusted_len)] #![feature(try_blocks)] #![feature(never_type)] #![recursion_limit = "256"] diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 6042d0e49c3..72b7c08f04b 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -38,6 +38,7 @@ use rustc_span::{self, BytePos, ExpnId, Pos, Span, SyntaxContext, DUMMY_SP}; use proc_macro::bridge::client::ProcMacro; use std::io; +use std::iter::TrustedLen; use std::mem; use std::num::NonZeroUsize; use std::path::Path; @@ -277,17 +278,25 @@ struct DecodeIterator<'a, 'tcx, T> { impl<'a, 'tcx, T: Decodable>> Iterator for DecodeIterator<'a, 'tcx, T> { type Item = T; + #[inline(always)] fn next(&mut self) -> Option { self.elem_counter.next().map(|_| T::decode(&mut self.dcx)) } + + #[inline(always)] + fn size_hint(&self) -> (usize, Option) { + self.elem_counter.size_hint() + } } impl<'a, 'tcx, T: Decodable>> ExactSizeIterator for DecodeIterator<'a, 'tcx, T> { - fn len(&self) -> usize { - self.elem_counter.len() - } +} + +unsafe impl<'a, 'tcx, T: Decodable>> TrustedLen + for DecodeIterator<'a, 'tcx, T> +{ } impl<'a: 'x, 'tcx: 'x, 'x, T: Decodable>> LazyArray { @@ -321,6 +330,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { self.cdata().map_encoded_cnum_to_current(cnum) } + #[inline] fn read_lazy_offset_then(&mut self, f: impl Fn(NonZeroUsize) -> T) -> T { let distance = self.read_usize(); let position = match self.lazy_state { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index da2ac41af92..e3581a7607f 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -32,24 +32,28 @@ trait ProcessQueryValue<'tcx, T> { } impl ProcessQueryValue<'_, Option> for Option { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option { self } } impl ProcessQueryValue<'_, T> for Option { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, err: impl Fn() -> !) -> T { if let Some(value) = self { value } else { err() } } } impl<'tcx, T: ArenaAllocatable<'tcx>> ProcessQueryValue<'tcx, &'tcx T> for Option { + #[inline(always)] fn process_decoded(self, tcx: TyCtxt<'tcx>, err: impl Fn() -> !) -> &'tcx T { if let Some(value) = self { tcx.arena.alloc(value) } else { err() } } } impl ProcessQueryValue<'_, Result, E>> for Option { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Result, E> { Ok(self) } @@ -58,12 +62,14 @@ impl ProcessQueryValue<'_, Result, E>> for Option { impl<'a, 'tcx, T: Copy + Decodable>> ProcessQueryValue<'tcx, &'tcx [T]> for Option> { + #[inline(always)] fn process_decoded(self, tcx: TyCtxt<'tcx>, _err: impl Fn() -> !) -> &'tcx [T] { if let Some(iter) = self { tcx.arena.alloc_from_iter(iter) } else { &[] } } } impl ProcessQueryValue<'_, Option> for Option { + #[inline(always)] fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> Option { self.map(DeprecationEntry::external) }