Skip to content

Commit

Permalink
Use Lrc<[T]> instead of Lrc<Vec<T>> in librustc
Browse files Browse the repository at this point in the history
There is one instace where Lrc::get_mut().unwrap() is used on
the reference to make a push, this cannot be converted.

One instance of Lrc::make_mut() was removed -- the side effect of
changing the original vector cannot have mattered since make_mut()
might have cloned it.
  • Loading branch information
birkenfeld committed Apr 4, 2018
1 parent 8ac8ba6 commit 639abc9
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 76 deletions.
5 changes: 2 additions & 3 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,9 @@ pub fn used_crates(tcx: TyCtxt, prefer: LinkagePreference)
Some((cnum, path))
})
.collect::<Vec<_>>();
let mut ordering = tcx.postorder_cnums(LOCAL_CRATE);
Lrc::make_mut(&mut ordering).reverse();
let ordering = tcx.postorder_cnums(LOCAL_CRATE);
libs.sort_by_key(|&(a, _)| {
ordering.iter().position(|x| *x == a)
ordering.iter().rev().position(|x| *x == a)
});
libs
}
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub struct ResolveLifetimes {
defs: FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Region>>>,
late_bound: FxHashMap<LocalDefId, Lrc<FxHashSet<ItemLocalId>>>,
object_lifetime_defaults:
FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<[ObjectLifetimeDefault]>>>>,
}

impl_stable_hash_for!(struct ::middle::resolve_lifetime::ResolveLifetimes {
Expand Down Expand Up @@ -406,7 +406,7 @@ fn resolve_lifetimes<'tcx>(
.or_insert_with(|| Lrc::new(FxHashMap()));
Lrc::get_mut(map)
.unwrap()
.insert(hir_id.local_id, Lrc::new(v));
.insert(hir_id.local_id, Lrc::from(v));
}

Lrc::new(ResolveLifetimes {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,11 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
fn vtable_methods<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>)
-> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>
-> Lrc<[Option<(DefId, &'tcx Substs<'tcx>)>]>
{
debug!("vtable_methods({:?})", trait_ref);

Lrc::new(
Lrc::from(
supertraits(tcx, trait_ref).flat_map(move |trait_ref| {
let trait_methods = tcx.associated_items(trait_ref.def_id())
.filter(|item| item.kind == ty::AssociatedKind::Method);
Expand Down Expand Up @@ -850,7 +850,7 @@ fn vtable_methods<'a, 'tcx>(

Some((def_id, substs))
})
}).collect()
}).collect::<Vec<_>>()
)
}

Expand Down
18 changes: 9 additions & 9 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ pub struct GlobalCtxt<'tcx> {
Lrc<StableVec<TraitCandidate>>>>>,

/// Export map produced by name resolution.
export_map: FxHashMap<DefId, Lrc<Vec<Export>>>,
export_map: FxHashMap<DefId, Lrc<[Export]>>,

pub hir: hir_map::Map<'tcx>,

Expand All @@ -859,7 +859,7 @@ pub struct GlobalCtxt<'tcx> {
// Records the free variables refrenced by every closure
// expression. Do not track deps for this, just recompute it from
// scratch every time.
freevars: FxHashMap<DefId, Lrc<Vec<hir::Freevar>>>,
freevars: FxHashMap<DefId, Lrc<[hir::Freevar]>>,

maybe_unused_trait_imports: FxHashSet<DefId>,

Expand Down Expand Up @@ -1254,10 +1254,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
types: common_types,
trait_map,
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
(k, Lrc::new(v))
(k, Lrc::from(v))
}).collect(),
freevars: resolutions.freevars.into_iter().map(|(k, v)| {
(hir.local_def_id(k), Lrc::new(v))
(hir.local_def_id(k), Lrc::from(v))
}).collect(),
maybe_unused_trait_imports:
resolutions.maybe_unused_trait_imports
Expand Down Expand Up @@ -1335,7 +1335,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.stability_index(LOCAL_CRATE)
}

pub fn crates(self) -> Lrc<Vec<CrateNum>> {
pub fn crates(self) -> Lrc<[CrateNum]> {
self.all_crate_nums(LOCAL_CRATE)
}

Expand Down Expand Up @@ -2450,7 +2450,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

pub fn object_lifetime_defaults(self, id: HirId)
-> Option<Lrc<Vec<ObjectLifetimeDefault>>>
-> Option<Lrc<[ObjectLifetimeDefault]>>
{
self.object_lifetime_defaults_map(id.owner)
.and_then(|map| map.get(&id.local_id).cloned())
Expand Down Expand Up @@ -2529,7 +2529,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
};
providers.maybe_unused_extern_crates = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Lrc::new(tcx.maybe_unused_extern_crates.clone())
Lrc::from(tcx.maybe_unused_extern_crates.clone())
};

providers.stability_index = |tcx, cnum| {
Expand All @@ -2552,11 +2552,11 @@ pub fn provide(providers: &mut ty::maps::Providers) {
};
providers.all_crate_nums = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Lrc::new(tcx.cstore.crates_untracked())
Lrc::from(tcx.cstore.crates_untracked())
};
providers.postorder_cnums = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Lrc::new(tcx.cstore.postorder_cnums_untracked())
Lrc::from(tcx.cstore.postorder_cnums_untracked())
};
providers.output_filenames = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Expand Down
40 changes: 20 additions & 20 deletions src/librustc/ty/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ define_maps! { <'tcx>

/// Maps from def-id of a type or region parameter to its
/// (inferred) variance.
[] fn variances_of: ItemVariances(DefId) -> Lrc<Vec<ty::Variance>>,
[] fn variances_of: ItemVariances(DefId) -> Lrc<[ty::Variance]>,

/// Maps from def-id of a type to its (inferred) outlives.
[] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Vec<ty::Predicate<'tcx>>,

/// Maps from an impl/trait def-id to a list of the def-ids of its items
[] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<Vec<DefId>>,
[] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Lrc<[DefId]>,

/// Maps from a trait item to the trait item "descriptor"
[] fn associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
Expand Down Expand Up @@ -252,7 +252,7 @@ define_maps! { <'tcx>
[] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
[] fn is_mir_available: IsMirAvailable(DefId) -> bool,
[] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
-> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,
-> Lrc<[Option<(DefId, &'tcx Substs<'tcx>)>]>,

[] fn trans_fulfill_obligation: fulfill_obligation_dep_node(
(ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> Vtable<'tcx, ()>,
Expand All @@ -279,7 +279,7 @@ define_maps! { <'tcx>
ty::layout::LayoutError<'tcx>>,

[] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
-> Lrc<Vec<(CrateNum, LinkagePreference)>>,
-> Lrc<[(CrateNum, LinkagePreference)]>,

[fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
[fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
Expand All @@ -294,7 +294,7 @@ define_maps! { <'tcx>
[] fn specializes: specializes_node((DefId, DefId)) -> bool,
[] fn in_scope_traits_map: InScopeTraits(DefIndex)
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<StableVec<TraitCandidate>>>>>,
[] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
[] fn module_exports: ModuleExports(DefId) -> Option<Lrc<[Export]>>,
[] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,

[] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
Expand All @@ -319,9 +319,9 @@ define_maps! { <'tcx>
[] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,


[] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
[] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<[NativeLibrary]>,

[] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<Vec<ForeignModule>>,
[] fn foreign_modules: ForeignModules(CrateNum) -> Lrc<[ForeignModule]>,

[] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
[] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
Expand All @@ -330,17 +330,17 @@ define_maps! { <'tcx>
[] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,

[] fn implementations_of_trait: implementations_of_trait_node((CrateNum, DefId))
-> Lrc<Vec<DefId>>,
-> Lrc<[DefId]>,
[] fn all_trait_implementations: AllTraitImplementations(CrateNum)
-> Lrc<Vec<DefId>>,
-> Lrc<[DefId]>,

[] fn dllimport_foreign_items: DllimportForeignItems(CrateNum)
-> Lrc<FxHashSet<DefId>>,
[] fn is_dllimport_foreign_item: IsDllimportForeignItem(DefId) -> bool,
[] fn is_statically_included_foreign_item: IsStaticallyIncludedForeignItem(DefId) -> bool,
[] fn native_library_kind: NativeLibraryKind(DefId)
-> Option<NativeLibraryKind>,
[] fn link_args: link_args_node(CrateNum) -> Lrc<Vec<String>>,
[] fn link_args: link_args_node(CrateNum) -> Lrc<[String]>,

// Lifetime resolution. See `middle::resolve_lifetimes`.
[] fn resolve_lifetimes: ResolveLifetimes(CrateNum) -> Lrc<ResolveLifetimes>,
Expand All @@ -349,31 +349,31 @@ define_maps! { <'tcx>
[] fn is_late_bound_map: IsLateBound(DefIndex) ->
Option<Lrc<FxHashSet<ItemLocalId>>>,
[] fn object_lifetime_defaults_map: ObjectLifetimeDefaults(DefIndex)
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<[ObjectLifetimeDefault]>>>>,

[] fn visibility: Visibility(DefId) -> ty::Visibility,
[] fn dep_kind: DepKind(CrateNum) -> DepKind,
[] fn crate_name: CrateName(CrateNum) -> Symbol,
[] fn item_children: ItemChildren(DefId) -> Lrc<Vec<Export>>,
[] fn item_children: ItemChildren(DefId) -> Lrc<[Export]>,
[] fn extern_mod_stmt_cnum: ExternModStmtCnum(DefId) -> Option<CrateNum>,

[] fn get_lang_items: get_lang_items_node(CrateNum) -> Lrc<LanguageItems>,
[] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<Vec<(DefId, usize)>>,
[] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<Vec<LangItem>>,
[] fn defined_lang_items: DefinedLangItems(CrateNum) -> Lrc<[(DefId, usize)]>,
[] fn missing_lang_items: MissingLangItems(CrateNum) -> Lrc<[LangItem]>,
[] fn extern_const_body: ExternConstBody(DefId) -> ExternConstBody<'tcx>,
[] fn visible_parent_map: visible_parent_map_node(CrateNum)
-> Lrc<DefIdMap<DefId>>,
[] fn missing_extern_crate_item: MissingExternCrateItem(CrateNum) -> bool,
[] fn used_crate_source: UsedCrateSource(CrateNum) -> Lrc<CrateSource>,
[] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
[] fn postorder_cnums: postorder_cnums_node(CrateNum) -> Lrc<[CrateNum]>,

[] fn freevars: Freevars(DefId) -> Option<Lrc<Vec<hir::Freevar>>>,
[] fn freevars: Freevars(DefId) -> Option<Lrc<[hir::Freevar]>>,
[] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
[] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
-> Lrc<Vec<(DefId, Span)>>,
-> Lrc<[(DefId, Span)]>,

[] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
[] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
[] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<[CrateNum]>,

[] fn exported_symbols: ExportedSymbols(CrateNum)
-> Arc<Vec<(ExportedSymbol, SymbolExportLevel)>>,
Expand Down Expand Up @@ -425,9 +425,9 @@ define_maps! { <'tcx>

[] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,

[] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc<Vec<Clause<'tcx>>>,
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Lrc<[Clause<'tcx>]>,

[] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<Vec<DefId>>,
[] fn wasm_custom_sections: WasmCustomSections(CrateNum) -> Lrc<[DefId]>,
[] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
-> Lrc<FxHashMap<DefId, String>>,
}
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ pub struct CrateVariancesMap {
/// For each item with generics, maps to a vector of the variance
/// of its generics. If an item has no generics, it will have no
/// entry.
pub variances: FxHashMap<DefId, Lrc<Vec<ty::Variance>>>,
pub variances: FxHashMap<DefId, Lrc<[ty::Variance]>>,

/// An empty vector, useful for cloning.
pub empty_variance: Lrc<Vec<ty::Variance>>,
pub empty_variance: Lrc<[ty::Variance]>,
}

impl Variance {
Expand Down Expand Up @@ -2641,7 +2641,7 @@ fn adt_sized_constraint<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> Lrc<Vec<DefId>> {
-> Lrc<[DefId]> {
let id = tcx.hir.as_local_node_id(def_id).unwrap();
let item = tcx.hir.expect_item(id);
let vec: Vec<_> = match item.node {
Expand All @@ -2660,7 +2660,7 @@ fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
hir::ItemTraitAlias(..) => vec![],
_ => span_bug!(item.span, "associated_item_def_ids: not impl or trait")
};
Lrc::new(vec)
Lrc::from(vec)
}

fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span {
Expand Down Expand Up @@ -2772,6 +2772,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
/// (constructing this map requires touching the entire crate).
#[derive(Clone, Debug)]
pub struct CrateInherentImpls {
// Note: needs to be a Lrc<Vec<DefId>> since get_mut().push() is used
pub inherent_impls: DefIdMap<Lrc<Vec<DefId>>>,
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> {
}

pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R,
variances: Option<&Vec<ty::Variance>>,
variances: Option<&[ty::Variance]>,
a_subst: &'tcx Substs<'tcx>,
b_subst: &'tcx Substs<'tcx>)
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
Expand Down
Loading

0 comments on commit 639abc9

Please sign in to comment.