Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
ba4c498
Add more info for Vec Drain doc
pickfire Aug 29, 2020
7148412
Vec slice example fix style and show type elision
pickfire Aug 29, 2020
a80d390
Use inline(never) instead of cold
howard0su Sep 2, 2020
941dca8
Add Arith Tests in Library
Sep 5, 2020
dc37b55
Minor refactoring
Sep 5, 2020
7d834c8
Move Various str tests in library
Sep 5, 2020
d85db82
Add documentation for `impl<T> From<T> for Poll<T>`
notriddle Sep 9, 2020
8b0d0a0
Add documentation for `impl<T> From<BinaryHeap<T>> for Vec<T>`
notriddle Sep 9, 2020
85ab152
Update bootstrap readme
jyn514 Sep 12, 2020
73e0a56
Make all methods of `Duration` const
CDirkx Sep 4, 2020
4f0047e
Add a comment on is_trivially_sized about obviously !Sized types
nox Sep 12, 2020
75f0f7a
Fix a typo
nox Sep 12, 2020
caf6c92
Clean up some language trait items comparisons
nox Sep 12, 2020
2e7ca73
Don't emit an error on private doc tests when they're ignored
GuillaumeGomez Sep 12, 2020
15d25a8
Add test for ignored private doc test
GuillaumeGomez Sep 12, 2020
b7ce5b4
remove orphaned files
tshepang Sep 13, 2020
c9686cb
Introduce a PartitioningCx struct
wesleywiser Jul 26, 2020
0eac38b
fix syntax error in suggesting generic constraint in trait parameter
iximeow Sep 14, 2020
dd57275
shrink const infer error
lcnr Sep 14, 2020
035f879
improve const infer err
lcnr Sep 14, 2020
b881551
Simplify iter flatten struct doc
pickfire Sep 14, 2020
43709f7
:arrow_up: rust-analyzer
Sep 14, 2020
5112f87
Remove flatten doc intra-doc links
pickfire Sep 14, 2020
1f26a18
Use intra-doc links for `DelaySpanBugEmitted`
camelid Sep 14, 2020
15349ef
Minor improvements to `mir::Constant` docs
camelid Sep 14, 2020
5c1043a
Fix diagram for `DebruijnIndex`
camelid Sep 14, 2020
e1607c8
clean up comment text a bit
iximeow Sep 14, 2020
32efcfc
Include non-JSON output in error display for lint-doc failure.
ehuss Sep 14, 2020
9dad908
Fix generating rustc docs with non-default lib directory.
ehuss Sep 14, 2020
58310ce
Use intra-doc links in `core::mem`
camelid Sep 14, 2020
f7f9a6c
Add a comment why `extern crate` is necessary for rustdoc
jyn514 Sep 15, 2020
1c7204f
Prefer asm! over llvm_asm! in core
tesuji Sep 14, 2020
1f572b0
Vec doc use elision as code rather than comment
pickfire Sep 15, 2020
176956c
Test and fix Sync & Send traits of BTreeMap artefacts
ssomers Sep 14, 2020
b93a831
Add a comment why rustdoc loads crates from the sysroot
jyn514 Sep 15, 2020
5f3145f
Avoid printing dry run timings
Mark-Simulacrum Sep 15, 2020
328c61c
Make the default stage for x.py configurable
jyn514 Sep 12, 2020
21b0c12
Extract some intrinsics out of rustc_codegen_llvm
khyperia Sep 15, 2020
e0c1621
Update books
ehuss Sep 15, 2020
eeffc1c
Rollup merge of #76056 - pickfire:patch-10, r=jyn514
Dylan-DPC Sep 16, 2020
fe989e9
Rollup merge of #76062 - pickfire:patch-13, r=jyn514
Dylan-DPC Sep 16, 2020
f2d9579
Rollup merge of #76262 - howard0su:patch-1, r=cramertj
Dylan-DPC Sep 16, 2020
bc42cd8
Rollup merge of #76335 - CDirkx:const-duration, r=ecstatic-morse
Dylan-DPC Sep 16, 2020
921c15c
Rollup merge of #76366 - ayushmishra2005:arith_tests_in_library, r=jy…
Dylan-DPC Sep 16, 2020
53cb50d
Rollup merge of #76369 - ayushmishra2005:move_various_str_tests_libra…
Dylan-DPC Sep 16, 2020
651210c
Rollup merge of #76534 - notriddle:doc-comments, r=jyn514
Dylan-DPC Sep 16, 2020
ca2db9e
Rollup merge of #76622 - jyn514:bootstrap-readme, r=Mark-Simulacrum
Dylan-DPC Sep 16, 2020
d33c57c
Rollup merge of #76625 - jyn514:default-stages, r=Mark-Simulacrum
Dylan-DPC Sep 16, 2020
0224a3e
Rollup merge of #76641 - nox:pointee-random-stuff, r=eddyb
Dylan-DPC Sep 16, 2020
b0e36db
Rollup merge of #76642 - GuillaumeGomez:ignored-private-doc-test, r=j…
Dylan-DPC Sep 16, 2020
1012d66
Rollup merge of #76669 - lzutao:core_asm, r=Amanieu
Dylan-DPC Sep 16, 2020
b5c8816
Rollup merge of #76681 - tshepang:unused, r=Mark-Simulacrum
Dylan-DPC Sep 16, 2020
0f834e6
Rollup merge of #76694 - wesleywiser:partitioning_cx_trait, r=davidtwco
Dylan-DPC Sep 16, 2020
f4be98a
Rollup merge of #76695 - iximeow:trait-generic-bound-suggestion, r=es…
Dylan-DPC Sep 16, 2020
55b9088
Rollup merge of #76699 - lcnr:const-infer-err, r=varkor
Dylan-DPC Sep 16, 2020
6ef8299
Rollup merge of #76707 - pickfire:patch-4, r=jonas-schievink
Dylan-DPC Sep 16, 2020
51fd7db
Rollup merge of #76710 - rust-lang:rust-analyzer-2020-09-14, r=jonas-…
Dylan-DPC Sep 16, 2020
ce2041b
Rollup merge of #76714 - camelid:patch-3, r=jonas-schievink
Dylan-DPC Sep 16, 2020
75cd58e
Rollup merge of #76717 - ehuss:fix-rustc-book-libdir, r=Mark-Simulacrum
Dylan-DPC Sep 16, 2020
dcb5c5b
Rollup merge of #76721 - camelid:intra-doc-links-for-core-mem, r=jyn514
Dylan-DPC Sep 16, 2020
d99896b
Rollup merge of #76722 - ssomers:btree_send_sync, r=Mark-Simulacrum
Dylan-DPC Sep 16, 2020
36bf0c9
Rollup merge of #76728 - jyn514:rustdoc-extern-crate, r=ehuss
Dylan-DPC Sep 16, 2020
31e0815
Rollup merge of #76741 - Mark-Simulacrum:no-dry-run-timing, r=alexcri…
Dylan-DPC Sep 16, 2020
f868f02
Rollup merge of #76764 - ehuss:update-books, r=ehuss
Dylan-DPC Sep 16, 2020
32ff2c9
Rollup merge of #76766 - khyperia:generic_intrinsics, r=eddyb
Dylan-DPC Sep 16, 2020
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
Prev Previous commit
Next Next commit
Introduce a PartitioningCx struct
  • Loading branch information
wesleywiser committed Sep 14, 2020
commit c9686cb31ad9dd9428825dbb3b362f5df72ab719
32 changes: 16 additions & 16 deletions compiler/rustc_mir/src/monomorphize/partitioning/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_middle::ty::print::characteristic_def_id_of_type;
use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt};
use rustc_span::symbol::Symbol;

use super::PartitioningCx;
use crate::monomorphize::collector::InliningMap;
use crate::monomorphize::partitioning::merging;
use crate::monomorphize::partitioning::{
Expand All @@ -22,35 +23,36 @@ pub struct DefaultPartitioning;
impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
fn place_root_mono_items(
&mut self,
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
mono_items: &mut dyn Iterator<Item = MonoItem<'tcx>>,
) -> PreInliningPartitioning<'tcx> {
let mut roots = FxHashSet::default();
let mut codegen_units = FxHashMap::default();
let is_incremental_build = tcx.sess.opts.incremental.is_some();
let is_incremental_build = cx.tcx.sess.opts.incremental.is_some();
let mut internalization_candidates = FxHashSet::default();

// Determine if monomorphizations instantiated in this crate will be made
// available to downstream crates. This depends on whether we are in
// share-generics mode and whether the current crate can even have
// downstream crates.
let export_generics = tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics();
let export_generics =
cx.tcx.sess.opts.share_generics() && cx.tcx.local_crate_exports_generics();

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
let cgu_name_cache = &mut FxHashMap::default();

for mono_item in mono_items {
match mono_item.instantiation_mode(tcx) {
match mono_item.instantiation_mode(cx.tcx) {
InstantiationMode::GloballyShared { .. } => {}
InstantiationMode::LocalCopy => continue,
}

let characteristic_def_id = characteristic_def_id_of_mono_item(tcx, mono_item);
let characteristic_def_id = characteristic_def_id_of_mono_item(cx.tcx, mono_item);
let is_volatile = is_incremental_build && mono_item.is_generic_fn();

let codegen_unit_name = match characteristic_def_id {
Some(def_id) => compute_codegen_unit_name(
tcx,
cx.tcx,
cgu_name_builder,
def_id,
is_volatile,
Expand All @@ -65,7 +67,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {

let mut can_be_internalized = true;
let (linkage, visibility) = mono_item_linkage_and_visibility(
tcx,
cx.tcx,
&mono_item,
&mut can_be_internalized,
export_generics,
Expand Down Expand Up @@ -97,17 +99,16 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {

fn merge_codegen_units(
&mut self,
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
target_cgu_count: usize,
) {
merging::merge_codegen_units(tcx, initial_partitioning, target_cgu_count);
merging::merge_codegen_units(cx, initial_partitioning);
}

fn place_inlined_mono_items(
&mut self,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: PreInliningPartitioning<'tcx>,
inlining_map: &InliningMap<'tcx>,
) -> PostInliningPartitioning<'tcx> {
let mut new_partitioning = Vec::new();
let mut mono_item_placements = FxHashMap::default();
Expand All @@ -124,7 +125,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
// Collect all items that need to be available in this codegen unit.
let mut reachable = FxHashSet::default();
for root in old_codegen_unit.items().keys() {
follow_inlining(*root, inlining_map, &mut reachable);
follow_inlining(*root, cx.inlining_map, &mut reachable);
}

let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name());
Expand Down Expand Up @@ -198,9 +199,8 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {

fn internalize_symbols(
&mut self,
_tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
partitioning: &mut PostInliningPartitioning<'tcx>,
inlining_map: &InliningMap<'tcx>,
) {
if partitioning.codegen_units.len() == 1 {
// Fast path for when there is only one codegen unit. In this case we
Expand All @@ -218,7 +218,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
// Build a map from every monomorphization to all the monomorphizations that
// reference it.
let mut accessor_map: FxHashMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>> = Default::default();
inlining_map.iter_accesses(|accessor, accessees| {
cx.inlining_map.iter_accesses(|accessor, accessees| {
for accessee in accessees {
accessor_map.entry(*accessee).or_default().push(accessor);
}
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_mir/src/monomorphize/partitioning/merging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ use std::cmp;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder};
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::{Symbol, SymbolStr};

use super::PartitioningCx;
use crate::monomorphize::partitioning::PreInliningPartitioning;

pub fn merge_codegen_units<'tcx>(
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
target_cgu_count: usize,
) {
assert!(target_cgu_count >= 1);
assert!(cx.target_cgu_count >= 1);
let codegen_units = &mut initial_partitioning.codegen_units;

// Note that at this point in time the `codegen_units` here may not be in a
Expand All @@ -32,7 +31,7 @@ pub fn merge_codegen_units<'tcx>(
codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name().as_str()])).collect();

// Merge the two smallest codegen units until the target size is reached.
while codegen_units.len() > target_cgu_count {
while codegen_units.len() > cx.target_cgu_count {
// Sort small cgus to the back
codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate()));
let mut smallest = codegen_units.pop().unwrap();
Expand All @@ -56,9 +55,9 @@ pub fn merge_codegen_units<'tcx>(
);
}

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);

if tcx.sess.opts.incremental.is_some() {
if cx.tcx.sess.opts.incremental.is_some() {
// If we are doing incremental compilation, we want CGU names to
// reflect the path of the source level module they correspond to.
// For CGUs that contain the code of multiple modules because of the
Expand All @@ -82,7 +81,7 @@ pub fn merge_codegen_units<'tcx>(

for cgu in codegen_units.iter_mut() {
if let Some(new_cgu_name) = new_cgu_names.get(&cgu.name()) {
if tcx.sess.opts.debugging_opts.human_readable_cgu_names {
if cx.tcx.sess.opts.debugging_opts.human_readable_cgu_names {
cgu.set_name(Symbol::intern(&new_cgu_name));
} else {
// If we don't require CGU names to be human-readable, we
Expand Down
25 changes: 15 additions & 10 deletions compiler/rustc_mir/src/monomorphize/partitioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,35 @@ use rustc_span::symbol::Symbol;
use crate::monomorphize::collector::InliningMap;
use crate::monomorphize::collector::{self, MonoItemCollectionMode};

pub struct PartitioningCx<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
target_cgu_count: usize,
inlining_map: &'a InliningMap<'tcx>,
}

trait Partitioner<'tcx> {
fn place_root_mono_items(
&mut self,
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
mono_items: &mut dyn Iterator<Item = MonoItem<'tcx>>,
) -> PreInliningPartitioning<'tcx>;

fn merge_codegen_units(
&mut self,
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
target_cgu_count: usize,
);

fn place_inlined_mono_items(
&mut self,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: PreInliningPartitioning<'tcx>,
inlining_map: &InliningMap<'tcx>,
) -> PostInliningPartitioning<'tcx>;

fn internalize_symbols(
&mut self,
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
partitioning: &mut PostInliningPartitioning<'tcx>,
inlining_map: &InliningMap<'tcx>,
);
}

Expand All @@ -156,12 +160,13 @@ pub fn partition<'tcx>(
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning");

let mut partitioner = get_partitioner(tcx);
let cx = &PartitioningCx { tcx, target_cgu_count: max_cgu_count, inlining_map };
// In the first step, we place all regular monomorphizations into their
// respective 'home' codegen unit. Regular monomorphizations are all
// functions and statics defined in the local crate.
let mut initial_partitioning = {
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_roots");
partitioner.place_root_mono_items(tcx, mono_items)
partitioner.place_root_mono_items(cx, mono_items)
};

initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
Expand All @@ -171,7 +176,7 @@ pub fn partition<'tcx>(
// Merge until we have at most `max_cgu_count` codegen units.
{
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
partitioner.merge_codegen_units(tcx, &mut initial_partitioning, max_cgu_count);
partitioner.merge_codegen_units(cx, &mut initial_partitioning);
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
}

Expand All @@ -181,7 +186,7 @@ pub fn partition<'tcx>(
// local functions the definition of which is marked with `#[inline]`.
let mut post_inlining = {
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_inline_items");
partitioner.place_inlined_mono_items(initial_partitioning, inlining_map)
partitioner.place_inlined_mono_items(cx, initial_partitioning)
};

post_inlining.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
Expand All @@ -192,7 +197,7 @@ pub fn partition<'tcx>(
// more freedom to optimize.
if !tcx.sess.link_dead_code() {
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
partitioner.internalize_symbols(tcx, &mut post_inlining, inlining_map);
partitioner.internalize_symbols(cx, &mut post_inlining);
}

// Finally, sort by codegen unit name, so that we get deterministic results.
Expand Down