-------------------------------------------------------------------------------- I1 cache: 65536 B, 64 B, 4-way associative D1 cache: 32768 B, 64 B, 8-way associative LL cache: 67108864 B, 64 B, 64-way associative Command: /usr/home/liquid/.rustup/toolchains/w-profiling/bin/rustc --crate-name language_tags --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=e58f3536052e7ed9 -C extra-filename=-e58f3536052e7ed9 --out-dir /usr/home/liquid/tmp/.tmpxgSteG/target/release/deps -L dependency=/usr/home/liquid/tmp/.tmpxgSteG/target/release/deps -Adeprecated -Aunknown-lints -Zincremental-verify-ich Data file: results/cgout-w-profiling-language-tags-0.3.2-Opt-Full Events recorded: Ir Events shown: Ir Event sort order: Ir Thresholds: 0.1 Include dirs: User annotated: Auto-annotation: on -------------------------------------------------------------------------------- Ir -------------------------------------------------------------------------------- 10,017,509,650 (100.0%) PROGRAM TOTALS -------------------------------------------------------------------------------- Ir file:function -------------------------------------------------------------------------------- 273,618,007 ( 2.73%) ./malloc/malloc.c:_int_malloc 262,221,816 ( 2.62%) ./malloc/malloc.c:_int_free 168,079,061 ( 1.68%) ./malloc/malloc.c:malloc 126,830,428 ( 1.27%) ???:llvm::InstCombinerImpl::run() 98,435,607 ( 0.98%) ./string/../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:__memcpy_avx_unaligned_erms 91,770,981 ( 0.92%) ???:combineInstructionsOverFunction(llvm::Function&, llvm::InstCombineWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, unsigned int, llvm::LoopInfo*) 84,116,057 ( 0.84%) ???:computeKnownBits(llvm::Value const*, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) [clone .llvm.15619146473165121143] 80,654,694 ( 0.81%) ./malloc/malloc.c:free 76,859,688 ( 0.77%) ???:(anonymous namespace)::LazyValueInfoImpl::getEdgeValue(llvm::Value*, llvm::BasicBlock*, llvm::BasicBlock*, llvm::Instruction*) [clone .llvm.4316243980339171764] 76,694,454 ( 0.77%) ???:computeKnownBits(llvm::Value const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) 75,214,437 ( 0.75%) ???:llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) 66,721,191 ( 0.67%) ???:computeKnownBitsFromOperator(llvm::Operator const*, llvm::APInt const&, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) 65,238,348 ( 0.65%) ???:(anonymous namespace)::LazyValueInfoImpl::solve() [clone .llvm.4316243980339171764] 60,832,710 ( 0.61%) ???:llvm::BasicAAResult::alias(llvm::MemoryLocation const&, llvm::MemoryLocation const&, llvm::AAQueryInfo&) 59,867,037 ( 0.60%) ???:llvm::AnalysisManager::getResultImpl(llvm::AnalysisKey*, llvm::Function&) 58,774,327 ( 0.59%) ???:llvm::ValueHandleBase::AddToUseList() 57,462,179 ( 0.57%) ???:llvm::AnalysisManager::invalidate(llvm::Function&, llvm::PreservedAnalyses const&) 54,543,969 ( 0.54%) ???:llvm::DomTreeBuilder::SemiNCAInfo >::CalculateFromScratch(llvm::DominatorTreeBase&, llvm::DomTreeBuilder::SemiNCAInfo >::BatchUpdateInfo*) 52,098,359 ( 0.52%) ???:llvm::FPPassManager::runOnFunction(llvm::Function&) 51,767,287 ( 0.52%) ???:llvm::DataLayout::getTypeSizeInBits(llvm::Type*) const 48,542,843 ( 0.48%) ???:computeKnownBitsFromAssume(llvm::Value const*, llvm::KnownBits&, unsigned int, (anonymous namespace)::Query const&) 48,186,617 ( 0.48%) ???:SimplifyICmpInst(unsigned int, llvm::Value*, llvm::Value*, llvm::SimplifyQuery const&, unsigned int) [clone .llvm.1619516508949622737] 46,435,446 ( 0.46%) ./malloc/malloc.c:malloc_consolidate 43,683,822 ( 0.44%) ???:runCVP(llvm::Module&) [clone .llvm.11785992503873176614] 43,314,995 ( 0.43%) ???:llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) 42,734,018 ( 0.43%) ???:llvm::DataLayout::getAlignment(llvm::Type*, bool) const 41,475,176 ( 0.41%) ???:bool llvm::DenseMapBase*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue>, llvm::detail::DenseMapPair<(anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*> >, (anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue>, llvm::detail::DenseMapPair<(anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*> >::LookupBucketFor<(anonymous namespace)::SimpleValue>((anonymous namespace)::SimpleValue const&, llvm::detail::DenseMapPair<(anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*> const*&) const 40,184,864 ( 0.40%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_index/src/bit_set.rs:>::union::> 39,704,222 ( 0.40%) ???:llvm::isNonEscapingLocalObject(llvm::Value const*, llvm::SmallDenseMap, llvm::detail::DenseMapPair >*) 39,471,750 ( 0.39%) ???:llvm::AttributeList::addAttributes(llvm::LLVMContext&, unsigned int, llvm::AttrBuilder const&) const 38,210,548 ( 0.38%) ???:llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Value*, llvm::APInt, llvm::KnownBits&, unsigned int, llvm::Instruction*) 36,556,666 ( 0.36%) ???:llvm::LoopBase::verifyLoop() const 35,397,791 ( 0.35%) ???:llvm::removeUnreachableBlocks(llvm::Function&, llvm::DomTreeUpdater*, llvm::MemorySSAUpdater*) 34,044,443 ( 0.34%) ???:llvm::DomTreeBuilder::SemiNCAInfo >::runSemiNCA(llvm::DominatorTreeBase&, unsigned int) 33,154,857 ( 0.33%) ./string/../sysdeps/x86_64/multiarch/memcmp-avx2-movbe.S:__memcmp_avx2_movbe 31,750,226 ( 0.32%) ???:llvm::SimplifyInstruction(llvm::Instruction*, llvm::SimplifyQuery const&, llvm::OptimizationRemarkEmitter*) 30,930,883 ( 0.31%) ./string/../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S:__memset_avx2_erms 30,756,140 ( 0.31%) ./malloc/malloc.c:unlink_chunk.constprop.0 30,519,293 ( 0.30%) ???:llvm::TargetLibraryInfoImpl::getLibFunc(llvm::Function const&, llvm::LibFunc&) const 27,648,291 ( 0.28%) ???:llvm::BitstreamCursor::readRecord(unsigned int, llvm::SmallVectorImpl&, llvm::StringRef*) 25,612,570 ( 0.26%) ???:(anonymous namespace)::SimplifyCFGOpt::simplifyCondBranch(llvm::BranchInst*, llvm::IRBuilder&) 25,387,313 ( 0.25%) ???:isKnownNonZero(llvm::Value const*, llvm::APInt const&, unsigned int, (anonymous namespace)::Query const&) [clone .llvm.15619146473165121143] 25,105,884 ( 0.25%) ???:llvm::simplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&, llvm::ArrayRef) 24,535,882 ( 0.24%) ???:llvm::MemoryDependenceResults::getNonLocalPointerDepFromBB(llvm::Instruction*, llvm::PHITransAddr const&, llvm::MemoryLocation const&, bool, llvm::BasicBlock*, llvm::SmallVectorImpl&, llvm::DenseMap, llvm::detail::DenseMapPair >&, bool, bool) 23,500,990 ( 0.23%) ???:llvm::InlineFunction(llvm::CallBase&, llvm::InlineFunctionInfo&, llvm::AAResults*, bool, llvm::Function*) 22,568,804 ( 0.23%) ???:llvm::FindFunctionBackedges(llvm::Function const&, llvm::SmallVectorImpl >&) 22,449,795 ( 0.22%) ???:llvm::Loop::isLCSSAForm(llvm::DominatorTree const&) const 22,442,293 ( 0.22%) ???:llvm::ConstantRange::makeExactICmpRegion(llvm::CmpInst::Predicate, llvm::APInt const&) 22,208,629 ( 0.22%) ???:llvm::InstCombinerImpl::visitCallInst(llvm::CallInst&) 21,344,634 ( 0.21%) ???:llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int) 19,997,441 ( 0.20%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_index/src/bit_set.rs:>::union::> 19,457,537 ( 0.19%) /tmp/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/libsupc++/../../../../gcc-5.5.0/libstdc++-v3/libsupc++/new_op.cc:operator new(unsigned long) 19,177,983 ( 0.19%) ???:llvm::GVN::processBlock(llvm::BasicBlock*) 18,866,377 ( 0.19%) ???:(anonymous namespace)::MachineCopyPropagation::runOnMachineFunction(llvm::MachineFunction&) 18,668,575 ( 0.19%) ???:(anonymous namespace)::EarlyCSE::run() [clone .llvm.7062997131228810369] 18,464,444 ( 0.18%) ???:llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) 18,269,507 ( 0.18%) ???:llvm::LoopBase::getExitBlocks(llvm::SmallVectorImpl&) const 18,142,625 ( 0.18%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/step.rs:>::run 17,931,696 ( 0.18%) ???:llvm::FoldBranchToCommonDest(llvm::BranchInst*, llvm::DomTreeUpdater*, llvm::MemorySSAUpdater*, llvm::TargetTransformInfo const*, unsigned int) 17,868,620 ( 0.18%) ???:llvm::MemorySSA::buildMemorySSA(llvm::BatchAAResults&) 17,407,509 ( 0.17%) ???:llvm::InterferenceCache::Entry::update(unsigned int) 16,836,976 ( 0.17%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/operand.rs:>::try_read_immediate 16,730,863 ( 0.17%) ???:llvm::SimplifyGEPInst(llvm::Type*, llvm::ArrayRef, llvm::SimplifyQuery const&) 16,699,322 ( 0.17%) ???:llvm::coro::declaresIntrinsics(llvm::Module const&, std::initializer_list) 16,225,517 ( 0.16%) ???:llvm::SmallPtrSetImplBase::insert_imp_big(void const*) 15,469,714 ( 0.15%) /usr/home/liquid/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.0/src/raw/mod.rs:>>::from_key_hashed_nocheck:: 15,435,242 ( 0.15%) ???:llvm::Loop::isRecursivelyLCSSAForm(llvm::DominatorTree const&, llvm::LoopInfo const&) const 15,426,241 ( 0.15%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs:rustc_mir_dataflow::drop_flag_effects::on_all_children_bits::is_terminal_path 15,385,510 ( 0.15%) ???:llvm::Value::stripAndAccumulateConstantOffsets(llvm::DataLayout const&, llvm::APInt&, bool, llvm::function_ref) const 15,330,187 ( 0.15%) ./string/../sysdeps/x86_64/multiarch/strcmp-avx2.S:__strncmp_avx2 15,038,341 ( 0.15%) ???:(anonymous namespace)::PruningFunctionCloner::CloneBlock(llvm::BasicBlock const*, llvm::ilist_iterator, false, true>, std::vector >&) 15,025,137 ( 0.15%) ???:llvm::LoopInfoBase::analyze(llvm::DominatorTreeBase const&) 15,019,478 ( 0.15%) /usr/home/liquid/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.0/src/raw/mod.rs:, (core::result::Result, rustc_middle::ty::layout::LayoutError>, rustc_query_system::dep_graph::graph::DepNodeIndex), core::hash::BuildHasherDefault>>::from_key_hashed_nocheck::> 14,871,861 ( 0.15%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/operand.rs:>::eval_operand 14,810,269 ( 0.15%) ???:llvm::InstCombinerImpl::visitLoadInst(llvm::LoadInst&) 14,766,716 ( 0.15%) ???:llvm::Type::isSizedDerivedType(llvm::SmallPtrSetImpl*) const 14,629,041 ( 0.15%) ???:llvm::Type::getPrimitiveSizeInBits() const 14,627,779 ( 0.15%) ???:(anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) 14,430,421 ( 0.14%) ???:llvm::DomTreeBuilder::SemiNCAInfo >::FindRoots(llvm::DominatorTreeBase const&, llvm::DomTreeBuilder::SemiNCAInfo >::BatchUpdateInfo*) 14,373,931 ( 0.14%) ???:(anonymous namespace)::eliminateDeadStores(llvm::Function&, llvm::AAResults&, llvm::MemorySSA&, llvm::DominatorTree&, llvm::PostDominatorTree&, llvm::TargetLibraryInfo const&, llvm::LoopInfo const&) [clone .llvm.5769264623867638418] 14,203,149 ( 0.14%) ???:llvm::PopulateLoopsDFS::traverse(llvm::BasicBlock*) 14,030,568 ( 0.14%) ???:llvm::DomTreeBuilder::SemiNCAInfo >::CalculateFromScratch(llvm::DominatorTreeBase&, llvm::DomTreeBuilder::SemiNCAInfo >::BatchUpdateInfo*) 13,956,497 ( 0.14%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_parse/src/lexer/mod.rs:::next_token 13,925,504 ( 0.14%) ???:llvm::SelectionDAG::computeKnownBits(llvm::SDValue, llvm::APInt const&, unsigned int) const 13,820,811 ( 0.14%) ???:llvm::detail::PassModel>, llvm::PreservedAnalyses, llvm::AnalysisManager>::run(llvm::Function&, llvm::AnalysisManager&) 13,796,473 ( 0.14%) ???:llvm::ScalarEvolution::forgetValue(llvm::Value*) 13,788,949 ( 0.14%) ???:llvm::getObjectSize(llvm::Value const*, unsigned long&, llvm::DataLayout const&, llvm::TargetLibraryInfo const*, llvm::ObjectSizeOpts) 13,675,873 ( 0.14%) ???:(anonymous namespace)::LazyValueInfoImpl::getValueInBlock(llvm::Value*, llvm::BasicBlock*, llvm::Instruction*) [clone .llvm.4316243980339171764] 13,671,198 ( 0.14%) ???:llvm::JumpThreadingPass::processBlock(llvm::BasicBlock*) 13,606,356 ( 0.14%) /usr/home/liquid/rust/worktree-benchmarking/library/core/src/result.rs:>::run 13,586,447 ( 0.14%) ???:llvm::AttributeList::get(llvm::LLVMContext&, llvm::ArrayRef) 13,582,557 ( 0.14%) ???:llvm::AttributeSetNode::get(llvm::LLVMContext&, llvm::AttrBuilder const&) 13,435,787 ( 0.13%) ???:llvm::DemandedBits::isInstructionDead(llvm::Instruction*) 13,088,077 ( 0.13%) ???:llvm::IDFCalculatorBase::calculate(llvm::SmallVectorImpl&) 12,855,903 ( 0.13%) ???:collectBitParts(llvm::Value*, bool, bool, std::map, std::less, std::allocator > > >&, int, bool&) 12,743,633 ( 0.13%) /usr/home/liquid/rust/worktree-benchmarking/library/core/src/num/uint_macros.rs:::short_write_process_buffer:: 12,692,748 ( 0.13%) ???:(anonymous namespace)::AggressiveDeadCodeElimination::performDeadCodeElimination() 12,638,802 ( 0.13%) ???:SimplifyOrInst(llvm::Value*, llvm::Value*, llvm::SimplifyQuery const&, unsigned int) [clone .llvm.1619516508949622737] 12,619,038 ( 0.13%) ???:updateCGAndAnalysisManagerForPass(llvm::LazyCallGraph&, llvm::LazyCallGraph::SCC&, llvm::LazyCallGraph::Node&, llvm::AnalysisManager&, llvm::CGSCCUpdateResult&, llvm::AnalysisManager&, bool) [clone .llvm.5426518467876156712] 12,528,886 ( 0.13%) ???:(anonymous namespace)::CVPLatticeFunc::ComputeInstructionState(llvm::Instruction&, llvm::DenseMap, llvm::PointerIntPairInfo > >, (anonymous namespace)::CVPLatticeVal, llvm::DenseMapInfo, llvm::PointerIntPairInfo > > >, llvm::detail::DenseMapPair, llvm::PointerIntPairInfo > >, (anonymous namespace)::CVPLatticeVal> >&, llvm::SparseSolver, llvm::PointerIntPairInfo > >, (anonymous namespace)::CVPLatticeVal, llvm::LatticeKeyInfo, llvm::PointerIntPairInfo > > > >&) 12,482,782 ( 0.12%) ???:llvm::SROA::runOnAlloca(llvm::AllocaInst&) 12,292,742 ( 0.12%) ./string/../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S:__memset_avx2_unaligned_erms 12,251,487 ( 0.12%) ???:llvm::TargetLoweringBase::getTypeConversion(llvm::LLVMContext&, llvm::EVT) const 12,184,966 ( 0.12%) ???:(anonymous namespace)::RAGreedy::growRegion((anonymous namespace)::RAGreedy::GlobalSplitCandidate&) 12,117,190 ( 0.12%) ???:(anonymous namespace)::Verifier::visitInstruction(llvm::Instruction&) 12,083,445 ( 0.12%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_parse/src/parser/mod.rs:::check 11,936,240 ( 0.12%) ???:llvm::ScalarEvolution::getAddExpr(llvm::SmallVectorImpl&, llvm::SCEV::NoWrapFlags, unsigned int) 11,514,736 ( 0.11%) ???:llvm::AttributeList::addAttribute(llvm::LLVMContext&, unsigned int, llvm::Attribute::AttrKind) const 11,446,155 ( 0.11%) /usr/home/liquid/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.0/src/raw/mod.rs:>>::get:: 11,403,758 ( 0.11%) ???:llvm::ScheduleDAGSDNodes::BuildSchedUnits() 11,264,871 ( 0.11%) ???:llvm::DenseMapBase, std::unique_ptr<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry, std::default_delete<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry> >, llvm::DenseMapInfo >, llvm::detail::DenseMapPair, std::unique_ptr<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry, std::default_delete<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry> > > >, llvm::PoisoningVH, std::unique_ptr<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry, std::default_delete<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry> >, llvm::DenseMapInfo >, llvm::detail::DenseMapPair, std::unique_ptr<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry, std::default_delete<(anonymous namespace)::LazyValueInfoCache::BlockCacheEntry> > > >::destroyAll() [clone .llvm.4316243980339171764] 11,021,212 ( 0.11%) ???:llvm::SCCPInstVisitor::solve() 10,970,142 ( 0.11%) ???:(anonymous namespace)::DeadMachineInstructionElim::eliminateDeadMI(llvm::MachineFunction&) 10,968,500 ( 0.11%) ???:llvm::FoldingSetBase::FindNodeOrInsertPos(llvm::FoldingSetNodeID const&, void*&, llvm::FoldingSetBase::FoldingSetInfo const&) 10,902,259 ( 0.11%) ???:llvm::InstCombinerImpl::visitStoreInst(llvm::StoreInst&) 10,886,806 ( 0.11%) /usr/home/liquid/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.0/src/raw/mod.rs:, (), core::hash::BuildHasherDefault>>::from_hash::>::{closure#0}> 10,873,989 ( 0.11%) ???:llvm::LivePhysRegs::stepBackward(llvm::MachineInstr const&) 10,778,668 ( 0.11%) ???:llvm::KnownBits::computeForAddSub(bool, bool, llvm::KnownBits const&, llvm::KnownBits) 10,741,733 ( 0.11%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/place.rs:>::force_allocation_maybe_sized 10,631,950 ( 0.11%) ???:llvm::MachineInstr::addOperand(llvm::MachineFunction&, llvm::MachineOperand const&) 10,583,765 ( 0.11%) ???:llvm::MemorySSA::OptimizeUses::optimizeUses() 10,557,407 ( 0.11%) ???:llvm::ReassociatePass::run(llvm::Function&, llvm::AnalysisManager&) 10,457,728 ( 0.10%) ???:llvm::BlockFrequencyInfoImpl::initializeRPOT() 10,418,362 ( 0.10%) ???:llvm::AAResults::getModRefInfo(llvm::Instruction const*, llvm::Optional const&, llvm::AAQueryInfo&) 10,342,405 ( 0.10%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_parse/src/lexer/tokentrees.rs:::parse_token_tree 10,309,636 ( 0.10%) ./elf/dl-lookup.c:_dl_lookup_symbol_x 10,283,280 ( 0.10%) ???:llvm::PassRegistry::enumerateWith(llvm::PassRegistrationListener*) 10,274,957 ( 0.10%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_span/src/caching_source_map_view.rs:::span_data_to_lines_and_cols 10,239,956 ( 0.10%) ???:llvm::computeConstantRange(llvm::Value const*, bool, llvm::AssumptionCache*, llvm::Instruction const*, unsigned int) 10,184,103 ( 0.10%) ???:llvm::TargetTransformInfo::Model::getUserCost(llvm::User const*, llvm::ArrayRef, llvm::TargetTransformInfo::TargetCostKind) 10,161,116 ( 0.10%) ???:llvm::ScalarEvolution::getSCEV(llvm::Value*) 10,077,197 ( 0.10%) /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/place.rs:>::copy_op_no_validate 10,045,803 ( 0.10%) ???:llvm::ConstantFoldTerminator(llvm::BasicBlock*, bool, llvm::TargetLibraryInfo const*, llvm::DomTreeUpdater*) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs -------------------------------------------------------------------------------- Ir -- line 10 ---------------------------------------- . pub fn move_path_children_matching<'tcx, F>( . move_data: &MoveData<'tcx>, . path: MovePathIndex, . mut cond: F, . ) -> Option . where . F: FnMut(mir::PlaceElem<'tcx>) -> bool, . { 7 ( 0.00%) let mut next_child = move_data.move_paths[path].first_child; 26 ( 0.00%) while let Some(child_index) = next_child { . let move_path_children = &move_data.move_paths[child_index]; 14 ( 0.00%) if let Some(&elem) = move_path_children.place.projection.last() { 22 ( 0.00%) if cond(elem) { . return Some(child_index); . } . } . next_child = move_path_children.next_sibling; . } . . None . } -- line 30 ---------------------------------------- -- line 48 ---------------------------------------- . // . // FIXME: we have to do something for moving slice patterns. . fn place_contents_drop_state_cannot_differ<'tcx>( . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . place: mir::Place<'tcx>, . ) -> bool { . let ty = place.ty(body, tcx).ty; 2,749,650 ( 0.03%) match ty.kind() { . ty::Array(..) => { . debug!( . "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} => false", . place, ty . ); . false . } . ty::Slice(..) | ty::Ref(..) | ty::RawPtr(..) => { . debug!( . "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} refd => true", . place, ty . ); . true . } 1,835,037 ( 0.02%) ty::Adt(def, _) if (def.has_dtor(tcx) && !def.is_box()) || def.is_union() => { . debug!( . "place_contents_drop_state_cannot_differ place: {:?} ty: {:?} Drop => true", . place, ty . ); . true . } . _ => false, . } -- line 79 ---------------------------------------- -- line 83 ---------------------------------------- . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . move_data: &MoveData<'tcx>, . lookup_result: LookupResult, . each_child: F, . ) where . F: FnMut(MovePathIndex), . { 126,672 ( 0.00%) match lookup_result { . LookupResult::Parent(..) => { . // access to untracked value - do not touch children . } . LookupResult::Exact(e) => on_all_children_bits(tcx, body, move_data, e, each_child), . } . } . . pub fn on_all_children_bits<'tcx, F>( -- line 99 ---------------------------------------- -- line 100 ---------------------------------------- . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . move_data: &MoveData<'tcx>, . move_path_index: MovePathIndex, . mut each_child: F, . ) where . F: FnMut(MovePathIndex), . { 3,713,504 ( 0.04%) fn is_terminal_path<'tcx>( . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . move_data: &MoveData<'tcx>, . path: MovePathIndex, . ) -> bool { 928,376 ( 0.01%) place_contents_drop_state_cannot_differ(tcx, body, move_data.move_paths[path].place) 3,713,504 ( 0.04%) } . 4,226,874 ( 0.04%) fn on_all_children_bits<'tcx, F>( . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . move_data: &MoveData<'tcx>, . move_path_index: MovePathIndex, . each_child: &mut F, . ) where . F: FnMut(MovePathIndex), . { 88,403 ( 0.00%) each_child(move_path_index); . 3,249,397 ( 0.03%) if is_terminal_path(tcx, body, move_data, move_path_index) { . return; . } . 446,285 ( 0.00%) let mut next_child_index = move_data.move_paths[move_path_index].first_child; 892,637 ( 0.01%) while let Some(child_index) = next_child_index { 84 ( 0.00%) on_all_children_bits(tcx, body, move_data, child_index, each_child); 14 ( 0.00%) next_child_index = move_data.move_paths[child_index].next_sibling; . } 3,578,460 ( 0.04%) } 2,814,297 ( 0.03%) on_all_children_bits(tcx, body, move_data, move_path_index, &mut each_child); . } . . pub fn on_all_drop_children_bits<'tcx, F>( . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . ctxt: &MoveDataParamEnv<'tcx>, . path: MovePathIndex, . mut each_child: F, . ) where . F: FnMut(MovePathIndex), . { 1,531 ( 0.00%) on_all_children_bits(tcx, body, &ctxt.move_data, path, |child| { 724 ( 0.00%) let place = &ctxt.move_data.move_paths[path].place; 181 ( 0.00%) let ty = place.ty(body, tcx).ty; . debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty); . 8 ( 0.00%) let erased_ty = tcx.erase_regions(ty); 1,103 ( 0.00%) if erased_ty.needs_drop(tcx, ctxt.param_env) { 121 ( 0.00%) each_child(child); . } else { . debug!("on_all_drop_children_bits - skipping") . } . }) . } . 11,891 ( 0.00%) pub fn drop_flag_effects_for_function_entry<'tcx, F>( . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . ctxt: &MoveDataParamEnv<'tcx>, . mut callback: F, . ) where . F: FnMut(MovePathIndex, DropFlagState), . { . let move_data = &ctxt.move_data; 1,064 ( 0.00%) for arg in body.args_iter() { 1,992 ( 0.00%) let place = mir::Place::from(arg); 2,988 ( 0.00%) let lookup_result = move_data.rev_lookup.find(place.as_ref()); . on_lookup_result_bits(tcx, body, move_data, lookup_result, |mpi| { 1,002 ( 0.00%) callback(mpi, DropFlagState::Present) . }); . } 8,512 ( 0.00%) } . 4,963,752 ( 0.05%) pub fn drop_flag_effects_for_location<'tcx, F>( . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . ctxt: &MoveDataParamEnv<'tcx>, . loc: Location, . mut callback: F, . ) where . F: FnMut(MovePathIndex, DropFlagState), . { . let move_data = &ctxt.move_data; . debug!("drop_flag_effects_for_location({:?})", loc); . . // first, move out of the RHS 207,096 ( 0.00%) for mi in &move_data.loc_map[loc] { 1,203,853 ( 0.01%) let path = mi.move_path_index(move_data); . debug!("moving out of path {:?}", move_data.move_paths[path]); . 312,071 ( 0.00%) on_all_children_bits(tcx, body, move_data, path, |mpi| callback(mpi, DropFlagState::Absent)) . } . . debug!("drop_flag_effects: assignment for location({:?})", loc); . 88,403 ( 0.00%) for_location_inits(tcx, body, move_data, loc, |mpi| callback(mpi, DropFlagState::Present)); 3,859,968 ( 0.04%) } . . pub fn for_location_inits<'tcx, F>( . tcx: TyCtxt<'tcx>, . body: &Body<'tcx>, . move_data: &MoveData<'tcx>, . loc: Location, . mut callback: F, . ) where . F: FnMut(MovePathIndex), . { 207,096 ( 0.00%) for ii in &move_data.init_loc_map[loc] { 642,912 ( 0.01%) let init = move_data.inits[*ii]; 466,106 ( 0.00%) match init.kind { . InitKind::Deep => { . let path = init.path; . . on_all_children_bits(tcx, body, move_data, path, &mut callback) . } . InitKind::Shallow => { . let mpi = init.path; . callback(mpi); -- line 226 ---------------------------------------- -- line 230 ---------------------------------------- . } . } . . /// Calls `handle_inactive_variant` for each descendant move path of `enum_place` that contains a . /// `Downcast` to a variant besides the `active_variant`. . /// . /// NOTE: If there are no move paths corresponding to an inactive variant, . /// `handle_inactive_variant` will not be called for that variant. 6,552 ( 0.00%) pub(crate) fn on_all_inactive_variants<'tcx>( . tcx: TyCtxt<'tcx>, . body: &mir::Body<'tcx>, . move_data: &MoveData<'tcx>, . enum_place: mir::Place<'tcx>, . active_variant: VariantIdx, . mut handle_inactive_variant: impl FnMut(MovePathIndex), . ) { 2,730 ( 0.00%) let enum_mpi = match move_data.rev_lookup.find(enum_place.as_ref()) { . LookupResult::Exact(mpi) => mpi, . LookupResult::Parent(_) => return, . }; . . let enum_path = &move_data.move_paths[enum_mpi]; 810 ( 0.00%) for (variant_mpi, variant_path) in enum_path.children(&move_data.move_paths) { . // Because of the way we build the `MoveData` tree, each child should have exactly one more . // projection than `enum_place`. This additional projection must be a downcast since the . // base is an enum. . let (downcast, base_proj) = variant_path.place.projection.split_last().unwrap(); . assert_eq!(enum_place.projection.len(), base_proj.len()); . . let variant_idx = match *downcast { . mir::ProjectionElem::Downcast(_, idx) => idx, -- line 260 ---------------------------------------- -- line 262 ---------------------------------------- . }; . . if variant_idx != active_variant { . on_all_children_bits(tcx, body, move_data, variant_mpi, |mpi| { . handle_inactive_variant(mpi) . }); . } . } 4,368 ( 0.00%) } 3,359,953 ( 0.03%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/place.rs -------------------------------------------------------------------------------- Ir -- line 14 ---------------------------------------- . use rustc_target::abi::{HasDataLayout, Size, VariantIdx, Variants}; . . use super::{ . alloc_range, mir_assign_valid_types, AllocId, AllocRef, AllocRefMut, CheckInAllocMsg, . ConstAlloc, ImmTy, Immediate, InterpCx, InterpResult, LocalValue, Machine, MemoryKind, OpTy, . Operand, Pointer, PointerArithmetic, Provenance, Scalar, ScalarMaybeUninit, . }; . 760,198 ( 0.01%) #[derive(Copy, Clone, Hash, PartialEq, Eq, HashStable, Debug)] . /// Information required for the sound usage of a `MemPlace`. . pub enum MemPlaceMeta { . /// The unsized payload (e.g. length for slices or vtable pointer for trait objects). . Meta(Scalar), . /// `Sized` types or unsized `extern type` . None, . /// The address of this place may not be taken. This protects the `MemPlace` from coming from . /// a ZST Operand without a backing allocation and being converted to an integer address. This -- line 30 ---------------------------------------- -- line 33 ---------------------------------------- . Poison, . } . . #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] . rustc_data_structures::static_assert_size!(MemPlaceMeta, 24); . . impl MemPlaceMeta { . pub fn unwrap_meta(self) -> Scalar { 9,886 ( 0.00%) match self { 7,272 ( 0.00%) Self::Meta(s) => s, . Self::None | Self::Poison => { . bug!("expected wide pointer extra data (e.g. slice length or trait object vtable)") . } . } . } . fn has_meta(self) -> bool { 135,245 ( 0.00%) match self { . Self::Meta(_) => true, . Self::None | Self::Poison => false, . } . } . } . . #[derive(Copy, Clone, Hash, PartialEq, Eq, HashStable, Debug)] . pub struct MemPlace { . /// The pointer can be a pure integer, with the `None` tag. 93 ( 0.00%) pub ptr: Pointer>, 186 ( 0.00%) pub align: Align, . /// Metadata for unsized places. Interpretation is up to the type. . /// Must not be present for sized types, but can be missing for unsized types . /// (e.g., `extern type`). . pub meta: MemPlaceMeta, . } . . #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] . rustc_data_structures::static_assert_size!(MemPlace, 48); -- line 68 ---------------------------------------- -- line 93 ---------------------------------------- . type Target = Place; . #[inline(always)] . fn deref(&self) -> &Place { . &self.place . } . } . . /// A MemPlace with its layout. Constructing it is only possible in this module. 651 ( 0.00%) #[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)] . pub struct MPlaceTy<'tcx, Tag: Provenance = AllocId> { . mplace: MemPlace, . pub layout: TyAndLayout<'tcx>, . } . . #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] . rustc_data_structures::static_assert_size!(MPlaceTy<'_>, 64); . -- line 109 ---------------------------------------- -- line 113 ---------------------------------------- . fn deref(&self) -> &MemPlace { . &self.mplace . } . } . . impl<'tcx, Tag: Provenance> From> for PlaceTy<'tcx, Tag> { . #[inline(always)] . fn from(mplace: MPlaceTy<'tcx, Tag>) -> Self { 7,622 ( 0.00%) PlaceTy { place: Place::Ptr(mplace.mplace), layout: mplace.layout } . } . } . . impl MemPlace { . #[inline(always)] . pub fn from_ptr(ptr: Pointer>, align: Align) -> Self { . MemPlace { ptr, align, meta: MemPlaceMeta::None } . } -- line 129 ---------------------------------------- -- line 132 ---------------------------------------- . pub fn map_provenance(self, f: impl FnOnce(Option) -> Option) -> Self { . MemPlace { ptr: self.ptr.map_provenance(f), ..self } . } . . /// Turn a mplace into a (thin or wide) pointer, as a reference, pointing to the same space. . /// This is the inverse of `ref_to_mplace`. . #[inline(always)] . pub fn to_ref(self, cx: &impl HasDataLayout) -> Immediate { 1,485 ( 0.00%) match self.meta { 441 ( 0.00%) MemPlaceMeta::None => Immediate::from(Scalar::from_maybe_pointer(self.ptr, cx)), . MemPlaceMeta::Meta(meta) => { 665 ( 0.00%) Immediate::ScalarPair(Scalar::from_maybe_pointer(self.ptr, cx).into(), meta.into()) . } . MemPlaceMeta::Poison => bug!( . "MPlaceTy::dangling may never be used to produce a \ . place that will have the address of its pointee taken" . ), . } . } . -- line 151 ---------------------------------------- -- line 163 ---------------------------------------- . }) . } . } . . impl<'tcx, Tag: Provenance> MPlaceTy<'tcx, Tag> { . /// Produces a MemPlace that works for ZST but nothing else . #[inline] . pub fn dangling(layout: TyAndLayout<'tcx>) -> Self { 12 ( 0.00%) let align = layout.align.abi; . let ptr = Pointer::new(None, Size::from_bytes(align.bytes())); // no provenance, absolute address . // `Poison` this to make sure that the pointer value `ptr` is never observable by the program. . MPlaceTy { mplace: MemPlace { ptr, align, meta: MemPlaceMeta::Poison }, layout } . } . . #[inline] . pub fn offset( . &self, . offset: Size, . meta: MemPlaceMeta, . layout: TyAndLayout<'tcx>, . cx: &impl HasDataLayout, . ) -> InterpResult<'tcx, Self> { 1,266,392 ( 0.01%) Ok(MPlaceTy { mplace: self.mplace.offset(offset, meta, cx)?, layout }) . } . . #[inline] . pub fn from_aligned_ptr(ptr: Pointer>, layout: TyAndLayout<'tcx>) -> Self { 275 ( 0.00%) MPlaceTy { mplace: MemPlace::from_ptr(ptr, layout.align.abi), layout } . } . . #[inline] 101,269 ( 0.00%) pub(super) fn len(&self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> { 468,238 ( 0.00%) if self.layout.is_unsized() { . // We need to consult `meta` metadata 13,902 ( 0.00%) match self.layout.ty.kind() { 4,943 ( 0.00%) ty::Slice(..) | ty::Str => self.mplace.meta.unwrap_meta().to_machine_usize(cx), . _ => bug!("len not supported on unsized type {:?}", self.layout.ty), . } . } else { . // Go through the layout. There are lots of types that support a length, . // e.g., SIMD types. (But not all repr(simd) types even have FieldsShape::Array!) 239,608 ( 0.00%) match self.layout.fields { 219,766 ( 0.00%) FieldsShape::Array { count, .. } => Ok(count), . _ => bug!("len not supported on sized type {:?}", self.layout.ty), . } . } 202,538 ( 0.00%) } . . #[inline] . pub(super) fn vtable(&self) -> Scalar { . match self.layout.ty.kind() { . ty::Dynamic(..) => self.mplace.meta.unwrap_meta(), . _ => bug!("vtable not supported on type {:?}", self.layout.ty), . } . } -- line 217 ---------------------------------------- -- line 218 ---------------------------------------- . } . . // These are defined here because they produce a place. . impl<'tcx, Tag: Provenance> OpTy<'tcx, Tag> { . #[inline(always)] . /// Note: do not call `as_ref` on the resulting place. This function should only be used to . /// read from the resulting mplace, not to get its address back. . pub fn try_as_mplace(&self) -> Result, ImmTy<'tcx, Tag>> { 824,064 ( 0.01%) match **self { 2,266,443 ( 0.02%) Operand::Indirect(mplace) => Ok(MPlaceTy { mplace, layout: self.layout }), 62 ( 0.00%) Operand::Immediate(_) if self.layout.is_zst() => Ok(MPlaceTy::dangling(self.layout)), 1,696,821 ( 0.02%) Operand::Immediate(imm) => Err(ImmTy::from_immediate(imm, self.layout)), . } . } . . #[inline(always)] . /// Note: do not call `as_ref` on the resulting place. This function should only be used to . /// read from the resulting mplace, not to get its address back. . pub fn assert_mem_place(&self) -> MPlaceTy<'tcx, Tag> { . self.try_as_mplace().unwrap() -- line 237 ---------------------------------------- -- line 263 ---------------------------------------- . M: Machine<'mir, 'tcx, PointerTag = Tag>, . { . /// Take a value, which represents a (thin or wide) reference, and make it a place. . /// Alignment is just based on the type. This is the inverse of `MemPlace::to_ref()`. . /// . /// Only call this if you are sure the place is "valid" (aligned and inbounds), or do not . /// want to ever use the place for memory access! . /// Generally prefer `deref_operand`. 26,460 ( 0.00%) pub fn ref_to_mplace( . &self, . val: &ImmTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { . let pointee_type = 7,938 ( 0.00%) val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type").ty; 7,938 ( 0.00%) let layout = self.layout_of(pointee_type)?; 13,230 ( 0.00%) let (ptr, meta) = match **val { 254 ( 0.00%) Immediate::Scalar(ptr) => (ptr, MemPlaceMeta::None), 17,633 ( 0.00%) Immediate::ScalarPair(ptr, meta) => (ptr, MemPlaceMeta::Meta(meta.check_init()?)), . }; . . let mplace = MemPlace { . ptr: self.scalar_to_ptr(ptr.check_init()?), . // We could use the run-time alignment here. For now, we do not, because . // the point of tracking the alignment here is to make sure that the *static* . // alignment information emitted with the loads is correct. The run-time . // alignment can only be more restrictive. 2,646 ( 0.00%) align: layout.align.abi, . meta, . }; 44,982 ( 0.00%) Ok(MPlaceTy { mplace, layout }) 23,814 ( 0.00%) } . . /// Take an operand, representing a pointer, and dereference it to a place -- that . /// will always be a MemPlace. Lives in `place.rs` because it creates a place. . pub fn deref_operand( . &self, . src: &OpTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { . let val = self.read_immediate(src)?; -- line 301 ---------------------------------------- -- line 306 ---------------------------------------- . } . . #[inline] . pub(super) fn get_alloc( . &self, . place: &MPlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, Option>> { . assert!(!place.layout.is_unsized()); 73,749 ( 0.00%) assert!(!place.meta.has_meta()); 73,749 ( 0.00%) let size = place.layout.size; 663,741 ( 0.01%) self.memory.get(place.ptr, size, place.align) . } . . #[inline] . pub(super) fn get_alloc_mut( . &mut self, . place: &MPlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, Option>> { 61,389 ( 0.00%) assert!(!place.layout.is_unsized()); 61,377 ( 0.00%) assert!(!place.meta.has_meta()); 61,377 ( 0.00%) let size = place.layout.size; 368,262 ( 0.00%) self.memory.get_mut(place.ptr, size, place.align) . } . . /// Check if this mplace is dereferenceable and sufficiently aligned. . fn check_mplace_access( . &self, . mplace: MPlaceTy<'tcx, M::PointerTag>, . msg: CheckInAllocMsg, . ) -> InterpResult<'tcx> { -- line 335 ---------------------------------------- -- line 349 ---------------------------------------- . /// This also works for arrays, but then the `usize` index type is restricting. . /// For indexing into arrays, use `mplace_index`. . #[inline(always)] . pub fn mplace_field( . &self, . base: &MPlaceTy<'tcx, M::PointerTag>, . field: usize, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { 469,905 ( 0.00%) let offset = base.layout.fields.offset(field); 365,246 ( 0.00%) let field_layout = base.layout.field(self, field); . . // Offset may need adjustment for unsized fields. 776,997 ( 0.01%) let (meta, offset) = if field_layout.is_unsized() { . // Re-use parent metadata to determine dynamic field layout. . // With custom DSTS, this *will* execute user-defined code, but the same . // happens at run-time so that's okay. . match self.size_and_align_of(&base.meta, &field_layout)? { . Some((_, align)) => (base.meta, offset.align_to(align)), . None => { . // For unsized types with an extern type tail we perform no adjustments. . // NOTE: keep this in sync with `PlaceRef::project_field` in the codegen backend. -- line 369 ---------------------------------------- -- line 374 ---------------------------------------- . } else { . // base.meta could be present; we might be accessing a sized field of an unsized . // struct. . (MemPlaceMeta::None, offset) . }; . . // We do not look at `base.layout.align` nor `field_layout.align`, unlike . // codegen -- mostly to see if we can get away with that 94,756 ( 0.00%) base.offset(offset, meta, field_layout, self) . } . . /// Index into an array. . #[inline(always)] . pub fn mplace_index( . &self, . base: &MPlaceTy<'tcx, M::PointerTag>, . index: u64, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { . // Not using the layout method because we want to compute on u64 90,315 ( 0.00%) match base.layout.fields { 30,105 ( 0.00%) FieldsShape::Array { stride, .. } => { 120,420 ( 0.00%) let len = base.len(self)?; 60,210 ( 0.00%) if index >= len { . // This can only be reached in ConstProp and non-rustc-MIR. . throw_ub!(BoundsCheckFailed { len, index }); . } . let offset = stride * index; // `Size` multiplication . // All fields have the same layout. 60,210 ( 0.00%) let field_layout = base.layout.field(self, 0); . 30,105 ( 0.00%) assert!(!field_layout.is_unsized()); . base.offset(offset, MemPlaceMeta::None, field_layout, self) . } . _ => span_bug!( . self.cur_span(), . "`mplace_index` called on non-array type {:?}", . base.layout.ty . ), . } . } . . // Iterates over all fields of an array. Much more efficient than doing the . // same by repeatedly calling `mplace_array`. 410,570 ( 0.00%) pub(super) fn mplace_array_fields<'a>( . &self, . base: &'a MPlaceTy<'tcx, Tag>, . ) -> InterpResult<'tcx, impl Iterator>> + 'a> . { 164,228 ( 0.00%) let len = base.len(self)?; // also asserts that we have a type where this makes sense 123,171 ( 0.00%) let stride = match base.layout.fields { 41,057 ( 0.00%) FieldsShape::Array { stride, .. } => stride, . _ => span_bug!(self.cur_span(), "mplace_array_fields: expected an array layout"), . }; 82,114 ( 0.00%) let layout = base.layout.field(self, 0); 41,057 ( 0.00%) let dl = &self.tcx.data_layout; . // `Size` multiplication 909,269 ( 0.01%) Ok((0..len).map(move |i| base.offset(stride * i, MemPlaceMeta::None, layout, dl))) 369,513 ( 0.00%) } . . fn mplace_subslice( . &self, . base: &MPlaceTy<'tcx, M::PointerTag>, . from: u64, . to: u64, . from_end: bool, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { -- line 439 ---------------------------------------- -- line 476 ---------------------------------------- . } . . pub(crate) fn mplace_downcast( . &self, . base: &MPlaceTy<'tcx, M::PointerTag>, . variant: VariantIdx, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { . // Downcasts only change the layout 119 ( 0.00%) assert!(!base.meta.has_meta()); 458 ( 0.00%) Ok(MPlaceTy { layout: base.layout.for_variant(self, variant), ..*base }) . } . . /// Project into an mplace 301,050 ( 0.00%) pub(super) fn mplace_projection( . &self, . base: &MPlaceTy<'tcx, M::PointerTag>, . proj_elem: mir::PlaceElem<'tcx>, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { . use rustc_middle::mir::ProjectionElem::*; 722,520 ( 0.01%) Ok(match proj_elem { . Field(field, _) => self.mplace_field(base, field.index())?, . Downcast(_, variant) => self.mplace_downcast(base, variant)?, . Deref => self.deref_operand(&base.into())?, . 30,105 ( 0.00%) Index(local) => { 150,525 ( 0.00%) let layout = self.layout_of(self.tcx.types.usize)?; 180,630 ( 0.00%) let n = self.access_local(self.frame(), local, Some(layout))?; 60,210 ( 0.00%) let n = self.read_scalar(&n)?; 30,105 ( 0.00%) let n = n.to_machine_usize(self)?; . self.mplace_index(base, n)? . } . . ConstantIndex { offset, min_length, from_end } => { . let n = base.len(self)?; . if n < min_length { . // This can only be reached in ConstProp and non-rustc-MIR. . throw_ub!(BoundsCheckFailed { len: min_length, index: n }); -- line 512 ---------------------------------------- -- line 520 ---------------------------------------- . offset . }; . . self.mplace_index(base, index)? . } . . Subslice { from, to, from_end } => self.mplace_subslice(base, from, to, from_end)?, . }) 240,840 ( 0.00%) } . . /// Converts a repr(simd) place into a place where `place_index` accesses the SIMD elements. . /// Also returns the number of elements. . pub fn mplace_to_simd( . &self, . base: &MPlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> { . // Basically we just transmute this place into an array following simd_size_and_type. -- line 536 ---------------------------------------- -- line 542 ---------------------------------------- . assert_eq!(layout.size, base.layout.size); . Ok((MPlaceTy { layout, ..*base }, len)) . } . . /// Gets the place of a field inside the place, and also the field's type. . /// Just a convenience function, but used quite a bit. . /// This is the only projection that might have a side-effect: We cannot project . /// into the field of a local `ScalarPair`, we have to first allocate it. 817,880 ( 0.01%) pub fn place_field( . &mut self, . base: &PlaceTy<'tcx, M::PointerTag>, . field: usize, . ) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> { . // FIXME: We could try to be smarter and avoid allocation for fields that span the . // entire place. 81,788 ( 0.00%) let mplace = self.force_allocation(base)?; 981,456 ( 0.01%) Ok(self.mplace_field(&mplace, field)?.into()) 654,304 ( 0.01%) } . . pub fn place_index( . &mut self, . base: &PlaceTy<'tcx, M::PointerTag>, . index: u64, . ) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> { . let mplace = self.force_allocation(base)?; . Ok(self.mplace_index(&mplace, index)?.into()) -- line 567 ---------------------------------------- -- line 568 ---------------------------------------- . } . . pub fn place_downcast( . &self, . base: &PlaceTy<'tcx, M::PointerTag>, . variant: VariantIdx, . ) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> { . // Downcast just changes the layout 440 ( 0.00%) Ok(match base.place { . Place::Ptr(mplace) => { . self.mplace_downcast(&MPlaceTy { mplace, layout: base.layout }, variant)?.into() . } . Place::Local { .. } => { 371 ( 0.00%) let layout = base.layout.for_variant(self, variant); 55 ( 0.00%) PlaceTy { layout, ..*base } . } . }) . } . . /// Projects into a place. . pub fn place_projection( . &mut self, . base: &PlaceTy<'tcx, M::PointerTag>, . &proj_elem: &mir::ProjectionElem>, . ) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> { . use rustc_middle::mir::ProjectionElem::*; 178,195 ( 0.00%) Ok(match proj_elem { 59,110 ( 0.00%) Field(field, _) => self.place_field(base, field.index())?, . Downcast(_, variant) => self.place_downcast(base, variant)?, . Deref => self.deref_operand(&self.place_to_op(base)?)?.into(), . // For the other variants, we have to force an allocation. . // This matches `operand_projection`. . Subslice { .. } | ConstantIndex { .. } | Index(_) => { . let mplace = self.force_allocation(base)?; . self.mplace_projection(&mplace, proj_elem)?.into() . } -- line 603 ---------------------------------------- -- line 611 ---------------------------------------- . base: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> { . let mplace = self.force_allocation(base)?; . self.mplace_to_simd(&mplace) . } . . /// Computes a place. You should only use this if you intend to write into this . /// place; for reading, a more efficient alternative is `eval_place_for_read`. 1,868,968 ( 0.02%) pub fn eval_place( . &mut self, . place: mir::Place<'tcx>, . ) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> { 1,168,085 ( 0.01%) let mut place_ty = PlaceTy { . // This works even for dead/uninitialized locals; we check further when writing . place: Place::Local { frame: self.frame_idx(), local: place.local }, . layout: self.layout_of_local(self.frame(), place.local, None)?, . }; . 23,770 ( 0.00%) for elem in place.projection.iter() { 11,877 ( 0.00%) place_ty = self.place_projection(&place_ty, &elem)? . } . . trace!("{:?}", self.dump_place(place_ty.place)); . // Sanity-check the type we ended up with. . debug_assert!(mir_assign_valid_types( . *self.tcx, . self.param_env, . self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions( . place.ty(&self.frame().body.local_decls, *self.tcx).ty . )?)?, . place_ty.layout, . )); 4,204,962 ( 0.04%) Ok(place_ty) 1,868,968 ( 0.02%) } . . /// Write an immediate to a place . #[inline(always)] . pub fn write_immediate( . &mut self, . src: Immediate, . dest: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { 276,369 ( 0.00%) self.write_immediate_no_validate(src, dest)?; . . if M::enforce_validity(self) { . // Data got changed, better make sure it matches the type! . self.validate_operand(&self.place_to_op(dest)?)?; . } . . Ok(()) . } -- line 661 ---------------------------------------- -- line 678 ---------------------------------------- . dest: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { . self.write_scalar(Scalar::from_maybe_pointer(ptr.into(), self), dest) . } . . /// Write an immediate to a place. . /// If you use this you are responsible for validating that things got copied at the . /// right type. 211,899 ( 0.00%) fn write_immediate_no_validate( . &mut self, . src: Immediate, . dest: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { . if cfg!(debug_assertions) { . // This is a very common path, avoid some checks in release mode . assert!(!dest.layout.is_unsized(), "Cannot write unsized data"); . match src { -- line 694 ---------------------------------------- -- line 705 ---------------------------------------- . // FIXME: Can we check anything here? . } . } . } . trace!("write_immediate: {:?} <- {:?}: {}", *dest, src, dest.layout.ty); . . // See if we can avoid an allocation. This is the counterpart to `try_read_immediate`, . // but not factored as a separate function. 424,662 ( 0.00%) let mplace = match dest.place { 302,237 ( 0.00%) Place::Local { frame, local } => { 1,114 ( 0.00%) match M::access_local_mut(self, frame, local)? { . Ok(local) => { . // Local can be updated in-place. 1,509,054 ( 0.02%) *local = LocalValue::Live(Operand::Immediate(src)); . return Ok(()); . } . Err(mplace) => { . // The local is in memory, go on below. . mplace . } . } . } 368,121 ( 0.00%) Place::Ptr(mplace) => mplace, // already referring to memory . }; 552,175 ( 0.01%) let dest = MPlaceTy { mplace, layout: dest.layout }; . . // This is already in memory, write there. 674,640 ( 0.01%) self.write_immediate_to_mplace_no_validate(src, &dest) 423,798 ( 0.00%) } . . /// Write an immediate to memory. . /// If you use this you are responsible for validating that things got copied at the . /// right type. 613,770 ( 0.01%) fn write_immediate_to_mplace_no_validate( . &mut self, . value: Immediate, . dest: &MPlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { . // Note that it is really important that the type here is the right one, and matches the . // type things are read at. In case `src_val` is a `ScalarPair`, we don't do any magic here . // to handle padding properly, which is only correct if we never look at this data with the . // wrong type. . . // Invalid places are a thing: the return place of a diverging function 61,377 ( 0.00%) let tcx = *self.tcx; 122,754 ( 0.00%) let mut alloc = match self.get_alloc_mut(dest)? { 306,855 ( 0.00%) Some(a) => a, . None => return Ok(()), // zero-sized access . }; . . // FIXME: We should check that there are dest.layout.size many bytes available in . // memory. The code below is not sufficient, with enough padding it might not . // cover all the bytes! 122,742 ( 0.00%) match value { . Immediate::Scalar(scalar) => { 121,384 ( 0.00%) match dest.layout.abi { . Abi::Scalar(_) => {} // fine . _ => span_bug!( . self.cur_span(), . "write_immediate_to_mplace: invalid Scalar layout: {:#?}", . dest.layout . ), . } 546,228 ( 0.01%) alloc.write_scalar(alloc_range(Size::ZERO, dest.layout.size), scalar) . } . Immediate::ScalarPair(a_val, b_val) => { . // We checked `ptr_align` above, so all fields will have the alignment they need. . // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, . // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. 1,358 ( 0.00%) let (a, b) = match dest.layout.abi { 2,037 ( 0.00%) Abi::ScalarPair(a, b) => (a.value, b.value), . _ => span_bug!( . self.cur_span(), . "write_immediate_to_mplace: invalid ScalarPair layout: {:#?}", . dest.layout . ), . }; . let (a_size, b_size) = (a.size(&tcx), b.size(&tcx)); . let b_offset = a_size.align_to(b.align(&tcx).abi); . . // It is tempting to verify `b_offset` against `layout.fields.offset(1)`, . // but that does not work: We could be a newtype around a pair, then the . // fields do not match the `ScalarPair` components. . 6,790 ( 0.00%) alloc.write_scalar(alloc_range(Size::ZERO, a_size), a_val)?; 5,432 ( 0.00%) alloc.write_scalar(alloc_range(b_offset, b_size), b_val) . } . } 491,016 ( 0.00%) } . . /// Copies the data from an operand to a place. This does not support transmuting! . /// Use `copy_op_transmute` if the layouts could disagree. . #[inline(always)] . pub fn copy_op( . &mut self, . src: &OpTy<'tcx, M::PointerTag>, . dest: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { 958,636 ( 0.01%) self.copy_op_no_validate(src, dest)?; . . if M::enforce_validity(self) { . // Data got changed, better make sure it matches the type! . self.validate_operand(&self.place_to_op(dest)?)?; . } . . Ok(()) . } . . /// Copies the data from an operand to a place. This does not support transmuting! . /// Use `copy_op_transmute` if the layouts could disagree. . /// Also, if you use this you are responsible for validating that things get copied at the . /// right type. 1,294,232 ( 0.01%) fn copy_op_no_validate( . &mut self, . src: &OpTy<'tcx, M::PointerTag>, . dest: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { . // We do NOT compare the types for equality, because well-typed code can . // actually "transmute" `&mut T` to `&T` in an assignment without a cast. 2,915,904 ( 0.03%) if !mir_assign_valid_types(*self.tcx, self.param_env, src.layout, dest.layout) { . span_bug!( . self.cur_span(), . "type mismatch when copying!\nsrc: {:?},\ndest: {:?}", . src.layout.ty, . dest.layout.ty, . ); . } . . // Let us see if the layout is simple so we take a shortcut, avoid force_allocation. 810,191 ( 0.01%) let src = match self.try_read_immediate(src)? { . Ok(src_val) => { 121,528 ( 0.00%) assert!(!src.layout.is_unsized(), "cannot have unsized immediates"); . // Yay, we got a value that we can write directly. . // FIXME: Add a check to make sure that if `src` is indirect, . // it does not overlap with `dest`. 1,575,496 ( 0.02%) return self.write_immediate_no_validate(*src_val, dest); . } 324,712 ( 0.00%) Err(mplace) => mplace, . }; . // Slow path, this does not fit into an immediate. Just memcpy. . trace!("copy_op: {:?} <- {:?}: {}", *dest, src, dest.layout.ty); . . // This interprets `src.meta` with the `dest` local's layout, if an unsized local . // is being initialized! 527,657 ( 0.01%) let (dest, size) = self.force_allocation_maybe_sized(dest, src.meta)?; . let size = size.unwrap_or_else(|| { 62,196 ( 0.00%) assert!( . !dest.layout.is_unsized(), . "Cannot copy into already initialized unsized place" . ); 20,732 ( 0.00%) dest.layout.size . }); 40,589 ( 0.00%) assert_eq!(src.meta, dest.meta, "Can only copy between equally-sized instances"); . 40,589 ( 0.00%) self.memory 121,767 ( 0.00%) .copy(src.ptr, src.align, dest.ptr, dest.align, size, /*nonoverlapping*/ true) 1,294,232 ( 0.01%) } . . /// Copies the data from an operand to a place. The layouts may disagree, but they must . /// have the same size. 159,800 ( 0.00%) pub fn copy_op_transmute( . &mut self, . src: &OpTy<'tcx, M::PointerTag>, . dest: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { 359,550 ( 0.00%) if mir_assign_valid_types(*self.tcx, self.param_env, src.layout, dest.layout) { . // Fast path: Just use normal `copy_op` . return self.copy_op(src, dest); . } . // We still require the sizes to match. . if src.layout.size != dest.layout.size { . // FIXME: This should be an assert instead of an error, but if we transmute within an . // array length computation, `typeck` may not have yet been run and errored out. In fact . // most likey we *are* running `typeck` right now. Investigate whether we can bail out -- line 878 ---------------------------------------- -- line 916 ---------------------------------------- . /// Ensures that a place is in memory, and returns where it is. . /// If the place currently refers to a local that doesn't yet have a matching allocation, . /// create such an allocation. . /// This is essentially `force_to_memplace`. . /// . /// This supports unsized types and returns the computed size to avoid some . /// redundant computation when copying; use `force_allocation` for a simpler, sized-only . /// version. 1,372,950 ( 0.01%) pub fn force_allocation_maybe_sized( . &mut self, . place: &PlaceTy<'tcx, M::PointerTag>, . meta: MemPlaceMeta, . ) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, Option)> { 1,525,476 ( 0.02%) let (mplace, size) = match place.place { 132,308 ( 0.00%) Place::Local { frame, local } => { 264,365 ( 0.00%) match M::access_local_mut(self, frame, local)? { 457,020 ( 0.00%) Ok(&mut local_val) => { . // We need to make an allocation. . . // We need the layout of the local. We can NOT use the layout we got, . // that might e.g., be an inner field of a struct with `Scalar` layout, . // that has different alignment than the outer field. . let local_layout = 254,560 ( 0.00%) self.layout_of_local(&self.stack()[frame], local, None)?; . // We also need to support unsized types, and hence cannot use `allocate`. 202,900 ( 0.00%) let (size, align) = self . .size_and_align_of(&meta, &local_layout)? . .expect("Cannot allocate for non-dyn-sized type"); 355,240 ( 0.00%) let ptr = self.memory.allocate(size, align, MemoryKind::Stack)?; . let mplace = MemPlace { ptr: ptr.into(), align, meta }; 253,900 ( 0.00%) if let LocalValue::Live(Operand::Immediate(value)) = local_val { . // Preserve old value. . // We don't have to validate as we can assume the local . // was already valid for its type. 140 ( 0.00%) let mplace = MPlaceTy { mplace, layout: local_layout }; 210 ( 0.00%) self.write_immediate_to_mplace_no_validate(value, &mplace)?; . } . // Now we can call `access_mut` again, asserting it goes well, . // and actually overwrite things. 964,160 ( 0.01%) *M::access_local_mut(self, frame, local).unwrap().unwrap() = . LocalValue::Live(Operand::Indirect(mplace)); 355,460 ( 0.00%) (mplace, Some(size)) . } 810,262 ( 0.01%) Err(mplace) => (mplace, None), // this already was an indirect local . } . } 269,510 ( 0.00%) Place::Ptr(mplace) => (mplace, None), . }; . // Return with the original layout, so that the caller can go on 1,830,564 ( 0.02%) Ok((MPlaceTy { mplace, layout: place.layout }, size)) 1,220,400 ( 0.01%) } . . #[inline(always)] . pub fn force_allocation( . &mut self, . place: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { 1,097,770 ( 0.01%) Ok(self.force_allocation_maybe_sized(place, MemPlaceMeta::None)?.0) . } . 784 ( 0.00%) pub fn allocate( . &mut self, . layout: TyAndLayout<'tcx>, . kind: MemoryKind, . ) -> InterpResult<'static, MPlaceTy<'tcx, M::PointerTag>> { 2,209 ( 0.00%) let ptr = self.memory.allocate(layout.size, layout.align.abi, kind)?; 588 ( 0.00%) Ok(MPlaceTy::from_aligned_ptr(ptr.into(), layout)) 686 ( 0.00%) } . . /// Returns a wide MPlace of type `&'static [mut] str` to a new 1-aligned allocation. 950 ( 0.00%) pub fn allocate_str( . &mut self, . str: &str, . kind: MemoryKind, . mutbl: Mutability, . ) -> MPlaceTy<'tcx, M::PointerTag> { 855 ( 0.00%) let ptr = self.memory.allocate_bytes(str.as_bytes(), Align::ONE, kind, mutbl); . let meta = Scalar::from_machine_usize(u64::try_from(str.len()).unwrap(), self); . let mplace = . MemPlace { ptr: ptr.into(), align: Align::ONE, meta: MemPlaceMeta::Meta(meta) }; . . let ty = self.tcx.mk_ref( 95 ( 0.00%) self.tcx.lifetimes.re_static, 95 ( 0.00%) ty::TypeAndMut { ty: self.tcx.types.str_, mutbl }, . ); 285 ( 0.00%) let layout = self.layout_of(ty).unwrap(); 950 ( 0.00%) MPlaceTy { mplace, layout } 760 ( 0.00%) } . . /// Writes the discriminant of the given variant. 1,694 ( 0.00%) pub fn write_discriminant( . &mut self, . variant_index: VariantIdx, . dest: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx> { . // This must be an enum or generator. 616 ( 0.00%) match dest.layout.ty.kind() { 308 ( 0.00%) ty::Adt(adt, _) => assert!(adt.is_enum()), . ty::Generator(..) => {} . _ => span_bug!( . self.cur_span(), . "write_discriminant called on non-variant-type (neither enum nor generator)" . ), . } . // Layout computation excludes uninhabited variants from consideration . // therefore there's no way to represent those variants in the given layout. . // Essentially, uninhabited variants do not have a tag that corresponds to their . // discriminant, so we cannot do anything here. . // When evaluating we will always error before even getting here, but ConstProp 'executes' . // dead code, so we cannot ICE here. 913 ( 0.00%) if dest.layout.for_variant(self, variant_index).abi.is_uninhabited() { . throw_ub!(UninhabitedEnumVariantWritten) . } . 770 ( 0.00%) match dest.layout.variants { . Variants::Single { index } => { . assert_eq!(index, variant_index); . } . Variants::Multiple { . tag_encoding: TagEncoding::Direct, 351 ( 0.00%) tag: tag_layout, 150 ( 0.00%) tag_field, . .. . } => { . // No need to validate that the discriminant here because the . // `TyAndLayout::for_variant()` call earlier already checks the variant is valid. . . let discr_val = 468 ( 0.00%) dest.layout.ty.discriminant_for_variant(*self.tcx, variant_index).unwrap().val; . . // raw discriminants for enums are isize or bigger during . // their computation, but the in-memory tag is the smallest possible . // representation . let size = tag_layout.value.size(self); . let tag_val = size.truncate(discr_val); . 501 ( 0.00%) let tag_dest = self.place_field(dest, tag_field)?; . self.write_scalar(Scalar::from_uint(tag_val, size), &tag_dest)?; . } . Variants::Multiple { . tag_encoding: . TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start }, . tag: tag_layout, . tag_field, . .. . } => { . // No need to validate that the discriminant here because the . // `TyAndLayout::for_variant()` call earlier already checks the variant is valid. . 37 ( 0.00%) if variant_index != dataful_variant { . let variants_start = niche_variants.start().as_u32(); . let variant_index_relative = variant_index . .as_u32() . .checked_sub(variants_start) . .expect("overflow computing relative variant idx"); . // We need to use machine arithmetic when taking into account `niche_start`: . // tag_val = variant_index_relative + niche_start_val 36 ( 0.00%) let tag_layout = self.layout_of(tag_layout.value.to_int_ty(*self.tcx))?; . let niche_start_val = ImmTy::from_uint(niche_start, tag_layout); . let variant_index_relative_val = . ImmTy::from_uint(variant_index_relative, tag_layout); . let tag_val = self.binary_op( . mir::BinOp::Add, . &variant_index_relative_val, . &niche_start_val, . )?; . // Write result. 48 ( 0.00%) let niche_dest = self.place_field(dest, tag_field)?; . self.write_immediate(*tag_val, &niche_dest)?; . } . } . } . . Ok(()) 1,232 ( 0.00%) } . 1,107 ( 0.00%) pub fn raw_const_to_mplace( . &self, . raw: ConstAlloc<'tcx>, . ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { . // This must be an allocation in `tcx` 369 ( 0.00%) let _ = self.tcx.global_alloc(raw.alloc_id); . let ptr = self.global_base_pointer(Pointer::from(raw.alloc_id))?; 456 ( 0.00%) let layout = self.layout_of(raw.ty)?; 738 ( 0.00%) Ok(MPlaceTy::from_aligned_ptr(ptr.into(), layout)) 861 ( 0.00%) } . . /// Turn a place with a `dyn Trait` type into a place with the actual dynamic type. . /// Also return some more information so drop doesn't have to run the same code twice. . pub(super) fn unpack_dyn_trait( . &self, . mplace: &MPlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, (ty::Instance<'tcx>, MPlaceTy<'tcx, M::PointerTag>)> { . let vtable = self.scalar_to_ptr(mplace.vtable()); // also sanity checks the type -- line 1109 ---------------------------------------- 2,534,854 ( 0.03%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/step.rs -------------------------------------------------------------------------------- Ir -- line 8 ---------------------------------------- . . use super::{InterpCx, Machine}; . . /// Classify whether an operator is "left-homogeneous", i.e., the LHS has the . /// same type as the result. . #[inline] . fn binop_left_homogeneous(op: mir::BinOp) -> bool { . use rustc_middle::mir::BinOp::*; 60,376 ( 0.00%) match op { . Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Offset | Shl | Shr => true, . Eq | Ne | Lt | Le | Gt | Ge => false, . } . } . /// Classify whether an operator is "right-homogeneous", i.e., the RHS has the . /// same type as the LHS. . #[inline] . fn binop_right_homogeneous(op: mir::BinOp) -> bool { . use rustc_middle::mir::BinOp::*; 180,660 ( 0.00%) match op { . Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Eq | Ne | Lt | Le | Gt | Ge => true, . Offset | Shl | Shr => false, . } . } . . impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { 861 ( 0.00%) pub fn run(&mut self) -> InterpResult<'tcx> { . while self.step()? {} . Ok(()) 1,107 ( 0.00%) } . . /// Returns `true` as long as there are more things to do. . /// . /// This is used by [priroda](https://github.com/oli-obk/priroda) . /// . /// This is marked `#inline(always)` to work around adverserial codegen when `opt-level = 3` . #[inline(always)] . pub fn step(&mut self) -> InterpResult<'tcx, bool> { 474,296 ( 0.00%) if self.stack().is_empty() { . return Ok(false); . } . 1,422,888 ( 0.01%) let loc = match self.frame().loc { 474,296 ( 0.00%) Ok(loc) => loc, . Err(_) => { . // We are unwinding and this fn has no cleanup code. . // Just go on unwinding. . trace!("unwinding: skipping frame"); . self.pop_stack_frame(/* unwinding */ true)?; . return Ok(true); . } . }; . let basic_block = &self.body().basic_blocks()[loc.block]; . . let old_frames = self.frame_idx(); . 474,296 ( 0.00%) if let Some(stmt) = basic_block.statements.get(loc.statement_index) { . assert_eq!(old_frames, self.frame_idx()); . self.statement(stmt)?; . return Ok(true); . } . . M::before_terminator(self)?; . . let terminator = basic_block.terminator(); . assert_eq!(old_frames, self.frame_idx()); . self.terminator(terminator)?; . Ok(true) . } . . /// Runs the interpretation logic for the given `mir::Statement` at the current frame and . /// statement counter. This also moves the statement counter forward. 968 ( 0.00%) pub fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> { . info!("{:?}", stmt); . . use rustc_middle::mir::StatementKind::*; . . // Some statements (e.g., box) push new stack frames. . // We have to record the stack frame number *before* executing the statement. . let frame_idx = self.frame_idx(); . 2,545,926 ( 0.03%) match &stmt.kind { 546,645 ( 0.01%) Assign(box (place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?, . . SetDiscriminant { place, variant_index } => { 1,078 ( 0.00%) let dest = self.eval_place(**place)?; 616 ( 0.00%) self.write_discriminant(*variant_index, &dest)?; . } . . // Mark locals as alive . StorageLive(local) => { 241,948 ( 0.00%) self.storage_live(*local)?; . } . . // Mark locals as dead . StorageDead(local) => { 241,948 ( 0.00%) self.storage_dead(*local)?; . } . . // No dynamic semantics attached to `FakeRead`; MIR . // interpreter is solely intended for borrowck'ed code. . FakeRead(..) => {} . . // Stacked Borrows. . Retag(kind, place) => { -- line 111 ---------------------------------------- -- line 137 ---------------------------------------- . // FIXME(#73156): Handle source code coverage in const eval . Coverage(..) => {} . . // Defined to do nothing. These are added by optimization passes, to avoid changing the . // size of MIR constantly. . Nop => {} . } . 2,121,605 ( 0.02%) self.stack_mut()[frame_idx].loc.as_mut().unwrap().statement_index += 1; . Ok(()) 847 ( 0.00%) } . . /// Evaluate an assignment statement. . /// . /// There is no separate `eval_rvalue` function. Instead, the code for handling each rvalue . /// type writes its results directly into the memory specified by the place. 12,290 ( 0.00%) pub fn eval_rvalue_into_place( . &mut self, . rvalue: &mir::Rvalue<'tcx>, . place: mir::Place<'tcx>, . ) -> InterpResult<'tcx> { 732,537 ( 0.01%) let dest = self.eval_place(place)?; . . use rustc_middle::mir::Rvalue::*; 917,170 ( 0.01%) match *rvalue { . ThreadLocalRef(did) => { . let ptr = M::thread_local_static_base_pointer(self, did)?; . self.write_pointer(ptr, &dest)?; . } . 71,967 ( 0.00%) Use(ref operand) => { . // Avoid recomputing the layout 578,456 ( 0.01%) let op = self.eval_operand(operand, Some(dest.layout))?; . self.copy_op(&op, &dest)?; . } . 30,268 ( 0.00%) BinaryOp(bin_op, box (ref left, ref right)) => { . let layout = binop_left_homogeneous(bin_op).then_some(dest.layout); 240,874 ( 0.00%) let left = self.read_immediate(&self.eval_operand(left, layout)?)?; 90,330 ( 0.00%) let layout = binop_right_homogeneous(bin_op).then_some(left.layout); 270,978 ( 0.00%) let right = self.read_immediate(&self.eval_operand(right, layout)?)?; 150,540 ( 0.00%) self.binop_ignore_overflow(bin_op, &left, &right, &dest)?; . } . 4 ( 0.00%) CheckedBinaryOp(bin_op, box (ref left, ref right)) => { . // Due to the extra boolean in the result, we can never reuse the `dest.layout`. 9 ( 0.00%) let left = self.read_immediate(&self.eval_operand(left, None)?)?; 3 ( 0.00%) let layout = binop_right_homogeneous(bin_op).then_some(left.layout); 8 ( 0.00%) let right = self.read_immediate(&self.eval_operand(right, layout)?)?; 6 ( 0.00%) self.binop_with_overflow(bin_op, &left, &right, &dest)?; . } . . UnaryOp(un_op, ref operand) => { . // The operand always has the same type as the result. . let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?; . let val = self.unary_op(un_op, &val)?; . assert_eq!(val.layout, dest.layout, "layout mismatch for result of {:?}", un_op); . self.write_immediate(*val, &dest)?; . } . . Aggregate(ref kind, ref operands) => { . // active_field_index is for union initialization. 238,308 ( 0.00%) let (dest, active_field_index) = match **kind { . mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => { . self.write_discriminant(variant_index, &dest)?; . if self.tcx.adt_def(adt_did).is_enum() { . assert!(active_field_index.is_none()); . (self.place_downcast(&dest, variant_index)?, None) . } else { . if active_field_index.is_some() { . assert_eq!(operands.len(), 1); . } . (dest, active_field_index) . } . } 178,731 ( 0.00%) _ => (dest, None), . }; . . for (i, operand) in operands.iter().enumerate() { 349,185 ( 0.00%) let op = self.eval_operand(operand, None)?; . let field_index = active_field_index.unwrap_or(i); 349,185 ( 0.00%) let field_dest = self.place_field(&dest, field_index)?; . self.copy_op(&op, &field_dest)?; . } . } . . Repeat(ref operand, _) => { 5 ( 0.00%) let src = self.eval_operand(operand, None)?; 5 ( 0.00%) assert!(!src.layout.is_unsized()); 4 ( 0.00%) let dest = self.force_allocation(&dest)?; 8 ( 0.00%) let length = dest.len(self)?; . 4 ( 0.00%) if length == 0 { . // Nothing to copy... but let's still make sure that `dest` as a place is valid. . self.get_alloc_mut(&dest)?; . } else { . // Write the src to the first element. . let first = self.mplace_field(&dest, 0)?; . self.copy_op(&src, &first.into())?; . . // This is performance-sensitive code for big static/const arrays! So we . // avoid writing each operand individually and instead just make many copies . // of the first element. 4 ( 0.00%) let elem_size = first.layout.size; . let first_ptr = first.ptr; 12 ( 0.00%) let rest_ptr = first_ptr.offset(elem_size, self)?; . // For the alignment of `rest_ptr`, we crucially do *not* use `first.align` as . // that place might be more aligned than its type mandates (a `u8` array could . // be 4-aligned if it sits at the right spot in a struct). Instead we use . // `first.layout.align`, i.e., the alignment given by the type. 22 ( 0.00%) self.memory.copy_repeatedly( . first_ptr, . first.align, . rest_ptr, . first.layout.align.abi, . elem_size, 2 ( 0.00%) length - 1, . /*nonoverlapping:*/ true, . )?; . } . } . 90,321 ( 0.00%) Len(place) => { 150,529 ( 0.00%) let src = self.eval_place(place)?; 30,105 ( 0.00%) let mplace = self.force_allocation(&src)?; 150,525 ( 0.00%) let len = mplace.len(self)?; . self.write_scalar(Scalar::from_machine_usize(len, self), &dest)?; . } . 126 ( 0.00%) AddressOf(_, place) | Ref(_, _, place) => { 315 ( 0.00%) let src = self.eval_place(place)?; . let place = self.force_allocation(&src)?; . self.write_immediate(place.to_ref(self), &dest)?; . } . . NullaryOp(null_op, ty) => { 5 ( 0.00%) let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?; 15 ( 0.00%) let layout = self.layout_of(ty)?; 11 ( 0.00%) if layout.is_unsized() { . // FIXME: This should be a span_bug (#80742) . self.tcx.sess.delay_span_bug( . self.frame().current_span(), . &format!("Nullary MIR operator called for unsized type {}", ty), . ); . throw_inval!(SizeOfUnsizedType(ty)); . } 10 ( 0.00%) let val = match null_op { 4 ( 0.00%) mir::NullOp::SizeOf => layout.size.bytes(), 2 ( 0.00%) mir::NullOp::AlignOf => layout.align.abi.bytes(), . }; . self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?; . } . . ShallowInitBox(ref operand, _) => { . let src = self.eval_operand(operand, None)?; . let v = self.read_immediate(&src)?; . self.write_immediate(*v, &dest)?; . } . 90,375 ( 0.00%) Cast(cast_kind, ref operand, cast_ty) => { 210,765 ( 0.00%) let src = self.eval_operand(operand, None)?; . let cast_ty = . self.subst_from_current_frame_and_normalize_erasing_regions(cast_ty)?; 301,150 ( 0.00%) self.cast(&src, cast_kind, cast_ty, &dest)?; . } . 201 ( 0.00%) Discriminant(place) => { 201 ( 0.00%) let op = self.eval_place_to_op(place, None)?; . let discr_val = self.read_discriminant(&op)?.0; . self.write_scalar(discr_val, &dest)?; . } . } . . trace!("{:?}", self.dump_place(*dest)); . . Ok(()) 11,061 ( 0.00%) } . . fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> InterpResult<'tcx> { . info!("{:?}", terminator.kind); . . self.eval_terminator(terminator)?; 50,096 ( 0.00%) if !self.stack().is_empty() { 349,811 ( 0.00%) if let Ok(loc) = self.frame().loc { . info!("// executing {:?}", loc.block); . } . } . Ok(()) . } . } 3,749,619 ( 0.04%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_index/src/bit_set.rs -------------------------------------------------------------------------------- Ir -- line 30 ---------------------------------------- . // Both start and end are inclusive. . let start = match range.start_bound().cloned() { . Bound::Included(start) => start.index(), . Bound::Excluded(start) => start.index() + 1, . Bound::Unbounded => 0, . }; . let end = match range.end_bound().cloned() { . Bound::Included(end) => end.index(), 20 ( 0.00%) Bound::Excluded(end) => end.index().checked_sub(1)?, . Bound::Unbounded => domain - 1, . }; 40 ( 0.00%) assert!(end < domain); 40 ( 0.00%) if start > end { . return None; . } . Some((start, end)) . } . . macro_rules! bit_relations_inherent_impls { . () => { . /// Sets `self = self | other` and returns `true` if `self` changed . /// (i.e., if new bits were added). 562,404 ( 0.01%) pub fn union(&mut self, other: &Rhs) -> bool . where . Self: BitRelations, . { . >::union(self, other) 427,601 ( 0.00%) } . . /// Sets `self = self - other` and returns `true` if `self` changed. . /// (i.e., if any bits were removed). 28,990 ( 0.00%) pub fn subtract(&mut self, other: &Rhs) -> bool . where . Self: BitRelations, . { . >::subtract(self, other) 28,990 ( 0.00%) } . . /// Sets `self = self & other` and return `true` if `self` changed. . /// (i.e., if any bits were removed). . pub fn intersect(&mut self, other: &Rhs) -> bool . where . Self: BitRelations, . { . >::intersect(self, other) -- line 74 ---------------------------------------- -- line 92 ---------------------------------------- . domain_size: usize, . words: Vec, . marker: PhantomData, . } . . impl BitSet { . /// Gets the domain size. . pub fn domain_size(&self) -> usize { 197 ( 0.00%) self.domain_size . } . } . . impl BitSet { . /// Creates a new, empty bitset with a given `domain_size`. . #[inline] . pub fn new_empty(domain_size: usize) -> BitSet { . let num_words = num_words(domain_size); 42,937 ( 0.00%) BitSet { domain_size, words: vec![0; num_words], marker: PhantomData } . } . . /// Creates a new, filled bitset with a given `domain_size`. . #[inline] . pub fn new_filled(domain_size: usize) -> BitSet { . let num_words = num_words(domain_size); 51,580 ( 0.00%) let mut result = BitSet { domain_size, words: vec![!0; num_words], marker: PhantomData }; . result.clear_excess_bits(); . result . } . . /// Clear all elements. . #[inline] . pub fn clear(&mut self) { . for word in &mut self.words { 364 ( 0.00%) *word = 0; . } . } . . /// Clear excess bits in the final word. . fn clear_excess_bits(&mut self) { 345 ( 0.00%) let num_bits_in_final_word = self.domain_size % WORD_BITS; 21,322 ( 0.00%) if num_bits_in_final_word > 0 { 20,977 ( 0.00%) let mask = (1 << num_bits_in_final_word) - 1; 42,299 ( 0.00%) let final_word_idx = self.words.len() - 1; 10,661 ( 0.00%) self.words[final_word_idx] &= mask; . } . } . . /// Count the number of set bits in the set. . pub fn count(&self) -> usize { . self.words.iter().map(|e| e.count_ones() as usize).sum() . } . . /// Returns `true` if `self` contains `elem`. . #[inline] . pub fn contains(&self, elem: T) -> bool { 941,587 ( 0.01%) assert!(elem.index() < self.domain_size); . let (word_index, mask) = word_index_and_mask(elem); 1,195,248 ( 0.01%) (self.words[word_index] & mask) != 0 . } . . /// Is `self` is a (non-strict) superset of `other`? . #[inline] . pub fn superset(&self, other: &BitSet) -> bool { . assert_eq!(self.domain_size, other.domain_size); . self.words.iter().zip(&other.words).all(|(a, b)| (a & b) == *b) . } -- line 157 ---------------------------------------- -- line 160 ---------------------------------------- . #[inline] . pub fn is_empty(&self) -> bool { . self.words.iter().all(|a| *a == 0) . } . . /// Insert `elem`. Returns whether the set has changed. . #[inline] . pub fn insert(&mut self, elem: T) -> bool { 2,465,047 ( 0.02%) assert!(elem.index() < self.domain_size); . let (word_index, mask) = word_index_and_mask(elem); . let word_ref = &mut self.words[word_index]; 690,421 ( 0.01%) let word = *word_ref; 1,380,842 ( 0.01%) let new_word = word | mask; 1,266,496 ( 0.01%) *word_ref = new_word; 729,364 ( 0.01%) new_word != word . } . . #[inline] . pub fn insert_range(&mut self, elems: impl RangeBounds) { . let Some((start, end)) = inclusive_start_end(elems, self.domain_size) else { . return; . }; . -- line 182 ---------------------------------------- -- line 199 ---------------------------------------- . } else { . self.words[start_word_index] |= end_mask | (end_mask - start_mask); . } . } . . /// Sets all bits to true. . pub fn insert_all(&mut self) { . for word in &mut self.words { 690 ( 0.00%) *word = !0; . } . self.clear_excess_bits(); . } . . /// Returns `true` if the set has changed. . #[inline] . pub fn remove(&mut self, elem: T) -> bool { 1,422,282 ( 0.01%) assert!(elem.index() < self.domain_size); . let (word_index, mask) = word_index_and_mask(elem); . let word_ref = &mut self.words[word_index]; 9,162 ( 0.00%) let word = *word_ref; 1,402,490 ( 0.01%) let new_word = word & !mask; 733,378 ( 0.01%) *word_ref = new_word; 18,324 ( 0.00%) new_word != word . } . . /// Gets a slice of the underlying words. . pub fn words(&self) -> &[Word] { . &self.words . } . . /// Iterates over the indices of set bits in a sorted order. -- line 229 ---------------------------------------- -- line 273 ---------------------------------------- . not_already |= (self.words[current_index] ^ new_bit_mask) != 0; . // Any bits in the tail? Note `clear_excess_bits` before. . not_already |= self.words[current_index + 1..].iter().any(|&x| x != 0); . . not_already . } . . fn last_set_in(&self, range: impl RangeBounds) -> Option { 20 ( 0.00%) let (start, end) = inclusive_start_end(range, self.domain_size)?; . let (start_word_index, _) = word_index_and_mask(start); . let (end_word_index, end_mask) = word_index_and_mask(end); . 100 ( 0.00%) let end_word = self.words[end_word_index] & (end_mask | (end_mask - 1)); 40 ( 0.00%) if end_word != 0 { 54 ( 0.00%) let pos = max_bit(end_word) + WORD_BITS * end_word_index; 36 ( 0.00%) if start <= pos { . return Some(T::new(pos)); . } . } . . // We exclude end_word_index from the range here, because we don't want . // to limit ourselves to *just* the last word: the bits set it in may be . // after `end`, so it may not work out. . if let Some(offset) = 1 ( 0.00%) self.words[start_word_index..end_word_index].iter().rposition(|&w| w != 0) . { 2 ( 0.00%) let word_idx = start_word_index + offset; 1 ( 0.00%) let start_word = self.words[word_idx]; 5 ( 0.00%) let pos = max_bit(start_word) + WORD_BITS * word_idx; 2 ( 0.00%) if start <= pos { . return Some(T::new(pos)); . } . } . . None . } . . bit_relations_inherent_impls! {} . } . . // dense REL dense . impl BitRelations> for BitSet { . fn union(&mut self, other: &BitSet) -> bool { 404,409 ( 0.00%) assert_eq!(self.domain_size, other.domain_size); 10,746,073 ( 0.11%) bitwise(&mut self.words, &other.words, |a, b| a | b) . } . . fn subtract(&mut self, other: &BitSet) -> bool { . assert_eq!(self.domain_size, other.domain_size); 557 ( 0.00%) bitwise(&mut self.words, &other.words, |a, b| a & !b) . } . . fn intersect(&mut self, other: &BitSet) -> bool { . assert_eq!(self.domain_size, other.domain_size); . bitwise(&mut self.words, &other.words, |a, b| a & b) . } . } . . // Applies a function to mutate a bitset, and returns true if any . // of the applications return true . fn sequential_update( . mut self_update: impl FnMut(T) -> bool, . it: impl Iterator, . ) -> bool { . let mut changed = false; 14,890 ( 0.00%) for elem in it { 44,670 ( 0.00%) changed |= self_update(elem); . } . changed 23,006 ( 0.00%) } . . // Optimization of intersection for SparseBitSet that's generic . // over the RHS . fn sparse_intersect( . set: &mut SparseBitSet, . other_contains: impl Fn(&T) -> bool, . ) -> bool { . let size = set.elems.len(); -- line 350 ---------------------------------------- -- line 413 ---------------------------------------- . HybridBitSet::Dense(dense) => dense.intersect(other), . } . } . } . . // dense REL hybrid . impl BitRelations> for BitSet { . fn union(&mut self, other: &HybridBitSet) -> bool { 23,192 ( 0.00%) assert_eq!(self.domain_size, other.domain_size()); 11,596 ( 0.00%) match other { . HybridBitSet::Sparse(sparse) => { . sequential_update(|elem| self.insert(elem), sparse.iter().cloned()) . } . HybridBitSet::Dense(dense) => self.union(dense), . } . } . . fn subtract(&mut self, other: &HybridBitSet) -> bool { 23,192 ( 0.00%) assert_eq!(self.domain_size, other.domain_size()); 11,596 ( 0.00%) match other { . HybridBitSet::Sparse(sparse) => { . sequential_update(|elem| self.remove(elem), sparse.iter().cloned()) . } . HybridBitSet::Dense(dense) => self.subtract(dense), . } . } . . fn intersect(&mut self, other: &HybridBitSet) -> bool { -- line 440 ---------------------------------------- -- line 455 ---------------------------------------- . HybridBitSet::Dense(dense) => self.intersect(dense), . } . } . } . . // hybrid REL hybrid . impl BitRelations> for HybridBitSet { . fn union(&mut self, other: &HybridBitSet) -> bool { 2,502 ( 0.00%) assert_eq!(self.domain_size(), other.domain_size()); 834 ( 0.00%) match self { . HybridBitSet::Sparse(_) => { 834 ( 0.00%) match other { . HybridBitSet::Sparse(other_sparse) => { . // Both sets are sparse. Add the elements in . // `other_sparse` to `self` one at a time. This . // may or may not cause `self` to be densified. . let mut changed = false; . for elem in other_sparse.iter() { 2,520 ( 0.00%) changed |= self.insert(*elem); . } . changed . } . . HybridBitSet::Dense(other_dense) => self.union(other_dense), . } . } . -- line 481 ---------------------------------------- -- line 511 ---------------------------------------- . } . } . . impl Clone for BitSet { . fn clone(&self) -> Self { . BitSet { domain_size: self.domain_size, words: self.words.clone(), marker: PhantomData } . } . 645,190 ( 0.01%) fn clone_from(&mut self, from: &Self) { 422,775 ( 0.00%) if self.domain_size != from.domain_size { . self.words.resize(from.domain_size, 0); . self.domain_size = from.domain_size; . } . . self.words.copy_from_slice(&from.words); . } . } . -- line 528 ---------------------------------------- -- line 599 ---------------------------------------- . } . } . } . . impl<'a, T: Idx> Iterator for BitIter<'a, T> { . type Item = T; . fn next(&mut self) -> Option { . loop { 232,706 ( 0.00%) if self.word != 0 { . // Get the position of the next set bit in the current word, . // then clear the bit. . let bit_pos = self.word.trailing_zeros() as usize; . let bit = 1 << bit_pos; . self.word ^= bit; 81,084 ( 0.00%) return Some(T::new(bit_pos + self.offset)); . } . . // Move onto the next word. `wrapping_add()` is needed to handle . // the degenerate initial value given to `offset` in `new()`. . let word = self.iter.next()?; 7,571 ( 0.00%) self.word = *word; . self.offset = self.offset.wrapping_add(WORD_BITS); . } . } . } . . #[inline] . fn bitwise(out_vec: &mut [Word], in_vec: &[Word], op: Op) -> bool . where . Op: Fn(Word, Word) -> Word, . { 539,584 ( 0.01%) assert_eq!(out_vec.len(), in_vec.len()); . let mut changed = 0; 229,139 ( 0.00%) for (out_elem, in_elem) in iter::zip(out_vec, in_vec) { 10,857,512 ( 0.11%) let old_val = *out_elem; 10,621,725 ( 0.11%) let new_val = op(old_val, *in_elem); 10,746,290 ( 0.11%) *out_elem = new_val; . // This is essentially equivalent to a != with changed being a bool, but . // in practice this code gets auto-vectorized by the compiler for most . // operators. Using != here causes us to generate quite poor code as the . // compiler tries to go back to a boolean on each loop iteration. 21,715,098 ( 0.22%) changed |= old_val ^ new_val; . } . changed != 0 . } . . const SPARSE_MAX: usize = 8; . . /// A fixed-size bitset type with a sparse representation and a maximum of . /// `SPARSE_MAX` elements. The elements are stored as a sorted `ArrayVec` with . /// no duplicates. . /// . /// This type is used by `HybridBitSet`; do not use directly. . #[derive(Clone, Debug)] . pub struct SparseBitSet { 8,362 ( 0.00%) domain_size: usize, . elems: ArrayVec, . } . . impl SparseBitSet { . fn new_empty(domain_size: usize) -> Self { . SparseBitSet { domain_size, elems: ArrayVec::new() } . } . . fn len(&self) -> usize { 36,186 ( 0.00%) self.elems.len() . } . . fn is_empty(&self) -> bool { . self.elems.len() == 0 . } . . fn contains(&self, elem: T) -> bool { 310 ( 0.00%) assert!(elem.index() < self.domain_size); . self.elems.contains(&elem) . } . . fn insert(&mut self, elem: T) -> bool { 36,036 ( 0.00%) assert!(elem.index() < self.domain_size); 15,637 ( 0.00%) let changed = if let Some(i) = self.elems.iter().position(|&e| e.index() >= elem.index()) { 7,102 ( 0.00%) if self.elems[i] == elem { . // `elem` is already in the set. . false . } else { . // `elem` is smaller than one or more existing elements. . self.elems.insert(i, elem); . true . } . } else { . // `elem` is larger than all existing elements. . self.elems.push(elem); . true . }; 36,036 ( 0.00%) assert!(self.len() <= SPARSE_MAX); . changed . } . . fn remove(&mut self, elem: T) -> bool { 29,162 ( 0.00%) assert!(elem.index() < self.domain_size); . if let Some(i) = self.elems.iter().position(|&e| e == elem) { 9,496 ( 0.00%) self.elems.remove(i); . true . } else { . false . } . } . . fn to_dense(&self) -> BitSet { . let mut dense = BitSet::new_empty(self.domain_size); . for elem in self.elems.iter() { 544 ( 0.00%) dense.insert(*elem); . } . dense . } . . fn iter(&self) -> slice::Iter<'_, T> { 4,406 ( 0.00%) self.elems.iter() . } . . bit_relations_inherent_impls! {} . } . . impl SparseBitSet { . fn last_set_in(&self, range: impl RangeBounds) -> Option { . let mut last_leq = None; -- line 723 ---------------------------------------- -- line 738 ---------------------------------------- . /// number of elements, but a large `domain_size`, and are cleared frequently. . /// . /// `T` is an index type, typically a newtyped `usize` wrapper, but it can also . /// just be `usize`. . /// . /// All operations that involve an element will panic if the element is equal . /// to or greater than the domain size. All operations that involve two bitsets . /// will panic if the bitsets have differing domain sizes. 77,066 ( 0.00%) #[derive(Clone)] . pub enum HybridBitSet { . Sparse(SparseBitSet), . Dense(BitSet), . } . . impl fmt::Debug for HybridBitSet { . fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result { . match self { -- line 754 ---------------------------------------- -- line 755 ---------------------------------------- . Self::Sparse(b) => b.fmt(w), . Self::Dense(b) => b.fmt(w), . } . } . } . . impl HybridBitSet { . pub fn new_empty(domain_size: usize) -> Self { 328 ( 0.00%) HybridBitSet::Sparse(SparseBitSet::new_empty(domain_size)) . } . . pub fn domain_size(&self) -> usize { . match self { . HybridBitSet::Sparse(sparse) => sparse.domain_size, . HybridBitSet::Dense(dense) => dense.domain_size, . } . } . . pub fn clear(&mut self) { . let domain_size = self.domain_size(); 1,822 ( 0.00%) *self = HybridBitSet::new_empty(domain_size); . } . . pub fn contains(&self, elem: T) -> bool { 170 ( 0.00%) match self { . HybridBitSet::Sparse(sparse) => sparse.contains(elem), . HybridBitSet::Dense(dense) => dense.contains(elem), . } . } . . pub fn superset(&self, other: &HybridBitSet) -> bool { . match (self, other) { . (HybridBitSet::Dense(self_dense), HybridBitSet::Dense(other_dense)) => { -- line 787 ---------------------------------------- -- line 799 ---------------------------------------- . HybridBitSet::Sparse(sparse) => sparse.is_empty(), . HybridBitSet::Dense(dense) => dense.is_empty(), . } . } . . /// Returns the previous element present in the bitset from `elem`, . /// inclusively of elem. That is, will return `Some(elem)` if elem is in the . /// bitset. 4,446 ( 0.00%) pub fn last_set_in(&self, range: impl RangeBounds) -> Option . where . T: Ord, . { 4,446 ( 0.00%) match self { . HybridBitSet::Sparse(sparse) => sparse.last_set_in(range), . HybridBitSet::Dense(dense) => dense.last_set_in(range), . } 6,669 ( 0.00%) } . 165,879 ( 0.00%) pub fn insert(&mut self, elem: T) -> bool { . // No need to check `elem` against `self.domain_size` here because all . // the match cases check it, one way or another. 36,862 ( 0.00%) match self { 36,186 ( 0.00%) HybridBitSet::Sparse(sparse) if sparse.len() < SPARSE_MAX => { . // The set is sparse and has space for `elem`. . sparse.insert(elem) . } . HybridBitSet::Sparse(sparse) if sparse.contains(elem) => { . // The set is sparse and does not have space for `elem`, but . // that doesn't matter because `elem` is already present. . false . } . HybridBitSet::Sparse(sparse) => { . // The set is sparse and full. Convert to a dense set. . let mut dense = sparse.to_dense(); . let changed = dense.insert(elem); 68 ( 0.00%) assert!(changed); 408 ( 0.00%) *self = HybridBitSet::Dense(dense); . changed . } . HybridBitSet::Dense(dense) => dense.insert(elem), . } 147,448 ( 0.00%) } . . pub fn insert_range(&mut self, elems: impl RangeBounds) { . // No need to check `elem` against `self.domain_size` here because all . // the match cases check it, one way or another. . let start = match elems.start_bound().cloned() { . Bound::Included(start) => start.index(), . Bound::Excluded(start) => start.index() + 1, . Bound::Unbounded => 0, -- line 848 ---------------------------------------- -- line 879 ---------------------------------------- . match self { . HybridBitSet::Sparse(_) => { . *self = HybridBitSet::Dense(BitSet::new_filled(domain_size)); . } . HybridBitSet::Dense(dense) => dense.insert_all(), . } . } . 14,517 ( 0.00%) pub fn remove(&mut self, elem: T) -> bool { . // Note: we currently don't bother going from Dense back to Sparse. 29,196 ( 0.00%) match self { . HybridBitSet::Sparse(sparse) => sparse.remove(elem), . HybridBitSet::Dense(dense) => dense.remove(elem), . } 29,034 ( 0.00%) } . . /// Converts to a dense set, consuming itself in the process. . pub fn to_dense(self) -> BitSet { . match self { . HybridBitSet::Sparse(sparse) => sparse.to_dense(), . HybridBitSet::Dense(dense) => dense, . } . } . . pub fn iter(&self) -> HybridIter<'_, T> { 1,224 ( 0.00%) match self { 2,470 ( 0.00%) HybridBitSet::Sparse(sparse) => HybridIter::Sparse(sparse.iter()), . HybridBitSet::Dense(dense) => HybridIter::Dense(dense.iter()), . } . } . . bit_relations_inherent_impls! {} . } . . pub enum HybridIter<'a, T: Idx> { -- line 913 ---------------------------------------- -- line 935 ---------------------------------------- . /// to or greater than the domain size. . #[derive(Clone, Debug, PartialEq)] . pub struct GrowableBitSet { . bit_set: BitSet, . } . . impl GrowableBitSet { . /// Ensure that the set can hold at least `min_domain_size` elements. 998,753 ( 0.01%) pub fn ensure(&mut self, min_domain_size: usize) { 285,358 ( 0.00%) if self.bit_set.domain_size < min_domain_size { 193 ( 0.00%) self.bit_set.domain_size = min_domain_size; . } . . let min_num_words = num_words(min_domain_size); 570,716 ( 0.01%) if self.bit_set.words.len() < min_num_words { . self.bit_set.words.resize(min_num_words, 0) . } 856,074 ( 0.01%) } . . pub fn new_empty() -> GrowableBitSet { 168 ( 0.00%) GrowableBitSet { bit_set: BitSet::new_empty(0) } . } . . pub fn with_capacity(capacity: usize) -> GrowableBitSet { 8 ( 0.00%) GrowableBitSet { bit_set: BitSet::new_empty(capacity) } . } . . /// Returns `true` if the set has changed. . #[inline] . pub fn insert(&mut self, elem: T) -> bool { 709,095 ( 0.01%) self.ensure(elem.index() + 1); . self.bit_set.insert(elem) . } . . /// Returns `true` if the set has changed. . #[inline] . pub fn remove(&mut self, elem: T) -> bool { . self.ensure(elem.index() + 1); . self.bit_set.remove(elem) -- line 973 ---------------------------------------- -- line 976 ---------------------------------------- . #[inline] . pub fn is_empty(&self) -> bool { . self.bit_set.is_empty() . } . . #[inline] . pub fn contains(&self, elem: T) -> bool { . let (word_index, mask) = word_index_and_mask(elem); 2,635 ( 0.00%) self.bit_set.words.get(word_index).map_or(false, |word| (word & mask) != 0) . } . } . . /// A fixed-size 2D bit matrix type with a dense representation. . /// . /// `R` and `C` are index types used to identify rows and columns respectively; . /// typically newtyped `usize` wrappers, but they can also just be `usize`. . /// -- line 992 ---------------------------------------- -- line 1001 ---------------------------------------- . } . . impl BitMatrix { . /// Creates a new `rows x columns` matrix, initially empty. . pub fn new(num_rows: usize, num_columns: usize) -> BitMatrix { . // For every element, we need one bit for every other . // element. Round up to an even number of words. . let words_per_row = num_words(num_columns); 1,336 ( 0.00%) BitMatrix { . num_rows, . num_columns, 972 ( 0.00%) words: vec![0; num_rows * words_per_row], . marker: PhantomData, . } . } . . /// Creates a new matrix, with `row` used as the value for every row. . pub fn from_row_n(row: &BitSet, num_rows: usize) -> BitMatrix { . let num_columns = row.domain_size(); . let words_per_row = num_words(num_columns); -- line 1020 ---------------------------------------- -- line 1029 ---------------------------------------- . . pub fn rows(&self) -> impl Iterator { . (0..self.num_rows).map(R::new) . } . . /// The range of bits for a given row. . fn range(&self, row: R) -> (usize, usize) { . let words_per_row = num_words(self.num_columns); 19,584 ( 0.00%) let start = row.index() * words_per_row; 16,566 ( 0.00%) (start, start + words_per_row) . } . . /// Sets the cell at `(row, column)` to true. Put another way, insert . /// `column` to the bitset for `row`. . /// . /// Returns `true` if this changed the matrix. . pub fn insert(&mut self, row: R, column: C) -> bool { 10,502 ( 0.00%) assert!(row.index() < self.num_rows && column.index() < self.num_columns); . let (start, _) = self.range(row); . let (word_index, mask) = word_index_and_mask(column); . let words = &mut self.words[..]; 10,530 ( 0.00%) let word = words[start + word_index]; 4,212 ( 0.00%) let new_word = word | mask; 2,106 ( 0.00%) words[start + word_index] = new_word; 4,212 ( 0.00%) word != new_word . } . . /// Do the bits from `row` contain `column`? Put another way, is . /// the matrix cell at `(row, column)` true? Put yet another way, . /// if the matrix represents (transitive) reachability, can . /// `row` reach `column`? 912 ( 0.00%) pub fn contains(&self, row: R, column: C) -> bool { 4,560 ( 0.00%) assert!(row.index() < self.num_rows && column.index() < self.num_columns); . let (start, _) = self.range(row); . let (word_index, mask) = word_index_and_mask(column); 4,560 ( 0.00%) (self.words[start + word_index] & mask) != 0 1,824 ( 0.00%) } . . /// Returns those indices that are true in rows `a` and `b`. This . /// is an *O*(*n*) operation where *n* is the number of elements . /// (somewhat independent from the actual size of the . /// intersection, in particular). . pub fn intersect_rows(&self, row1: R, row2: R) -> Vec { . assert!(row1.index() < self.num_rows && row2.index() < self.num_rows); . let (row1_start, row1_end) = self.range(row1); -- line 1073 ---------------------------------------- -- line 1090 ---------------------------------------- . . /// Adds the bits from row `read` to the bits from row `write`, and . /// returns `true` if anything changed. . /// . /// This is used when computing transitive reachability because if . /// you have an edge `write -> read`, because in that case . /// `write` can reach everything that `read` can (and . /// potentially more). 2,078 ( 0.00%) pub fn union_rows(&mut self, read: R, write: R) -> bool { 10,530 ( 0.00%) assert!(read.index() < self.num_rows && write.index() < self.num_rows); 2,106 ( 0.00%) let (read_start, read_end) = self.range(read); . let (write_start, write_end) = self.range(write); . let words = &mut self.words[..]; . let mut changed = false; . for (read_index, write_index) in iter::zip(read_start..read_end, write_start..write_end) { 10,754 ( 0.00%) let word = words[write_index]; 6,318 ( 0.00%) let new_word = word | words[read_index]; 2,106 ( 0.00%) words[write_index] = new_word; 10,558 ( 0.00%) changed |= word != new_word; . } . changed 6,234 ( 0.00%) } . . /// Adds the bits from `with` to the bits from row `write`, and . /// returns `true` if anything changed. . pub fn union_row_with(&mut self, with: &BitSet, write: R) -> bool { . assert!(write.index() < self.num_rows); . assert_eq!(with.domain_size(), self.num_columns); . let (write_start, write_end) = self.range(write); . let mut changed = false; -- line 1119 ---------------------------------------- -- line 1209 ---------------------------------------- . /// Creates a new empty sparse bit matrix with no rows or columns. . pub fn new(num_columns: usize) -> Self { . Self { num_columns, rows: IndexVec::new() } . } . . fn ensure_row(&mut self, row: R) -> &mut HybridBitSet { . // Instantiate any missing rows up to and including row `row` with an empty HybridBitSet. . // Then replace row `row` with a full HybridBitSet if necessary. 959 ( 0.00%) self.rows.get_or_insert_with(row, || HybridBitSet::new_empty(self.num_columns)) . } . . /// Sets the cell at `(row, column)` to true. Put another way, insert . /// `column` to the bitset for `row`. . /// . /// Returns `true` if this changed the matrix. . pub fn insert(&mut self, row: R, column: C) -> bool { 1,164 ( 0.00%) self.ensure_row(row).insert(column) . } . . /// Sets the cell at `(row, column)` to false. Put another way, delete . /// `column` from the bitset for `row`. Has no effect if `row` does not . /// exist. . /// . /// Returns `true` if this changed the matrix. . pub fn remove(&mut self, row: R, column: C) -> bool { -- line 1233 ---------------------------------------- -- line 1255 ---------------------------------------- . . /// Adds the bits from row `read` to the bits from row `write`, and . /// returns `true` if anything changed. . /// . /// This is used when computing transitive reachability because if . /// you have an edge `write -> read`, because in that case . /// `write` can reach everything that `read` can (and . /// potentially more). 71,750 ( 0.00%) pub fn union_rows(&mut self, read: R, write: R) -> bool { 10,250 ( 0.00%) if read == write || self.row(read).is_none() { . return false; . } . . self.ensure_row(write); 4,587 ( 0.00%) if let (Some(read_row), Some(write_row)) = self.rows.pick2_mut(read, write) { . write_row.union(read_row) . } else { . unreachable!() . } 92,250 ( 0.00%) } . . /// Insert all bits in the given row. . pub fn insert_all_into_row(&mut self, row: R) { . self.ensure_row(row).insert_all(); . } . . pub fn rows(&self) -> impl Iterator { . self.rows.indices() -- line 1282 ---------------------------------------- -- line 1284 ---------------------------------------- . . /// Iterates through all the columns set to true in a given row of . /// the matrix. . pub fn iter<'a>(&'a self, row: R) -> impl Iterator + 'a { . self.row(row).into_iter().flat_map(|r| r.iter()) . } . . pub fn row(&self, row: R) -> Option<&HybridBitSet> { 26,194 ( 0.00%) if let Some(Some(row)) = self.rows.get(row) { Some(row) } else { None } . } . . /// Interescts `row` with `set`. `set` can be either `BitSet` or . /// `HybridBitSet`. Has no effect if `row` does not exist. . /// . /// Returns true if the row was changed. . pub fn intersect_row(&mut self, row: R, set: &Set) -> bool . where -- line 1300 ---------------------------------------- -- line 1329 ---------------------------------------- . HybridBitSet: BitRelations, . { . self.ensure_row(row).union(set) . } . } . . #[inline] . fn num_words(domain_size: T) -> usize { 767,455 ( 0.01%) (domain_size.index() + WORD_BITS - 1) / WORD_BITS . } . . #[inline] . fn word_index_and_mask(elem: T) -> (usize, Word) { . let elem = elem.index(); 4,567,475 ( 0.05%) let word_index = elem / WORD_BITS; 1,085,663 ( 0.01%) let mask = 1 << (elem % WORD_BITS); . (word_index, mask) . } . . #[inline] . fn max_bit(word: Word) -> usize { 2 ( 0.00%) WORD_BITS - 1 - word.leading_zeros() as usize . } . . /// Integral type used to represent the bit set. . pub trait FiniteBitSetTy: . BitAnd . + BitAndAssign . + BitOrAssign . + Clone -- line 1358 ---------------------------------------- 1,555,167 ( 0.02%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_parse/src/lexer/tokentrees.rs -------------------------------------------------------------------------------- Ir -- line 8 ---------------------------------------- . }; . use rustc_ast_pretty::pprust::token_to_string; . use rustc_data_structures::fx::FxHashMap; . use rustc_errors::PResult; . use rustc_span::Span; . . impl<'a> StringReader<'a> { . pub(super) fn into_token_trees(self) -> (PResult<'a, TokenStream>, Vec) { 38 ( 0.00%) let mut tt_reader = TokenTreesReader { . string_reader: self, 2 ( 0.00%) token: Token::dummy(), . open_braces: Vec::new(), . unmatched_braces: Vec::new(), . matching_delim_spans: Vec::new(), . last_unclosed_found_span: None, . last_delim_empty_block_spans: FxHashMap::default(), . matching_block_spans: Vec::new(), . }; 2 ( 0.00%) let res = tt_reader.parse_all_token_trees(); 12 ( 0.00%) (res, tt_reader.unmatched_braces) . } . } . . struct TokenTreesReader<'a> { . string_reader: StringReader<'a>, . token: Token, . /// Stack of open delimiters and their spans. Used for error message. . open_braces: Vec<(token::DelimToken, Span)>, -- line 35 ---------------------------------------- -- line 43 ---------------------------------------- . last_delim_empty_block_spans: FxHashMap, . /// Collect the spans of braces (Open, Close). Used only . /// for detecting if blocks are empty and only braces. . matching_block_spans: Vec<(Span, Span)>, . } . . impl<'a> TokenTreesReader<'a> { . // Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`. 16 ( 0.00%) fn parse_all_token_trees(&mut self) -> PResult<'a, TokenStream> { . let mut buf = TokenStreamBuilder::default(); . . self.bump(); 1,264 ( 0.00%) while self.token != token::Eof { 5,040 ( 0.00%) buf.push(self.parse_token_tree()?); . } . . Ok(buf.into_token_stream()) 18 ( 0.00%) } . . // Parse a stream of tokens into a list of `TokenTree`s, up to a `CloseDelim`. . fn parse_token_trees_until_close_delim(&mut self) -> TokenStream { . let mut buf = TokenStreamBuilder::default(); . loop { 297,126 ( 0.00%) if let token::CloseDelim(..) = self.token.kind { . return buf.into_token_stream(); . } . 635,100 ( 0.01%) match self.parse_token_tree() { 1,143,180 ( 0.01%) Ok(tree) => buf.push(tree), . Err(mut e) => { . e.emit(); . return buf.into_token_stream(); . } . } . } . } . 1,148,850 ( 0.01%) fn parse_token_tree(&mut self) -> PResult<'a, TreeAndSpacing> { 255,300 ( 0.00%) let sm = self.string_reader.sess.source_map(); . 1,062,678 ( 0.01%) match self.token.kind { . token::Eof => { . let msg = "this file contains an unclosed delimiter"; . let mut err = . self.string_reader.sess.span_diagnostic.struct_span_err(self.token.span, msg); . for &(_, sp) in &self.open_braces { . err.span_label(sp, "unclosed delimiter"); . self.unmatched_braces.push(UnmatchedBrace { . expected_delim: token::DelimToken::Brace, -- line 91 ---------------------------------------- -- line 113 ---------------------------------------- . err.span_label( . *close_sp, . "...as it matches this but it has different indentation", . ); . } . } . Err(err) . } 21,543 ( 0.00%) token::OpenDelim(delim) => { . // The span for beginning of the delimited section 21,543 ( 0.00%) let pre_span = self.token.span; . . // Parse the open delimiter. 150,801 ( 0.00%) self.open_braces.push((delim, self.token.span)); . self.bump(); . . // Parse the token trees within the delimiters. . // We stop at any delimiter so we can try to recover if the user . // uses an incorrect delimiter. 21,543 ( 0.00%) let tts = self.parse_token_trees_until_close_delim(); . . // Expand to cover the entire delimited token tree 107,715 ( 0.00%) let delim_span = DelimSpan::from_pair(pre_span, self.token.span); . 43,086 ( 0.00%) match self.token.kind { . // Correct delimiter. 43,086 ( 0.00%) token::CloseDelim(d) if d == delim => { . let (open_brace, open_brace_span) = self.open_braces.pop().unwrap(); 43,086 ( 0.00%) let close_brace_span = self.token.span; . 64,629 ( 0.00%) if tts.is_empty() { 426 ( 0.00%) let empty_block_span = open_brace_span.to(close_brace_span); 568 ( 0.00%) if !sm.is_multiline(empty_block_span) { . // Only track if the block is in the form of `{}`, otherwise it is . // likely that it was written on purpose. . self.last_delim_empty_block_spans.insert(delim, empty_block_span); . } . } . . //only add braces 86,172 ( 0.00%) if let (DelimToken::Brace, DelimToken::Brace) = (open_brace, delim) { . self.matching_block_spans.push((open_brace_span, close_brace_span)); . } . 21,543 ( 0.00%) if self.open_braces.is_empty() { . // Clear up these spans to avoid suggesting them as we've found . // properly matched delimiters so far for an entire block. . self.matching_delim_spans.clear(); . } else { . self.matching_delim_spans.push(( . open_brace, . open_brace_span, . close_brace_span, -- line 165 ---------------------------------------- -- line 218 ---------------------------------------- . token::Eof => { . // Silently recover, the EOF token will be seen again . // and an error emitted then. Thus we don't pop from . // self.open_braces here. . } . _ => {} . } . 150,801 ( 0.00%) Ok(TokenTree::Delimited(delim_span, delim, tts).into()) . } . token::CloseDelim(delim) => { . // An unexpected closing delimiter (i.e., there is no . // matching opening delimiter). . let token_str = token_to_string(&self.token); . let msg = format!("unexpected closing delimiter: `{}`", token_str); . let mut err = . self.string_reader.sess.span_diagnostic.struct_span_err(self.token.span, &msg); -- line 234 ---------------------------------------- -- line 253 ---------------------------------------- . err.span_label(parent.1, "...matches this closing brace"); . } . } . . err.span_label(self.token.span, "unexpected closing delimiter"); . Err(err) . } . _ => { 530,535 ( 0.01%) let tt = TokenTree::Token(self.token.take()); . let mut spacing = self.bump(); 212,214 ( 0.00%) if !self.token.is_op() { . spacing = Alone; . } 636,642 ( 0.01%) Ok((tt, spacing)) . } . } 1,021,200 ( 0.01%) } . . fn bump(&mut self) -> Spacing { 1,235,034 ( 0.01%) let (spacing, token) = self.string_reader.next_token(); 638,268 ( 0.01%) self.token = token; . spacing . } . } . 21,543 ( 0.00%) #[derive(Default)] . struct TokenStreamBuilder { . buf: Vec, . } . . impl TokenStreamBuilder { 1,659,450 ( 0.02%) fn push(&mut self, (tree, joint): TreeAndSpacing) { 801,417 ( 0.01%) if let Some((TokenTree::Token(prev_token), Joint)) = self.buf.last() { 82,672 ( 0.00%) if let TokenTree::Token(token) = &tree { 164,888 ( 0.00%) if let Some(glued) = prev_token.glue(token) { . self.buf.pop(); 122,640 ( 0.00%) self.buf.push((TokenTree::Token(glued), joint)); . return; . } . } . } 587,150 ( 0.01%) self.buf.push((tree, joint)) 1,021,200 ( 0.01%) } . . fn into_token_stream(self) -> TokenStream { 215,448 ( 0.00%) TokenStream::new(self.buf) . } . } 512,795 ( 0.01%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/library/core/src/result.rs -------------------------------------------------------------------------------- Ir -- line 491 ---------------------------------------- . . use crate::iter::{self, FromIterator, FusedIterator, TrustedLen}; . use crate::ops::{self, ControlFlow, Deref, DerefMut}; . use crate::{convert, fmt, hint}; . . /// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]). . /// . /// See the [module documentation](self) for details. 120 ( 0.00%) #[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] . #[must_use = "this `Result` may be an `Err` variant, which should be handled"] . #[rustc_diagnostic_item = "Result"] . #[stable(feature = "rust1", since = "1.0.0")] . pub enum Result { . /// Contains the success value . #[lang = "Ok"] . #[stable(feature = "rust1", since = "1.0.0")] 3 ( 0.00%) Ok(#[stable(feature = "rust1", since = "1.0.0")] T), . . /// Contains the error value . #[lang = "Err"] . #[stable(feature = "rust1", since = "1.0.0")] . Err(#[stable(feature = "rust1", since = "1.0.0")] E), . } . . ///////////////////////////////////////////////////////////////////////////// -- line 515 ---------------------------------------- -- line 534 ---------------------------------------- . /// let x: Result = Err("Some error message"); . /// assert_eq!(x.is_ok(), false); . /// ``` . #[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"] . #[rustc_const_stable(feature = "const_result", since = "1.48.0")] . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub const fn is_ok(&self) -> bool { 22,280 ( 0.00%) matches!(*self, Ok(_)) . } . . /// Returns `true` if the result is [`Ok`] wrapping a value matching the predicate. . /// . /// # Examples . /// . /// ``` . /// #![feature(is_some_with)] -- line 550 ---------------------------------------- -- line 628 ---------------------------------------- . /// assert_eq!(x.ok(), Some(2)); . /// . /// let x: Result = Err("Nothing here"); . /// assert_eq!(x.ok(), None); . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn ok(self) -> Option { 69,035 ( 0.00%) match self { 4,384 ( 0.00%) Ok(x) => Some(x), . Err(_) => None, . } 1 ( 0.00%) } . . /// Converts from `Result` to [`Option`]. . /// . /// Converts `self` into an [`Option`], consuming `self`, . /// and discarding the success value, if any. . /// . /// # Examples . /// -- line 648 ---------------------------------------- -- line 657 ---------------------------------------- . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn err(self) -> Option { . match self { . Ok(_) => None, . Err(x) => Some(x), . } 4 ( 0.00%) } . . ///////////////////////////////////////////////////////////////////////// . // Adapter for working with references . ///////////////////////////////////////////////////////////////////////// . . /// Converts from `&Result` to `Result<&T, &E>`. . /// . /// Produces a new `Result`, containing a reference -- line 673 ---------------------------------------- -- line 683 ---------------------------------------- . /// . /// let x: Result = Err("Error"); . /// assert_eq!(x.as_ref(), Err(&"Error")); . /// ``` . #[inline] . #[rustc_const_stable(feature = "const_result", since = "1.48.0")] . #[stable(feature = "rust1", since = "1.0.0")] . pub const fn as_ref(&self) -> Result<&T, &E> { 62 ( 0.00%) match *self { . Ok(ref x) => Ok(x), . Err(ref x) => Err(x), . } . } . . /// Converts from `&mut Result` to `Result<&mut T, &mut E>`. . /// . /// # Examples -- line 699 ---------------------------------------- -- line 715 ---------------------------------------- . /// let mut x: Result = Err(13); . /// mutate(&mut x); . /// assert_eq!(x.unwrap_err(), 0); . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_unstable(feature = "const_result", issue = "82814")] . pub const fn as_mut(&mut self) -> Result<&mut T, &mut E> { 3,394,571 ( 0.03%) match *self { . Ok(ref mut x) => Ok(x), . Err(ref mut x) => Err(x), . } . } . . ///////////////////////////////////////////////////////////////////////// . // Transforming contained values . ///////////////////////////////////////////////////////////////////////// -- line 731 ---------------------------------------- -- line 747 ---------------------------------------- . /// Ok(n) => println!("{}", n), . /// Err(..) => {} . /// } . /// } . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn map U>(self, op: F) -> Result { 850,961 ( 0.01%) match self { 994,660 ( 0.01%) Ok(t) => Ok(op(t)), 111,037 ( 0.00%) Err(e) => Err(e), . } 90,351 ( 0.00%) } . . /// Returns the provided default (if [`Err`]), or . /// applies a function to the contained value (if [`Ok`]), . /// . /// Arguments passed to `map_or` are eagerly evaluated; if you are passing . /// the result of a function call, it is recommended to use [`map_or_else`], . /// which is lazily evaluated. . /// -- line 767 ---------------------------------------- -- line 774 ---------------------------------------- . /// assert_eq!(x.map_or(42, |v| v.len()), 3); . /// . /// let x: Result<&str, _> = Err("bar"); . /// assert_eq!(x.map_or(42, |v| v.len()), 42); . /// ``` . #[inline] . #[stable(feature = "result_map_or", since = "1.41.0")] . pub fn map_or U>(self, default: U, f: F) -> U { 10,139 ( 0.00%) match self { 114 ( 0.00%) Ok(t) => f(t), . Err(_) => default, . } . } . . /// Maps a `Result` to `U` by applying fallback function `default` to . /// a contained [`Err`] value, or function `f` to a contained [`Ok`] value. . /// . /// This function can be used to unpack a successful result -- line 791 ---------------------------------------- -- line 831 ---------------------------------------- . /// let x: Result = Ok(2); . /// assert_eq!(x.map_err(stringify), Ok(2)); . /// . /// let x: Result = Err(13); . /// assert_eq!(x.map_err(stringify), Err("error code: 13".to_string())); . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] 125 ( 0.00%) pub fn map_err F>(self, op: O) -> Result { 2,089,606 ( 0.02%) match self { 1,886,276 ( 0.02%) Ok(t) => Ok(t), 896 ( 0.00%) Err(e) => Err(op(e)), . } 309 ( 0.00%) } . . /// Calls the provided closure with a reference to the contained value (if [`Ok`]). . /// . /// # Examples . /// . /// ``` . /// #![feature(result_option_inspect)] . /// -- line 852 ---------------------------------------- -- line 1012 ---------------------------------------- . /// ``` . #[inline] . #[track_caller] . #[stable(feature = "result_expect", since = "1.4.0")] . pub fn expect(self, msg: &str) -> T . where . E: fmt::Debug, . { 121,682 ( 0.00%) match self { 3,794 ( 0.00%) Ok(t) => t, . Err(e) => unwrap_failed(msg, &e), . } . } . . /// Returns the contained [`Ok`] value, consuming the `self` value. . /// . /// Because this function may panic, its use is generally discouraged. . /// Instead, prefer to use pattern matching and handle the [`Err`] -- line 1029 ---------------------------------------- -- line 1051 ---------------------------------------- . /// . /// ```should_panic . /// let x: Result = Err("emergency failure"); . /// x.unwrap(); // panics with `emergency failure` . /// ``` . #[inline] . #[track_caller] . #[stable(feature = "rust1", since = "1.0.0")] 101,726 ( 0.00%) pub fn unwrap(self) -> T . where . E: fmt::Debug, . { 1,151,020 ( 0.01%) match self { 1,694,487 ( 0.02%) Ok(t) => t, . Err(e) => unwrap_failed("called `Result::unwrap()` on an `Err` value", &e), . } 152,589 ( 0.00%) } . . /// Returns the contained [`Ok`] value or a default . /// . /// Consumes the `self` argument then, if [`Ok`], returns the contained . /// value, otherwise if [`Err`], returns the default value for that . /// type. . /// . /// # Examples -- line 1075 ---------------------------------------- -- line 1092 ---------------------------------------- . /// [`parse`]: str::parse . /// [`FromStr`]: crate::str::FromStr . #[inline] . #[stable(feature = "result_unwrap_or_default", since = "1.16.0")] . pub fn unwrap_or_default(self) -> T . where . T: Default, . { 30,724 ( 0.00%) match self { 20,443 ( 0.00%) Ok(x) => x, . Err(_) => Default::default(), . } . } . . /// Returns the contained [`Err`] value, consuming the `self` value. . /// . /// # Panics . /// -- line 1109 ---------------------------------------- -- line 1152 ---------------------------------------- . /// ``` . #[inline] . #[track_caller] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn unwrap_err(self) -> E . where . T: fmt::Debug, . { 80 ( 0.00%) match self { . Ok(t) => unwrap_failed("called `Result::unwrap_err()` on an `Ok` value", &t), . Err(e) => e, . } . } . . /// Returns the contained [`Ok`] value, but never panics. . /// . /// Unlike [`unwrap`], this method is known to never panic on the -- line 1168 ---------------------------------------- -- line 1190 ---------------------------------------- . /// ``` . #[unstable(feature = "unwrap_infallible", reason = "newly added", issue = "61695")] . #[inline] . pub fn into_ok(self) -> T . where . E: Into, . { . match self { 802,412 ( 0.01%) Ok(x) => x, . Err(e) => e.into(), . } . } . . /// Returns the contained [`Err`] value, but never panics. . /// . /// Unlike [`unwrap_err`], this method is known to never panic on the . /// result types it is implemented for. Therefore, it can be used -- line 1206 ---------------------------------------- -- line 1290 ---------------------------------------- . /// assert_eq!(Ok(2).and_then(sq).and_then(sq), Ok(16)); . /// assert_eq!(Ok(2).and_then(sq).and_then(err), Err(4)); . /// assert_eq!(Ok(2).and_then(err).and_then(sq), Err(2)); . /// assert_eq!(Err(3).and_then(sq).and_then(sq), Err(3)); . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn and_then Result>(self, op: F) -> Result { 400,956 ( 0.00%) match self { 892,825 ( 0.01%) Ok(t) => op(t), 22,272 ( 0.00%) Err(e) => Err(e), . } . } . . /// Returns `res` if the result is [`Err`], otherwise returns the [`Ok`] value of `self`. . /// . /// Arguments passed to `or` are eagerly evaluated; if you are passing the . /// result of a function call, it is recommended to use [`or_else`], which is . /// lazily evaluated. -- line 1308 ---------------------------------------- -- line 1355 ---------------------------------------- . /// assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2)); . /// assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2)); . /// assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9)); . /// assert_eq!(Err(3).or_else(err).or_else(err), Err(3)); . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn or_else Result>(self, op: O) -> Result { 628,310 ( 0.01%) match self { 1,641,921 ( 0.02%) Ok(t) => Ok(t), . Err(e) => op(e), . } . } . . /// Returns the contained [`Ok`] value or a provided default. . /// . /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing . /// the result of a function call, it is recommended to use [`unwrap_or_else`], -- line 1372 ---------------------------------------- -- line 1384 ---------------------------------------- . /// assert_eq!(x.unwrap_or(default), 9); . /// . /// let x: Result = Err("error"); . /// assert_eq!(x.unwrap_or(default), default); . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn unwrap_or(self, default: T) -> T { 376 ( 0.00%) match self { 15 ( 0.00%) Ok(t) => t, . Err(_) => default, . } . } . . /// Returns the contained [`Ok`] value or computes it from a closure. . /// . /// . /// # Examples -- line 1401 ---------------------------------------- -- line 1406 ---------------------------------------- . /// fn count(x: &str) -> usize { x.len() } . /// . /// assert_eq!(Ok(2).unwrap_or_else(count), 2); . /// assert_eq!(Err("foo").unwrap_or_else(count), 3); . /// ``` . #[inline] . #[stable(feature = "rust1", since = "1.0.0")] . pub fn unwrap_or_else T>(self, op: F) -> T { 776,448 ( 0.01%) match self { 140,977 ( 0.00%) Ok(t) => t, . Err(e) => op(e), . } . } . . /// Returns the contained [`Ok`] value, consuming the `self` value, . /// without checking that the value is not an [`Err`]. . /// . /// # Safety -- line 1423 ---------------------------------------- -- line 1647 ---------------------------------------- . /// let x: Result, SomeErr> = Ok(Some(5)); . /// let y: Option> = Some(Ok(5)); . /// assert_eq!(x.transpose(), y); . /// ``` . #[inline] . #[stable(feature = "transpose_result", since = "1.33.0")] . #[rustc_const_unstable(feature = "const_result", issue = "82814")] . pub const fn transpose(self) -> Option> { 440 ( 0.00%) match self { . Ok(Some(x)) => Some(Ok(x)), . Ok(None) => None, . Err(e) => Some(Err(e)), . } . } . } . . impl Result, E> { -- line 1663 ---------------------------------------- -- line 1751 ---------------------------------------- . . ///////////////////////////////////////////////////////////////////////////// . // Trait implementations . ///////////////////////////////////////////////////////////////////////////// . . #[stable(feature = "rust1", since = "1.0.0")] . impl Clone for Result { . #[inline] 43,012 ( 0.00%) fn clone(&self) -> Self { 1,686,828 ( 0.02%) match self { 258,868 ( 0.00%) Ok(x) => Ok(x.clone()), 232,824 ( 0.00%) Err(x) => Err(x.clone()), . } 209,904 ( 0.00%) } . . #[inline] . fn clone_from(&mut self, source: &Self) { . match (self, source) { . (Ok(to), Ok(from)) => to.clone_from(from), . (Err(to), Err(from)) => to.clone_from(from), . (to, from) => *to = from.clone(), . } -- line 1772 ---------------------------------------- -- line 2011 ---------------------------------------- . /// . /// Since the third element caused an underflow, no further elements were taken, . /// so the final value of `shared` is 6 (= `3 + 2 + 1`), not 16. . #[inline] . fn from_iter>>(iter: I) -> Result { . // FIXME(#11084): This could be replaced with Iterator::scan when this . // performance bug is closed. . 6,603 ( 0.00%) iter::process_results(iter.into_iter(), |i| i.collect()) . } . } . . #[unstable(feature = "try_trait_v2", issue = "84277")] . #[rustc_const_unstable(feature = "const_convert", issue = "88674")] . impl const ops::Try for Result { . type Output = T; . type Residual = Result; . . #[inline] . fn from_output(output: Self::Output) -> Self { 2,342 ( 0.00%) Ok(output) . } . . #[inline] . fn branch(self) -> ControlFlow { 9,408,821 ( 0.09%) match self { 24,498,543 ( 0.24%) Ok(v) => ControlFlow::Continue(v), 41,421 ( 0.00%) Err(e) => ControlFlow::Break(Err(e)), . } . } . } . . #[unstable(feature = "try_trait_v2", issue = "84277")] . #[rustc_const_unstable(feature = "const_convert", issue = "88674")] . impl> const ops::FromResidual> . for Result . { . #[inline] . #[track_caller] . fn from_residual(residual: Result) -> Self { . match residual { 69,260 ( 0.00%) Err(e) => Err(From::from(e)), . } . } . } . . #[unstable(feature = "try_trait_v2_residual", issue = "91285")] . impl ops::Residual for Result { . type TryType = Result; . } -- line 2060 ---------------------------------------- 7,543,955 ( 0.08%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_span/src/caching_source_map_view.rs -------------------------------------------------------------------------------- Ir -- line 27 ---------------------------------------- . impl CacheEntry { . #[inline] . fn update( . &mut self, . new_file_and_idx: Option<(Lrc, usize)>, . pos: BytePos, . time_stamp: usize, . ) { 12,917 ( 0.00%) if let Some((file, file_idx)) = new_file_and_idx { 1,735 ( 0.00%) self.file = file; 1,307 ( 0.00%) self.file_index = file_idx; . } . 11,998 ( 0.00%) let line_index = self.file.lookup_line(pos).unwrap(); . let line_bounds = self.file.line_bounds(line_index); 26,024 ( 0.00%) self.line_number = line_index + 1; 39,444 ( 0.00%) self.line = line_bounds; . self.touch(time_stamp); . } . . #[inline] . fn touch(&mut self, time_stamp: usize) { 281,861 ( 0.00%) self.time_stamp = time_stamp; . } . } . . #[derive(Clone)] . pub struct CachingSourceMapView<'sm> { . source_map: &'sm SourceMap, . line_cache: [CacheEntry; 3], . time_stamp: usize, . } . . impl<'sm> CachingSourceMapView<'sm> { 860 ( 0.00%) pub fn new(source_map: &'sm SourceMap) -> CachingSourceMapView<'sm> { . let files = source_map.files(); 430 ( 0.00%) let first_file = files[0].clone(); . let entry = CacheEntry { . time_stamp: 0, . line_number: 0, . line: BytePos(0)..BytePos(0), . file: first_file, . file_index: 0, . }; . 2,150 ( 0.00%) CachingSourceMapView { . source_map, 3,010 ( 0.00%) line_cache: [entry.clone(), entry.clone(), entry], . time_stamp: 0, . } 1,720 ( 0.00%) } . . pub fn byte_pos_to_line_and_col( . &mut self, . pos: BytePos, . ) -> Option<(Lrc, usize, BytePos)> { . self.time_stamp += 1; . . // Check if the position is in one of the cached lines -- line 85 ---------------------------------------- -- line 106 ---------------------------------------- . }; . . let cache_entry = &mut self.line_cache[oldest]; . cache_entry.update(new_file_and_idx, pos, self.time_stamp); . . Some((cache_entry.file.clone(), cache_entry.line_number, pos - cache_entry.line.start)) . } . 1,029,532 ( 0.01%) pub fn span_data_to_lines_and_cols( . &mut self, . span_data: &SpanData, . ) -> Option<(Lrc, usize, BytePos, usize, BytePos)> { 588,304 ( 0.01%) self.time_stamp += 1; . . // Check if lo and hi are in the cached lines. 147,076 ( 0.00%) let lo_cache_idx = self.cache_entry_index(span_data.lo); 147,076 ( 0.00%) let hi_cache_idx = self.cache_entry_index(span_data.hi); . 269,600 ( 0.00%) if lo_cache_idx != -1 && hi_cache_idx != -1 { . // Cache hit for span lo and hi. Check if they belong to the same file. . let result = { 269,570 ( 0.00%) let lo = &self.line_cache[lo_cache_idx as usize]; . let hi = &self.line_cache[hi_cache_idx as usize]; . 808,710 ( 0.01%) if lo.file_index != hi.file_index { . return None; . } . . ( 269,570 ( 0.00%) lo.file.clone(), . lo.line_number, . span_data.lo - lo.line.start, 134,785 ( 0.00%) hi.line_number, . span_data.hi - hi.line.start, . ) . }; . 134,785 ( 0.00%) self.line_cache[lo_cache_idx as usize].touch(self.time_stamp); 134,785 ( 0.00%) self.line_cache[hi_cache_idx as usize].touch(self.time_stamp); . 539,140 ( 0.01%) return Some(result); . } . . // No cache hit or cache hit for only one of span lo and hi. 24,552 ( 0.00%) let oldest = if lo_cache_idx != -1 || hi_cache_idx != -1 { . let avoid_idx = if lo_cache_idx != -1 { lo_cache_idx } else { hi_cache_idx }; . self.oldest_cache_entry_index_avoid(avoid_idx as usize) . } else { . self.oldest_cache_entry_index() . }; . . // If the entry doesn't point to the correct file, get the new file and index. . // Return early if the file containing beginning of span doesn't contain end of span. 98,328 ( 0.00%) let new_file_and_idx = if !file_contains(&self.line_cache[oldest].file, span_data.lo) { 1,465 ( 0.00%) let new_file_and_idx = self.file_for_position(span_data.lo)?; 1,758 ( 0.00%) if !file_contains(&new_file_and_idx.0, span_data.hi) { . return None; . } . 1,172 ( 0.00%) Some(new_file_and_idx) . } else { . let file = &self.line_cache[oldest].file; 35,994 ( 0.00%) if !file_contains(&file, span_data.hi) { . return None; . } . 35,994 ( 0.00%) None . }; . . // Update the cache entries. 61,455 ( 0.00%) let (lo_idx, hi_idx) = match (lo_cache_idx, hi_cache_idx) { . // Oldest cache entry is for span_data.lo line. . (-1, -1) => { . let lo = &mut self.line_cache[oldest]; . lo.update(new_file_and_idx, span_data.lo, self.time_stamp); . 35,889 ( 0.00%) if !lo.line.contains(&span_data.hi) { . let new_file_and_idx = Some((lo.file.clone(), lo.file_index)); . let next_oldest = self.oldest_cache_entry_index_avoid(oldest); . let hi = &mut self.line_cache[next_oldest]; . hi.update(new_file_and_idx, span_data.hi, self.time_stamp); . (oldest, next_oldest) . } else { . (oldest, oldest) . } . } . // Oldest cache entry is for span_data.lo line. . (-1, _) => { . let lo = &mut self.line_cache[oldest]; . lo.update(new_file_and_idx, span_data.lo, self.time_stamp); 30 ( 0.00%) let hi = &mut self.line_cache[hi_cache_idx as usize]; 45 ( 0.00%) hi.touch(self.time_stamp); . (oldest, hi_cache_idx as usize) . } . // Oldest cache entry is for span_data.hi line. . (_, -1) => { . let hi = &mut self.line_cache[oldest]; 313 ( 0.00%) hi.update(new_file_and_idx, span_data.hi, self.time_stamp); 626 ( 0.00%) let lo = &mut self.line_cache[lo_cache_idx as usize]; 1,252 ( 0.00%) lo.touch(self.time_stamp); . (lo_cache_idx as usize, oldest) . } . _ => { . panic!(); . } . }; . . let lo = &self.line_cache[lo_idx]; . let hi = &self.line_cache[hi_idx]; . . // Span lo and hi may equal line end when last line doesn't . // end in newline, hence the inclusive upper bounds below. 24,582 ( 0.00%) assert!(span_data.lo >= lo.line.start); 12,291 ( 0.00%) assert!(span_data.lo <= lo.line.end); 24,582 ( 0.00%) assert!(span_data.hi >= hi.line.start); 12,291 ( 0.00%) assert!(span_data.hi <= hi.line.end); 61,455 ( 0.00%) assert!(lo.file.contains(span_data.lo)); 36,873 ( 0.00%) assert!(lo.file.contains(span_data.hi)); 36,873 ( 0.00%) assert_eq!(lo.file_index, hi.file_index); . 36,873 ( 0.00%) Some(( 12,291 ( 0.00%) lo.file.clone(), . lo.line_number, . span_data.lo - lo.line.start, 12,291 ( 0.00%) hi.line_number, . span_data.hi - hi.line.start, . )) 1,323,684 ( 0.01%) } . . fn cache_entry_index(&self, pos: BytePos) -> isize { . for (idx, cache_entry) in self.line_cache.iter().enumerate() { 1,761,121 ( 0.02%) if cache_entry.line.contains(&pos) { . return idx as isize; . } . } . . -1 . } . . fn oldest_cache_entry_index(&self) -> usize { . let mut oldest = 0; . . for idx in 1..self.line_cache.len() { 71,778 ( 0.00%) if self.line_cache[idx].time_stamp < self.line_cache[oldest].time_stamp { . oldest = idx; . } . } . . oldest . } . . fn oldest_cache_entry_index_avoid(&self, avoid_idx: usize) -> usize { . let mut oldest = if avoid_idx != 0 { 0 } else { 1 }; . . for idx in 0..self.line_cache.len() { 6,771 ( 0.00%) if idx != avoid_idx 3,230 ( 0.00%) && self.line_cache[idx].time_stamp < self.line_cache[oldest].time_stamp . { . oldest = idx; . } . } . . oldest . } . 1,465 ( 0.00%) fn file_for_position(&self, pos: BytePos) -> Option<(Lrc, usize)> { 293 ( 0.00%) if !self.source_map.files().is_empty() { 586 ( 0.00%) let file_idx = self.source_map.lookup_source_file_idx(pos); . let file = &self.source_map.files()[file_idx]; . 2,344 ( 0.00%) if file_contains(file, pos) { . return Some((file.clone(), file_idx)); . } . } . . None 1,465 ( 0.00%) } . } . . #[inline] . fn file_contains(file: &SourceFile, pos: BytePos) -> bool { . // `SourceMap::lookup_source_file_idx` and `SourceFile::contains` both consider the position . // one past the end of a file to belong to it. Normally, that's what we want. But for the . // purposes of converting a byte position to a line and column number, we can't come up with a . // line and column number if the file is empty, because an empty file doesn't contain any -- line 290 ---------------------------------------- 1,691,465 ( 0.02%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_parse/src/lexer/mod.rs -------------------------------------------------------------------------------- Ir -- line 26 ---------------------------------------- . pub struct UnmatchedBrace { . pub expected_delim: token::DelimToken, . pub found_delim: Option, . pub found_span: Span, . pub unclosed_span: Option, . pub candidate_span: Option, . } . 28 ( 0.00%) crate fn parse_token_trees<'a>( . sess: &'a ParseSess, . src: &'a str, . start_pos: BytePos, . override_span: Option, . ) -> (PResult<'a, TokenStream>, Vec) { . StringReader { sess, start_pos, pos: start_pos, end_src_index: src.len(), src, override_span } . .into_token_trees() 18 ( 0.00%) } . . struct StringReader<'a> { . sess: &'a ParseSess, . /// Initial position, read-only. . start_pos: BytePos, . /// The absolute offset within the source_map of the current character. . pos: BytePos, . /// Stop reading src at this index. -- line 50 ---------------------------------------- -- line 51 ---------------------------------------- . end_src_index: usize, . /// Source text to tokenize. . src: &'a str, . override_span: Option, . } . . impl<'a> StringReader<'a> { . fn mk_sp(&self, lo: BytePos, hi: BytePos) -> Span { 171,263 ( 0.00%) self.override_span.unwrap_or_else(|| Span::with_root_ctxt(lo, hi)) . } . . /// Returns the next token, and info about preceding whitespace, if any. 1,044,365 ( 0.01%) fn next_token(&mut self) -> (Spacing, Token) { . let mut spacing = Spacing::Joint; . . // Skip `#!` at the start of the file 298,390 ( 0.00%) let start_src_index = self.src_index(self.pos); 447,585 ( 0.00%) let text: &str = &self.src[start_src_index..self.end_src_index]; . let is_beginning_of_file = self.pos == self.start_pos; 149,195 ( 0.00%) if is_beginning_of_file { 8 ( 0.00%) if let Some(shebang_len) = rustc_lexer::strip_shebang(text) { . self.pos = self.pos + BytePos::from_usize(shebang_len); . spacing = Spacing::Alone; . } . } . . // Skip trivial (whitespace & comments) tokens . loop { 218,177 ( 0.00%) let start_src_index = self.src_index(self.pos); 551,058 ( 0.01%) let text: &str = &self.src[start_src_index..self.end_src_index]; . 183,686 ( 0.00%) if text.is_empty() { . let span = self.mk_sp(self.pos, self.pos); 10 ( 0.00%) return (spacing, Token::new(token::Eof, span)); . } . 551,052 ( 0.01%) let token = rustc_lexer::first_token(text); . 367,368 ( 0.00%) let start = self.pos; 183,684 ( 0.00%) self.pos = self.pos + BytePos::from_usize(token.len); . . debug!("next_token: {:?}({:?})", token.kind, self.str_from(start)); . 1,470,540 ( 0.01%) match self.cook_lexer_token(token.kind, start) { 1,193,544 ( 0.01%) Some(kind) => { . let span = self.mk_sp(start, self.pos); 895,158 ( 0.01%) return (spacing, Token::new(kind, span)); . } . None => spacing = Spacing::Alone, . } . } 1,342,755 ( 0.01%) } . . /// Report a fatal lexical error with a given span. . fn fatal_span(&self, sp: Span, m: &str) -> FatalError { . self.sess.span_diagnostic.span_fatal(sp, m) . } . . /// Report a lexical error with a given span. . fn err_span(&self, sp: Span, m: &str) { -- line 110 ---------------------------------------- -- line 130 ---------------------------------------- . ) -> DiagnosticBuilder<'a> { . self.sess . .span_diagnostic . .struct_span_fatal(self.mk_sp(from_pos, to_pos), &format!("{}: {}", m, escaped_char(c))) . } . . /// Detect usages of Unicode codepoints changing the direction of the text on screen and loudly . /// complain about it. 294 ( 0.00%) fn lint_unicode_text_flow(&self, start: BytePos) { . // Opening delimiter of the length 2 is not included into the comment text. . let content_start = start + BytePos(2); . let content = self.str_from(content_start); . if contains_text_flow_control_chars(content) { . let span = self.mk_sp(start, self.pos); . self.sess.buffer_lint_with_diagnostic( . &TEXT_DIRECTION_CODEPOINT_IN_COMMENT, . span, . ast::CRATE_NODE_ID, . "unicode codepoint changing visible direction of text present in comment", . BuiltinLintDiagnostics::UnicodeTextFlow(span, content.to_string()), . ); . } 336 ( 0.00%) } . . /// Turns simple `rustc_lexer::TokenKind` enum into a rich . /// `rustc_ast::TokenKind`. This turns strings into interned . /// symbols and runs additional validation. . fn cook_lexer_token(&self, token: rustc_lexer::TokenKind, start: BytePos) -> Option { 918,420 ( 0.01%) Some(match token { 309 ( 0.00%) rustc_lexer::TokenKind::LineComment { doc_style } => { . // Skip non-doc comments 1,419 ( 0.00%) let doc_style = if let Some(doc_style) = doc_style { . doc_style . } else { . self.lint_unicode_text_flow(start); . return None; . }; . . // Opening delimiter of the length 3 is not included into the symbol. . let content_start = start + BytePos(3); . let content = self.str_from(content_start); 1,335 ( 0.00%) self.cook_doc_comment(content_start, content, CommentKind::Line, doc_style) . } . rustc_lexer::TokenKind::BlockComment { doc_style, terminated } => { . if !terminated { . let msg = match doc_style { . Some(_) => "unterminated block doc-comment", . None => "unterminated block comment", . }; . let last_bpos = self.pos; -- line 179 ---------------------------------------- -- line 198 ---------------------------------------- . let content_end = self.pos - BytePos(if terminated { 2 } else { 0 }); . let content = self.str_from_to(content_start, content_end); . self.cook_doc_comment(content_start, content, CommentKind::Block, doc_style) . } . rustc_lexer::TokenKind::Whitespace => return None, . rustc_lexer::TokenKind::Ident . | rustc_lexer::TokenKind::RawIdent . | rustc_lexer::TokenKind::UnknownPrefix => { 88,264 ( 0.00%) let is_raw_ident = token == rustc_lexer::TokenKind::RawIdent; 110,330 ( 0.00%) let is_unknown_prefix = token == rustc_lexer::TokenKind::UnknownPrefix; . let mut ident_start = start; 44,132 ( 0.00%) if is_raw_ident { . ident_start = ident_start + BytePos(2); . } 66,198 ( 0.00%) if is_unknown_prefix { . self.report_unknown_prefix(start); . } 110,330 ( 0.00%) let sym = nfc_normalize(self.str_from(ident_start)); . let span = self.mk_sp(start, self.pos); 88,264 ( 0.00%) self.sess.symbol_gallery.insert(sym, span); 44,132 ( 0.00%) if is_raw_ident { . if !sym.can_be_raw() { . self.err_span(span, &format!("`{}` cannot be a raw identifier", sym)); . } . self.sess.raw_identifier_spans.borrow_mut().push(span); . } 154,462 ( 0.00%) token::Ident(sym, is_raw_ident) . } . rustc_lexer::TokenKind::InvalidIdent . // Do not recover an identifier with emoji if the codepoint is a confusable . // with a recoverable substitution token, like `âž–`. . if UNICODE_ARRAY . .iter() . .find(|&&(c, _, _)| { . let sym = self.str_from(start); -- line 232 ---------------------------------------- -- line 234 ---------------------------------------- . }) . .is_none() => . { . let sym = nfc_normalize(self.str_from(start)); . let span = self.mk_sp(start, self.pos); . self.sess.bad_unicode_identifiers.borrow_mut().entry(sym).or_default().push(span); . token::Ident(sym, false) . } 493,696 ( 0.00%) rustc_lexer::TokenKind::Literal { kind, suffix_start } => { . let suffix_start = start + BytePos(suffix_start as u32); . let (kind, symbol) = self.cook_lexer_literal(start, suffix_start, kind); 92,568 ( 0.00%) let suffix = if suffix_start < self.pos { . let string = self.str_from(suffix_start); . if string == "_" { . self.sess . .span_diagnostic . .struct_span_warn( . self.mk_sp(suffix_start, self.pos), . "underscore literal suffix is not allowed", . ) -- line 253 ---------------------------------------- -- line 264 ---------------------------------------- . .emit(); . None . } else { . Some(Symbol::intern(string)) . } . } else { . None . }; 246,848 ( 0.00%) token::Literal(token::Lit { kind, symbol, suffix }) . } 76 ( 0.00%) rustc_lexer::TokenKind::Lifetime { starts_with_number } => { . // Include the leading `'` in the real identifier, for macro . // expansion purposes. See #12512 for the gory details of why . // this is necessary. . let lifetime_name = self.str_from(start); 38 ( 0.00%) if starts_with_number { . self.err_span_(start, self.pos, "lifetimes cannot start with a number"); . } 114 ( 0.00%) let ident = Symbol::intern(lifetime_name); 152 ( 0.00%) token::Lifetime(ident) . } . rustc_lexer::TokenKind::Semi => token::Semi, . rustc_lexer::TokenKind::Comma => token::Comma, . rustc_lexer::TokenKind::Dot => token::Dot, . rustc_lexer::TokenKind::OpenParen => token::OpenDelim(token::Paren), . rustc_lexer::TokenKind::CloseParen => token::CloseDelim(token::Paren), . rustc_lexer::TokenKind::OpenBrace => token::OpenDelim(token::Brace), . rustc_lexer::TokenKind::CloseBrace => token::CloseDelim(token::Brace), -- line 291 ---------------------------------------- -- line 324 ---------------------------------------- . err.help("source files must contain UTF-8 encoded text, unexpected null bytes might occur when a different encoding is used"); . } . err.emit(); . token? . } . }) . } . 3,204 ( 0.00%) fn cook_doc_comment( . &self, . content_start: BytePos, . content: &str, . comment_kind: CommentKind, . doc_style: DocStyle, . ) -> TokenKind { 267 ( 0.00%) if content.contains('\r') { . for (idx, _) in content.char_indices().filter(|&(_, c)| c == '\r') { . self.err_span_( . content_start + BytePos(idx as u32), . content_start + BytePos(idx as u32 + 1), . match comment_kind { . CommentKind::Line => "bare CR not allowed in doc-comment", . CommentKind::Block => "bare CR not allowed in block doc-comment", . }, -- line 347 ---------------------------------------- -- line 349 ---------------------------------------- . } . } . . let attr_style = match doc_style { . DocStyle::Outer => AttrStyle::Outer, . DocStyle::Inner => AttrStyle::Inner, . }; . 801 ( 0.00%) token::DocComment(comment_kind, attr_style, Symbol::intern(content)) 4,005 ( 0.00%) } . . fn cook_lexer_literal( . &self, . start: BytePos, . suffix_start: BytePos, . kind: rustc_lexer::LiteralKind, . ) -> (token::LitKind, Symbol) { . // prefix means `"` or `br"` or `r###"`, ... . let (lit_kind, mode, prefix_len, postfix_len) = match kind { 30,138 ( 0.00%) rustc_lexer::LiteralKind::Char { terminated } => { 30,138 ( 0.00%) if !terminated { . self.sess.span_diagnostic.span_fatal_with_code( . self.mk_sp(start, suffix_start), . "unterminated character literal", . error_code!(E0762), . ) . } . (token::Char, Mode::Char, 1, 1) // ' ' . } 5 ( 0.00%) rustc_lexer::LiteralKind::Byte { terminated } => { 5 ( 0.00%) if !terminated { . self.sess.span_diagnostic.span_fatal_with_code( . self.mk_sp(start + BytePos(1), suffix_start), . "unterminated byte constant", . error_code!(E0763), . ) . } . (token::Byte, Mode::Byte, 2, 1) // b' ' . } 616 ( 0.00%) rustc_lexer::LiteralKind::Str { terminated } => { 616 ( 0.00%) if !terminated { . self.sess.span_diagnostic.span_fatal_with_code( . self.mk_sp(start, suffix_start), . "unterminated double quote string", . error_code!(E0765), . ) . } . (token::Str, Mode::Str, 1, 1) // " " . } -- line 397 ---------------------------------------- -- line 410 ---------------------------------------- . let n = u32::from(n_hashes); . (token::StrRaw(n_hashes), Mode::RawStr, 2 + n, 1 + n) // r##" "## . } . rustc_lexer::LiteralKind::RawByteStr { n_hashes, err } => { . self.report_raw_str_error(start, err); . let n = u32::from(n_hashes); . (token::ByteStrRaw(n_hashes), Mode::RawByteStr, 3 + n, 1 + n) // br##" "## . } 194 ( 0.00%) rustc_lexer::LiteralKind::Int { base, empty_int } => { 97 ( 0.00%) return if empty_int { . self.sess . .span_diagnostic . .struct_span_err_with_code( . self.mk_sp(start, suffix_start), . "no valid digits found for number", . error_code!(E0768), . ) . .emit(); . (token::Integer, sym::integer(0)) . } else { . self.validate_int_literal(base, start, suffix_start); 291 ( 0.00%) (token::Integer, self.symbol_from_to(start, suffix_start)) . }; . } . rustc_lexer::LiteralKind::Float { base, empty_exponent } => { . if empty_exponent { . self.err_span_(start, self.pos, "expected at least one digit in exponent"); . } . . match base { -- line 439 ---------------------------------------- -- line 452 ---------------------------------------- . } . . let id = self.symbol_from_to(start, suffix_start); . return (token::Float, id); . } . }; . let content_start = start + BytePos(prefix_len); . let content_end = suffix_start - BytePos(postfix_len); 92,277 ( 0.00%) let id = self.symbol_from_to(content_start, content_end); . self.validate_literal_escape(mode, content_start, content_end, prefix_len, postfix_len); . (lit_kind, id) . } . . #[inline] . fn src_index(&self, pos: BytePos) -> usize { . (pos - self.start_pos).to_usize() . } . . /// Slice of the source text from `start` up to but excluding `self.pos`, . /// meaning the slice does not include the character `self.ch`. . fn str_from(&self, start: BytePos) -> &str { 135,073 ( 0.00%) self.str_from_to(start, self.pos) . } . . /// As symbol_from, with an explicit endpoint. . fn symbol_from_to(&self, start: BytePos, end: BytePos) -> Symbol { . debug!("taking an ident from {:?} to {:?}", start, end); 369,787 ( 0.00%) Symbol::intern(self.str_from_to(start, end)) . } . . /// Slice of the source text spanning from `start` up to but excluding `end`. 84,028 ( 0.00%) fn str_from_to(&self, start: BytePos, end: BytePos) -> &str { . &self.src[self.src_index(start)..self.src_index(end)] 336,112 ( 0.00%) } . . fn report_raw_str_error(&self, start: BytePos, opt_err: Option) { . match opt_err { . Some(RawStrError::InvalidStarter { bad_char }) => { . self.report_non_started_raw_string(start, bad_char) . } . Some(RawStrError::NoTerminator { expected, found, possible_terminator_offset }) => self . .report_unterminated_raw_string(start, expected, possible_terminator_offset, found), -- line 493 ---------------------------------------- -- line 609 ---------------------------------------- . fn validate_literal_escape( . &self, . mode: Mode, . content_start: BytePos, . content_end: BytePos, . prefix_len: u32, . postfix_len: u32, . ) { 184,554 ( 0.00%) let lit_content = self.str_from_to(content_start, content_end); 948,866 ( 0.01%) unescape::unescape_literal(lit_content, mode, &mut |range, result| { . // Here we only check for errors. The actual unescaping is done later. 68,042 ( 0.00%) if let Err(err) = result { . let span_with_quotes = self . .mk_sp(content_start - BytePos(prefix_len), content_end + BytePos(postfix_len)); . let (start, end) = (range.start as u32, range.end as u32); . let lo = content_start + BytePos(start); . let hi = lo + BytePos(end - start); . let span = self.mk_sp(lo, hi); . emit_unescape_error( . &self.sess.span_diagnostic, -- line 628 ---------------------------------------- -- line 629 ---------------------------------------- . lit_content, . span_with_quotes, . span, . mode, . range, . err, . ); . } 306,189 ( 0.00%) }); . } . . fn validate_int_literal(&self, base: Base, content_start: BytePos, content_end: BytePos) { 388 ( 0.00%) let base = match base { . Base::Binary => 2, . Base::Octal => 8, . _ => return, . }; . let s = self.str_from_to(content_start + BytePos(2), content_end); . for (idx, c) in s.char_indices() { . let idx = idx as u32; . if c != '_' && c.to_digit(base).is_none() { -- line 649 ---------------------------------------- -- line 650 ---------------------------------------- . let lo = content_start + BytePos(2 + idx); . let hi = content_start + BytePos(2 + idx + c.len_utf8() as u32); . self.err_span_(lo, hi, &format!("invalid digit for a base {} literal", base)); . } . } . } . } . 198,594 ( 0.00%) pub fn nfc_normalize(string: &str) -> Symbol { . use unicode_normalization::{is_nfc_quick, IsNormalized, UnicodeNormalization}; 44,132 ( 0.00%) match is_nfc_quick(string.chars()) { 220,660 ( 0.00%) IsNormalized::Yes => Symbol::intern(string), . _ => { . let normalized_str: String = string.chars().nfc().collect(); . Symbol::intern(&normalized_str) . } . } . } 907,733 ( 0.01%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_const_eval/src/interpret/operand.rs -------------------------------------------------------------------------------- Ir -- line 41 ---------------------------------------- . fn from(val: ScalarMaybeUninit) -> Self { . Immediate::Scalar(val) . } . } . . impl From> for Immediate { . #[inline(always)] . fn from(val: Scalar) -> Self { 12 ( 0.00%) Immediate::Scalar(val.into()) . } . } . . impl<'tcx, Tag: Provenance> Immediate { . pub fn from_pointer(p: Pointer, cx: &impl HasDataLayout) -> Self { . Immediate::Scalar(ScalarMaybeUninit::from_pointer(p, cx)) . } . . pub fn from_maybe_pointer(p: Pointer>, cx: &impl HasDataLayout) -> Self { . Immediate::Scalar(ScalarMaybeUninit::from_maybe_pointer(p, cx)) . } . 544 ( 0.00%) pub fn new_slice(val: Scalar, len: u64, cx: &impl HasDataLayout) -> Self { 9,386 ( 0.00%) Immediate::ScalarPair(val.into(), Scalar::from_machine_usize(len, cx).into()) 816 ( 0.00%) } . . pub fn new_dyn_trait( . val: Scalar, . vtable: Pointer>, . cx: &impl HasDataLayout, . ) -> Self { . Immediate::ScalarPair(val.into(), ScalarMaybeUninit::from_maybe_pointer(vtable, cx)) . } . . #[inline] . pub fn to_scalar_or_uninit(self) -> ScalarMaybeUninit { 301,746 ( 0.00%) match self { 121,124 ( 0.00%) Immediate::Scalar(val) => val, . Immediate::ScalarPair(..) => bug!("Got a scalar pair where a scalar was expected"), . } . } . . #[inline] . pub fn to_scalar(self) -> InterpResult<'tcx, Scalar> { . self.to_scalar_or_uninit().check_init() . } -- line 85 ---------------------------------------- -- line 159 ---------------------------------------- . fn deref(&self) -> &Immediate { . &self.imm . } . } . . /// An `Operand` is the result of computing a `mir::Operand`. It can be immediate, . /// or still in memory. The latter is an optimization, to delay reading that chunk of . /// memory and to avoid having to store arbitrary-sized data here. 10,114 ( 0.00%) #[derive(Copy, Clone, PartialEq, Eq, HashStable, Hash, Debug)] . pub enum Operand { . Immediate(Immediate), . Indirect(MemPlace), . } . . #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] . pub struct OpTy<'tcx, Tag: Provenance = AllocId> { . op: Operand, // Keep this private; it helps enforce invariants. -- line 175 ---------------------------------------- -- line 185 ---------------------------------------- . fn deref(&self) -> &Operand { . &self.op . } . } . . impl<'tcx, Tag: Provenance> From> for OpTy<'tcx, Tag> { . #[inline(always)] . fn from(mplace: MPlaceTy<'tcx, Tag>) -> Self { 11,659 ( 0.00%) OpTy { op: Operand::Indirect(*mplace), layout: mplace.layout } . } . } . . impl<'tcx, Tag: Provenance> From<&'_ MPlaceTy<'tcx, Tag>> for OpTy<'tcx, Tag> { . #[inline(always)] . fn from(mplace: &MPlaceTy<'tcx, Tag>) -> Self { . OpTy { op: Operand::Indirect(**mplace), layout: mplace.layout } . } -- line 201 ---------------------------------------- -- line 206 ---------------------------------------- . fn from(val: ImmTy<'tcx, Tag>) -> Self { . OpTy { op: Operand::Immediate(val.imm), layout: val.layout } . } . } . . impl<'tcx, Tag: Provenance> ImmTy<'tcx, Tag> { . #[inline] . pub fn from_scalar(val: Scalar, layout: TyAndLayout<'tcx>) -> Self { 201 ( 0.00%) ImmTy { imm: val.into(), layout } . } . . #[inline] . pub fn from_immediate(imm: Immediate, layout: TyAndLayout<'tcx>) -> Self { . ImmTy { imm, layout } . } . . #[inline] . pub fn try_from_uint(i: impl Into, layout: TyAndLayout<'tcx>) -> Option { . Some(Self::from_scalar(Scalar::try_from_uint(i, layout.size)?, layout)) . } . #[inline] . pub fn from_uint(i: impl Into, layout: TyAndLayout<'tcx>) -> Self { 15 ( 0.00%) Self::from_scalar(Scalar::from_uint(i, layout.size), layout) . } . . #[inline] . pub fn try_from_int(i: impl Into, layout: TyAndLayout<'tcx>) -> Option { . Some(Self::from_scalar(Scalar::try_from_int(i, layout.size)?, layout)) . } . . #[inline] -- line 236 ---------------------------------------- -- line 248 ---------------------------------------- . . impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { . /// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`. . /// Returns `None` if the layout does not permit loading this as a value. . fn try_read_immediate_from_mplace( . &self, . mplace: &MPlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, Option>> { 154,949 ( 0.00%) if mplace.layout.is_unsized() { . // Don't touch unsized . return Ok(None); . } . 221,247 ( 0.00%) let alloc = match self.get_alloc(mplace)? { 368,710 ( 0.00%) Some(ptr) => ptr, . None => { . return Ok(Some(ImmTy { . // zero-sized type 63 ( 0.00%) imm: Scalar::ZST.into(), . layout: mplace.layout, . })); . } . }; . 584,876 ( 0.01%) match mplace.layout.abi { . Abi::Scalar(..) => { 30,619 ( 0.00%) let scalar = alloc.read_scalar(alloc_range(Size::ZERO, mplace.layout.size))?; . Ok(Some(ImmTy { imm: scalar.into(), layout: mplace.layout })) . } 7,590 ( 0.00%) Abi::ScalarPair(a, b) => { . // We checked `ptr_align` above, so all fields will have the alignment they need. . // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, . // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. . let (a, b) = (a.value, b.value); . let (a_size, b_size) = (a.size(self), b.size(self)); . let b_offset = a_size.align_to(b.align(self).abi); 5,060 ( 0.00%) assert!(b_offset.bytes() > 0); // we later use the offset to tell apart the fields . let a_val = alloc.read_scalar(alloc_range(Size::ZERO, a_size))?; 7,590 ( 0.00%) let b_val = alloc.read_scalar(alloc_range(b_offset, b_size))?; 12,650 ( 0.00%) Ok(Some(ImmTy { imm: Immediate::ScalarPair(a_val, b_val), layout: mplace.layout })) . } . _ => Ok(None), . } . } . . /// Try returning an immediate for the operand. . /// If the layout does not permit loading this as an immediate, return where in memory . /// we can find the data. . /// Note that for a given layout, this operation will either always fail or always . /// succeed! Whether it succeeds depends on whether the layout can be represented . /// in an `Immediate`, not on which data is stored there currently. 2,844,720 ( 0.03%) pub fn try_read_immediate( . &self, . src: &OpTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, Result, MPlaceTy<'tcx, M::PointerTag>>> { 5,689,440 ( 0.06%) Ok(match src.try_as_mplace() { . Ok(ref mplace) => { 147,498 ( 0.00%) if let Some(val) = self.try_read_immediate_from_mplace(mplace)? { . Ok(val) . } else { . Err(*mplace) . } . } 2,423,310 ( 0.02%) Err(val) => Ok(val), . }) 2,844,720 ( 0.03%) } . . /// Read an immediate from a place, asserting that that is possible with the given layout. . #[inline(always)] . pub fn read_immediate( . &self, . op: &OpTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, ImmTy<'tcx, M::PointerTag>> { 797,745 ( 0.01%) if let Ok(imm) = self.try_read_immediate(op)? { 1,107,739 ( 0.01%) Ok(imm) . } else { . span_bug!(self.cur_span(), "primitive read failed for type: {:?}", op.layout.ty); . } . } . . /// Read a scalar from a place 333,091 ( 0.00%) pub fn read_scalar( . &self, . op: &OpTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, ScalarMaybeUninit> { 30,281 ( 0.00%) Ok(self.read_immediate(op)?.to_scalar_or_uninit()) 272,529 ( 0.00%) } . . /// Read a pointer from a place. . pub fn read_pointer( . &self, . op: &OpTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, Pointer>> { . Ok(self.scalar_to_ptr(self.read_scalar(op)?.check_init()?)) . } -- line 342 ---------------------------------------- -- line 345 ---------------------------------------- . pub fn read_str(&self, mplace: &MPlaceTy<'tcx, M::PointerTag>) -> InterpResult<'tcx, &str> { . let len = mplace.len(self)?; . let bytes = self.memory.read_bytes(mplace.ptr, Size::from_bytes(len))?; . let str = std::str::from_utf8(bytes).map_err(|err| err_ub!(InvalidStr(err)))?; . Ok(str) . } . . /// Projection functions 235,890 ( 0.00%) pub fn operand_field( . &self, . op: &OpTy<'tcx, M::PointerTag>, . field: usize, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . let base = match op.try_as_mplace() { . Ok(ref mplace) => { . // We can reuse the mplace field computation logic for indirect operands. . let field = self.mplace_field(mplace, field)?; 258,863 ( 0.00%) return Ok(field.into()); . } 392 ( 0.00%) Err(value) => value, . }; . 270 ( 0.00%) let field_layout = op.layout.field(self, field); . if field_layout.is_zst() { . let immediate = Scalar::ZST.into(); . return Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout }); . } 168 ( 0.00%) let offset = op.layout.fields.offset(field); 4 ( 0.00%) let immediate = match *base { . // the field covers the entire type 714 ( 0.00%) _ if offset.bytes() == 0 && field_layout.size == op.layout.size => *base, . // extract fields from types with `ScalarPair` ABI . Immediate::ScalarPair(a, b) => { 2 ( 0.00%) let val = if offset.bytes() == 0 { a } else { b }; . Immediate::from(val) . } . Immediate::Scalar(val) => span_bug!( . self.cur_span(), . "field access on non aggregate {:#?}, {:#?}", . val, . op.layout . ), . }; 784 ( 0.00%) Ok(OpTy { op: Operand::Immediate(immediate), layout: field_layout }) 212,301 ( 0.00%) } . . pub fn operand_index( . &self, . op: &OpTy<'tcx, M::PointerTag>, . index: u64, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . if let Ok(index) = usize::try_from(index) { . // We can just treat this as a field. -- line 397 ---------------------------------------- -- line 398 ---------------------------------------- . self.operand_field(op, index) . } else { . // Indexing into a big array. This must be an mplace. . let mplace = op.assert_mem_place(); . Ok(self.mplace_index(&mplace, index)?.into()) . } . } . 1,122 ( 0.00%) pub fn operand_downcast( . &self, . op: &OpTy<'tcx, M::PointerTag>, . variant: VariantIdx, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . // Downcasts only change the layout 1,734 ( 0.00%) Ok(match op.try_as_mplace() { 750 ( 0.00%) Ok(ref mplace) => self.mplace_downcast(mplace, variant)?.into(), . Err(..) => { 81 ( 0.00%) let layout = op.layout.for_variant(self, variant); 378 ( 0.00%) OpTy { layout, ..*op } . } . }) 918 ( 0.00%) } . 120,716 ( 0.00%) pub fn operand_projection( . &self, . base: &OpTy<'tcx, M::PointerTag>, . proj_elem: mir::PlaceElem<'tcx>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . use rustc_middle::mir::ProjectionElem::*; 482,864 ( 0.00%) Ok(match proj_elem { 129 ( 0.00%) Field(field, _) => self.operand_field(base, field.index())?, 93 ( 0.00%) Downcast(_, variant) => self.operand_downcast(base, variant)?, . Deref => self.deref_operand(base)?.into(), . Subslice { .. } | ConstantIndex { .. } | Index(_) => { . // The rest should only occur as mplace, we do not use Immediates for types . // allowing such operations. This matches place_projection forcing an allocation. . let mplace = base.assert_mem_place(); 240,840 ( 0.00%) self.mplace_projection(&mplace, proj_elem)?.into() . } . }) 120,716 ( 0.00%) } . . /// Converts a repr(simd) operand into an operand where `place_index` accesses the SIMD elements. . /// Also returns the number of elements. . pub fn operand_to_simd( . &self, . base: &OpTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> { . // Basically we just transmute this place into an array following simd_size_and_type. -- line 446 ---------------------------------------- -- line 449 ---------------------------------------- . self.mplace_to_simd(&base.assert_mem_place()) . } . . /// Read from a local. Will not actually access the local if reading from a ZST. . /// Will not access memory, instead an indirect `Operand` is returned. . /// . /// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) to get an . /// OpTy from a local 2,283,039 ( 0.02%) pub fn access_local( . &self, . frame: &super::Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>, . local: mir::Local, . layout: Option>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . let layout = self.layout_of_local(frame, local, layout)?; 70,757 ( 0.00%) let op = if layout.is_zst() { . // Do not read from ZST, they might not be initialized 35 ( 0.00%) Operand::Immediate(Scalar::ZST.into()) . } else { 4,998 ( 0.00%) M::access_local(&self, frame, local)? . }; 3,274,869 ( 0.03%) Ok(OpTy { op, layout }) 2,026,588 ( 0.02%) } . . /// Every place can be read from, so we can turn them into an operand. . /// This will definitely return `Indirect` if the place is a `Ptr`, i.e., this . /// will never actually read from memory. . #[inline(always)] . pub fn place_to_op( . &self, . place: &PlaceTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { 16 ( 0.00%) let op = match **place { . Place::Ptr(mplace) => Operand::Indirect(mplace), . Place::Local { frame, local } => { 72 ( 0.00%) *self.access_local(&self.stack()[frame], local, None)? . } . }; . Ok(OpTy { op, layout: place.layout }) . } . . // Evaluate a place with the goal of reading from it. This lets us sometimes . // avoid allocations. 1,703,592 ( 0.02%) pub fn eval_place_to_op( . &self, . place: mir::Place<'tcx>, . layout: Option>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . // Do not use the layout passed in as argument if the base we are looking at . // here is not the entire place. 212,949 ( 0.00%) let layout = if place.projection.is_empty() { layout } else { None }; . 638,847 ( 0.01%) let base_op = self.access_local(self.frame(), place.local, layout)?; . . let op = place . .projection . .iter() 271,611 ( 0.00%) .try_fold(base_op, |op, elem| self.operand_projection(&op, elem))?; . . trace!("eval_place_to_op: got {:?}", *op); . // Sanity-check the type we ended up with. . debug_assert!(mir_assign_valid_types( . *self.tcx, . self.param_env, . self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions( . place.ty(&self.frame().body.local_decls, *self.tcx).ty . )?)?, . op.layout, . )); 635,265 ( 0.01%) Ok(op) 1,916,541 ( 0.02%) } . . /// Evaluate the operand, returning a place where you can then find the data. . /// If you already know the layout, you can save two table lookups . /// by passing it in here. . #[inline] 2,449,541 ( 0.02%) pub fn eval_operand( . &self, . mir_op: &mir::Operand<'tcx>, . layout: Option>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . use rustc_middle::mir::Operand::*; 567,087 ( 0.01%) let op = match *mir_op { . // FIXME: do some more logic on `move` to invalidate the old location 1,051,810 ( 0.01%) Copy(place) | Move(place) => self.eval_place_to_op(place, layout)?, . . Constant(ref constant) => { . let val = 1,065,889 ( 0.01%) self.subst_from_current_frame_and_normalize_erasing_regions(constant.literal)?; . // This can still fail: . // * During ConstProp, with `TooGeneric` or since the `requried_consts` were not all . // checked yet. . // * During CTFE, since promoteds in `const`/`static` initializer bodies can fail. . 863 ( 0.00%) self.mir_const_to_op(&val, layout)? . } . }; . trace!("{:?}: {:?}", mir_op, *op); 3,641,317 ( 0.04%) Ok(op) 1,633,028 ( 0.02%) } . . /// Evaluate a bunch of operands at once . pub(super) fn eval_operands( . &self, . ops: &[mir::Operand<'tcx>], . ) -> InterpResult<'tcx, Vec>> { . ops.iter().map(|op| self.eval_operand(op, None)).collect() . } . . // Used when the miri-engine runs into a constant and for extracting information from constants . // in patterns via the `const_eval` module . /// The `val` and `layout` are assumed to already be in our interpreter . /// "universe" (param_env). 849,660 ( 0.01%) pub fn const_to_op( . &self, . val: &ty::Const<'tcx>, . layout: Option>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { 358,520 ( 0.00%) match val.val { . ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric), . ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorReported)), 116 ( 0.00%) ty::ConstKind::Unevaluated(uv) => { . let instance = self.resolve(uv.def, uv.substs)?; 319 ( 0.00%) Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into()) . } . ty::ConstKind::Infer(..) | ty::ConstKind::Placeholder(..) => { . span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val) . } 713,270 ( 0.01%) ty::ConstKind::Value(val_val) => self.const_val_to_op(val_val, val.ty, layout), . } 637,245 ( 0.01%) } . 9,889 ( 0.00%) pub fn mir_const_to_op( . &self, . val: &mir::ConstantKind<'tcx>, . layout: Option>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { 143,408 ( 0.00%) match val { 285,018 ( 0.00%) mir::ConstantKind::Ty(ct) => self.const_to_op(ct, layout), . mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, ty, layout), . } 8,091 ( 0.00%) } . 716,750 ( 0.01%) crate fn const_val_to_op( . &self, . val_val: ConstValue<'tcx>, . ty: Ty<'tcx>, . layout: Option>, . ) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> { . // Other cases need layout. . let tag_scalar = |scalar| -> InterpResult<'tcx, _> { 425,730 ( 0.00%) Ok(match scalar { . Scalar::Ptr(ptr, size) => Scalar::Ptr(self.global_base_pointer(ptr)?, size), 212,778 ( 0.00%) Scalar::Int(int) => Scalar::Int(int), . }) . }; 122,268 ( 0.00%) let layout = from_known_layout(self.tcx, self.param_env, layout, || self.layout_of(ty))?; 216,465 ( 0.00%) let op = match val_val { 34 ( 0.00%) ConstValue::ByRef { alloc, offset } => { 34 ( 0.00%) let id = self.tcx.create_memory_alloc(alloc); . // We rely on mutability being set correctly in that allocation to prevent writes . // where none should happen. . let ptr = self.global_base_pointer(Pointer::new(id, offset))?; 68 ( 0.00%) Operand::Indirect(MemPlace::from_ptr(ptr.into(), layout.align.abi)) . } 639,345 ( 0.01%) ConstValue::Scalar(x) => Operand::Immediate(tag_scalar(x)?.into()), 2,109 ( 0.00%) ConstValue::Slice { data, start, end } => { . // We rely on mutability being set correctly in `data` to prevent writes . // where none should happen. . let ptr = Pointer::new( 2,109 ( 0.00%) self.tcx.create_memory_alloc(data), . Size::from_bytes(start), // offset: `start` . ); 2,760 ( 0.00%) Operand::Immediate(Immediate::new_slice( . Scalar::from_pointer(self.global_base_pointer(ptr)?, &*self.tcx), . u64::try_from(end.checked_sub(start).unwrap()).unwrap(), // len: `end - start` . self, . )) . } . }; 1,505,175 ( 0.02%) Ok(OpTy { op, layout }) 573,400 ( 0.01%) } . . /// Read discriminant, return the runtime value as well as the variant index. . /// Can also legally be called on non-enums (e.g. through the discriminant_value intrinsic)! 1,150 ( 0.00%) pub fn read_discriminant( . &self, . op: &OpTy<'tcx, M::PointerTag>, . ) -> InterpResult<'tcx, (Scalar, VariantIdx)> { . trace!("read_discriminant_value {:#?}", op.layout); . // Get type and layout of the discriminant. 1,380 ( 0.00%) let discr_layout = self.layout_of(op.layout.ty.discriminant_ty(*self.tcx))?; . trace!("discriminant type: {:?}", discr_layout.ty); . . // We use "discriminant" to refer to the value associated with a particular enum variant. . // This is not to be confused with its "variant index", which is just determining its position in the . // declared list of variants -- they can differ with explicitly assigned discriminants. . // We use "tag" to refer to how the discriminant is encoded in memory, which can be either . // straight-forward (`TagEncoding::Direct`) or with a niche (`TagEncoding::Niche`). 345 ( 0.00%) let (tag_scalar_layout, tag_encoding, tag_field) = match op.layout.variants { . Variants::Single { index } => { . let discr = match op.layout.ty.discriminant_for_variant(*self.tcx, index) { . Some(discr) => { . // This type actually has discriminants. . assert_eq!(discr.ty, discr_layout.ty); . Scalar::from_uint(discr.val, discr_layout.size) . } . None => { . // On a type without actual discriminants, variant is 0. . assert_eq!(index.as_u32(), 0); . Scalar::from_uint(index.as_u32(), discr_layout.size) . } . }; . return Ok((discr, index)); . } 230 ( 0.00%) Variants::Multiple { tag, ref tag_encoding, tag_field, .. } => { . (tag, tag_encoding, tag_field) . } . }; . . // There are *three* layouts that come into play here: . // - The discriminant has a type for typechecking. This is `discr_layout`, and is used for . // the `Scalar` we return. . // - The tag (encoded discriminant) has layout `tag_layout`. This is always an integer type, . // and used to interpret the value we read from the tag field. . // For the return value, a cast to `discr_layout` is performed. . // - The field storing the tag has a layout, which is very similar to `tag_layout` but . // may be a pointer. This is `tag_val.layout`; we just use it for sanity checks. . . // Get layout for tag. 690 ( 0.00%) let tag_layout = self.layout_of(tag_scalar_layout.value.to_int_ty(*self.tcx))?; . . // Read tag and sanity-check `tag_layout`. 805 ( 0.00%) let tag_val = self.read_immediate(&self.operand_field(op, tag_field)?)?; 230 ( 0.00%) assert_eq!(tag_layout.size, tag_val.layout.size); 920 ( 0.00%) assert_eq!(tag_layout.abi.is_signed(), tag_val.layout.abi.is_signed()); . let tag_val = tag_val.to_scalar()?; . trace!("tag value: {:?}", tag_val); . . // Figure out which discriminant and variant this corresponds to. 1,035 ( 0.00%) Ok(match *tag_encoding { . TagEncoding::Direct => { 2,300 ( 0.00%) let tag_bits = tag_val . .try_to_int() . .map_err(|dbg_val| err_ub!(InvalidTag(dbg_val)))? . .assert_bits(tag_layout.size); . // Cast bits from tag layout to discriminant layout. 920 ( 0.00%) let discr_val = self.cast_from_scalar(tag_bits, tag_layout, discr_layout.ty); 230 ( 0.00%) let discr_bits = discr_val.assert_bits(discr_layout.size); . // Convert discriminant to variant index, and catch invalid discriminants. 575 ( 0.00%) let index = match *op.layout.ty.kind() { 115 ( 0.00%) ty::Adt(adt, _) => { 1,746 ( 0.00%) adt.discriminants(*self.tcx).find(|(_, var)| var.val == discr_bits) . } . ty::Generator(def_id, substs, _) => { . let substs = substs.as_generator(); . substs . .discriminants(def_id, *self.tcx) . .find(|(_, var)| var.val == discr_bits) . } . _ => span_bug!(self.cur_span(), "tagged layout for non-adt non-generator"), . } . .ok_or_else(|| err_ub!(InvalidTag(Scalar::from_uint(tag_bits, tag_layout.size))))?; . // Return the cast value, and the index. 460 ( 0.00%) (discr_val, index.0) . } . TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start } => { . // Compute the variant this niche value/"tag" corresponds to. With niche layout, . // discriminant (encoded in niche/tag) and variant index are the same. . let variants_start = niche_variants.start().as_u32(); . let variants_end = niche_variants.end().as_u32(); . let variant = match tag_val.try_to_int() { . Err(dbg_val) => { -- line 721 ---------------------------------------- -- line 766 ---------------------------------------- . } . }; . // Compute the size of the scalar we need to return. . // No need to cast, because the variant index directly serves as discriminant and is . // encoded in the tag. . (Scalar::from_uint(variant.as_u32(), discr_layout.size), variant) . } . }) 1,035 ( 0.00%) } . } 6,492,436 ( 0.06%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/library/core/src/num/uint_macros.rs -------------------------------------------------------------------------------- Ir -- line 57 ---------------------------------------- . /// # Examples . /// . /// Basic usage: . /// . /// ``` . #[doc = concat!("assert_eq!(", stringify!($SelfT), "::from_str_radix(\"A\", 16), Ok(10));")] . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] 192 ( 0.00%) pub fn from_str_radix(src: &str, radix: u32) -> Result { 96 ( 0.00%) from_str_radix(src, radix) 288 ( 0.00%) } . . /// Returns the number of ones in the binary representation of `self`. . /// . /// # Examples . /// . /// Basic usage: . /// . /// ``` -- line 75 ---------------------------------------- -- line 80 ---------------------------------------- . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_math", since = "1.32.0")] . #[doc(alias = "popcount")] . #[doc(alias = "popcnt")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn count_ones(self) -> u32 { 464,445 ( 0.00%) intrinsics::ctpop(self as $ActualT) as u32 . } . . /// Returns the number of zeros in the binary representation of `self`. . /// . /// # Examples . /// . /// Basic usage: . /// -- line 96 ---------------------------------------- -- line 118 ---------------------------------------- . /// assert_eq!(n.leading_zeros(), 2); . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn leading_zeros(self) -> u32 { 608,542 ( 0.01%) intrinsics::ctlz(self as $ActualT) as u32 . } . . /// Returns the number of trailing zeros in the binary representation . /// of `self`. . /// . /// # Examples . /// . /// Basic usage: -- line 134 ---------------------------------------- -- line 139 ---------------------------------------- . /// assert_eq!(n.trailing_zeros(), 3); . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn trailing_zeros(self) -> u32 { 1,429,873 ( 0.01%) intrinsics::cttz(self) as u32 . } . . /// Returns the number of leading ones in the binary representation of `self`. . /// . /// # Examples . /// . /// Basic usage: . /// -- line 155 ---------------------------------------- -- line 204 ---------------------------------------- . #[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")] . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn rotate_left(self, n: u32) -> Self { 16,339,408 ( 0.16%) intrinsics::rotate_left(self, n as $SelfT) . } . . /// Shifts the bits to the right by a specified amount, `n`, . /// wrapping the truncated bits to the beginning of the resulting . /// integer. . /// . /// Please note this isn't the same operation as the `>>` shifting operator! . /// -- line 220 ---------------------------------------- -- line 430 ---------------------------------------- . #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);")] . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline] . pub const fn checked_add(self, rhs: Self) -> Option { 4 ( 0.00%) let (a, b) = self.overflowing_add(rhs); . if unlikely!(b) {None} else {Some(a)} . } . . /// Unchecked integer addition. Computes `self + rhs`, assuming overflow . /// cannot occur. . /// . /// # Safety . /// -- line 446 ---------------------------------------- -- line 456 ---------------------------------------- . )] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] . #[inline(always)] . pub const unsafe fn unchecked_add(self, rhs: Self) -> Self { . // SAFETY: the caller must uphold the safety contract for . // `unchecked_add`. 1,640,713 ( 0.02%) unsafe { intrinsics::unchecked_add(self, rhs) } . } . . /// Checked addition with a signed integer. Computes `self + rhs`, . /// returning `None` if overflow occurred. . /// . /// # Examples . /// . /// Basic usage: -- line 472 ---------------------------------------- -- line 525 ---------------------------------------- . )] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")] . #[inline(always)] . pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self { . // SAFETY: the caller must uphold the safety contract for . // `unchecked_sub`. 136,609 ( 0.00%) unsafe { intrinsics::unchecked_sub(self, rhs) } . } . . /// Checked integer multiplication. Computes `self * rhs`, returning . /// `None` if overflow occurred. . /// . /// # Examples . /// . /// Basic usage: -- line 541 ---------------------------------------- -- line 596 ---------------------------------------- . without modifying the original"] . #[inline] . pub const fn checked_div(self, rhs: Self) -> Option { . if unlikely!(rhs == 0) { . None . } else { . // SAFETY: div by zero has been checked above and unsigned types have no other . // failure modes for division 496 ( 0.00%) Some(unsafe { intrinsics::unchecked_div(self, rhs) }) . } . } . . /// Checked Euclidean division. Computes `self.div_euclid(rhs)`, returning `None` . /// if `rhs == 0`. . /// . /// # Examples . /// -- line 612 ---------------------------------------- -- line 1035 ---------------------------------------- . #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_add(127), ", stringify!($SelfT), "::MAX);")] . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] . #[inline(always)] . pub const fn saturating_add(self, rhs: Self) -> Self { 361,250 ( 0.00%) intrinsics::saturating_add(self, rhs) . } . . /// Saturating addition with a signed integer. Computes `self + rhs`, . /// saturating at the numeric bounds instead of overflowing. . /// . /// # Examples . /// . /// Basic usage: -- line 1051 ---------------------------------------- -- line 1084 ---------------------------------------- . #[doc = concat!("assert_eq!(13", stringify!($SelfT), ".saturating_sub(127), 0);")] . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")] . #[inline(always)] . pub const fn saturating_sub(self, rhs: Self) -> Self { 776,015 ( 0.01%) intrinsics::saturating_sub(self, rhs) . } . . /// Saturating integer multiplication. Computes `self * rhs`, . /// saturating at the numeric bounds instead of overflowing. . /// . /// # Examples . /// . /// Basic usage: -- line 1100 ---------------------------------------- -- line 1175 ---------------------------------------- . #[doc = concat!("assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::MAX), 199);")] . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn wrapping_add(self, rhs: Self) -> Self { 10,208,116 ( 0.10%) intrinsics::wrapping_add(self, rhs) . } . . /// Wrapping (modular) addition with a signed integer. Computes . /// `self + rhs`, wrapping around at the boundary of the type. . /// . /// # Examples . /// . /// Basic usage: -- line 1191 ---------------------------------------- -- line 1217 ---------------------------------------- . #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::MAX), 101);")] . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn wrapping_sub(self, rhs: Self) -> Self { 5,824,168 ( 0.06%) intrinsics::wrapping_sub(self, rhs) . } . . /// Wrapping (modular) multiplication. Computes `self * . /// rhs`, wrapping around at the boundary of the type. . /// . /// # Examples . /// . /// Basic usage: -- line 1233 ---------------------------------------- -- line 1240 ---------------------------------------- . /// assert_eq!(25u8.wrapping_mul(12), 44); . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn wrapping_mul(self, rhs: Self) -> Self { 12,417,013 ( 0.12%) intrinsics::wrapping_mul(self, rhs) . } . . /// Wrapping (modular) division. Computes `self / rhs`. . /// Wrapped division on unsigned types is just normal division. . /// There's no way wrapping could ever happen. . /// This function exists, so that all operations . /// are accounted for in the wrapping operations. . /// -- line 1256 ---------------------------------------- -- line 1491 ---------------------------------------- . #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false));")] . #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (0, true));")] . /// ``` . #[stable(feature = "wrapping", since = "1.7.0")] . #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] 12 ( 0.00%) pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) { 4,279,646 ( 0.04%) let (a, b) = intrinsics::add_with_overflow(self as $ActualT, rhs as $ActualT); . (a as Self, b) 24 ( 0.00%) } . . /// Calculates `self + rhs + carry` without the ability to overflow. . /// . /// Performs "ternary addition" which takes in an extra bit to add, and may return an . /// additional bit of overflow. This allows for chaining together multiple additions . /// to create "big integers" which represent larger values. . /// . #[doc = concat!("This can be thought of as a ", stringify!($BITS), "-bit \"full adder\", in the electronics sense.")] -- line 1510 ---------------------------------------- -- line 1588 ---------------------------------------- . #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".overflowing_sub(1), (", stringify!($SelfT), "::MAX, true));")] . /// ``` . #[stable(feature = "wrapping", since = "1.7.0")] . #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] . pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) { 455,725 ( 0.00%) let (a, b) = intrinsics::sub_with_overflow(self as $ActualT, rhs as $ActualT); . (a as Self, b) . } . . /// Calculates `self - rhs - borrow` without the ability to overflow. . /// . /// Performs "ternary subtraction" which takes in an extra bit to subtract, and may return . /// an additional bit of overflow. This allows for chaining together multiple subtractions . /// to create "big integers" which represent larger values. -- line 1604 ---------------------------------------- -- line 1673 ---------------------------------------- . /// assert_eq!(5u32.overflowing_mul(2), (10, false)); . /// assert_eq!(1_000_000_000u32.overflowing_mul(10), (1410065408, true)); . /// ``` . #[stable(feature = "wrapping", since = "1.7.0")] . #[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline(always)] 2 ( 0.00%) pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool) { 2,665,078 ( 0.03%) let (a, b) = intrinsics::mul_with_overflow(self as $ActualT, rhs as $ActualT); . (a as Self, b) 1 ( 0.00%) } . . /// Calculates the divisor when `self` is divided by `rhs`. . /// . /// Returns a tuple of the divisor along with a boolean indicating . /// whether an arithmetic overflow would occur. Note that for unsigned . /// integers overflow never occurs, so the second value is always . /// `false`. . /// -- line 1692 ---------------------------------------- -- line 2132 ---------------------------------------- . #[doc = concat!("assert!(16", stringify!($SelfT), ".is_power_of_two());")] . #[doc = concat!("assert!(!10", stringify!($SelfT), ".is_power_of_two());")] . /// ``` . #[must_use] . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_is_power_of_two", since = "1.32.0")] . #[inline(always)] . pub const fn is_power_of_two(self) -> bool { 150 ( 0.00%) self.count_ones() == 1 . } . . // Returns one less than next power of two. . // (For 8u8 next power of two is 8u8 and for 6u8 it is 8u8) . // . // 8u8.one_less_than_next_power_of_two() == 7 . // 6u8.one_less_than_next_power_of_two() == 7 . // . // This method cannot overflow, as in the `next_power_of_two` . // overflow cases it instead ends up returning the maximum value . // of the type, and can return 0 for 0. . #[inline] . #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] . const fn one_less_than_next_power_of_two(self) -> Self { 4,790 ( 0.00%) if self <= 1 { return 0; } . 9,297 ( 0.00%) let p = self - 1; . // SAFETY: Because `p > 0`, it cannot consist entirely of leading zeros. . // That means the shift is always in-bounds, and some processors . // (such as intel pre-haswell) have more efficient ctlz . // intrinsics when the argument is non-zero. 27,774 ( 0.00%) let z = unsafe { intrinsics::ctlz_nonzero(p) }; 9,350 ( 0.00%) <$SelfT>::MAX >> z . } . . /// Returns the smallest power of two greater than or equal to `self`. . /// . /// When return value overflows (i.e., `self > (1 << (N-1))` for type . /// `uN`), it panics in debug mode and the return value is wrapped to 0 in . /// release mode (the only situation in which method can return 0). . /// -- line 2171 ---------------------------------------- -- line 2179 ---------------------------------------- . /// ``` . #[stable(feature = "rust1", since = "1.0.0")] . #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")] . #[must_use = "this returns the result of the operation, \ . without modifying the original"] . #[inline] . #[rustc_inherit_overflow_checks] . pub const fn next_power_of_two(self) -> Self { 13,774 ( 0.00%) self.one_less_than_next_power_of_two() + 1 . } . . /// Returns the smallest power of two greater than or equal to `n`. If . /// the next power of two is greater than the type's maximum value, . /// `None` is returned, otherwise the power of two is wrapped in `Some`. . /// . /// # Examples . /// -- line 2195 ---------------------------------------- 102,715 ( 0.00%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/rust/worktree-benchmarking/compiler/rustc_parse/src/parser/mod.rs -------------------------------------------------------------------------------- Ir -- line 36 ---------------------------------------- . use rustc_session::parse::ParseSess; . use rustc_span::source_map::{MultiSpan, Span, DUMMY_SP}; . use rustc_span::symbol::{kw, sym, Ident, Symbol}; . use tracing::debug; . . use std::ops::Range; . use std::{cmp, mem, slice}; . 167,282 ( 0.00%) bitflags::bitflags! { . struct Restrictions: u8 { . const STMT_EXPR = 1 << 0; . const NO_STRUCT_LITERAL = 1 << 1; . const CONST_EXPR = 1 << 2; . } . } . . #[derive(Clone, Copy, PartialEq, Debug)] -- line 52 ---------------------------------------- -- line 104 ---------------------------------------- . $self.bump(); . return $self.maybe_recover_from_bad_qpath_stage_2($self.prev_token.span, ty); . } . } . } . }; . } . 1,638 ( 0.00%) #[derive(Clone)] . pub struct Parser<'a> { 36 ( 0.00%) pub sess: &'a ParseSess, . /// The current token. 22 ( 0.00%) pub token: Token, . /// The spacing for the current token 25 ( 0.00%) pub token_spacing: Spacing, . /// The previous token. 33 ( 0.00%) pub prev_token: Token, 39 ( 0.00%) pub capture_cfg: bool, 92 ( 0.00%) restrictions: Restrictions, 50 ( 0.00%) expected_tokens: Vec, . // Important: This must only be advanced from `next_tok` . // to ensure that `token_cursor.num_next_calls` is updated properly . token_cursor: TokenCursor, 50 ( 0.00%) desugar_doc_comments: bool, . /// This field is used to keep track of how many left angle brackets we have seen. This is . /// required in order to detect extra leading left angle brackets (`<` characters) and error . /// appropriately. . /// . /// See the comments in the `parse_path_segment` function for more details. 50 ( 0.00%) unmatched_angle_bracket_count: u32, 75 ( 0.00%) max_angle_bracket_count: u32, . /// A list of all unclosed delimiters found by the lexer. If an entry is used for error recovery . /// it gets removed from here. Every entry left at the end gets emitted as an independent . /// error. 25 ( 0.00%) pub(super) unclosed_delims: Vec, . last_unexpected_token_span: Option, . /// Span pointing at the `:` for the last type ascription the parser has seen, and whether it . /// looked like it could have been a mistyped path or literal `Option:Some(42)`). . pub last_type_ascription: Option<(Span, bool /* likely path typo */)>, . /// If present, this `Parser` is not parsing Rust code but rather a macro call. . subparser_name: Option<&'static str>, . capture_state: CaptureState, . /// This allows us to recover when the user forget to add braces around -- line 146 ---------------------------------------- -- line 173 ---------------------------------------- . /// the first macro inner attribute to invoke a proc-macro). . /// When create a `TokenStream`, the inner attributes get inserted . /// into the proper place in the token stream. . pub type ReplaceRange = (Range, Vec<(FlatToken, Spacing)>); . . /// Controls how we capture tokens. Capturing can be expensive, . /// so we try to avoid performing capturing in cases where . /// we will never need an `AttrAnnotatedTokenStream` 25 ( 0.00%) #[derive(Copy, Clone)] . pub enum Capturing { . /// We aren't performing any capturing - this is the default mode. . No, . /// We are capturing tokens . Yes, . } . 100 ( 0.00%) #[derive(Clone)] . struct CaptureState { 100 ( 0.00%) capturing: Capturing, 25 ( 0.00%) replace_ranges: Vec, . inner_attr_ranges: FxHashMap, . } . . impl<'a> Drop for Parser<'a> { . fn drop(&mut self) { 232 ( 0.00%) emit_unclosed_delims(&mut self.unclosed_delims, &self.sess); . } . } . 9,594 ( 0.00%) #[derive(Clone)] . struct TokenCursor { . frame: TokenCursorFrame, 2,277 ( 0.00%) stack: Vec, . desugar_doc_comments: bool, . // Counts the number of calls to `next` or `next_desugared`, . // depending on whether `desugar_doc_comments` is set. 696 ( 0.00%) num_next_calls: usize, . // During parsing, we may sometimes need to 'unglue' a . // glued token into two component tokens . // (e.g. '>>' into '>' and '>), so that the parser . // can consume them one at a time. This process . // bypasses the normal capturing mechanism . // (e.g. `num_next_calls` will not be incremented), . // since the 'unglued' tokens due not exist in . // the original `TokenStream`. -- line 217 ---------------------------------------- -- line 226 ---------------------------------------- . // in `Option>` requires us to unglue . // the trailing `>>` token. The `break_last_token` . // field is used to track this token - it gets . // appended to the captured stream when . // we evaluate a `LazyTokenStream` . break_last_token: bool, . } . 4,427 ( 0.00%) #[derive(Clone)] . struct TokenCursorFrame { 1,673 ( 0.00%) delim: token::DelimToken, . span: DelimSpan, . open_delim: bool, 3,346 ( 0.00%) tree_cursor: tokenstream::Cursor, . close_delim: bool, . } . . impl TokenCursorFrame { . fn new(span: DelimSpan, delim: DelimToken, tts: TokenStream) -> Self { 195 ( 0.00%) TokenCursorFrame { . delim, . span, . open_delim: false, 21,684 ( 0.00%) tree_cursor: tts.into_trees(), . close_delim: false, . } . } . } . . impl TokenCursor { 1,674,216 ( 0.02%) fn next(&mut self) -> (Token, Spacing) { . loop { 848,770 ( 0.01%) let (tree, spacing) = if !self.frame.open_delim { 21,606 ( 0.00%) self.frame.open_delim = true; 108,030 ( 0.00%) TokenTree::open_tt(self.frame.span, self.frame.delim).into() 1,630,765 ( 0.02%) } else if let Some(tree) = self.frame.tree_cursor.next_with_spacing() { . tree 86,386 ( 0.00%) } else if !self.frame.close_delim { 21,575 ( 0.00%) self.frame.close_delim = true; 107,875 ( 0.00%) TokenTree::close_tt(self.frame.span, self.frame.delim).into() 43,150 ( 0.00%) } else if let Some(frame) = self.stack.pop() { 280,475 ( 0.00%) self.frame = frame; . continue; . } else { 774 ( 0.00%) (TokenTree::Token(Token::new(token::Eof, DUMMY_SP)), Spacing::Alone) . }; . 322,248 ( 0.00%) match tree { . TokenTree::Token(token) => { 1,116,144 ( 0.01%) return (token, spacing); . } . TokenTree::Delimited(sp, delim, tts) => { . let frame = TokenCursorFrame::new(sp, delim, tts); . self.stack.push(mem::replace(&mut self.frame, frame)); . } . } . } 1,116,144 ( 0.01%) } . 1,440 ( 0.00%) fn next_desugared(&mut self) -> (Token, Spacing) { 432 ( 0.00%) let (data, attr_style, sp) = match self.next() { . (Token { kind: token::DocComment(_, attr_style, data), span }, _) => { . (data, attr_style, span) . } 720 ( 0.00%) tok => return tok, . }; . . // Searches for the occurrences of `"#*` and returns the minimum number of `#`s . // required to wrap the text. . let mut num_of_hashes = 0; . let mut count = 0; . for ch in data.as_str().chars() { . count = match ch { -- line 298 ---------------------------------------- -- line 332 ---------------------------------------- . .iter() . .cloned() . .collect::() . }, . ), . )); . . self.next() 1,296 ( 0.00%) } . } . 2,670 ( 0.00%) #[derive(Debug, Clone, PartialEq)] . enum TokenType { 2,136 ( 0.00%) Token(TokenKind), . Keyword(Symbol), . Operator, . Lifetime, . Ident, . Path, . Type, . Const, . } -- line 353 ---------------------------------------- -- line 378 ---------------------------------------- . /// The separator token. . sep: Option, . /// `true` if a trailing separator is allowed. . trailing_sep_allowed: bool, . } . . impl SeqSep { . fn trailing_allowed(t: TokenKind) -> SeqSep { 57 ( 0.00%) SeqSep { sep: Some(t), trailing_sep_allowed: true } . } . . fn none() -> SeqSep { . SeqSep { sep: None, trailing_sep_allowed: false } . } . } . . pub enum FollowedByType { . Yes, . No, . } . . fn token_descr_opt(token: &Token) -> Option<&'static str> { 162 ( 0.00%) Some(match token.kind { 324 ( 0.00%) _ if token.is_special_ident() => "reserved identifier", 324 ( 0.00%) _ if token.is_used_keyword() => "keyword", 324 ( 0.00%) _ if token.is_unused_keyword() => "reserved keyword", . token::DocComment(..) => "doc comment", . _ => return None, . }) . } . 567 ( 0.00%) pub(super) fn token_descr(token: &Token) -> String { 162 ( 0.00%) let token_str = pprust::token_to_string(token); . match token_descr_opt(token) { . Some(prefix) => format!("{} `{}`", prefix, token_str), 567 ( 0.00%) _ => format!("`{}`", token_str), . } 405 ( 0.00%) } . . impl<'a> Parser<'a> { 546 ( 0.00%) pub fn new( . sess: &'a ParseSess, . tokens: TokenStream, . desugar_doc_comments: bool, . subparser_name: Option<&'static str>, . ) -> Self { 39 ( 0.00%) let mut start_frame = TokenCursorFrame::new(DelimSpan::dummy(), token::NoDelim, tokens); 78 ( 0.00%) start_frame.open_delim = true; . start_frame.close_delim = true; . 1,209 ( 0.00%) let mut parser = Parser { . sess, 39 ( 0.00%) token: Token::dummy(), . token_spacing: Spacing::Alone, 39 ( 0.00%) prev_token: Token::dummy(), . capture_cfg: false, . restrictions: Restrictions::empty(), . expected_tokens: Vec::new(), . token_cursor: TokenCursor { 234 ( 0.00%) frame: start_frame, . stack: Vec::new(), . num_next_calls: 0, . desugar_doc_comments, . break_last_token: false, . }, . desugar_doc_comments, . unmatched_angle_bracket_count: 0, . max_angle_bracket_count: 0, -- line 445 ---------------------------------------- -- line 451 ---------------------------------------- . capturing: Capturing::No, . replace_ranges: Vec::new(), . inner_attr_ranges: Default::default(), . }, . current_closure: None, . }; . . // Make parser point to the first token. 78 ( 0.00%) parser.bump(); . . parser 351 ( 0.00%) } . . fn next_tok(&mut self, fallback_span: Span) -> (Token, Spacing) { . loop { 835,830 ( 0.01%) let (mut next, spacing) = if self.desugar_doc_comments { 576 ( 0.00%) self.token_cursor.next_desugared() . } else { 417,483 ( 0.00%) self.token_cursor.next() . }; 557,220 ( 0.01%) self.token_cursor.num_next_calls += 1; . // We've retrieved an token from the underlying . // cursor, so we no longer need to worry about . // an unglued token. See `break_and_eat` for more details 139,305 ( 0.00%) self.token_cursor.break_last_token = false; 557,220 ( 0.01%) if next.span.is_dummy() { . // Tweak the location for better diagnostics, but keep syntactic context intact. 164 ( 0.00%) next.span = fallback_span.with_ctxt(next.span.ctxt()); . } 482,640 ( 0.00%) if matches!( 278,610 ( 0.00%) next.kind, . token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim) . ) { . continue; . } 557,220 ( 0.01%) return (next, spacing); . } . } . . pub fn unexpected(&mut self) -> PResult<'a, T> { . match self.expect_one_of(&[], &[]) { . Err(e) => Err(e), . // We can get `Ok(true)` from `recover_closing_delimiter` . // which is called in `expected_one_of_not_found`. . Ok(_) => FatalError.raise(), . } . } . . /// Expects and consumes the token `t`. Signals an error if the next token is not `t`. 295,677 ( 0.00%) pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, bool /* recovered */> { 32,853 ( 0.00%) if self.expected_tokens.is_empty() { 342 ( 0.00%) if self.token == *t { 285 ( 0.00%) self.bump(); . Ok(false) . } else { . self.unexpected_try_recover(t) . } . } else { 393,552 ( 0.00%) self.expect_one_of(slice::from_ref(t), &[]) . } 492,795 ( 0.00%) } . . /// Expect next token to be edible or inedible token. If edible, . /// then consume it; if inedible, then return without consuming . /// anything. Signal a fatal error if next token is unexpected. 396,324 ( 0.00%) pub fn expect_one_of( . &mut self, . edible: &[TokenKind], . inedible: &[TokenKind], . ) -> PResult<'a, bool /* recovered */> { 66,054 ( 0.00%) if edible.contains(&self.token.kind) { 98,508 ( 0.00%) self.bump(); . Ok(false) . } else if inedible.contains(&self.token.kind) { . // leave it in the input . Ok(false) . } else if self.last_unexpected_token_span == Some(self.token.span) { . FatalError.raise(); . } else { . self.expected_one_of_not_found(edible, inedible) . } 495,405 ( 0.00%) } . . // Public for rustfmt usage. . pub fn parse_ident(&mut self) -> PResult<'a, Ident> { 85,601 ( 0.00%) self.parse_ident_common(true) . } . . fn ident_or_err(&mut self) -> PResult<'a, (Ident, /* is_raw */ bool)> { 64,353 ( 0.00%) self.token.ident().ok_or_else(|| match self.prev_token.kind { . TokenKind::DocComment(..) => { . self.span_err(self.prev_token.span, Error::UselessDocComment) . } . _ => self.expected_ident_found(), . }) . } . 149,884 ( 0.00%) fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, Ident> { 21,412 ( 0.00%) let (ident, is_raw) = self.ident_or_err()?; 128,472 ( 0.00%) if !is_raw && ident.is_reserved() { . let mut err = self.expected_ident_found(); . if recover { . err.emit(); . } else { . return Err(err); . } . } 85,648 ( 0.00%) self.bump(); . Ok(ident) 214,120 ( 0.00%) } . . /// Checks if the next token is `tok`, and returns `true` if so. . /// . /// This method will automatically add `tok` to `expected_tokens` if `tok` is not . /// encountered. 3,647,847 ( 0.04%) fn check(&mut self, tok: &TokenKind) -> bool { 1,584,551 ( 0.02%) let is_present = self.token == *tok; 1,083,628 ( 0.01%) if !is_present { 2,223,348 ( 0.02%) self.expected_tokens.push(TokenType::Token(tok.clone())); . } . is_present 3,647,847 ( 0.04%) } . . /// Consumes a token 'tok' if it exists. Returns whether the given token was present. 4 ( 0.00%) pub fn eat(&mut self, tok: &TokenKind) -> bool { 651,896 ( 0.01%) let is_present = self.check(tok); 447,348 ( 0.00%) if is_present { 85,241 ( 0.00%) self.bump() . } . is_present 5 ( 0.00%) } . . /// If the next token is the given keyword, returns `true` without eating it. . /// An expectation is also added for diagnostics purposes. 7,145 ( 0.00%) fn check_keyword(&mut self, kw: Symbol) -> bool { 1,387 ( 0.00%) self.expected_tokens.push(TokenType::Keyword(kw)); 42,176 ( 0.00%) self.token.is_keyword(kw) . } . . /// If the next token is the given keyword, eats it and returns `true`. . /// Otherwise, returns `false`. An expectation is also added for diagnostics purposes. . // Public for rustfmt usage. 13,100 ( 0.00%) pub fn eat_keyword(&mut self, kw: Symbol) -> bool { 9,502 ( 0.00%) if self.check_keyword(kw) { 986 ( 0.00%) self.bump(); . true . } else { . false . } 13,100 ( 0.00%) } . . fn eat_keyword_noexpect(&mut self, kw: Symbol) -> bool { 1,076 ( 0.00%) if self.token.is_keyword(kw) { 248 ( 0.00%) self.bump(); . true . } else { . false . } . } . . /// If the given word is not a keyword, signals an error. . /// If the next token is not the given word, signals an error. . /// Otherwise, eats it. 115 ( 0.00%) fn expect_keyword(&mut self, kw: Symbol) -> PResult<'a, ()> { . if !self.eat_keyword(kw) { self.unexpected() } else { Ok(()) } 92 ( 0.00%) } . . /// Is the given keyword `kw` followed by a non-reserved identifier? 8,600 ( 0.00%) fn is_kw_followed_by_ident(&self, kw: Symbol) -> bool { 4,300 ( 0.00%) self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident()) 9,675 ( 0.00%) } . 68,004 ( 0.00%) fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool { 23,206 ( 0.00%) if ok { . true . } else { 1,496 ( 0.00%) self.expected_tokens.push(typ); . false . } 68,004 ( 0.00%) } . . fn check_ident(&mut self) -> bool { 1,772 ( 0.00%) self.check_or_expected(self.token.is_ident(), TokenType::Ident) . } . 43,192 ( 0.00%) fn check_path(&mut self) -> bool { 87,362 ( 0.00%) self.check_or_expected(self.token.is_path_start(), TokenType::Path) 53,990 ( 0.00%) } . . fn check_type(&mut self) -> bool { 408 ( 0.00%) self.check_or_expected(self.token.can_begin_type(), TokenType::Type) . } . . fn check_const_arg(&mut self) -> bool { 408 ( 0.00%) self.check_or_expected(self.token.can_begin_const_arg(), TokenType::Const) . } . 2,358 ( 0.00%) fn check_inline_const(&self, dist: usize) -> bool { 1,310 ( 0.00%) self.is_keyword_ahead(dist, &[kw::Const]) . && self.look_ahead(dist + 1, |t| match t.kind { . token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)), . token::OpenDelim(DelimToken::Brace) => true, . _ => false, . }) 2,358 ( 0.00%) } . . /// Checks to see if the next token is either `+` or `+=`. . /// Otherwise returns `false`. . fn check_plus(&mut self) -> bool { 652 ( 0.00%) self.check_or_expected( 326 ( 0.00%) self.token.is_like_plus(), 326 ( 0.00%) TokenType::Token(token::BinOp(token::Plus)), . ) . } . . /// Eats the expected token if it's present possibly breaking . /// compound tokens like multi-character operators in process. . /// Returns `true` if the token was eaten. 132,168 ( 0.00%) fn break_and_eat(&mut self, expected: TokenKind) -> bool { 77,098 ( 0.00%) if self.token.kind == expected { 474 ( 0.00%) self.bump(); . return true; . } 53,885 ( 0.00%) match self.token.kind.break_two_token_op() { 7 ( 0.00%) Some((first, second)) if first == expected => { 4 ( 0.00%) let first_span = self.sess.source_map().start_point(self.token.span); 5 ( 0.00%) let second_span = self.token.span.with_lo(first_span.hi()); 9 ( 0.00%) self.token = Token::new(first, first_span); . // Keep track of this token - if we end token capturing now, . // we'll want to append this token to the captured stream. . // . // If we consume any additional tokens, then this token . // is not needed (we'll capture the entire 'glued' token), . // and `next_tok` will set this field to `None` 1 ( 0.00%) self.token_cursor.break_last_token = true; . // Use the spacing of the glued token as the spacing . // of the unglued second token. 14 ( 0.00%) self.bump_with((Token::new(second, second_span), self.token_spacing)); . true . } . _ => { 32,328 ( 0.00%) self.expected_tokens.push(TokenType::Token(expected)); . false . } . } 142,230 ( 0.00%) } . . /// Eats `+` possibly breaking tokens like `+=` in process. . fn eat_plus(&mut self) -> bool { 84 ( 0.00%) self.break_and_eat(token::BinOp(token::Plus)) . } . . /// Eats `&` possibly breaking tokens like `&&` in process. . /// Signals an error if `&` is not eaten. . fn expect_and(&mut self) -> PResult<'a, ()> { 660 ( 0.00%) if self.break_and_eat(token::BinOp(token::And)) { Ok(()) } else { self.unexpected() } . } . . /// Eats `|` possibly breaking tokens like `||` in process. . /// Signals an error if `|` was not eaten. . fn expect_or(&mut self) -> PResult<'a, ()> { 114 ( 0.00%) if self.break_and_eat(token::BinOp(token::Or)) { Ok(()) } else { self.unexpected() } . } . . /// Eats `<` possibly breaking tokens like `<<` in process. 570 ( 0.00%) fn eat_lt(&mut self) -> bool { 32,559 ( 0.00%) let ate = self.break_and_eat(token::Lt); 21,666 ( 0.00%) if ate { . // See doc comment for `unmatched_angle_bracket_count`. 204 ( 0.00%) self.unmatched_angle_bracket_count += 1; 215 ( 0.00%) self.max_angle_bracket_count += 1; . debug!("eat_lt: (increment) count={:?}", self.unmatched_angle_bracket_count); . } . ate 570 ( 0.00%) } . . /// Eats `<` possibly breaking tokens like `<<` in process. . /// Signals an error if `<` was not eaten. . fn expect_lt(&mut self) -> PResult<'a, ()> { . if self.eat_lt() { Ok(()) } else { self.unexpected() } . } . . /// Eats `>` possibly breaking tokens like `>>` in process. . /// Signals an error if `>` was not eaten. . fn expect_gt(&mut self) -> PResult<'a, ()> { 306 ( 0.00%) if self.break_and_eat(token::Gt) { . // See doc comment for `unmatched_angle_bracket_count`. 153 ( 0.00%) if self.unmatched_angle_bracket_count > 0 { 102 ( 0.00%) self.unmatched_angle_bracket_count -= 1; . debug!("expect_gt: (decrement) count={:?}", self.unmatched_angle_bracket_count); . } . Ok(()) . } else { . self.unexpected() . } . } . . fn expect_any_with_type(&mut self, kets: &[&TokenKind], expect: TokenExpectType) -> bool { . kets.iter().any(|k| match expect { 255,264 ( 0.00%) TokenExpectType::Expect => self.check(k), 285 ( 0.00%) TokenExpectType::NoExpect => self.token == **k, . }) . } . . fn parse_seq_to_before_tokens( . &mut self, . kets: &[&TokenKind], . sep: SeqSep, . expect: TokenExpectType, -- line 759 ---------------------------------------- -- line 761 ---------------------------------------- . ) -> PResult<'a, (Vec, bool /* trailing */, bool /* recovered */)> { . let mut first = true; . let mut recovered = false; . let mut trailing = false; . let mut v = vec![]; . let unclosed_delims = !self.unclosed_delims.is_empty(); . . while !self.expect_any_with_type(kets, expect) { 223,211 ( 0.00%) if let token::CloseDelim(..) | token::Eof = self.token.kind { . break; . } 149,051 ( 0.00%) if let Some(ref t) = sep.sep { 176,446 ( 0.00%) if first { . first = false; . } else { 169,244 ( 0.00%) match self.expect(t) { . Ok(false) => { . self.current_closure.take(); . } . Ok(true) => { . self.current_closure.take(); . recovered = true; . break; . } -- line 784 ---------------------------------------- -- line 857 ---------------------------------------- . e.cancel(); . break; . } . } . } . } . } . } 84,842 ( 0.00%) if sep.trailing_sep_allowed && self.expect_any_with_type(kets, expect) { . trailing = true; . break; . } . 42,095 ( 0.00%) let t = f(self)?; 488 ( 0.00%) v.push(t); . } . 84,888 ( 0.00%) Ok((v, trailing, recovered)) . } . . fn recover_missing_braces_around_closure_body( . &mut self, . closure_spans: ClosureSpans, . mut expect_err: DiagnosticBuilder<'_>, . ) -> PResult<'a, ()> { . let initial_semicolon = self.token.span; -- line 882 ---------------------------------------- -- line 937 ---------------------------------------- . /// `f` must consume tokens until reaching the next separator or . /// closing bracket. . fn parse_seq_to_before_end( . &mut self, . ket: &TokenKind, . sep: SeqSep, . f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, . ) -> PResult<'a, (Vec, bool, bool)> { 74,093 ( 0.00%) self.parse_seq_to_before_tokens(&[ket], sep, TokenExpectType::Expect, f) . } . . /// Parses a sequence, including the closing delimiter. The function . /// `f` must consume tokens until reaching the next separator or . /// closing bracket. 102,560 ( 0.00%) fn parse_seq_to_end( . &mut self, . ket: &TokenKind, . sep: SeqSep, . f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, . ) -> PResult<'a, (Vec, bool /* trailing */)> { 52,665 ( 0.00%) let (val, trailing, recovered) = self.parse_seq_to_before_end(ket, sep, f)?; 32,147 ( 0.00%) if !recovered { . self.eat(ket); . } 114,377 ( 0.00%) Ok((val, trailing)) 82,048 ( 0.00%) } . . /// Parses a sequence, including the closing delimiter. The function . /// `f` must consume tokens until reaching the next separator or . /// closing bracket. . fn parse_unspanned_seq( . &mut self, . bra: &TokenKind, . ket: &TokenKind, . sep: SeqSep, . f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, . ) -> PResult<'a, (Vec, bool)> { 30,949 ( 0.00%) self.expect(bra)?; 82,048 ( 0.00%) self.parse_seq_to_end(ket, sep, f) . } . . fn parse_delim_comma_seq( . &mut self, . delim: DelimToken, . f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, . ) -> PResult<'a, (Vec, bool)> { . self.parse_unspanned_seq( 10,375 ( 0.00%) &token::OpenDelim(delim), 10,497 ( 0.00%) &token::CloseDelim(delim), . SeqSep::trailing_allowed(token::Comma), . f, . ) . } . . fn parse_paren_comma_seq( . &mut self, . f: impl FnMut(&mut Parser<'a>) -> PResult<'a, T>, . ) -> PResult<'a, (Vec, bool)> { . self.parse_delim_comma_seq(token::Paren, f) . } . . /// Advance the parser by one token using provided token as the next one. 1,810,978 ( 0.02%) fn bump_with(&mut self, (next_token, next_spacing): (Token, Spacing)) { . // Bumping after EOF is a bad sign, usually an infinite loop. 835,836 ( 0.01%) if self.prev_token.kind == TokenKind::Eof { . let msg = "attempted to bump the parser past EOF (may be stuck in a loop)"; . self.span_bug(self.token.span, msg); . } . . // Update the current and previous tokens. 557,224 ( 0.01%) self.prev_token = mem::replace(&mut self.token, next_token); 139,306 ( 0.00%) self.token_spacing = next_spacing; . . // Diagnostics. 139,306 ( 0.00%) self.expected_tokens.clear(); . } . . /// Advance the parser by one token. 1,114,440 ( 0.01%) pub fn bump(&mut self) { 557,220 ( 0.01%) let next_token = self.next_tok(self.token.span); 835,830 ( 0.01%) self.bump_with(next_token); 1,114,440 ( 0.01%) } . . /// Look-ahead `dist` tokens of `self.token` and get access to that token there. . /// When `dist == 0` then the current token is looked at. . pub fn look_ahead(&self, dist: usize, looker: impl FnOnce(&Token) -> R) -> R { 758 ( 0.00%) if dist == 0 { 326 ( 0.00%) return looker(&self.token); . } . 73,920 ( 0.00%) let frame = &self.token_cursor.frame; 84,122 ( 0.00%) if frame.delim != DelimToken::NoDelim { . let all_normal = (0..dist).all(|i| { 242,039 ( 0.00%) let token = frame.tree_cursor.look_ahead(i); 325,084 ( 0.00%) !matches!(token, Some(TokenTree::Delimited(_, DelimToken::NoDelim, _))) . }); . if all_normal { 409,652 ( 0.00%) return match frame.tree_cursor.look_ahead(dist - 1) { 146,330 ( 0.00%) Some(tree) => match tree { 62,928 ( 0.00%) TokenTree::Token(token) => looker(token), . TokenTree::Delimited(dspan, delim, _) => { 71,859 ( 0.00%) looker(&Token::new(token::OpenDelim(*delim), dspan.open)) . } . }, 75,465 ( 0.00%) None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)), . }; . } . } . . let mut cursor = self.token_cursor.clone(); . let mut i = 0; 215 ( 0.00%) let mut token = Token::dummy(); 152 ( 0.00%) while i < dist { 1,555 ( 0.00%) token = cursor.next().0; 717 ( 0.00%) if matches!( 426 ( 0.00%) token.kind, . token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim) . ) { . continue; . } 80 ( 0.00%) i += 1; . } 6 ( 0.00%) return looker(&token); . } . . /// Returns whether any of the given keywords are `dist` tokens ahead of the current one. 3,177 ( 0.00%) fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool { 838 ( 0.00%) self.look_ahead(dist, |t| kws.iter().any(|&kw| t.is_keyword(kw))) 3,177 ( 0.00%) } . . /// Parses asyncness: `async` or nothing. . fn parse_asyncness(&mut self) -> Async { . if self.eat_keyword(kw::Async) { . let span = self.prev_token.uninterpolated_span(); . Async::Yes { span, closure_id: DUMMY_NODE_ID, return_impl_trait_id: DUMMY_NODE_ID } . } else { . Async::No . } . } . . /// Parses unsafety: `unsafe` or nothing. 160 ( 0.00%) fn parse_unsafety(&mut self) -> Unsafe { . if self.eat_keyword(kw::Unsafe) { . Unsafe::Yes(self.prev_token.uninterpolated_span()) . } else { . Unsafe::No . } 640 ( 0.00%) } . . /// Parses constness: `const` or nothing. 2,088 ( 0.00%) fn parse_constness(&mut self) -> Const { . // Avoid const blocks to be parsed as const items 604 ( 0.00%) if self.look_ahead(1, |t| t != &token::OpenDelim(DelimToken::Brace)) . && self.eat_keyword(kw::Const) . { 85 ( 0.00%) Const::Yes(self.prev_token.uninterpolated_span()) . } else { . Const::No . } 3,654 ( 0.00%) } . . /// Parses inline const expressions. . fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P> { . if pat { . self.sess.gated_spans.gate(sym::inline_const_pat, span); . } else { . self.sess.gated_spans.gate(sym::inline_const, span); . } -- line 1104 ---------------------------------------- -- line 1110 ---------------------------------------- . }; . let blk_span = anon_const.value.span; . Ok(self.mk_expr(span.to(blk_span), ExprKind::ConstBlock(anon_const), AttrVec::new())) . } . . /// Parses mutability (`mut` or nothing). . fn parse_mutability(&mut self) -> Mutability { . if self.eat_keyword(kw::Mut) { Mutability::Mut } else { Mutability::Not } 220 ( 0.00%) } . . /// Possibly parses mutability (`const` or `mut`). . fn parse_const_or_mut(&mut self) -> Option { . if self.eat_keyword(kw::Mut) { . Some(Mutability::Mut) . } else if self.eat_keyword(kw::Const) { . Some(Mutability::Not) . } else { . None . } . } . . fn parse_field_name(&mut self) -> PResult<'a, Ident> { 36 ( 0.00%) if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) = self.token.kind . { . self.expect_no_suffix(self.token.span, "a tuple index", suffix); . self.bump(); . Ok(Ident::new(symbol, self.prev_token.span)) . } else { 54 ( 0.00%) self.parse_ident_common(true) . } . } . . fn parse_mac_args(&mut self) -> PResult<'a, P> { 2 ( 0.00%) self.parse_mac_args_common(true).map(P) . } . . fn parse_attr_args(&mut self) -> PResult<'a, MacArgs> { 84 ( 0.00%) self.parse_mac_args_common(false) . } . 261 ( 0.00%) fn parse_mac_args_common(&mut self, delimited_only: bool) -> PResult<'a, MacArgs> { 232 ( 0.00%) Ok( 209 ( 0.00%) if self.check(&token::OpenDelim(DelimToken::Paren)) 48 ( 0.00%) || self.check(&token::OpenDelim(DelimToken::Bracket)) 48 ( 0.00%) || self.check(&token::OpenDelim(DelimToken::Brace)) . { 52 ( 0.00%) match self.parse_token_tree() { 65 ( 0.00%) TokenTree::Delimited(dspan, delim, tokens) => . // We've confirmed above that there is a delimiter so unwrapping is OK. . { 26 ( 0.00%) MacArgs::Delimited(dspan, MacDelimiter::from_token(delim).unwrap(), tokens) . } . _ => unreachable!(), . } 32 ( 0.00%) } else if !delimited_only { . if self.eat(&token::Eq) { . let eq_span = self.prev_token.span; . . // Collect tokens because they are used during lowering to HIR. . let expr = self.parse_expr_force_collect()?; . let span = expr.span; . . let token_kind = token::Interpolated(Lrc::new(token::NtExpr(expr))); -- line 1172 ---------------------------------------- -- line 1173 ---------------------------------------- . MacArgs::Eq(eq_span, Token::new(token_kind, span)) . } else { . MacArgs::Empty . } . } else { . return self.unexpected(); . }, . ) 203 ( 0.00%) } . . fn parse_or_use_outer_attributes( . &mut self, . already_parsed_attrs: Option, . ) -> PResult<'a, AttrWrapper> { 157,407 ( 0.00%) if let Some(attrs) = already_parsed_attrs { . Ok(attrs) . } else { 104,430 ( 0.00%) self.parse_outer_attributes() . } . } . . /// Parses a single token tree from the input. 296 ( 0.00%) pub(crate) fn parse_token_tree(&mut self) -> TokenTree { 111 ( 0.00%) match self.token.kind { . token::OpenDelim(..) => { . let depth = self.token_cursor.stack.len(); . . // We keep advancing the token cursor until we hit . // the matching `CloseDelim` token. 806 ( 0.00%) while !(depth == self.token_cursor.stack.len() . && matches!(self.token.kind, token::CloseDelim(_))) . { . // Advance one token at a time, so `TokenCursor::next()` . // can capture these tokens if necessary. 390 ( 0.00%) self.bump(); . } . // We are still inside the frame corresponding . // to the delimited stream we captured, so grab . // the tokens from this frame. . let frame = &self.token_cursor.frame; 74 ( 0.00%) let stream = frame.tree_cursor.stream.clone(); 74 ( 0.00%) let span = frame.span; 37 ( 0.00%) let delim = frame.delim; . // Consume close delimiter 74 ( 0.00%) self.bump(); 185 ( 0.00%) TokenTree::Delimited(span, delim, stream) . } . token::CloseDelim(_) | token::Eof => unreachable!(), . _ => { . self.bump(); . TokenTree::Token(self.prev_token.clone()) . } . } 259 ( 0.00%) } . . /// Parses a stream of tokens into a list of `TokenTree`s, up to EOF. . pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec> { . let mut tts = Vec::new(); . while self.token != token::Eof { . tts.push(self.parse_token_tree()); . } . Ok(tts) -- line 1234 ---------------------------------------- -- line 1244 ---------------------------------------- . } . TokenStream::new(result) . } . . /// Evaluates the closure with restrictions in place. . /// . /// Afters the closure is evaluated, restrictions are reset. . fn with_res(&mut self, res: Restrictions, f: impl FnOnce(&mut Self) -> T) -> T { 52,499 ( 0.00%) let old = self.restrictions; 52,945 ( 0.00%) self.restrictions = res; . let res = f(self); 52,918 ( 0.00%) self.restrictions = old; . res . } . 3,456 ( 0.00%) fn is_crate_vis(&self) -> bool { 2,160 ( 0.00%) self.token.is_keyword(kw::Crate) && self.look_ahead(1, |t| t != &token::ModSep) 3,888 ( 0.00%) } . . /// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`, . /// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`. . /// If the following element can't be a tuple (i.e., it's a function definition), then . /// it's not a tuple struct field), and the contents within the parentheses aren't valid, . /// so emit a proper diagnostic. . // Public for rustfmt usage. 2,910 ( 0.00%) pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> { 582 ( 0.00%) maybe_whole!(self, NtVis, |x| x); . 291 ( 0.00%) self.expected_tokens.push(TokenType::Keyword(kw::Crate)); 1,164 ( 0.00%) if self.is_crate_vis() { . self.bump(); // `crate` . self.sess.gated_spans.gate(sym::crate_visibility_modifier, self.prev_token.span); . return Ok(Visibility { . span: self.prev_token.span, . kind: VisibilityKind::Crate(CrateSugar::JustCrate), . tokens: None, . }); . } . . if !self.eat_keyword(kw::Pub) { . // We need a span for our `Spanned`, but there's inherently no . // keyword to grab a span from for inherited visibility; an empty span at the . // beginning of the current token would seem to be the "Schelling span". 251 ( 0.00%) return Ok(Visibility { 753 ( 0.00%) span: self.token.span.shrink_to_lo(), . kind: VisibilityKind::Inherited, . tokens: None, . }); . } 40 ( 0.00%) let lo = self.prev_token.span; . 200 ( 0.00%) if self.check(&token::OpenDelim(token::Paren)) { . // We don't `self.bump()` the `(` yet because this might be a struct definition where . // `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`. . // Because of this, we only `bump` the `(` if we're assured it is appropriate to do so . // by the following tokens. . if self.is_keyword_ahead(1, &[kw::Crate]) && self.look_ahead(2, |t| t != &token::ModSep) . // account for `pub(crate::foo)` . { . // Parse `pub(crate)`. -- line 1303 ---------------------------------------- -- line 1338 ---------------------------------------- . } else if let FollowedByType::No = fbt { . // Provide this diagnostic if a type cannot follow; . // in particular, if this is not a tuple struct. . self.recover_incorrect_vis_restriction()?; . // Emit diagnostic, but continue with public visibility. . } . } . 120 ( 0.00%) Ok(Visibility { span: lo, kind: VisibilityKind::Public, tokens: None }) 2,619 ( 0.00%) } . . /// Recovery for e.g. `pub(something) fn ...` or `struct X { pub(something) y: Z }` . fn recover_incorrect_vis_restriction(&mut self) -> PResult<'a, ()> { . self.bump(); // `(` . let path = self.parse_path(PathStyle::Mod)?; . self.expect(&token::CloseDelim(token::Paren))?; // `)` . . let msg = "incorrect visibility restriction"; -- line 1355 ---------------------------------------- -- line 1370 ---------------------------------------- . ) . .emit(); . . Ok(()) . } . . /// Parses `extern string_literal?`. . fn parse_extern(&mut self) -> Extern { 57 ( 0.00%) if self.eat_keyword(kw::Extern) { Extern::from_abi(self.parse_abi()) } else { Extern::None } . } . . /// Parses a string literal as an ABI spec. . fn parse_abi(&mut self) -> Option { . match self.parse_str_lit() { . Ok(str_lit) => Some(str_lit), . Err(Some(lit)) => match lit.kind { . ast::LitKind::Err(_) => None, -- line 1386 ---------------------------------------- -- line 1409 ---------------------------------------- . self.collect_tokens_trailing_token( . AttrWrapper::empty(), . ForceCollect::Yes, . |this, _attrs| Ok((f(this)?, TrailingToken::None)), . ) . } . . /// `::{` or `::*` 168,096 ( 0.00%) fn is_import_coupler(&mut self) -> bool { 84,048 ( 0.00%) self.check(&token::ModSep) . && self.look_ahead(1, |t| { 160,336 ( 0.00%) *t == token::OpenDelim(token::Brace) || *t == token::BinOp(token::Star) . }) 99,018 ( 0.00%) } . . pub fn clear_expected_tokens(&mut self) { . self.expected_tokens.clear(); . } . } . . crate fn make_unclosed_delims_error( . unmatched: UnmatchedBrace, -- line 1430 ---------------------------------------- -- line 1450 ---------------------------------------- . err.span_label(sp, "closing delimiter possibly meant for this"); . } . if let Some(sp) = unmatched.unclosed_span { . err.span_label(sp, "unclosed delimiter"); . } . Some(err) . } . 512 ( 0.00%) pub fn emit_unclosed_delims(unclosed_delims: &mut Vec, sess: &ParseSess) { 256 ( 0.00%) *sess.reached_eof.borrow_mut() |= . unclosed_delims.iter().any(|unmatched_delim| unmatched_delim.found_delim.is_none()); 256 ( 0.00%) for unmatched in unclosed_delims.drain(..) { . if let Some(mut e) = make_unclosed_delims_error(unmatched, sess) { . e.emit(); . } . } 512 ( 0.00%) } . . /// A helper struct used when building an `AttrAnnotatedTokenStream` from . /// a `LazyTokenStream`. Both delimiter and non-delimited tokens . /// are stored as `FlatToken::Token`. A vector of `FlatToken`s . /// is then 'parsed' to build up an `AttrAnnotatedTokenStream` with nested . /// `AttrAnnotatedTokenTree::Delimited` tokens . #[derive(Debug, Clone)] . pub enum FlatToken { -- line 1474 ---------------------------------------- 941,480 ( 0.01%) -------------------------------------------------------------------------------- -- Auto-annotated source: /usr/home/liquid/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.0/src/raw/mod.rs -------------------------------------------------------------------------------- Ir -- line 111 ---------------------------------------- . const EMPTY: u8 = 0b1111_1111; . . /// Control byte value for a deleted bucket. . const DELETED: u8 = 0b1000_0000; . . /// Checks whether a control byte represents a full bucket (top bit is clear). . #[inline] . fn is_full(ctrl: u8) -> bool { 2,905,321 ( 0.03%) ctrl & 0x80 == 0 . } . . /// Checks whether a control byte represents a special value (top bit is set). . #[inline] . fn is_special(ctrl: u8) -> bool { . ctrl & 0x80 != 0 . } . . /// Checks whether a special control value is EMPTY (just check 1 bit). . #[inline] . fn special_is_empty(ctrl: u8) -> bool { . debug_assert!(is_special(ctrl)); 76,941 ( 0.00%) ctrl & 0x01 != 0 . } . . /// Primary hash function, used to select the initial bucket to probe from. . #[inline] . #[allow(clippy::cast_possible_truncation)] . fn h1(hash: u64) -> usize { . // On 32-bit platforms we simply ignore the higher hash bits. . hash as usize -- line 140 ---------------------------------------- -- line 143 ---------------------------------------- . /// Secondary hash function, saved in the low 7 bits of the control byte. . #[inline] . #[allow(clippy::cast_possible_truncation)] . fn h2(hash: u64) -> u8 { . // Grab the top 7 bits of the hash. While the hash is normally a full 64-bit . // value, some hash functions (such as FxHash) produce a usize result . // instead, which means that the top 32 bits are 0 on 32-bit platforms. . let hash_len = usize::min(mem::size_of::(), mem::size_of::()); 63,843,536 ( 0.64%) let top7 = hash >> (hash_len * 8 - 7); . (top7 & 0x7f) as u8 // truncation . } . . /// Probe sequence based on triangular numbers, which is guaranteed (since our . /// table size is a power of two) to visit every group of elements exactly once. . /// . /// A triangular probe has us jump by 1 more group every time. So first we . /// jump by 1 group (meaning we just continue our linear scan), then 2 groups -- line 159 ---------------------------------------- -- line 170 ---------------------------------------- . #[inline] . fn move_next(&mut self, bucket_mask: usize) { . // We should have found an empty bucket by now and ended the probe. . debug_assert!( . self.stride <= bucket_mask, . "Went past end of probe sequence" . ); . 245,842 ( 0.00%) self.stride += Group::WIDTH; 245,842 ( 0.00%) self.pos += self.stride; 213,843 ( 0.00%) self.pos &= bucket_mask; . } . } . . /// Returns the number of buckets needed to hold the given number of items, . /// taking the maximum load factor into account. . /// . /// Returns `None` if an overflow occurs. . // Workaround for emscripten bug emscripten-core/emscripten-fastcomp#258 . #[cfg_attr(target_os = "emscripten", inline(never))] . #[cfg_attr(not(target_os = "emscripten"), inline)] . fn capacity_to_buckets(cap: usize) -> Option { . debug_assert_ne!(cap, 0); . . // For small tables we require at least 1 empty bucket so that lookups are . // guaranteed to terminate if an element doesn't exist in the table. 89,366 ( 0.00%) if cap < 8 { . // We don't bother with a table size of 2 buckets since that can only . // hold a single element. Instead we skip directly to a 4 bucket table . // which can hold 3 elements. 198,490 ( 0.00%) return Some(if cap < 4 { 4 } else { 8 }); . } . . // Otherwise require 1/8 buckets to be empty (87.5% load) . // . // Be careful when modifying this, calculate_layout relies on the . // overflow check here. 29,910 ( 0.00%) let adjusted_cap = cap.checked_mul(8)? / 7; . . // Any overflows will have been caught by the checked_mul. Also, any . // rounding errors from the division above will be cleaned up by . // next_power_of_two (which can't overflow because of the previous division). . Some(adjusted_cap.next_power_of_two()) . } . . /// Returns the maximum effective capacity for the given bucket mask, taking . /// the maximum load factor into account. . #[inline] . fn bucket_mask_to_capacity(bucket_mask: usize) -> usize { 214,481 ( 0.00%) if bucket_mask < 8 { . // For tables with 1/2/4/8 buckets, we always reserve one empty slot. . // Keep in mind that the bucket mask is one less than the bucket count. . bucket_mask . } else { . // For larger tables we reserve 12.5% of the slots as empty. 41,254 ( 0.00%) ((bucket_mask + 1) / 8) * 7 . } . } . . /// Helper which allows the max calculation for ctrl_align to be statically computed for each T . /// while keeping the rest of `calculate_layout_for` independent of `T` . #[derive(Copy, Clone)] . struct TableLayout { . size: usize, -- line 233 ---------------------------------------- -- line 246 ---------------------------------------- . . #[inline] . fn calculate_layout_for(self, buckets: usize) -> Option<(Layout, usize)> { . debug_assert!(buckets.is_power_of_two()); . . let TableLayout { size, ctrl_align } = self; . // Manual layout calculation since Layout methods are not yet stable. . let ctrl_offset = 197,185 ( 0.00%) size.checked_mul(buckets)?.checked_add(ctrl_align - 1)? & !(ctrl_align - 1); 252,456 ( 0.00%) let len = ctrl_offset.checked_add(buckets + Group::WIDTH)?; . . Some(( . unsafe { Layout::from_size_align_unchecked(len, ctrl_align) }, . ctrl_offset, . )) . } . } . -- line 263 ---------------------------------------- -- line 337 ---------------------------------------- . } . } . #[cfg_attr(feature = "inline-more", inline)] . pub unsafe fn drop(&self) { . self.as_ptr().drop_in_place(); . } . #[inline] . pub unsafe fn read(&self) -> T { 410 ( 0.00%) self.as_ptr().read() . } . #[inline] . pub unsafe fn write(&self, val: T) { . self.as_ptr().write(val); . } . #[inline] . pub unsafe fn as_ref<'a>(&self) -> &'a T { . &*self.as_ptr() -- line 353 ---------------------------------------- -- line 422 ---------------------------------------- . /// Creates a new empty hash table without allocating any memory, using the . /// given allocator. . /// . /// In effect this returns a table with exactly 1 bucket. However we can . /// leave the data pointer dangling since that bucket is never written to . /// due to our load factor forcing us to always have at least 1 free bucket. . #[inline] . pub fn new_in(alloc: A) -> Self { 75 ( 0.00%) Self { . table: RawTableInner::new_in(alloc), . marker: PhantomData, . } . } . . /// Allocates a new hash table with the given number of buckets. . /// . /// The control bytes are left uninitialized. -- line 438 ---------------------------------------- -- line 440 ---------------------------------------- . unsafe fn new_uninitialized( . alloc: A, . buckets: usize, . fallibility: Fallibility, . ) -> Result { . debug_assert!(buckets.is_power_of_two()); . . Ok(Self { 70 ( 0.00%) table: RawTableInner::new_uninitialized( . alloc, . TableLayout::new::(), . buckets, . fallibility, . )?, . marker: PhantomData, . }) . } -- line 456 ---------------------------------------- -- line 458 ---------------------------------------- . /// Attempts to allocate a new hash table with at least enough capacity . /// for inserting the given number of elements without reallocating. . fn fallible_with_capacity( . alloc: A, . capacity: usize, . fallibility: Fallibility, . ) -> Result { . Ok(Self { 8,233 ( 0.00%) table: RawTableInner::fallible_with_capacity( . alloc, . TableLayout::new::(), . capacity, . fallibility, . )?, . marker: PhantomData, . }) . } -- line 474 ---------------------------------------- -- line 527 ---------------------------------------- . debug_assert_ne!(self.table.bucket_mask, 0); . debug_assert!(index < self.buckets()); . Bucket::from_base_index(self.data_end(), index) . } . . /// Erases an element from the table without dropping it. . #[cfg_attr(feature = "inline-more", inline)] . #[deprecated(since = "0.8.1", note = "use erase or remove instead")] 6,870 ( 0.00%) pub unsafe fn erase_no_drop(&mut self, item: &Bucket) { 6,870 ( 0.00%) let index = self.bucket_index(item); . self.table.erase(index); 13,740 ( 0.00%) } . . /// Erases an element from the table, dropping it in place. . #[cfg_attr(feature = "inline-more", inline)] . #[allow(clippy::needless_pass_by_value)] . #[allow(deprecated)] . pub unsafe fn erase(&mut self, item: Bucket) { . // Erase the element from the table first since drop might panic. 3,526 ( 0.00%) self.erase_no_drop(&item); . item.drop(); . } . . /// Finds and erases an element from the table, dropping it in place. . /// Returns true if an element was found. . #[cfg(feature = "raw")] . #[cfg_attr(feature = "inline-more", inline)] . pub fn erase_entry(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> bool { -- line 554 ---------------------------------------- -- line 563 ---------------------------------------- . } . } . . /// Removes an element from the table, returning it. . #[cfg_attr(feature = "inline-more", inline)] . #[allow(clippy::needless_pass_by_value)] . #[allow(deprecated)] . pub unsafe fn remove(&mut self, item: Bucket) -> T { 10,214 ( 0.00%) self.erase_no_drop(&item); 42 ( 0.00%) item.read() . } . . /// Finds and removes an element from the table, returning it. . #[cfg_attr(feature = "inline-more", inline)] 1,099,178 ( 0.01%) pub fn remove_entry(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option { . // Avoid `Option::map` because it bloats LLVM IR. 1,472 ( 0.00%) match self.find(hash, eq) { 42,496 ( 0.00%) Some(bucket) => Some(unsafe { self.remove(bucket) }), 492,392 ( 0.00%) None => None, . } 1,832,764 ( 0.02%) } . . /// Marks all table buckets as empty without dropping their contents. . #[cfg_attr(feature = "inline-more", inline)] . pub fn clear_no_drop(&mut self) { . self.table.clear_no_drop(); . } . . /// Removes all elements from the table without freeing the backing memory. . #[cfg_attr(feature = "inline-more", inline)] . pub fn clear(&mut self) { . // Ensure that the table is reset even if one of the drops panic . let mut self_ = guard(self, |self_| self_.clear_no_drop()); . unsafe { 1 ( 0.00%) self_.drop_elements(); . } . } . 7 ( 0.00%) unsafe fn drop_elements(&mut self) { 5,456 ( 0.00%) if mem::needs_drop::() && !self.is_empty() { . for item in self.iter() { . item.drop(); . } . } 8 ( 0.00%) } . . /// Shrinks the table to fit `max(self.len(), min_size)` elements. . #[cfg_attr(feature = "inline-more", inline)] . pub fn shrink_to(&mut self, min_size: usize, hasher: impl Fn(&T) -> u64) { . // Calculate the minimal number of elements that we need to reserve . // space for. . let min_size = usize::max(self.table.items, min_size); . if min_size == 0 { -- line 615 ---------------------------------------- -- line 642 ---------------------------------------- . } . } . } . . /// Ensures that at least `additional` items can be inserted into the table . /// without reallocation. . #[cfg_attr(feature = "inline-more", inline)] . pub fn reserve(&mut self, additional: usize, hasher: impl Fn(&T) -> u64) { 202,663 ( 0.00%) if additional > self.table.growth_left { . // Avoid `Result::unwrap_or_else` because it bloats LLVM IR. 151,224 ( 0.00%) if self . .reserve_rehash(additional, hasher, Fallibility::Infallible) . .is_err() . { . unsafe { hint::unreachable_unchecked() } . } . } . } . -- line 660 ---------------------------------------- -- line 671 ---------------------------------------- . } else { . Ok(()) . } . } . . /// Out-of-line slow path for `reserve` and `try_reserve`. . #[cold] . #[inline(never)] 370,957 ( 0.00%) fn reserve_rehash( . &mut self, . additional: usize, . hasher: impl Fn(&T) -> u64, . fallibility: Fallibility, . ) -> Result<(), TryReserveError> { . unsafe { . self.table.reserve_rehash_inner( . additional, -- line 687 ---------------------------------------- -- line 690 ---------------------------------------- . TableLayout::new::(), . if mem::needs_drop::() { . Some(mem::transmute(ptr::drop_in_place:: as unsafe fn(*mut T))) . } else { . None . }, . ) . } 288,760 ( 0.00%) } . . /// Allocates a new table of a different size and moves the contents of the . /// current table into it. . fn resize( . &mut self, . capacity: usize, . hasher: impl Fn(&T) -> u64, . fallibility: Fallibility, -- line 706 ---------------------------------------- -- line 714 ---------------------------------------- . ) . } . } . . /// Inserts a new element into the table, and returns its raw bucket. . /// . /// This does not check if the given element already exists in the table. . #[cfg_attr(feature = "inline-more", inline)] 3,607,848 ( 0.04%) pub fn insert(&mut self, hash: u64, value: T, hasher: impl Fn(&T) -> u64) -> Bucket { . unsafe { . let mut index = self.table.find_insert_slot(hash); . . // We can avoid growing the table once we have reached our load . // factor if we are replacing a tombstone. This works since the . // number of EMPTY slots does not change in this case. 2,169 ( 0.00%) let old_ctrl = *self.table.ctrl(index); 2,787,009 ( 0.03%) if unlikely(self.table.growth_left == 0 && special_is_empty(old_ctrl)) { . self.reserve(1, hasher); . index = self.table.find_insert_slot(hash); . } . . self.table.record_item_insert_at(index, old_ctrl, hash); . . let bucket = self.bucket(index); 4 ( 0.00%) bucket.write(value); . bucket . } 2,689,663 ( 0.03%) } . . /// Attempts to insert a new element without growing the table and return its raw bucket. . /// . /// Returns an `Err` containing the given element if inserting it would require growing the . /// table. . /// . /// This does not check if the given element already exists in the table. . #[cfg(feature = "raw")] -- line 749 ---------------------------------------- -- line 760 ---------------------------------------- . } . } . } . . /// Inserts a new element into the table, and returns a mutable reference to it. . /// . /// This does not check if the given element already exists in the table. . #[cfg_attr(feature = "inline-more", inline)] 423,456 ( 0.00%) pub fn insert_entry(&mut self, hash: u64, value: T, hasher: impl Fn(&T) -> u64) -> &mut T { 74 ( 0.00%) unsafe { self.insert(hash, value, hasher).as_mut() } 317,592 ( 0.00%) } . . /// Inserts a new element into the table, without growing the table. . /// . /// There must be enough space in the table to insert the new element. . /// . /// This does not check if the given element already exists in the table. . #[cfg_attr(feature = "inline-more", inline)] . #[cfg(any(feature = "raw", feature = "rustc-internal-api"))] 364 ( 0.00%) pub unsafe fn insert_no_grow(&mut self, hash: u64, value: T) -> Bucket { 227,339 ( 0.00%) let (index, old_ctrl) = self.table.prepare_insert_slot(hash); 4,417 ( 0.00%) let bucket = self.table.bucket(index); . . // If we are replacing a DELETED entry then we don't need to update . // the load counter. 463,375 ( 0.00%) self.table.growth_left -= special_is_empty(old_ctrl) as usize; . . bucket.write(value); 365,210 ( 0.00%) self.table.items += 1; . bucket 723 ( 0.00%) } . . /// Temporary removes a bucket, applying the given function to the removed . /// element and optionally put back the returned value in the same bucket. . /// . /// Returns `true` if the bucket still contains an element . /// . /// This does not check if the given bucket is actually occupied. . #[cfg_attr(feature = "inline-more", inline)] -- line 798 ---------------------------------------- -- line 813 ---------------------------------------- . true . } else { . false . } . } . . /// Searches for an element in the table. . #[inline] 45,944 ( 0.00%) pub fn find(&self, hash: u64, mut eq: impl FnMut(&T) -> bool) -> Option> { 163,559 ( 0.00%) let result = self.table.find_inner(hash, &mut |index| unsafe { 107,066 ( 0.00%) eq(self.bucket(index).as_ref()) 129,646 ( 0.00%) }); . . // Avoid `Option::map` because it bloats LLVM IR. . match result { 31,157 ( 0.00%) Some(index) => Some(unsafe { self.bucket(index) }), . None => None, . } 52,328 ( 0.00%) } . . /// Gets a reference to an element in the table. . #[inline] . pub fn get(&self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<&T> { . // Avoid `Option::map` because it bloats LLVM IR. 74,781 ( 0.00%) match self.find(hash, eq) { . Some(bucket) => Some(unsafe { bucket.as_ref() }), . None => None, . } . } . . /// Gets a mutable reference to an element in the table. . #[inline] 1,715 ( 0.00%) pub fn get_mut(&mut self, hash: u64, eq: impl FnMut(&T) -> bool) -> Option<&mut T> { . // Avoid `Option::map` because it bloats LLVM IR. 19,819 ( 0.00%) match self.find(hash, eq) { . Some(bucket) => Some(unsafe { bucket.as_mut() }), . None => None, . } 1,960 ( 0.00%) } . . /// Attempts to get mutable references to `N` entries in the table at once. . /// . /// Returns an array of length `N` with the results of each query. . /// . /// At most one mutable reference will be returned to any entry. `None` will be returned if any . /// of the hashes are duplicates. `None` will be returned if the hash is not found. . /// -- line 859 ---------------------------------------- -- line 920 ---------------------------------------- . #[inline] . pub fn len(&self) -> usize { . self.table.items . } . . /// Returns `true` if the table contains no elements. . #[inline] . pub fn is_empty(&self) -> bool { 3,286,711 ( 0.03%) self.len() == 0 . } . . /// Returns the number of buckets in the table. . #[inline] . pub fn buckets(&self) -> usize { . self.table.bucket_mask + 1 . } . -- line 936 ---------------------------------------- -- line 938 ---------------------------------------- . /// the caller to ensure that the `RawTable` outlives the `RawIter`. . /// Because we cannot make the `next` method unsafe on the `RawIter` . /// struct, we have to make the `iter` method unsafe. . #[inline] . pub unsafe fn iter(&self) -> RawIter { . let data = Bucket::from_base_index(self.data_end(), 0); . RawIter { . iter: RawIterRange::new(self.table.ctrl.as_ptr(), data, self.table.buckets()), 427,341 ( 0.00%) items: self.table.items, . } . } . . /// Returns an iterator over occupied buckets that could match a given hash. . /// . /// `RawTable` only stores 7 bits of the hash value, so this iterator may . /// return items that have a hash value different than the one provided. You . /// should always validate the returned values before using them. -- line 954 ---------------------------------------- -- line 995 ---------------------------------------- . /// Iteration starts at the provided iterator's current location. . /// . /// It is up to the caller to ensure that the iterator is valid for this . /// `RawTable` and covers all items that remain in the table. . pub unsafe fn into_iter_from(self, iter: RawIter) -> RawIntoIter { . debug_assert_eq!(iter.len(), self.len()); . . let alloc = self.table.alloc.clone(); 3,040 ( 0.00%) let allocation = self.into_allocation(); 2,280 ( 0.00%) RawIntoIter { 3,800 ( 0.00%) iter, . allocation, . marker: PhantomData, . alloc, . } . } . . /// Converts the table into a raw allocation. The contents of the table . /// should be dropped using a `RawIter` before freeing the allocation. . #[cfg_attr(feature = "inline-more", inline)] . pub(crate) fn into_allocation(self) -> Option<(NonNull, Layout)> { 1,212 ( 0.00%) let alloc = if self.table.is_empty_singleton() { . None . } else { . // Avoid `Option::unwrap_or_else` because it bloats LLVM IR. . let (layout, ctrl_offset) = match calculate_layout::(self.table.buckets()) { . Some(lco) => lco, . None => unsafe { hint::unreachable_unchecked() }, . }; . Some(( 262 ( 0.00%) unsafe { NonNull::new_unchecked(self.table.ctrl.as_ptr().sub(ctrl_offset)) }, . layout, . )) . }; . mem::forget(self); . alloc . } . } . -- line 1033 ---------------------------------------- -- line 1042 ---------------------------------------- . T: Sync, . A: Sync, . { . } . . impl RawTableInner { . #[inline] . const fn new_in(alloc: A) -> Self { 1,535,985 ( 0.02%) Self { . // Be careful to cast the entire slice to a raw pointer. . ctrl: unsafe { NonNull::new_unchecked(Group::static_empty() as *const _ as *mut u8) }, . bucket_mask: 0, . items: 0, . growth_left: 0, . alloc, . } . } . } . . impl RawTableInner { . #[cfg_attr(feature = "inline-more", inline)] 379,367 ( 0.00%) unsafe fn new_uninitialized( . alloc: A, . table_layout: TableLayout, . buckets: usize, . fallibility: Fallibility, . ) -> Result { . debug_assert!(buckets.is_power_of_two()); . . // Avoid `Option::ok_or_else` because it bloats LLVM IR. -- line 1071 ---------------------------------------- -- line 1078 ---------------------------------------- . // exceed `isize::MAX`. We can skip this check on 64-bit systems since . // such allocations will never succeed anyways. . // . // This mirrors what Vec does in the standard library. . if mem::size_of::() < 8 && layout.size() > isize::MAX as usize { . return Err(fallibility.capacity_overflow()); . } . 81,220 ( 0.00%) let ptr: NonNull = match do_alloc(&alloc, layout) { . Ok(block) => block.cast(), . Err(_) => return Err(fallibility.alloc_err(layout)), . }; . . let ctrl = NonNull::new_unchecked(ptr.as_ptr().add(ctrl_offset)); 209,076 ( 0.00%) Ok(Self { . ctrl, 79,543 ( 0.00%) bucket_mask: buckets - 1, . items: 0, . growth_left: bucket_mask_to_capacity(buckets - 1), . alloc, . }) 276,142 ( 0.00%) } . . #[inline] 21,151 ( 0.00%) fn fallible_with_capacity( . alloc: A, . table_layout: TableLayout, . capacity: usize, . fallibility: Fallibility, . ) -> Result { 5,392 ( 0.00%) if capacity == 0 { 4,250 ( 0.00%) Ok(Self::new_in(alloc)) . } else { . unsafe { . let buckets = . capacity_to_buckets(capacity).ok_or_else(|| fallibility.capacity_overflow())?; . 172,687 ( 0.00%) let result = Self::new_uninitialized(alloc, table_layout, buckets, fallibility)?; . result.ctrl(0).write_bytes(EMPTY, result.num_ctrl_bytes()); . 10,910 ( 0.00%) Ok(result) . } . } 21,151 ( 0.00%) } . . /// Searches for an empty or deleted bucket which is suitable for inserting . /// a new element and sets the hash for that slot. . /// . /// There must be at least 1 empty bucket in the table. . #[inline] 76,582 ( 0.00%) unsafe fn prepare_insert_slot(&self, hash: u64) -> (usize, u8) { . let index = self.find_insert_slot(hash); 76,582 ( 0.00%) let old_ctrl = *self.ctrl(index); . self.set_ctrl_h2(index, hash); . (index, old_ctrl) 153,164 ( 0.00%) } . . /// Searches for an empty or deleted bucket which is suitable for inserting . /// a new element. . /// . /// There must be at least 1 empty bucket in the table. . #[inline] . fn find_insert_slot(&self, hash: u64) -> usize { . let mut probe_seq = self.probe_seq(hash); . loop { . unsafe { . let group = Group::load(self.ctrl(probe_seq.pos)); 1,793,602 ( 0.02%) if let Some(bit) = group.match_empty_or_deleted().lowest_set_bit() { 5,304,991 ( 0.05%) let result = (probe_seq.pos + bit) & self.bucket_mask; . . // In tables smaller than the group width, trailing control . // bytes outside the range of the table are filled with . // EMPTY entries. These will unfortunately trigger a . // match, but once masked may point to a full bucket that . // is already occupied. We detect this situation here and . // perform a second scan starting at the beginning of the . // table. This second scan is guaranteed to find an empty . // slot (due to the load factor) before hitting the trailing . // control bytes (containing EMPTY). 2,461,603 ( 0.02%) if unlikely(is_full(*self.ctrl(result))) { . debug_assert!(self.bucket_mask < Group::WIDTH); . debug_assert_ne!(probe_seq.pos, 0); . return Group::load_aligned(self.ctrl(0)) . .match_empty_or_deleted() . .lowest_set_bit_nonzero(); . } . . return result; -- line 1165 ---------------------------------------- -- line 1171 ---------------------------------------- . . /// Searches for an element in the table. This uses dynamic dispatch to reduce the amount of . /// code generated, but it is eliminated by LLVM optimizations. . #[inline] . fn find_inner(&self, hash: u64, eq: &mut dyn FnMut(usize) -> bool) -> Option { . let h2_hash = h2(hash); . let mut probe_seq = self.probe_seq(hash); . 49,380 ( 0.00%) loop { . let group = unsafe { Group::load(self.ctrl(probe_seq.pos)) }; . 8,289,183 ( 0.08%) for bit in group.match_byte(h2_hash) { 17,919,919 ( 0.18%) let index = (probe_seq.pos + bit) & self.bucket_mask; . 13,358,430 ( 0.13%) if likely(eq(index)) { . return Some(index); . } . } . 1,837,451 ( 0.02%) if likely(group.match_empty().any_bit_set()) { . return None; . } . . probe_seq.move_next(self.bucket_mask); . } . } . . #[allow(clippy::mut_mut)] -- line 1198 ---------------------------------------- -- line 1225 ---------------------------------------- . Bucket::from_base_index(self.data_end(), index) . } . . #[inline] . unsafe fn bucket_ptr(&self, index: usize, size_of: usize) -> *mut u8 { . debug_assert_ne!(self.bucket_mask, 0); . debug_assert!(index < self.buckets()); . let base: *mut u8 = self.data_end().as_ptr(); 7,716,960 ( 0.08%) base.sub((index + 1) * size_of) . } . . #[inline] . unsafe fn data_end(&self) -> NonNull { . NonNull::new_unchecked(self.ctrl.as_ptr().cast()) . } . . /// Returns an iterator-like object for a probe sequence on the table. . /// . /// This iterator never terminates, but is guaranteed to visit each bucket . /// group exactly once. The loop using `probe_seq` must terminate upon . /// reaching a group containing an empty bucket. . #[inline] . fn probe_seq(&self, hash: u64) -> ProbeSeq { . ProbeSeq { 42,435,025 ( 0.42%) pos: h1(hash) & self.bucket_mask, . stride: 0, . } . } . . /// Returns the index of a bucket for which a value must be inserted if there is enough rooom . /// in the table, otherwise returns error . #[cfg(feature = "raw")] . #[inline] -- line 1257 ---------------------------------------- -- line 1263 ---------------------------------------- . } else { . self.record_item_insert_at(index, old_ctrl, hash); . Ok(index) . } . } . . #[inline] . unsafe fn record_item_insert_at(&mut self, index: usize, old_ctrl: u8, hash: u64) { 3,483,542 ( 0.03%) self.growth_left -= special_is_empty(old_ctrl) as usize; . self.set_ctrl_h2(index, hash); 2,786,792 ( 0.03%) self.items += 1; . } . . #[inline] . fn is_in_same_group(&self, i: usize, new_i: usize, hash: u64) -> bool { . let probe_seq_pos = self.probe_seq(hash).pos; . let probe_index = . |pos: usize| (pos.wrapping_sub(probe_seq_pos) & self.bucket_mask) / Group::WIDTH; . probe_index(i) == probe_index(new_i) -- line 1281 ---------------------------------------- -- line 1312 ---------------------------------------- . // replicate the buckets at the end of the trailing group. For example . // with 2 buckets and a group size of 4, the control bytes will look . // like this: . // . // Real | Replicated . // --------------------------------------------- . // | [A] | [B] | [EMPTY] | [EMPTY] | [A] | [B] | . // --------------------------------------------- 5,216,575 ( 0.05%) let index2 = ((index.wrapping_sub(Group::WIDTH)) & self.bucket_mask) + Group::WIDTH; . 1,738,259 ( 0.02%) *self.ctrl(index) = ctrl; 1,738,384 ( 0.02%) *self.ctrl(index2) = ctrl; . } . . /// Returns a pointer to a control byte. . #[inline] . unsafe fn ctrl(&self, index: usize) -> *mut u8 { . debug_assert!(index < self.num_ctrl_bytes()); . self.ctrl.as_ptr().add(index) . } . . #[inline] . fn buckets(&self) -> usize { 771,389 ( 0.01%) self.bucket_mask + 1 . } . . #[inline] . fn num_ctrl_bytes(&self) -> usize { 194,874 ( 0.00%) self.bucket_mask + 1 + Group::WIDTH . } . . #[inline] . fn is_empty_singleton(&self) -> bool { 2,414,069 ( 0.02%) self.bucket_mask == 0 . } . . #[allow(clippy::mut_mut)] . #[inline] . unsafe fn prepare_resize( . &self, . table_layout: TableLayout, . capacity: usize, . fallibility: Fallibility, . ) -> Result, TryReserveError> { . debug_assert!(self.items <= capacity); . . // Allocate and initialize the new table. 1,809 ( 0.00%) let mut new_table = RawTableInner::fallible_with_capacity( . self.alloc.clone(), . table_layout, . capacity, . fallibility, . )?; 91,685 ( 0.00%) new_table.growth_left -= self.items; . new_table.items = self.items; . . // The hash function may panic, in which case we simply free the new . // table without dropping any elements that may have been copied into . // it. . // . // This guard is also used to free the old table on success, see . // the comment at the bottom of this function. . Ok(guard(new_table, move |self_| { 43,467 ( 0.00%) if !self_.is_empty_singleton() { . self_.free_buckets(table_layout); . } . })) . } . . /// Reserves or rehashes to make room for `additional` more elements. . /// . /// This uses dynamic dispatch to reduce the amount of -- line 1383 ---------------------------------------- -- line 1388 ---------------------------------------- . &mut self, . additional: usize, . hasher: &dyn Fn(&mut Self, usize) -> u64, . fallibility: Fallibility, . layout: TableLayout, . drop: Option, . ) -> Result<(), TryReserveError> { . // Avoid `Option::ok_or_else` because it bloats LLVM IR. 86,934 ( 0.00%) let new_items = match self.items.checked_add(additional) { . Some(new_items) => new_items, . None => return Err(fallibility.capacity_overflow()), . }; 86,934 ( 0.00%) let full_capacity = bucket_mask_to_capacity(self.bucket_mask); 179,114 ( 0.00%) if new_items <= full_capacity / 2 { . // Rehash in-place without re-allocating if we have plenty of spare . // capacity that is locked up due to DELETED entries. . self.rehash_in_place(hasher, layout.size, drop); . Ok(()) . } else { . // Otherwise, conservatively resize to at least the next size up . // to avoid churning deletes into frequent rehashes. . self.resize_inner( 43,467 ( 0.00%) usize::max(new_items, full_capacity + 1), . hasher, . fallibility, . layout, . ) . } . } . . /// Allocates a new table of a different size and moves the contents of the -- line 1418 ---------------------------------------- -- line 1424 ---------------------------------------- . #[inline(always)] . unsafe fn resize_inner( . &mut self, . capacity: usize, . hasher: &dyn Fn(&mut Self, usize) -> u64, . fallibility: Fallibility, . layout: TableLayout, . ) -> Result<(), TryReserveError> { 4,544 ( 0.00%) let mut new_table = self.prepare_resize(layout, capacity, fallibility)?; . . // Copy all elements to the new table. . for i in 0..self.buckets() { 1,140,416 ( 0.01%) if !is_full(*self.ctrl(i)) { . continue; . } . . // This may panic. . let hash = hasher(self, i); . . // We can use a simpler version of insert() here since: . // - there are no DELETED entries. -- line 1444 ---------------------------------------- -- line 1454 ---------------------------------------- . } . . // We successfully copied all elements without panicking. Now replace . // self with the new table. The old table will have its memory freed but . // the items will not be dropped (since they have been moved into the . // new table). . mem::swap(self, &mut new_table); . 43,467 ( 0.00%) Ok(()) . } . . /// Rehashes the contents of the table in place (i.e. without changing the . /// allocation). . /// . /// If `hasher` panics then some the table's contents may be lost. . /// . /// This uses dynamic dispatch to reduce the amount of -- line 1470 ---------------------------------------- -- line 1554 ---------------------------------------- . #[inline] . unsafe fn free_buckets(&mut self, table_layout: TableLayout) { . // Avoid `Option::unwrap_or_else` because it bloats LLVM IR. . let (layout, ctrl_offset) = match table_layout.calculate_layout_for(self.buckets()) { . Some(lco) => lco, . None => hint::unreachable_unchecked(), . }; . self.alloc.deallocate( 35,995 ( 0.00%) NonNull::new_unchecked(self.ctrl.as_ptr().sub(ctrl_offset)), . layout, . ); . } . . /// Marks all table buckets as empty without dropping their contents. . #[inline] . fn clear_no_drop(&mut self) { 4,206 ( 0.00%) if !self.is_empty_singleton() { . unsafe { . self.ctrl(0).write_bytes(EMPTY, self.num_ctrl_bytes()); . } . } 5,060 ( 0.00%) self.items = 0; 4,219 ( 0.00%) self.growth_left = bucket_mask_to_capacity(self.bucket_mask); . } . . #[inline] . unsafe fn erase(&mut self, index: usize) { . debug_assert!(is_full(*self.ctrl(index))); 138,296 ( 0.00%) let index_before = index.wrapping_sub(Group::WIDTH) & self.bucket_mask; . let empty_before = Group::load(self.ctrl(index_before)).match_empty(); . let empty_after = Group::load(self.ctrl(index)).match_empty(); . . // If we are inside a continuous block of Group::WIDTH full or deleted . // cells then a probe window may have seen a full block when trying to . // insert. We therefore need to keep that block non-empty so that . // lookups will continue searching to the next probe window. . // . // Note that in this context `leading_zeros` refers to the bytes at the . // end of a group, while `trailing_zeros` refers to the bytes at the . // beginning of a group. 553,184 ( 0.01%) let ctrl = if empty_before.leading_zeros() + empty_after.trailing_zeros() >= Group::WIDTH { . DELETED . } else { 686,800 ( 0.01%) self.growth_left += 1; . EMPTY . }; . self.set_ctrl(index, ctrl); 553,184 ( 0.01%) self.items -= 1; . } . } . . impl Clone for RawTable { 216 ( 0.00%) fn clone(&self) -> Self { 44 ( 0.00%) if self.table.is_empty_singleton() { . Self::new_in(self.table.alloc.clone()) . } else { . unsafe { . let mut new_table = ManuallyDrop::new( . // Avoid `Result::ok_or_else` because it bloats LLVM IR. . match Self::new_uninitialized( . self.table.alloc.clone(), . self.table.buckets(), -- line 1615 ---------------------------------------- -- line 1624 ---------------------------------------- . // We need to free the memory allocated for the new table. . new_table.free_buckets(); . }); . . // Return the newly created table. . ManuallyDrop::into_inner(new_table) . } . } 243 ( 0.00%) } . . fn clone_from(&mut self, source: &Self) { . if source.table.is_empty_singleton() { . *self = Self::new_in(self.table.alloc.clone()); . } else { . unsafe { . // First, drop all our elements without clearing the control bytes. . self.drop_elements(); -- line 1640 ---------------------------------------- -- line 1687 ---------------------------------------- . .table . .ctrl(0) . .copy_to_nonoverlapping(self.table.ctrl(0), self.table.num_ctrl_bytes()); . source . .data_start() . .copy_to_nonoverlapping(self.data_start(), self.table.buckets()); . . self.table.items = source.table.items; 28 ( 0.00%) self.table.growth_left = source.table.growth_left; . } . } . . impl RawTable { . /// Common code for clone and clone_from. Assumes `self.buckets() == source.buckets()`. . #[cfg_attr(feature = "inline-more", inline)] . unsafe fn clone_from_impl(&mut self, source: &Self, mut on_panic: impl FnMut(&mut Self)) { . // Copy the control bytes unchanged. We do this in a single pass -- line 1703 ---------------------------------------- -- line 1790 ---------------------------------------- . fn default() -> Self { . Self::new_in(Default::default()) . } . } . . #[cfg(feature = "nightly")] . unsafe impl<#[may_dangle] T, A: Allocator + Clone> Drop for RawTable { . #[cfg_attr(feature = "inline-more", inline)] 818,159 ( 0.01%) fn drop(&mut self) { 1,045,954 ( 0.01%) if !self.table.is_empty_singleton() { . unsafe { . self.drop_elements(); . self.free_buckets(); . } . } 954,060 ( 0.01%) } . } . #[cfg(not(feature = "nightly"))] . impl Drop for RawTable { . #[cfg_attr(feature = "inline-more", inline)] . fn drop(&mut self) { . if !self.table.is_empty_singleton() { . unsafe { . self.drop_elements(); -- line 1813 ---------------------------------------- -- line 1817 ---------------------------------------- . } . } . . impl IntoIterator for RawTable { . type Item = T; . type IntoIter = RawIntoIter; . . #[cfg_attr(feature = "inline-more", inline)] 3,040 ( 0.00%) fn into_iter(self) -> RawIntoIter { . unsafe { . let iter = self.iter(); . self.into_iter_from(iter) . } 3,800 ( 0.00%) } . } . . /// Iterator over a sub-range of a table. Unlike `RawIter` this iterator does . /// not track an item count. . pub(crate) struct RawIterRange { . // Mask of full buckets in the current group. Bits are cleared from this . // mask as each element is processed. . current_group: BitMask, -- line 1838 ---------------------------------------- -- line 1934 ---------------------------------------- . . impl Iterator for RawIterRange { . type Item = Bucket; . . #[cfg_attr(feature = "inline-more", inline)] . fn next(&mut self) -> Option> { . unsafe { . loop { 538,753 ( 0.01%) if let Some(index) = self.current_group.lowest_set_bit() { 107,959 ( 0.00%) self.current_group = self.current_group.remove_lowest_bit(); 189,848 ( 0.00%) return Some(self.data.next_n(index)); . } . 602,428 ( 0.01%) if self.next_ctrl >= self.end { . return None; . } . . // We might read past self.end up to the next group boundary, . // but this is fine because it only occurs on tables smaller . // than the group size where the trailing control bytes are all . // EMPTY. On larger tables self.end is guaranteed to be aligned . // to the group size (since tables are power-of-two sized). 12,580 ( 0.00%) self.current_group = Group::load_aligned(self.next_ctrl).match_full(); 22,399 ( 0.00%) self.data = self.data.next_n(Group::WIDTH); 15,052 ( 0.00%) self.next_ctrl = self.next_ctrl.add(Group::WIDTH); . } . } . } . . #[inline] . fn size_hint(&self) -> (usize, Option) { . // We don't have an item count, so just guess based on the range size. . ( -- line 1966 ---------------------------------------- -- line 2102 ---------------------------------------- . } . } else { . // We must have already iterated past the removed item. . } . } . } . . unsafe fn drop_elements(&mut self) { 575 ( 0.00%) if mem::needs_drop::() && self.len() != 0 { . for item in self { . item.drop(); . } . } . } . } . . impl Clone for RawIter { -- line 2118 ---------------------------------------- -- line 2124 ---------------------------------------- . } . } . } . . impl Iterator for RawIter { . type Item = Bucket; . . #[cfg_attr(feature = "inline-more", inline)] 128,755 ( 0.00%) fn next(&mut self) -> Option> { 245,568 ( 0.00%) if let Some(b) = self.iter.next() { 631,315 ( 0.01%) self.items -= 1; . Some(b) . } else { . // We don't check against items == 0 here to allow the . // compiler to optimize away the item count entirely if the . // iterator length is never queried. . debug_assert_eq!(self.items, 0); . None . } 257,510 ( 0.00%) } . . #[inline] . fn size_hint(&self) -> (usize, Option) { . (self.items, Some(self.items)) . } . } . . impl ExactSizeIterator for RawIter {} -- line 2151 ---------------------------------------- -- line 2177 ---------------------------------------- . T: Sync, . A: Sync, . { . } . . #[cfg(feature = "nightly")] . unsafe impl<#[may_dangle] T, A: Allocator + Clone> Drop for RawIntoIter { . #[cfg_attr(feature = "inline-more", inline)] 1,342 ( 0.00%) fn drop(&mut self) { . unsafe { . // Drop all remaining elements . self.iter.drop_elements(); . . // Free the table 5,646 ( 0.00%) if let Some((ptr, layout)) = self.allocation { . self.alloc.deallocate(ptr, layout); . } . } 270 ( 0.00%) } . } . #[cfg(not(feature = "nightly"))] . impl Drop for RawIntoIter { . #[cfg_attr(feature = "inline-more", inline)] . fn drop(&mut self) { . unsafe { . // Drop all remaining elements . self.iter.drop_elements(); -- line 2203 ---------------------------------------- -- line 2209 ---------------------------------------- . } . } . } . . impl Iterator for RawIntoIter { . type Item = T; . . #[cfg_attr(feature = "inline-more", inline)] 1,468 ( 0.00%) fn next(&mut self) -> Option { 177 ( 0.00%) unsafe { Some(self.iter.next()?.read()) } 4,155 ( 0.00%) } . . #[inline] . fn size_hint(&self) -> (usize, Option) { 4 ( 0.00%) self.iter.size_hint() . } . } . . impl ExactSizeIterator for RawIntoIter {} . impl FusedIterator for RawIntoIter {} . . /// Iterator which consumes elements without freeing the table storage. . pub struct RawDrain<'a, T, A: Allocator + Clone = Global> { -- line 2231 ---------------------------------------- -- line 2259 ---------------------------------------- . where . T: Sync, . A: Sync, . { . } . . impl Drop for RawDrain<'_, T, A> { . #[cfg_attr(feature = "inline-more", inline)] 8 ( 0.00%) fn drop(&mut self) { . unsafe { . // Drop all remaining elements. Note that this may panic. . self.iter.drop_elements(); . . // Reset the contents of the table now that all elements have been . // dropped. . self.table.clear_no_drop(); . . // Move the now empty table back to its original location. 1 ( 0.00%) self.orig_table . .as_ptr() . .copy_from_nonoverlapping(&*self.table, 1); . } 8 ( 0.00%) } . } . . impl Iterator for RawDrain<'_, T, A> { . type Item = T; . . #[cfg_attr(feature = "inline-more", inline)] . fn next(&mut self) -> Option { . unsafe { -- line 2289 ---------------------------------------- 22,577,918 ( 0.23%) -------------------------------------------------------------------------------- The following files chosen for auto-annotation could not be found: -------------------------------------------------------------------------------- ./elf/dl-lookup.c ./malloc/malloc.c ./string/../sysdeps/x86_64/multiarch/memcmp-avx2-movbe.S ./string/../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S ./string/../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S ./string/../sysdeps/x86_64/multiarch/strcmp-avx2.S /tmp/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/libsupc++/../../../../gcc-5.5.0/libstdc++-v3/libsupc++/new_op.cc -------------------------------------------------------------------------------- Ir -------------------------------------------------------------------------------- 664,383,450 ( 6.63%) events annotated