Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rc<str> and Rc<[T]> instead of Rc<String> and Rc<Vec<T>> #49645

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -824,11 +824,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 @@ -871,7 +871,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 @@ -847,7 +847,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 @@ -860,7 +860,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 @@ -1255,10 +1255,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 @@ -1338,7 +1338,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 @@ -2617,7 +2617,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 @@ -2696,7 +2696,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 @@ -2719,11 +2719,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 @@ -136,13 +136,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 @@ -256,7 +256,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 @@ -283,7 +283,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 @@ -298,7 +298,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 Down Expand Up @@ -329,9 +329,9 @@ define_maps! { <'tcx>
[] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId)
-> Option<Lrc<FxHashMap<&'tcx Substs<'tcx>, CrateNum>>>,

[] 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 @@ -341,17 +341,17 @@ define_maps! { <'tcx>
[] fn extra_filename: ExtraFileName(CrateNum) -> String,

[] 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 @@ -360,31 +360,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<'tcx>, SymbolExportLevel)>>,
Expand Down Expand Up @@ -435,9 +435,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