Skip to content

Commit

Permalink
Rollup merge of rust-lang#55882 - hugwijst:rc_return_crate_inherent_i…
Browse files Browse the repository at this point in the history
…mpls, r=Mark-Simulacrum

Reference count `crate_inherent_impls`s return value.

The repeated cloning of the result in `inherent_impls` queries has quite
an impact on crates with many inherent trait implementations.

For instance on https://github.com/jmesmon/stm32f429, `cargo check` went from 75 seconds to 38 seconds on my machine.
  • Loading branch information
pietroalbini authored Nov 12, 2018
2 parents 35bb8bc + 4fdae85 commit ec3983f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ define_queries! { <'tcx>
/// Gets a complete map from all types to their inherent impls.
/// Not meant to be used directly outside of coherence.
/// (Defined only for LOCAL_CRATE)
[] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
[] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum)
-> Lrc<CrateInherentImpls>,

/// Checks all types in the krate for overlap in their inherent impls. Reports errors.
/// Not meant to be used directly outside of coherence.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/coherence/inherent_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use syntax_pos::Span;
/// On-demand query: yields a map containing all types mapped to their inherent impls.
pub fn crate_inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
crate_num: CrateNum)
-> CrateInherentImpls {
-> Lrc<CrateInherentImpls> {
assert_eq!(crate_num, LOCAL_CRATE);

let krate = tcx.hir.krate();
Expand All @@ -42,7 +42,7 @@ pub fn crate_inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
};
krate.visit_all_item_likes(&mut collect);
collect.impls_map
Lrc::new(collect.impls_map)
}

/// On-demand query: yields a vector of the inherent impls for a specific type.
Expand Down

0 comments on commit ec3983f

Please sign in to comment.