Skip to content

Rollup of 14 pull requests #79200

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

Merged
merged 43 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
91eabf5
Add a sane error for rust-call functions not taking tuples during typ…
CraftSpider Nov 11, 2020
bf04b04
Missing feature-gate-abi file
CraftSpider Nov 11, 2020
1e9d5c7
Minor stylistic / review changes
CraftSpider Nov 12, 2020
2b7ffec
Don't special case constant operands when lowering intrinsics
tmiasko Nov 16, 2020
207de01
libary: Forward compiler-builtins "asm" and "mangled-names" feature
stlankes Nov 16, 2020
c03790f
Add //ignore-macos to pretty-std-collections.rs
est31 Nov 16, 2020
ed26f6e
compiletest: Fix a warning in debuginfo tests on windows-gnu
petrochenkov Nov 16, 2020
78a37f8
add optimization fuel checks to some mir passes
cjkenn Nov 16, 2020
2a5a379
Add two regression tests
Alexendoo Nov 16, 2020
b4c9424
update ui test for increased fuel usage
cjkenn Nov 17, 2020
92aa0e6
Use `span_suggestion_verbose` instead of `span_suggestion` for `fn` w…
ThePuzzlemaker Nov 15, 2020
b8ed466
Fix ui tests for `fn`s with qualifiers in `extern` blocks
ThePuzzlemaker Nov 15, 2020
c825c74
Move change to check_fn, fix up overloaded-calls-nontuple
CraftSpider Nov 17, 2020
e8426a6
Remove unnecessary abi import
CraftSpider Nov 17, 2020
614a748
Highlight MIR as Rust on GitHub
camelid Nov 17, 2020
7faebe5
Move capture lowering from THIR to MIR
arora-aman Nov 17, 2020
9f70e78
Remove THIR::ExprKind::SelfRef
arora-aman Nov 17, 2020
36972b0
fix handling the default config for profiler and sanitizers
12101111 Nov 18, 2020
5163912
Allow using `download-ci-llvm` from directories other than the root
jyn514 Nov 18, 2020
efcbf1b
Permit standalone generic parameters as const generic arguments in ma…
varkor Nov 18, 2020
85bc953
Add tests for multi-segment paths in const generic arguments
varkor Nov 18, 2020
51c2218
move fuel checks to later points in instcombine and const_prop, add o…
cjkenn Nov 18, 2020
1e524fb
change print-fuel ui test to check-pass
cjkenn Nov 18, 2020
2098ade
Remove redundant notes in E0275
estebank Nov 16, 2020
3527964
Account for indirect cyclic requirements
estebank Nov 18, 2020
c12e77b
review comment
estebank Nov 18, 2020
b556690
move checks later into optimization passes
cjkenn Nov 19, 2020
1d3305a
remove check from const promotion
cjkenn Nov 19, 2020
07de702
update print fuel test output again...
cjkenn Nov 19, 2020
5a58b50
Rollup merge of #78961 - CraftSpider:22565, r=oli-obk
Dylan-DPC Nov 19, 2020
3f0f224
Rollup merge of #79082 - ThePuzzlemaker:issue-78941-fix, r=estebank
Dylan-DPC Nov 19, 2020
29c8e50
Rollup merge of #79090 - hermitcore:builtins, r=Mark-Simulacrum
Dylan-DPC Nov 19, 2020
552d8c5
Rollup merge of #79094 - est31:ignore_macos, r=pietroalbini
Dylan-DPC Nov 19, 2020
05ff58e
Rollup merge of #79101 - tmiasko:lower-func-type, r=jonas-schievink
Dylan-DPC Nov 19, 2020
6010f7b
Rollup merge of #79102 - Alexendoo:ice-regression-tests, r=Mark-Simul…
Dylan-DPC Nov 19, 2020
470f768
Rollup merge of #79110 - estebank:issue-58964, r=oli-obk
Dylan-DPC Nov 19, 2020
04a4404
Rollup merge of #79116 - petrochenkov:gdbwarn, r=Mark-Simulacrum
Dylan-DPC Nov 19, 2020
2fdcd24
Rollup merge of #79117 - cjkenn:mir-fuel, r=oli-obk
Dylan-DPC Nov 19, 2020
62838c6
Rollup merge of #79147 - camelid:mir-gitattributes, r=oli-obk
Dylan-DPC Nov 19, 2020
5c7d530
Rollup merge of #79149 - sexxi-goose:upvar_ref, r=nikomatsakis
Dylan-DPC Nov 19, 2020
3b857a5
Rollup merge of #79155 - 12101111:fix-profiler-config, r=Mark-Simulacrum
Dylan-DPC Nov 19, 2020
de62272
Rollup merge of #79156 - jyn514:relative-llvm, r=Mark-Simulacrum
Dylan-DPC Nov 19, 2020
b5fffdc
Rollup merge of #79164 - varkor:unbraced-single-segment-const-argumen…
Dylan-DPC Nov 19, 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.h rust
*.rs rust diff=rust
*.fixed linguist-language=Rust
*.mir linguist-language=Rust
src/etc/installer/gfx/* binary
*.woff binary
src/vendor/** -text
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl<'a> AstValidator<'a> {
self.err_handler()
.struct_span_err(ident.span, "functions in `extern` blocks cannot have qualifiers")
.span_label(self.current_extern_span(), "in this `extern` block")
.span_suggestion(
.span_suggestion_verbose(
span.until(ident.span.shrink_to_lo()),
"remove the qualifiers",
"fn ".to_string(),
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_mir/src/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}
}

trace!("attepting to replace {:?} with {:?}", rval, value);
trace!("attempting to replace {:?} with {:?}", rval, value);
if let Err(e) = self.ecx.const_validate_operand(
value,
vec![],
Expand Down Expand Up @@ -890,6 +890,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
return false;
}

if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - OpTy: {:?}", op)) {
return false;
}

match *op {
interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUninit::Scalar(s))) => {
s.is_bits()
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_mir/src/transform/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
let should_cleanup = !opts_to_apply.is_empty();

for opt_to_apply in opts_to_apply {
if !tcx.consider_optimizing(|| format!("EarlyOtherwiseBranch {:?}", &opt_to_apply)) {
break;
}

trace!("SUCCESS: found optimization possibility to apply: {:?}", &opt_to_apply);

let statements_before =
Expand Down
28 changes: 21 additions & 7 deletions compiler/rustc_mir/src/transform/instcombine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ pub struct InstCombineVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
}

impl<'tcx> InstCombineVisitor<'tcx> {
fn should_combine(&self, rvalue: &Rvalue<'tcx>, location: Location) -> bool {
self.tcx.consider_optimizing(|| {
format!("InstCombine - Rvalue: {:?} Location: {:?}", rvalue, location)
})
}
}

impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}

fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
if self.optimizations.and_stars.remove(&location) {
if self.optimizations.and_stars.remove(&location) && self.should_combine(rvalue, location) {
debug!("replacing `&*`: {:?}", rvalue);
let new_place = match rvalue {
Rvalue::Ref(_, _, place) => {
Expand All @@ -67,18 +75,24 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
}

if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) {
debug!("replacing `Len([_; N])`: {:?}", rvalue);
*rvalue = Rvalue::Use(Operand::Constant(box constant));
if self.should_combine(rvalue, location) {
debug!("replacing `Len([_; N])`: {:?}", rvalue);
*rvalue = Rvalue::Use(Operand::Constant(box constant));
}
}

if let Some(operand) = self.optimizations.unneeded_equality_comparison.remove(&location) {
debug!("replacing {:?} with {:?}", rvalue, operand);
*rvalue = Rvalue::Use(operand);
if self.should_combine(rvalue, location) {
debug!("replacing {:?} with {:?}", rvalue, operand);
*rvalue = Rvalue::Use(operand);
}
}

if let Some(place) = self.optimizations.unneeded_deref.remove(&location) {
debug!("unneeded_deref: replacing {:?} with {:?}", rvalue, place);
*rvalue = Rvalue::Use(Operand::Copy(place));
if self.should_combine(rvalue, location) {
debug!("unneeded_deref: replacing {:?} with {:?}", rvalue, place);
*rvalue = Rvalue::Use(Operand::Copy(place));
}
}

self.super_rvalue(rvalue, location)
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_mir/src/transform/lower_intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ pub struct LowerIntrinsics;

impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
for block in body.basic_blocks_mut() {
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
for block in basic_blocks {
let terminator = block.terminator.as_mut().unwrap();
if let TerminatorKind::Call {
func: Operand::Constant(box Constant { literal: ty::Const { ty: func_ty, .. }, .. }),
args,
destination,
..
} = &mut terminator.kind
{
if let TerminatorKind::Call { func, args, destination, .. } = &mut terminator.kind {
let func_ty = func.ty(local_decls, tcx);
let (intrinsic_name, substs) = match resolve_rust_intrinsic(tcx, func_ty) {
None => continue,
Some(it) => it,
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_mir/src/transform/match_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
}

let param_env = tcx.param_env(body.source.def_id());
let def_id = body.source.def_id();
let (bbs, local_decls) = body.basic_blocks_and_local_decls_mut();
'outer: for bb_idx in bbs.indices() {
if !tcx.consider_optimizing(|| format!("MatchBranchSimplification {:?} ", def_id)) {
continue;
}

let (discr, val, switch_ty, first, second) = match bbs[bb_idx].terminator().kind {
TerminatorKind::SwitchInt {
discr: ref discr @ (Operand::Copy(_) | Operand::Move(_)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {

// find basic blocks with no statement and a return terminator
let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks().len());
let def_id = body.source.def_id();
let bbs = body.basic_blocks_mut();
for idx in bbs.indices() {
if bbs[idx].statements.is_empty()
Expand All @@ -26,6 +27,10 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
}

for bb in bbs {
if !tcx.consider_optimizing(|| format!("MultipleReturnTerminators {:?} ", def_id)) {
break;
}

if let TerminatorKind::Goto { target } = bb.terminator().kind {
if bbs_simple_returns.contains(target) {
bb.terminator_mut().kind = TerminatorKind::Return;
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_mir/src/transform/nrvo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
return;
}

let def_id = body.source.def_id();
let returned_local = match local_eligible_for_nrvo(body) {
Some(l) => l,
None => {
debug!("`{:?}` was ineligible for NRVO", body.source.def_id());
debug!("`{:?}` was ineligible for NRVO", def_id);
return;
}
};

if !tcx.consider_optimizing(|| format!("RenameReturnPlace {:?}", def_id)) {
return;
}

debug!(
"`{:?}` was eligible for NRVO, making {:?} the return place",
body.source.def_id(),
returned_local
def_id, returned_local
);

RenameToReturnPlace { tcx, to_rename: returned_local }.visit_body(body);
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_mir/src/transform/remove_unneeded_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
opt_finder.visit_body(body);
let should_simplify = !opt_finder.optimizations.is_empty();
for (loc, target) in opt_finder.optimizations {
if !tcx
.consider_optimizing(|| format!("RemoveUnneededDrops {:?} ", body.source.def_id()))
{
break;
}

let terminator = body.basic_blocks_mut()[loc.block].terminator_mut();
debug!("SUCCESS: replacing `drop` with goto({:?})", target);
terminator.kind = TerminatorKind::Goto { target };
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_mir/src/transform/unreachable_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ impl MirPass<'_> for UnreachablePropagation {

let replaced = !replacements.is_empty();
for (bb, terminator_kind) in replacements {
if !tcx.consider_optimizing(|| {
format!("UnreachablePropagation {:?} ", body.source.def_id())
}) {
break;
}

body.basic_blocks_mut()[bb].terminator_mut().kind = terminator_kind;
}

Expand Down
80 changes: 79 additions & 1 deletion compiler/rustc_mir_build/src/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
expr_span,
source_info,
),
ExprKind::SelfRef => block.and(PlaceBuilder::from(Local::new(1))),
ExprKind::UpvarRef { closure_def_id, var_hir_id } => {
let capture = this
.hir
.typeck_results
.closure_captures
.get(&closure_def_id)
.and_then(|captures| captures.get_full(&var_hir_id));

if capture.is_none() {
if !this.hir.tcx().features().capture_disjoint_fields {
bug!(
"No associated capture found for {:?} even though \
capture_disjoint_fields isn't enabled",
expr.kind
)
}
// FIXME(project-rfc-2229#24): Handle this case properly
}

// Unwrap until the FIXME has been resolved
let (capture_index, _, upvar_id) = capture.unwrap();
this.lower_closure_capture(block, capture_index, *upvar_id)
}

ExprKind::VarRef { id } => {
let place_builder = if this.is_bound_var_in_guard(id) {
let index = this.var_local_id(id, RefWithinGuard);
Expand Down Expand Up @@ -270,6 +293,61 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}

/// Lower a closure/generator capture by representing it as a field
/// access within the desugared closure/generator.
///
/// `capture_index` is the index of the capture within the desugared
/// closure/generator.
fn lower_closure_capture(
&mut self,
block: BasicBlock,
capture_index: usize,
upvar_id: ty::UpvarId,
) -> BlockAnd<PlaceBuilder<'tcx>> {
let closure_ty = self
.hir
.typeck_results()
.node_type(self.hir.tcx().hir().local_def_id_to_hir_id(upvar_id.closure_expr_id));

// Captures are represented using fields inside a structure.
// This represents accessing self in the closure structure
let mut place_builder = PlaceBuilder::from(Local::new(1));

// In case of Fn/FnMut closures we must deref to access the fields
// Generators are considered FnOnce, so we ignore this step for them.
if let ty::Closure(_, closure_substs) = closure_ty.kind() {
match self.hir.infcx().closure_kind(closure_substs).unwrap() {
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => {
place_builder = place_builder.deref();
}
ty::ClosureKind::FnOnce => {}
}
}

let substs = match closure_ty.kind() {
ty::Closure(_, substs) => ty::UpvarSubsts::Closure(substs),
ty::Generator(_, substs, _) => ty::UpvarSubsts::Generator(substs),
_ => bug!("Lowering capture for non-closure type {:?}", closure_ty)
};

// Access the capture by accessing the field within the Closure struct.
//
// We must have inferred the capture types since we are building MIR, therefore
// it's safe to call `upvar_tys` and we can unwrap here because
// we know that the capture exists and is the `capture_index`-th capture.
let var_ty = substs.upvar_tys().nth(capture_index).unwrap();
place_builder = place_builder.field(Field::new(capture_index), var_ty);

// If the variable is captured via ByRef(Immutable/Mutable) Borrow,
// we need to deref it
match self.hir.typeck_results.upvar_capture(upvar_id) {
ty::UpvarCapture::ByRef(_) => {
block.and(place_builder.deref())
}
ty::UpvarCapture::ByValue(_) => block.and(place_builder),
}
}

/// Lower an index expression
///
/// This has two complications;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
| ExprKind::Deref { .. }
| ExprKind::Index { .. }
| ExprKind::VarRef { .. }
| ExprKind::SelfRef
| ExprKind::UpvarRef { .. }
| ExprKind::Break { .. }
| ExprKind::Continue { .. }
| ExprKind::Return { .. }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Category {
ExprKind::Field { .. }
| ExprKind::Deref { .. }
| ExprKind::Index { .. }
| ExprKind::SelfRef
| ExprKind::UpvarRef { .. }
| ExprKind::VarRef { .. }
| ExprKind::PlaceTypeAscription { .. }
| ExprKind::ValueTypeAscription { .. } => Some(Category::Place),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

// Avoid creating a temporary
ExprKind::VarRef { .. }
| ExprKind::SelfRef
| ExprKind::UpvarRef { .. }
| ExprKind::PlaceTypeAscription { .. }
| ExprKind::ValueTypeAscription { .. } => {
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
Expand Down
Loading