Skip to content

Commit 128b4c8

Browse files
committed
Auto merge of #60969 - Centril:rollup-3j71mqj, r=Centril
Rollup of 6 pull requests Successful merges: - #60590 (Test interaction of unions with non-zero/niche-filling optimization) - #60745 (Perform constant propagation into terminators) - #60895 (Enable thumbv7a-pc-windows-msvc target build end to end in rust/master) - #60908 (Fix lints handling in rustdoc) - #60960 (Stop using gensyms in HIR lowering) - #60962 (Fix data types indication) Failed merges: r? @ghost
2 parents a5000c5 + 614ffe5 commit 128b4c8

File tree

23 files changed

+402
-128
lines changed

23 files changed

+402
-128
lines changed

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl Step for RustdocUi {
683683
target: self.target,
684684
mode: "ui",
685685
suite: "rustdoc-ui",
686-
path: None,
686+
path: Some("src/test/rustdoc-ui"),
687687
compare_mode: None,
688688
})
689689
}

src/libcore/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ pub trait Pointer {
886886
///
887887
/// # Examples
888888
///
889-
/// Basic usage with `i32`:
889+
/// Basic usage with `f64`:
890890
///
891891
/// ```
892892
/// let x = 42.0; // 42.0 is '4.2e1' in scientific notation
@@ -929,7 +929,7 @@ pub trait LowerExp {
929929
///
930930
/// # Examples
931931
///
932-
/// Basic usage with `f32`:
932+
/// Basic usage with `f64`:
933933
///
934934
/// ```
935935
/// let x = 42.0; // 42.0 is '4.2E1' in scientific notation

src/librustc/hir/lowering.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,6 @@ impl<'a> LoweringContext<'a> {
855855
self.sess.diagnostic()
856856
}
857857

858-
fn str_to_ident(&self, s: &'static str) -> Ident {
859-
Ident::with_empty_ctxt(Symbol::gensym(s))
860-
}
861-
862858
fn with_anonymous_lifetime_mode<R>(
863859
&mut self,
864860
anonymous_lifetime_mode: AnonymousLifetimeMode,
@@ -4621,18 +4617,18 @@ impl<'a> LoweringContext<'a> {
46214617
);
46224618
head.span = desugared_span;
46234619

4624-
let iter = self.str_to_ident("iter");
4620+
let iter = Ident::with_empty_ctxt(sym::iter);
46254621

4626-
let next_ident = self.str_to_ident("__next");
4622+
let next_ident = Ident::with_empty_ctxt(sym::__next);
46274623
let (next_pat, next_pat_hid) = self.pat_ident_binding_mode(
46284624
desugared_span,
46294625
next_ident,
46304626
hir::BindingAnnotation::Mutable,
46314627
);
46324628

4633-
// `::std::option::Option::Some(val) => next = val`
4629+
// `::std::option::Option::Some(val) => __next = val`
46344630
let pat_arm = {
4635-
let val_ident = self.str_to_ident("val");
4631+
let val_ident = Ident::with_empty_ctxt(sym::val);
46364632
let (val_pat, val_pat_hid) = self.pat_ident(pat.span, val_ident);
46374633
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat_hid));
46384634
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat_hid));
@@ -4771,17 +4767,13 @@ impl<'a> LoweringContext<'a> {
47714767
let unstable_span = self.sess.source_map().mark_span_with_reason(
47724768
CompilerDesugaringKind::QuestionMark,
47734769
e.span,
4774-
Some(vec![
4775-
Symbol::intern("try_trait")
4776-
].into()),
4770+
Some(vec![sym::try_trait].into()),
47774771
);
47784772
let try_span = self.sess.source_map().end_point(e.span);
47794773
let try_span = self.sess.source_map().mark_span_with_reason(
47804774
CompilerDesugaringKind::QuestionMark,
47814775
try_span,
4782-
Some(vec![
4783-
Symbol::intern("try_trait")
4784-
].into()),
4776+
Some(vec![sym::try_trait].into()),
47854777
);
47864778

47874779
// `Try::into_result(<expr>)`
@@ -4802,7 +4794,8 @@ impl<'a> LoweringContext<'a> {
48024794
// `allow(unreachable_code)`
48034795
let allow = {
48044796
let allow_ident = Ident::with_empty_ctxt(sym::allow).with_span_pos(e.span);
4805-
let uc_ident = Ident::from_str("unreachable_code").with_span_pos(e.span);
4797+
let uc_ident = Ident::with_empty_ctxt(sym::unreachable_code)
4798+
.with_span_pos(e.span);
48064799
let uc_nested = attr::mk_nested_word_item(uc_ident);
48074800
attr::mk_list_item(e.span, allow_ident, vec![uc_nested])
48084801
};
@@ -4812,7 +4805,7 @@ impl<'a> LoweringContext<'a> {
48124805

48134806
// `Ok(val) => #[allow(unreachable_code)] val,`
48144807
let ok_arm = {
4815-
let val_ident = self.str_to_ident("val");
4808+
let val_ident = Ident::with_empty_ctxt(sym::val);
48164809
let (val_pat, val_pat_nid) = self.pat_ident(e.span, val_ident);
48174810
let val_expr = P(self.expr_ident_with_attrs(
48184811
e.span,
@@ -4828,7 +4821,7 @@ impl<'a> LoweringContext<'a> {
48284821
// `Err(err) => #[allow(unreachable_code)]
48294822
// return Try::from_error(From::from(err)),`
48304823
let err_arm = {
4831-
let err_ident = self.str_to_ident("err");
4824+
let err_ident = Ident::with_empty_ctxt(sym::err);
48324825
let (err_local, err_local_nid) = self.pat_ident(try_span, err_ident);
48334826
let from_expr = {
48344827
let from_path = &[sym::convert, sym::From, sym::from];
@@ -5552,7 +5545,7 @@ impl<'a> LoweringContext<'a> {
55525545
// match ::std::future::poll_with_tls_context(unsafe {
55535546
// ::std::pin::Pin::new_unchecked(&mut pinned)
55545547
// }) {
5555-
// ::std::task::Poll::Ready(x) => break x,
5548+
// ::std::task::Poll::Ready(result) => break result,
55565549
// ::std::task::Poll::Pending => {},
55575550
// }
55585551
// yield ();
@@ -5580,12 +5573,12 @@ impl<'a> LoweringContext<'a> {
55805573
let gen_future_span = self.sess.source_map().mark_span_with_reason(
55815574
CompilerDesugaringKind::Await,
55825575
await_span,
5583-
Some(vec![Symbol::intern("gen_future")].into()),
5576+
Some(vec![sym::gen_future].into()),
55845577
);
55855578

55865579
// let mut pinned = <expr>;
55875580
let expr = P(self.lower_expr(expr));
5588-
let pinned_ident = self.str_to_ident("pinned");
5581+
let pinned_ident = Ident::with_empty_ctxt(sym::pinned);
55895582
let (pinned_pat, pinned_pat_hid) = self.pat_ident_binding_mode(
55905583
span,
55915584
pinned_ident,
@@ -5621,11 +5614,11 @@ impl<'a> LoweringContext<'a> {
56215614
))
56225615
};
56235616

5624-
// `::std::task::Poll::Ready(x) => break x`
5617+
// `::std::task::Poll::Ready(result) => break result`
56255618
let loop_node_id = self.sess.next_node_id();
56265619
let loop_hir_id = self.lower_node_id(loop_node_id);
56275620
let ready_arm = {
5628-
let x_ident = self.str_to_ident("x");
5621+
let x_ident = Ident::with_empty_ctxt(sym::result);
56295622
let (x_pat, x_pat_hid) = self.pat_ident(span, x_ident);
56305623
let x_expr = P(self.expr_ident(span, x_ident, x_pat_hid));
56315624
let ready_pat = self.pat_std_enum(

src/librustc/lint/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,9 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum)
778778

779779
let push = builder.levels.push(&krate.attrs);
780780
builder.levels.register_id(hir::CRATE_HIR_ID);
781+
for macro_def in &krate.exported_macros {
782+
builder.levels.register_id(macro_def.hir_id);
783+
}
781784
intravisit::walk_crate(&mut builder, krate);
782785
builder.levels.pop(push);
783786

src/librustc_codegen_llvm/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,10 @@ fn create_msvc_imps(
795795
return
796796
}
797797
// The x86 ABI seems to require that leading underscores are added to symbol
798-
// names, so we need an extra underscore on 32-bit. There's also a leading
798+
// names, so we need an extra underscore on x86. There's also a leading
799799
// '\x01' here which disables LLVM's symbol mangling (e.g., no extra
800800
// underscores added in front).
801-
let prefix = if cgcx.target_pointer_width == "32" {
801+
let prefix = if cgcx.target_arch == "x86" {
802802
"\x01__imp__"
803803
} else {
804804
"\x01__imp_"

src/librustc_codegen_ssa/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
248248
pub tm_factory: TargetMachineFactory<B>,
249249
pub msvc_imps_needed: bool,
250250
pub target_pointer_width: String,
251+
pub target_arch: String,
251252
pub debuginfo: config::DebugInfo,
252253

253254
// Number of cgus excluding the allocator/metadata modules
@@ -1103,6 +1104,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
11031104
total_cgus,
11041105
msvc_imps_needed: msvc_imps_needed(tcx),
11051106
target_pointer_width: tcx.sess.target.target.target_pointer_width.clone(),
1107+
target_arch: tcx.sess.target.target.arch.clone(),
11061108
debuginfo: tcx.sess.opts.debuginfo,
11071109
assembler_cmd,
11081110
};

src/librustc_mir/transform/const_prop.rs

+108-67
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
546546
}
547547
}
548548
}
549+
550+
fn should_const_prop(&self) -> bool {
551+
self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2
552+
}
549553
}
550554

551555
fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -639,7 +643,7 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
639643
assert!(self.places[local].is_none());
640644
self.places[local] = Some(value);
641645

642-
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
646+
if self.should_const_prop() {
643647
self.replace_with_const(rval, value, statement.source_info.span);
644648
}
645649
}
@@ -656,75 +660,112 @@ impl<'b, 'a, 'tcx> MutVisitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
656660
location: Location,
657661
) {
658662
self.super_terminator(terminator, location);
659-
let source_info = terminator.source_info;;
660-
if let TerminatorKind::Assert { expected, msg, cond, .. } = &terminator.kind {
661-
if let Some(value) = self.eval_operand(&cond, source_info) {
662-
trace!("assertion on {:?} should be {:?}", value, expected);
663-
let expected = ScalarMaybeUndef::from(Scalar::from_bool(*expected));
664-
if expected != self.ecx.read_scalar(value).unwrap() {
665-
// poison all places this operand references so that further code
666-
// doesn't use the invalid value
667-
match cond {
668-
Operand::Move(ref place) | Operand::Copy(ref place) => {
669-
let mut place = place;
670-
while let Place::Projection(ref proj) = *place {
671-
place = &proj.base;
672-
}
673-
if let Place::Base(PlaceBase::Local(local)) = *place {
674-
self.places[local] = None;
663+
let source_info = terminator.source_info;
664+
match &mut terminator.kind {
665+
TerminatorKind::Assert { expected, msg, ref mut cond, .. } => {
666+
if let Some(value) = self.eval_operand(&cond, source_info) {
667+
trace!("assertion on {:?} should be {:?}", value, expected);
668+
let expected = ScalarMaybeUndef::from(Scalar::from_bool(*expected));
669+
let value_const = self.ecx.read_scalar(value).unwrap();
670+
if expected != value_const {
671+
// poison all places this operand references so that further code
672+
// doesn't use the invalid value
673+
match cond {
674+
Operand::Move(ref place) | Operand::Copy(ref place) => {
675+
let mut place = place;
676+
while let Place::Projection(ref proj) = *place {
677+
place = &proj.base;
678+
}
679+
if let Place::Base(PlaceBase::Local(local)) = *place {
680+
self.places[local] = None;
681+
}
682+
},
683+
Operand::Constant(_) => {}
684+
}
685+
let span = terminator.source_info.span;
686+
let hir_id = self
687+
.tcx
688+
.hir()
689+
.as_local_hir_id(self.source.def_id())
690+
.expect("some part of a failing const eval must be local");
691+
use rustc::mir::interpret::InterpError::*;
692+
let msg = match msg {
693+
Overflow(_) |
694+
OverflowNeg |
695+
DivisionByZero |
696+
RemainderByZero => msg.description().to_owned(),
697+
BoundsCheck { ref len, ref index } => {
698+
let len = self
699+
.eval_operand(len, source_info)
700+
.expect("len must be const");
701+
let len = match self.ecx.read_scalar(len) {
702+
Ok(ScalarMaybeUndef::Scalar(Scalar::Bits {
703+
bits, ..
704+
})) => bits,
705+
other => bug!("const len not primitive: {:?}", other),
706+
};
707+
let index = self
708+
.eval_operand(index, source_info)
709+
.expect("index must be const");
710+
let index = match self.ecx.read_scalar(index) {
711+
Ok(ScalarMaybeUndef::Scalar(Scalar::Bits {
712+
bits, ..
713+
})) => bits,
714+
other => bug!("const index not primitive: {:?}", other),
715+
};
716+
format!(
717+
"index out of bounds: \
718+
the len is {} but the index is {}",
719+
len,
720+
index,
721+
)
722+
},
723+
// Need proper const propagator for these
724+
_ => return,
725+
};
726+
self.tcx.lint_hir(
727+
::rustc::lint::builtin::CONST_ERR,
728+
hir_id,
729+
span,
730+
&msg,
731+
);
732+
} else {
733+
if self.should_const_prop() {
734+
if let ScalarMaybeUndef::Scalar(scalar) = value_const {
735+
*cond = self.operand_from_scalar(
736+
scalar,
737+
self.tcx.types.bool,
738+
source_info.span,
739+
);
675740
}
676-
},
677-
Operand::Constant(_) => {}
741+
}
678742
}
679-
let span = terminator.source_info.span;
680-
let hir_id = self
681-
.tcx
682-
.hir()
683-
.as_local_hir_id(self.source.def_id())
684-
.expect("some part of a failing const eval must be local");
685-
use rustc::mir::interpret::InterpError::*;
686-
let msg = match msg {
687-
Overflow(_) |
688-
OverflowNeg |
689-
DivisionByZero |
690-
RemainderByZero => msg.description().to_owned(),
691-
BoundsCheck { ref len, ref index } => {
692-
let len = self
693-
.eval_operand(len, source_info)
694-
.expect("len must be const");
695-
let len = match self.ecx.read_scalar(len) {
696-
Ok(ScalarMaybeUndef::Scalar(Scalar::Bits {
697-
bits, ..
698-
})) => bits,
699-
other => bug!("const len not primitive: {:?}", other),
700-
};
701-
let index = self
702-
.eval_operand(index, source_info)
703-
.expect("index must be const");
704-
let index = match self.ecx.read_scalar(index) {
705-
Ok(ScalarMaybeUndef::Scalar(Scalar::Bits {
706-
bits, ..
707-
})) => bits,
708-
other => bug!("const index not primitive: {:?}", other),
709-
};
710-
format!(
711-
"index out of bounds: \
712-
the len is {} but the index is {}",
713-
len,
714-
index,
715-
)
716-
},
717-
// Need proper const propagator for these
718-
_ => return,
719-
};
720-
self.tcx.lint_hir(
721-
::rustc::lint::builtin::CONST_ERR,
722-
hir_id,
723-
span,
724-
&msg,
725-
);
726743
}
727-
}
744+
},
745+
TerminatorKind::SwitchInt { ref mut discr, switch_ty, .. } => {
746+
if self.should_const_prop() {
747+
if let Some(value) = self.eval_operand(&discr, source_info) {
748+
if let ScalarMaybeUndef::Scalar(scalar) =
749+
self.ecx.read_scalar(value).unwrap() {
750+
*discr = self.operand_from_scalar(scalar, switch_ty, source_info.span);
751+
}
752+
}
753+
}
754+
},
755+
//none of these have Operands to const-propagate
756+
TerminatorKind::Goto { .. } |
757+
TerminatorKind::Resume |
758+
TerminatorKind::Abort |
759+
TerminatorKind::Return |
760+
TerminatorKind::Unreachable |
761+
TerminatorKind::Drop { .. } |
762+
TerminatorKind::DropAndReplace { .. } |
763+
TerminatorKind::Yield { .. } |
764+
TerminatorKind::GeneratorDrop |
765+
TerminatorKind::FalseEdges { .. } |
766+
TerminatorKind::FalseUnwind { .. } => { }
767+
//FIXME(wesleywiser) Call does have Operands that could be const-propagated
768+
TerminatorKind::Call { .. } => { }
728769
}
729770
}
730771
}

0 commit comments

Comments
 (0)