fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>,
                                   starting_point: TransItem<'tcx>,
                                   visited: &mut FnvHashSet<TransItem<'tcx>>,
                                   recursion_depths: &mut DefIdMap<usize>,
                                   inlining_map: &mut InliningMap<'tcx>) {
    if !visited.insert(starting_point.clone()) {
        // We've been here already, no need to search again.
        return;
    }
    debug!("BEGIN collect_items_rec({})", starting_point.to_string(scx.tcx()));

    let mut neighbors = Vec::new();
    let recursion_depth_reset;

    match starting_point {
        TransItem::DropGlue(t) => {
            find_drop_glue_neighbors(scx, t, &mut neighbors);
            recursion_depth_reset = None;
        }
        TransItem::Static(node_id) => {
            let def_id = scx.tcx().map.local_def_id(node_id);
            let ty = scx.tcx().lookup_item_type(def_id).ty;
            let ty = glue::get_drop_glue_type(scx.tcx(), ty);
            neighbors.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));

            recursion_depth_reset = None;

            // Scan the MIR in order to find function calls, closures, and
            // drop-glue
            let mir = errors::expect(scx.sess().diagnostic(), scx.get_mir(def_id),
                || format!("Could not find MIR for static: {:?}", def_id));

            let empty_substs = scx.empty_substs_for_def_id(def_id);
            let visitor = MirNeighborCollector {
                scx: scx,
                mir: &mir,
                output: &mut neighbors,
                param_substs: empty_substs
            };

            visit_mir_and_promoted(visitor, &mir);
        }
        TransItem::Fn(instance) => {
            // Keep track of the monomorphization recursion depth
            recursion_depth_reset = Some(check_recursion_limit(scx.tcx(),
                                                               instance,
                                                               recursion_depths));

            // Scan the MIR in order to find function calls, closures, and
            // drop-glue
            let mir = errors::expect(scx.sess().diagnostic(), scx.get_mir(instance.def),
                || format!("Could not find MIR for function: {}", instance));

            let visitor = MirNeighborCollector {
                scx: scx,
                mir: &mir,
                output: &mut neighbors,
                param_substs: instance.substs
            };

            visit_mir_and_promoted(visitor, &mir);
        }
    }

    record_inlining_canditates(scx.tcx(), starting_point, &neighbors[..], inlining_map);

    for neighbour in neighbors {
        collect_items_rec(scx, neighbour, visited, recursion_depths, inlining_map);
    }

    if let Some((def_id, depth)) = recursion_depth_reset {
        recursion_depths.insert(def_id, depth);
    }

    debug!("END collect_items_rec({})", starting_point.to_string(scx.tcx()));
}
// Collect all monomorphized translation items reachable from `starting_point`
Collect all monomorphized translation items reachable from `starting_point`
Collect all monomorphized translation items reachable from ` starting_point `
fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>,
                                   starting_point: TransItem<'tcx>,
                                   visited: &mut FnvHashSet<TransItem<'tcx>>,
                                   recursion_depths: &mut DefIdMap<usize>,
                                   inlining_map: &mut InliningMap<'tcx>) {
    if !visited.insert(starting_point.clone()) {
        // We've been here already, no need to search again.
        return;
    }
    debug!("BEGIN collect_items_rec({})", starting_point.to_string(scx.tcx()));
    let mut neighbors = Vec::new();
    let recursion_depth_reset;
    match starting_point {
        TransItem::DropGlue(t) => {
            find_drop_glue_neighbors(scx, t, &mut neighbors);
            recursion_depth_reset = None;
        }
        TransItem::Static(node_id) => {
            let def_id = scx.tcx().map.local_def_id(node_id);
            let ty = scx.tcx().lookup_item_type(def_id).ty;
            let ty = glue::get_drop_glue_type(scx.tcx(), ty);
            neighbors.push(TransItem::DropGlue(DropGlueKind::Ty(ty)));
            recursion_depth_reset = None;
            // Scan the MIR in order to find function calls, closures, and
            // drop-glue
            let mir = errors::expect(scx.sess().diagnostic(), scx.get_mir(def_id),
                || format!("Could not find MIR for static: {:?}", def_id));
            let empty_substs = scx.empty_substs_for_def_id(def_id);
            let visitor = MirNeighborCollector {
                scx: scx,
                mir: &mir,
                output: &mut neighbors,
                param_substs: empty_substs
            };
            visit_mir_and_promoted(visitor, &mir);
        }
        TransItem::Fn(instance) => {
            // Keep track of the monomorphization recursion depth
            recursion_depth_reset = Some(check_recursion_limit(scx.tcx(),
                                                               instance,
                                                               recursion_depths));
            // Scan the MIR in order to find function calls, closures, and
            // drop-glue
            let mir = errors::expect(scx.sess().diagnostic(), scx.get_mir(instance.def),
                || format!("Could not find MIR for function: {}", instance));
            let visitor = MirNeighborCollector {
                scx: scx,
                mir: &mir,
                output: &mut neighbors,
                param_substs: instance.substs
            };
            visit_mir_and_promoted(visitor, &mir);
        }
    }
    record_inlining_canditates(scx.tcx(), starting_point, &neighbors[..], inlining_map);
    for neighbour in neighbors {
        collect_items_rec(scx, neighbour, visited, recursion_depths, inlining_map);
    }
    if let Some((def_id, depth)) = recursion_depth_reset {
        recursion_depths.insert(def_id, depth);
    }
    debug!("END collect_items_rec({})", starting_point.to_string(scx.tcx()));
}
fn collect_items_rec < ' a , ' tcx : ' a > ( scx : & SharedCrateContext < ' a , ' tcx > , starting_point : TransItem < ' tcx > , visited : & mut FnvHashSet < TransItem < ' tcx > > , recursion_depths : & mut DefIdMap < usize > , inlining_map : & mut InliningMap < ' tcx > ) { if ! visited . insert ( starting_point . clone ( ) ) { // We've been here already, no need to search again. return ; } debug ! ( " " starting_point to_string ( scx tcx ( ) ) ) ; let mut neighbors = Vec :: new ( ) ; let recursion_depth_reset ; match starting_point { TransItem :: DropGlue ( t ) => { find_drop_glue_neighbors ( scx , t , & mut neighbors ) ; recursion_depth_reset = None ; } TransItem :: Static ( node_id ) => { let def_id = scx . tcx ( ) . map . local_def_id ( node_id ) ; let ty = scx . tcx ( ) . lookup_item_type ( def_id ) . ty ; let ty = glue :: get_drop_glue_type ( scx . tcx ( ) , ty ) ; neighbors . push ( TransItem :: DropGlue ( DropGlueKind :: Ty ( ty ) ) ) ; recursion_depth_reset = None ; // Scan the MIR in order to find function calls, closures, and // drop-glue let mir = errors :: expect ( scx . sess ( ) . diagnostic ( ) , scx . get_mir ( def_id ) , | | format ! ( " " def_id ) ) ; let empty_substs = scx . empty_substs_for_def_id ( def_id ) ; let visitor = MirNeighborCollector { scx : scx , mir : & mir , output : & mut neighbors , param_substs : empty_substs } ; visit_mir_and_promoted ( visitor , & mir ) ; } TransItem :: Fn ( instance ) => { // Keep track of the monomorphization recursion depth recursion_depth_reset = Some ( check_recursion_limit ( scx . tcx ( ) , instance , recursion_depths ) ) ; // Scan the MIR in order to find function calls, closures, and // drop-glue let mir = errors :: expect ( scx . sess ( ) . diagnostic ( ) , scx . get_mir ( instance . def ) , | | format ! ( " " instance ) ) ; let visitor = MirNeighborCollector { scx : scx , mir : & mir , output : & mut neighbors , param_substs : instance . substs } ; visit_mir_and_promoted ( visitor , & mir ) ; } } record_inlining_canditates ( scx . tcx ( ) , starting_point , & neighbors [ .. ] , inlining_map ) ; for neighbour in neighbors { collect_items_rec ( scx , neighbour , visited , recursion_depths , inlining_map ) ; } if let Some ( ( def_id , depth ) ) = recursion_depth_reset { recursion_depths . insert ( def_id , depth ) ; } debug ! ( " " starting_point to_string ( scx tcx ( ) ) ) ; }
Collect all monomorphized translation items reachable from `starting_point`
Collect all monomorphized translation items reachable from ` starting_point `
scx
&SharedCrateContext<'a, 'tcx>
starting_point
TransItem<'tcx>
visited
&mut FnvHashSet<TransItem<'tcx>>
recursion_depths
&mut DefIdMap<usize>
inlining_map
&mut InliningMap<'tcx>
scx
&SharedCrateContext<'a, 'tcx>
starting_point
TransItem<'tcx>
visited
&mut FnvHashSet<TransItem<'tcx>>
recursion_depths
&mut DefIdMap<usize>
inlining_map
&mut InliningMap<'tcx>