Skip to content

Commit fa9e3d8

Browse files
committed
WIP
1 parent 544d124 commit fa9e3d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+157
-159
lines changed

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
230230

231231
fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
232232
let check = match terminator.kind {
233-
mir::TerminatorKind::Call { func: mir::Operand::Constant(ref c), ref args, .. } => {
233+
mir::TerminatorKind::Call { func: mir::Operand::Constant(box(_, ref c)), ref args, .. } => {
234234
match *c.ty().kind() {
235235
ty::FnDef(did, _) => Some((did, args)),
236236
_ => None,

compiler/rustc_codegen_ssa/src/mir/block.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
633633
// checked by const-qualification, which also
634634
// promotes any complex rvalues to constants.
635635
if i == 2 && intrinsic.as_str().starts_with("simd_shuffle") {
636-
if let mir::Operand::Constant(constant) = arg {
637-
let c = self.eval_mir_constant(constant);
636+
if let mir::Operand::Constant(box(span, constant)) = arg {
637+
let c = self.eval_mir_constant(*span, constant);
638638
let (llval, ty) =
639-
self.simd_shuffle_indices(&bx, constant.span, constant.ty(), c);
639+
self.simd_shuffle_indices(&bx, *span, constant.ty(), c);
640640
return OperandRef {
641641
val: Immediate(llval),
642642
layout: bx.layout_of(ty),
@@ -821,9 +821,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
821821
out_place.map(|out_place| self.codegen_place(&mut bx, out_place.as_ref()));
822822
InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
823823
}
824-
mir::InlineAsmOperand::Const { ref value } => {
824+
mir::InlineAsmOperand::Const { span, ref value } => {
825825
let const_value = self
826-
.eval_mir_constant(value)
826+
.eval_mir_constant(span, value)
827827
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
828828
let ty = value.ty();
829829
let size = bx.layout_of(ty).size;

compiler/rustc_codegen_ssa/src/mir/constant.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1313
pub fn eval_mir_constant_to_operand(
1414
&self,
1515
bx: &mut Bx,
16+
span: Span,
1617
constant: &mir::Constant<'tcx>,
1718
) -> Result<OperandRef<'tcx, Bx::Value>, ErrorHandled> {
18-
let val = self.eval_mir_constant(constant)?;
19+
let val = self.eval_mir_constant(span, constant)?;
1920
let ty = self.monomorphize(constant.ty());
2021
Ok(OperandRef::from_const(bx, val, ty))
2122
}
2223

2324
pub fn eval_mir_constant(
2425
&self,
26+
span: Span,
2527
constant: &mir::Constant<'tcx>,
2628
) -> Result<ConstValue<'tcx>, ErrorHandled> {
2729
let ct = self.monomorphize(constant.literal);
@@ -35,12 +37,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3537
.tcx()
3638
.const_eval_resolve(ty::ParamEnv::reveal_all(), ct, None)
3739
.map_err(|err| {
38-
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
40+
self.cx.tcx().sess.span_err(span, "erroneous constant encountered");
3941
err
4042
}),
4143
ty::ConstKind::Value(value) => Ok(value),
4244
err => span_bug!(
43-
constant.span,
45+
span,
4446
"encountered bad ConstKind after monomorphizing: {:?}",
4547
err
4648
),

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
420420
None => continue,
421421
};
422422

423-
if let Ok(operand) = self.eval_mir_constant_to_operand(bx, &c) {
423+
if let Ok(operand) = self.eval_mir_constant_to_operand(bx, var.source_info.span, &c) {
424424
let base = Self::spill_operand_to_stack(
425425
&operand,
426426
Some(var.name.to_string()),

compiler/rustc_codegen_ssa/src/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
188188

189189
// Evaluate all required consts; codegen later assumes that CTFE will never fail.
190190
let mut all_consts_ok = true;
191-
for const_ in &mir.required_consts {
192-
if let Err(err) = fx.eval_mir_constant(const_) {
191+
for (span, const_) in &mir.required_consts {
192+
if let Err(err) = fx.eval_mir_constant(*span, const_) {
193193
all_consts_ok = false;
194194
match err {
195195
// errored or at least linted
196196
ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => {}
197197
ErrorHandled::TooGeneric => {
198-
span_bug!(const_.span, "codgen encountered polymorphic constant: {:?}", err)
198+
span_bug!(*span, "codgen encountered polymorphic constant: {:?}", err)
199199
}
200200
}
201201
}

compiler/rustc_codegen_ssa/src/mir/operand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
437437
self.codegen_consume(bx, place.as_ref())
438438
}
439439

440-
mir::Operand::Constant(ref constant) => {
440+
mir::Operand::Constant(box(span, ref constant)) => {
441441
// This cannot fail because we checked all required_consts in advance.
442-
self.eval_mir_constant_to_operand(bx, constant).unwrap_or_else(|_err| {
443-
span_bug!(constant.span, "erroneous constant not captured by required_consts")
442+
self.eval_mir_constant_to_operand(bx, span, constant).unwrap_or_else(|_err| {
443+
span_bug!(span, "erroneous constant not captured by required_consts")
444444
})
445445
}
446446
}

compiler/rustc_middle/src/mir/mod.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub struct Body<'tcx> {
217217

218218
/// Constants that are required to evaluate successfully for this MIR to be well-formed.
219219
/// We hold in this field all the constants we are not able to evaluate yet.
220-
pub required_consts: Vec<Constant<'tcx>>,
220+
pub required_consts: Vec<(Span, Constant<'tcx>)>,
221221

222222
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
223223
///
@@ -1222,6 +1222,7 @@ pub enum InlineAsmOperand<'tcx> {
12221222
out_place: Option<Place<'tcx>>,
12231223
},
12241224
Const {
1225+
span: Span,
12251226
value: Box<Constant<'tcx>>,
12261227
},
12271228
SymFn {
@@ -2029,7 +2030,7 @@ pub enum Operand<'tcx> {
20292030
Move(Place<'tcx>),
20302031

20312032
/// Synthesizes a constant value.
2032-
Constant(Box<Constant<'tcx>>),
2033+
Constant(Box<(Span, Constant<'tcx>)>),
20332034
}
20342035

20352036
#[cfg(target_arch = "x86_64")]
@@ -2057,11 +2058,10 @@ impl<'tcx> Operand<'tcx> {
20572058
span: Span,
20582059
) -> Self {
20592060
let ty = tcx.type_of(def_id).subst(tcx, substs);
2060-
Operand::Constant(box Constant {
2061-
span,
2061+
Operand::Constant(box (span, Constant {
20622062
user_ty: None,
20632063
literal: ConstantKind::Ty(ty::Const::zero_sized(tcx, ty)),
2064-
})
2064+
}))
20652065
}
20662066

20672067
pub fn is_move(&self) -> bool {
@@ -2088,11 +2088,10 @@ impl<'tcx> Operand<'tcx> {
20882088
};
20892089
scalar_size == type_size
20902090
});
2091-
Operand::Constant(box Constant {
2092-
span,
2091+
Operand::Constant(box (span, Constant {
20932092
user_ty: None,
20942093
literal: ConstantKind::Val(val.into(), ty),
2095-
})
2094+
}))
20962095
}
20972096

20982097
pub fn to_copy(&self) -> Self {
@@ -2113,9 +2112,9 @@ impl<'tcx> Operand<'tcx> {
21132112

21142113
/// Returns the `Constant` that is the target of this `Operand`, or `None` if this `Operand` is a
21152114
/// place.
2116-
pub fn constant(&self) -> Option<&Constant<'tcx>> {
2115+
pub fn constant(&self) -> Option<(&Span, &Constant<'tcx>)> {
21172116
match self {
2118-
Operand::Constant(x) => Some(&**x),
2117+
Operand::Constant(box(span, c)) => Some((span, c)),
21192118
Operand::Copy(_) | Operand::Move(_) => None,
21202119
}
21212120
}
@@ -2426,8 +2425,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24262425
24272426
#[derive(Clone, Copy, PartialEq, PartialOrd, TyEncodable, TyDecodable, Hash, HashStable)]
24282427
pub struct Constant<'tcx> {
2429-
pub span: Span,
2430-
24312428
/// Optional user-given type: for something like
24322429
/// `collect::<Vec<_>>`, this would be present and would
24332430
/// indicate that `Vec<_>` was explicitly specified.

compiler/rustc_middle/src/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'tcx> Operand<'tcx> {
227227
{
228228
match self {
229229
&Operand::Copy(ref l) | &Operand::Move(ref l) => l.ty(local_decls, tcx).ty,
230-
&Operand::Constant(ref c) => c.literal.ty(),
230+
&Operand::Constant(box (_, ref c)) => c.literal.ty(),
231231
}
232232
}
233233
}

compiler/rustc_middle/src/mir/terminator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ impl<'tcx> TerminatorKind<'tcx> {
527527
InlineAsmOperand::InOut { reg, late, in_value, out_place: None } => {
528528
write!(fmt, "in{}out({}) {:?} => _", print_late(late), reg, in_value)?;
529529
}
530-
InlineAsmOperand::Const { value } => {
530+
InlineAsmOperand::Const { value, .. } => {
531+
// FIXME consider span?
531532
write!(fmt, "const {:?}", value)?;
532533
}
533534
InlineAsmOperand::SymFn { value } => {

compiler/rustc_middle/src/mir/type_foldable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
336336
impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
337337
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
338338
Constant {
339-
span: self.span,
340339
user_ty: self.user_ty.fold_with(folder),
341340
literal: self.literal.fold_with(folder),
342341
}

compiler/rustc_middle/src/mir/visit.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,9 @@ macro_rules! make_mir_visitor {
291291

292292
self.visit_span(&$($mutability)? body.span);
293293

294-
for const_ in &$($mutability)? body.required_consts {
294+
for (span, const_) in &$($mutability)? body.required_consts {
295295
let location = START_BLOCK.start_location();
296+
self.visit_span(span);
296297
self.visit_constant(const_, location);
297298
}
298299
}
@@ -606,8 +607,11 @@ macro_rules! make_mir_visitor {
606607
);
607608
}
608609
}
609-
InlineAsmOperand::Const { value }
610-
| InlineAsmOperand::SymFn { value } => {
610+
InlineAsmOperand::Const { value, span } => {
611+
self.visit_span(span);
612+
self.visit_constant(value, location);
613+
}
614+
InlineAsmOperand::SymFn { value } => {
611615
self.visit_constant(value, location);
612616
}
613617
InlineAsmOperand::SymStatic { def_id: _ } => {}
@@ -775,7 +779,8 @@ macro_rules! make_mir_visitor {
775779
location
776780
);
777781
}
778-
Operand::Constant(constant) => {
782+
Operand::Constant(box(span, constant)) => {
783+
self.visit_span(span);
779784
self.visit_constant(constant, location);
780785
}
781786
}
@@ -864,12 +869,10 @@ macro_rules! make_mir_visitor {
864869
constant: & $($mutability)? Constant<'tcx>,
865870
location: Location) {
866871
let Constant {
867-
span,
868872
user_ty,
869873
literal,
870874
} = constant;
871875

872-
self.visit_span(span);
873876
drop(user_ty); // no visit method for this
874877
match literal {
875878
ConstantKind::Ty(ct) => self.visit_const(ct, location),

compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
565565
{
566566
// Just point to the function, to reduce the chance of overlapping spans.
567567
let function_span = match func {
568-
Operand::Constant(c) => c.span,
568+
Operand::Constant(box (span, _)) => *span,
569569
Operand::Copy(place) | Operand::Move(place) => {
570570
if let Some(l) = place.as_local() {
571571
let local_decl = &self.body.local_decls[l];

compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
8181
let terminator = self.body[location.block].terminator();
8282
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
8383
if let TerminatorKind::Call {
84-
func: Operand::Constant(box Constant { literal, .. }),
84+
func: Operand::Constant(box (_, Constant { literal, .. })),
8585
args,
8686
..
8787
} = &terminator.kind

compiler/rustc_mir/src/borrow_check/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
218218
self.mutate_place(location, out_place, Shallow(None), JustWrite);
219219
}
220220
}
221-
InlineAsmOperand::Const { value: _ }
221+
InlineAsmOperand::Const { span: _, value: _ }
222222
| InlineAsmOperand::SymFn { value: _ }
223223
| InlineAsmOperand::SymStatic { def_id: _ } => {}
224224
}

compiler/rustc_mir/src/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
756756
);
757757
}
758758
}
759-
InlineAsmOperand::Const { value: _ }
759+
InlineAsmOperand::Const { span: _, value: _ }
760760
| InlineAsmOperand::SymFn { value: _ }
761761
| InlineAsmOperand::SymStatic { def_id: _ } => {}
762762
}

compiler/rustc_mir/src/dataflow/move_paths/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
441441
self.gather_init(out_place.as_ref(), InitKind::Deep);
442442
}
443443
}
444-
InlineAsmOperand::Const { value: _ }
444+
InlineAsmOperand::Const { span: _, value: _ }
445445
| InlineAsmOperand::SymFn { value: _ }
446446
| InlineAsmOperand::SymStatic { def_id: _ } => {}
447447
}

compiler/rustc_mir/src/interpret/eval_context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -683,14 +683,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
683683
self.stack_mut().push(frame);
684684

685685
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
686-
for const_ in &body.required_consts {
687-
let span = const_.span;
686+
for (span, const_) in &body.required_consts {
688687
let const_ =
689688
self.subst_from_current_frame_and_normalize_erasing_regions(const_.literal);
690689
self.mir_const_to_op(&const_, None).map_err(|err| {
691690
// If there was an error, set the span of the current frame to this constant.
692691
// Avoiding doing this when evaluation succeeds.
693-
self.frame_mut().loc = Err(span);
692+
self.frame_mut().loc = Err(*span);
694693
err
695694
})?;
696695
}

compiler/rustc_mir/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
517517
// FIXME: do some more logic on `move` to invalidate the old location
518518
Copy(place) | Move(place) => self.eval_place_to_op(place, layout)?,
519519

520-
Constant(ref constant) => {
520+
Constant(box (_, ref constant)) => {
521521
let val =
522522
self.subst_from_current_frame_and_normalize_erasing_regions(constant.literal);
523523
// This can still fail:

compiler/rustc_mir/src/shim.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,10 @@ impl CloneShimBuilder<'tcx> {
418418

419419
// `func == Clone::clone(&ty) -> ty`
420420
let func_ty = tcx.mk_fn_def(self.def_id, substs);
421-
let func = Operand::Constant(box Constant {
422-
span: self.span,
421+
let func = Operand::Constant(box (self.span, Constant {
423422
user_ty: None,
424423
literal: ty::Const::zero_sized(tcx, func_ty).into(),
425-
});
424+
}));
426425

427426
let ref_loc = self.make_place(
428427
Mutability::Not,
@@ -474,12 +473,11 @@ impl CloneShimBuilder<'tcx> {
474473
);
475474
}
476475

477-
fn make_usize(&self, value: u64) -> Box<Constant<'tcx>> {
478-
box Constant {
479-
span: self.span,
476+
fn make_usize(&self, value: u64) -> Box<(Span, Constant<'tcx>)> {
477+
box (self.span, Constant {
480478
user_ty: None,
481479
literal: ty::Const::from_usize(self.tcx, value).into(),
482-
}
480+
})
483481
}
484482

485483
fn array_shim(
@@ -506,11 +504,10 @@ impl CloneShimBuilder<'tcx> {
506504
))),
507505
self.make_statement(StatementKind::Assign(box (
508506
end,
509-
Rvalue::Use(Operand::Constant(box Constant {
510-
span: self.span,
507+
Rvalue::Use(Operand::Constant(box (self.span, Constant {
511508
user_ty: None,
512509
literal: len.into(),
513-
})),
510+
}))),
514511
))),
515512
];
516513
self.block(inits, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);
@@ -765,11 +762,10 @@ fn build_call_shim<'tcx>(
765762
CallKind::Direct(def_id) => {
766763
let ty = tcx.type_of(def_id);
767764
(
768-
Operand::Constant(box Constant {
769-
span,
765+
Operand::Constant(box (span, Constant {
770766
user_ty: None,
771767
literal: ty::Const::zero_sized(tcx, ty).into(),
772-
}),
768+
})),
773769
rcvr.into_iter().collect::<Vec<_>>(),
774770
)
775771
}

0 commit comments

Comments
 (0)