Skip to content

Commit 307798a

Browse files
committed
fixing fallout due to InterpError refactor
1 parent 4f0ab6c commit 307798a

File tree

21 files changed

+259
-266
lines changed

21 files changed

+259
-266
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::{
44
Pointer, InterpResult, AllocId, ScalarMaybeUndef, write_target_uint, read_target_uint, Scalar,
55
};
66

7+
use super::error::UnsupportedInfo::*;
78
use crate::ty::layout::{Size, Align};
89
use syntax::ast::Mutability;
910
use std::iter;
@@ -244,7 +245,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
244245
Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size])
245246
}
246247
// This includes the case where `offset` is out-of-bounds to begin with.
247-
None => err!(UnterminatedCString(ptr.erase_tag())),
248+
None => err!(Unsupported(UnterminatedCString(ptr.erase_tag()))),
248249
}
249250
}
250251

@@ -446,7 +447,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
446447
if self.relocations(cx, ptr, size).is_empty() {
447448
Ok(())
448449
} else {
449-
err!(ReadPointerAsBytes)
450+
err!(Unsupported(ReadPointerAsBytes))
450451
}
451452
}
452453

@@ -516,7 +517,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
516517
self.undef_mask.is_range_defined(
517518
ptr.offset,
518519
ptr.offset + size,
519-
).or_else(|idx| err!(ReadUndefBytes(idx)))
520+
).or_else(|idx| err!(Unsupported(ReadUndefBytes(idx))))
520521
}
521522

522523
pub fn mark_definedness(

src/librustc/mir/interpret/error.rs

Lines changed: 104 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
142142
InterpError::InvalidProgram(Layout(LayoutError::Unknown(_))) |
143143
InterpError::InvalidProgram(TooGeneric) =>
144144
return Err(ErrorHandled::TooGeneric),
145-
InterpError::Layout(LayoutError::SizeOverflow(_)) |
145+
InterpError::InvalidProgram(Layout(LayoutError::SizeOverflow(_))) |
146146
InterpError::InvalidProgram(TypeckError) =>
147147
return Err(ErrorHandled::Reported),
148148
_ => {},
@@ -325,16 +325,47 @@ pub enum InvalidProgramInfo<'tcx> {
325325
Layout(layout::LayoutError<'tcx>),
326326
}
327327

328+
impl fmt::Debug for InvalidProgramInfo<'tcx> {
329+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
330+
use InvalidProgramInfo::*;
331+
match self {
332+
TooGeneric =>
333+
write!(f, "encountered overly generic constant"),
334+
ReferencedConstant =>
335+
write!(f, "referenced constant has errors"),
336+
TypeckError =>
337+
write!(f, "encountered constants with type errors, stopping evaluation"),
338+
Layout(ref err) =>
339+
write!(f, "rustc layout computation failed: {:?}", err),
340+
}
341+
}
342+
}
343+
328344
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
329345
pub enum UndefinedBehaviourInfo {
330-
/// Handle cases which for which we do not have a fixed variant
346+
/// Handle cases which for which we do not have a fixed variant.
331347
Ub(String),
348+
/// Unreachable code was executed.
332349
Unreachable,
333350
}
334351

352+
impl fmt::Debug for UndefinedBehaviourInfo {
353+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
354+
use UndefinedBehaviourInfo::*;
355+
match self {
356+
Ub(ref msg) =>
357+
write!(f, "{}", msg),
358+
Unreachable =>
359+
write!(f, "entered unreachable code"),
360+
}
361+
}
362+
}
363+
335364
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
336365
pub enum UnsupportedInfo<'tcx> {
337366
Unimplemented(String),
367+
368+
// -- Everything below is not classified yet --
338369
FunctionAbiMismatch(Abi, Abi),
339370
FunctionArgMismatch(Ty<'tcx>, Ty<'tcx>),
340371
FunctionRetMismatch(Ty<'tcx>, Ty<'tcx>),
@@ -400,6 +431,19 @@ pub enum ResourceExhaustionInfo {
400431
InfiniteLoop,
401432
}
402433

434+
impl fmt::Debug for ResourceExhaustionInfo {
435+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
436+
use ResourceExhaustionInfo::*;
437+
match self {
438+
StackFrameLimitReached =>
439+
write!(f, "reached the configured maximum number of stack frames"),
440+
InfiniteLoop =>
441+
write!(f, "duplicate interpreter state observed here, const evaluation will never \
442+
terminate"),
443+
}
444+
}
445+
}
446+
403447
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
404448
pub enum InterpError<'tcx> {
405449
/// The program panicked.
@@ -431,139 +475,131 @@ impl fmt::Display for InterpError<'_> {
431475
impl fmt::Debug for InterpError<'_> {
432476
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
433477
use InterpError::*;
478+
use UnsupportedInfo::*;
434479
match *self {
435-
PointerOutOfBounds { ptr, msg, allocation_size } => {
480+
Unsupported(PointerOutOfBounds { ptr, msg, allocation_size }) => {
436481
write!(f, "{} failed: pointer must be in-bounds at offset {}, \
437482
but is outside bounds of allocation {} which has size {}",
438483
msg, ptr.offset.bytes(), ptr.alloc_id, allocation_size.bytes())
439484
},
440-
ValidationFailure(ref err) => {
485+
Unsupported(ValidationFailure(ref err)) => {
441486
write!(f, "type validation failed: {}", err)
442487
}
443-
NoMirFor(ref func) => write!(f, "no mir for `{}`", func),
444-
FunctionAbiMismatch(caller_abi, callee_abi) =>
488+
Unsupported(NoMirFor(ref func)) => write!(f, "no mir for `{}`", func),
489+
Unsupported(FunctionAbiMismatch(caller_abi, callee_abi)) =>
445490
write!(f, "tried to call a function with ABI {:?} using caller ABI {:?}",
446491
callee_abi, caller_abi),
447-
FunctionArgMismatch(caller_ty, callee_ty) =>
492+
Unsupported(FunctionArgMismatch(caller_ty, callee_ty)) =>
448493
write!(f, "tried to call a function with argument of type {:?} \
449494
passing data of type {:?}",
450495
callee_ty, caller_ty),
451-
FunctionRetMismatch(caller_ty, callee_ty) =>
496+
Unsupported(FunctionRetMismatch(caller_ty, callee_ty)) =>
452497
write!(f, "tried to call a function with return type {:?} \
453498
passing return place of type {:?}",
454499
callee_ty, caller_ty),
455-
FunctionArgCountMismatch =>
500+
Unsupported(FunctionArgCountMismatch) =>
456501
write!(f, "tried to call a function with incorrect number of arguments"),
457-
ReallocatedWrongMemoryKind(ref old, ref new) =>
502+
Unsupported(ReallocatedWrongMemoryKind(ref old, ref new)) =>
458503
write!(f, "tried to reallocate memory from {} to {}", old, new),
459-
DeallocatedWrongMemoryKind(ref old, ref new) =>
504+
Unsupported(DeallocatedWrongMemoryKind(ref old, ref new)) =>
460505
write!(f, "tried to deallocate {} memory but gave {} as the kind", old, new),
461-
InvalidChar(c) =>
506+
Unsupported(InvalidChar(c)) =>
462507
write!(f, "tried to interpret an invalid 32-bit value as a char: {}", c),
463-
AlignmentCheckFailed { required, has } =>
508+
Unsupported(AlignmentCheckFailed { required, has }) =>
464509
write!(f, "tried to access memory with alignment {}, but alignment {} is required",
465510
has.bytes(), required.bytes()),
466-
TypeNotPrimitive(ty) =>
511+
Unsupported(TypeNotPrimitive(ty)) =>
467512
write!(f, "expected primitive type, got {}", ty),
468-
Layout(ref err) =>
469-
write!(f, "rustc layout computation failed: {:?}", err),
470-
PathNotFound(ref path) =>
513+
Unsupported(PathNotFound(ref path)) =>
471514
write!(f, "Cannot find path {:?}", path),
472-
IncorrectAllocationInformation(size, size2, align, align2) =>
515+
Unsupported(IncorrectAllocationInformation(size, size2, align, align2)) =>
473516
write!(f, "incorrect alloc info: expected size {} and align {}, \
474517
got size {} and align {}",
475518
size.bytes(), align.bytes(), size2.bytes(), align2.bytes()),
476-
InvalidDiscriminant(val) =>
519+
Unsupported(InvalidDiscriminant(val)) =>
477520
write!(f, "encountered invalid enum discriminant {}", val),
478-
Exit(code) =>
479-
write!(f, "exited with status code {}", code),
480-
InvalidMemoryAccess =>
521+
Unsupported(InvalidMemoryAccess) =>
481522
write!(f, "tried to access memory through an invalid pointer"),
482-
DanglingPointerDeref =>
523+
Unsupported(DanglingPointerDeref) =>
483524
write!(f, "dangling pointer was dereferenced"),
484-
DoubleFree =>
525+
Unsupported(DoubleFree) =>
485526
write!(f, "tried to deallocate dangling pointer"),
486-
InvalidFunctionPointer =>
527+
Unsupported(InvalidFunctionPointer) =>
487528
write!(f, "tried to use a function pointer after offsetting it"),
488-
InvalidBool =>
529+
Unsupported(InvalidBool) =>
489530
write!(f, "invalid boolean value read"),
490-
InvalidNullPointerUsage =>
531+
Unsupported(InvalidNullPointerUsage) =>
491532
write!(f, "invalid use of NULL pointer"),
492-
ReadPointerAsBytes =>
533+
Unsupported(ReadPointerAsBytes) =>
493534
write!(f, "a raw memory access tried to access part of a pointer value as raw \
494535
bytes"),
495-
ReadBytesAsPointer =>
536+
Unsupported(ReadBytesAsPointer) =>
496537
write!(f, "a memory access tried to interpret some bytes as a pointer"),
497-
ReadForeignStatic =>
538+
Unsupported(ReadForeignStatic) =>
498539
write!(f, "tried to read from foreign (extern) static"),
499-
InvalidPointerMath =>
540+
Unsupported(InvalidPointerMath) =>
500541
write!(f, "attempted to do invalid arithmetic on pointers that would leak base \
501542
addresses, e.g., comparing pointers into different allocations"),
502-
DeadLocal =>
543+
Unsupported(DeadLocal) =>
503544
write!(f, "tried to access a dead local variable"),
504-
DerefFunctionPointer =>
545+
Unsupported(DerefFunctionPointer) =>
505546
write!(f, "tried to dereference a function pointer"),
506-
ExecuteMemory =>
547+
Unsupported(ExecuteMemory) =>
507548
write!(f, "tried to treat a memory pointer as a function pointer"),
508-
StackFrameLimitReached =>
509-
write!(f, "reached the configured maximum number of stack frames"),
510-
OutOfTls =>
549+
Unsupported(OutOfTls) =>
511550
write!(f, "reached the maximum number of representable TLS keys"),
512-
TlsOutOfBounds =>
551+
Unsupported(TlsOutOfBounds) =>
513552
write!(f, "accessed an invalid (unallocated) TLS key"),
514-
CalledClosureAsFunction =>
553+
Unsupported(CalledClosureAsFunction) =>
515554
write!(f, "tried to call a closure through a function pointer"),
516-
VtableForArgumentlessMethod =>
555+
Unsupported(VtableForArgumentlessMethod) =>
517556
write!(f, "tried to call a vtable function without arguments"),
518-
ModifiedConstantMemory =>
557+
Unsupported(ModifiedConstantMemory) =>
519558
write!(f, "tried to modify constant memory"),
520-
ModifiedStatic =>
559+
Unsupported(ModifiedStatic) =>
521560
write!(f, "tried to modify a static's initial value from another static's \
522561
initializer"),
523-
AssumptionNotHeld =>
562+
Unsupported(AssumptionNotHeld) =>
524563
write!(f, "`assume` argument was false"),
525-
InlineAsm =>
564+
Unsupported(InlineAsm) =>
526565
write!(f, "miri does not support inline assembly"),
527-
ReallocateNonBasePtr =>
566+
Unsupported(ReallocateNonBasePtr) =>
528567
write!(f, "tried to reallocate with a pointer not to the beginning of an \
529568
existing object"),
530-
DeallocateNonBasePtr =>
569+
Unsupported(DeallocateNonBasePtr) =>
531570
write!(f, "tried to deallocate with a pointer not to the beginning of an \
532571
existing object"),
533-
HeapAllocZeroBytes =>
572+
Unsupported(HeapAllocZeroBytes) =>
534573
write!(f, "tried to re-, de- or allocate zero bytes on the heap"),
535-
Unreachable =>
536-
write!(f, "entered unreachable code"),
537-
ReadFromReturnPointer =>
574+
Unsupported(ReadFromReturnPointer) =>
538575
write!(f, "tried to read from the return pointer"),
539-
UnimplementedTraitSelection =>
576+
Unsupported(UnimplementedTraitSelection) =>
540577
write!(f, "there were unresolved type arguments during trait selection"),
541-
TypeckError =>
542-
write!(f, "encountered constants with type errors, stopping evaluation"),
543-
TooGeneric =>
544-
write!(f, "encountered overly generic constant"),
545-
ReferencedConstant =>
546-
write!(f, "referenced constant has errors"),
547-
InfiniteLoop =>
548-
write!(f, "duplicate interpreter state observed here, const evaluation will never \
549-
terminate"),
550-
InvalidBoolOp(_) =>
578+
Unsupported(InvalidBoolOp(_)) =>
551579
write!(f, "invalid boolean operation"),
552-
UnterminatedCString(_) =>
580+
Unsupported(UnterminatedCString(_)) =>
553581
write!(f, "attempted to get length of a null terminated string, but no null \
554582
found before end of allocation"),
555-
ReadUndefBytes(_) =>
583+
Unsupported(ReadUndefBytes(_)) =>
556584
write!(f, "attempted to read undefined bytes"),
557-
HeapAllocNonPowerOfTwoAlignment(_) =>
585+
Unsupported(HeapAllocNonPowerOfTwoAlignment(_)) =>
558586
write!(f, "tried to re-, de-, or allocate heap memory with alignment that is \
559587
not a power of two"),
560-
MachineError(ref msg) |
561-
Unimplemented(ref msg) |
562-
AbiViolation(ref msg) |
563-
Intrinsic(ref msg) =>
588+
Unsupported(MachineError(ref msg)) |
589+
Unsupported(Unimplemented(ref msg)) |
590+
Unsupported(AbiViolation(ref msg)) |
591+
Unsupported(Intrinsic(ref msg)) =>
564592
write!(f, "{}", msg),
593+
InvalidProgram(ref msg) =>
594+
write!(f, "{:?}", msg),
595+
UndefinedBehaviour(ref msg) =>
596+
write!(f, "{:?}", msg),
597+
ResourceExhaustion(ref msg) =>
598+
write!(f, "{:?}", msg),
565599
Panic(ref msg) =>
566600
write!(f, "{:?}", msg),
601+
Exit(code) =>
602+
write!(f, "exited with status code {}", code),
567603
}
568604
}
569605
}

src/librustc/mir/interpret/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ mod pointer;
1212

1313
pub use self::error::{
1414
InterpErrorInfo, InterpResult, InterpError, AssertMessage, ConstEvalErr, struct_error,
15-
FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicMessage
15+
FrameInfo, ConstEvalRawResult, ConstEvalResult, ErrorHandled, PanicMessage, UnsupportedInfo,
16+
InvalidProgramInfo, ResourceExhaustionInfo, UndefinedBehaviourInfo,
1617
};
1718

1819
pub use self::value::{Scalar, ScalarMaybeUndef, RawConst, ConstValue};

src/librustc/mir/interpret/pointer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt::{self, Display};
22

3+
use super::error::UnsupportedInfo::*;
34
use crate::mir;
45
use crate::ty::layout::{self, HasDataLayout, Size};
56
use rustc_macros::HashStable;
@@ -198,11 +199,11 @@ impl<'tcx, Tag> Pointer<Tag> {
198199
msg: CheckInAllocMsg,
199200
) -> InterpResult<'tcx, ()> {
200201
if self.offset > allocation_size {
201-
err!(PointerOutOfBounds {
202+
err!(Unsupported(PointerOutOfBounds {
202203
ptr: self.erase_tag(),
203204
msg,
204205
allocation_size,
205-
})
206+
}))
206207
} else {
207208
Ok(())
208209
}

src/librustc/mir/interpret/value.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fmt;
22
use rustc_macros::HashStable;
33
use rustc_apfloat::{Float, ieee::{Double, Single}};
44

5+
use super::error::UnsupportedInfo::*;
56
use crate::ty::{Ty, InferConst, ParamConst, layout::{HasDataLayout, Size, Align}, subst::SubstsRef};
67
use crate::ty::PlaceholderConst;
78
use crate::hir::def_id::DefId;
@@ -360,7 +361,7 @@ impl<'tcx, Tag> Scalar<Tag> {
360361
Scalar::check_data(data, size);
361362
Ok(data)
362363
}
363-
Scalar::Ptr(_) => err!(ReadPointerAsBytes),
364+
Scalar::Ptr(_) => err!(Unsupported(ReadPointerAsBytes)),
364365
}
365366
}
366367

@@ -373,8 +374,8 @@ impl<'tcx, Tag> Scalar<Tag> {
373374
#[inline]
374375
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
375376
match self {
376-
Scalar::Raw { data: 0, .. } => err!(InvalidNullPointerUsage),
377-
Scalar::Raw { .. } => err!(ReadBytesAsPointer),
377+
Scalar::Raw { data: 0, .. } => err!(Unsupported(InvalidNullPointerUsage)),
378+
Scalar::Raw { .. } => err!(Unsupported(ReadBytesAsPointer)),
378379
Scalar::Ptr(p) => Ok(p),
379380
}
380381
}
@@ -406,15 +407,15 @@ impl<'tcx, Tag> Scalar<Tag> {
406407
match self {
407408
Scalar::Raw { data: 0, size: 1 } => Ok(false),
408409
Scalar::Raw { data: 1, size: 1 } => Ok(true),
409-
_ => err!(InvalidBool),
410+
_ => err!(Unsupported(InvalidBool)),
410411
}
411412
}
412413

413414
pub fn to_char(self) -> InterpResult<'tcx, char> {
414415
let val = self.to_u32()?;
415416
match ::std::char::from_u32(val) {
416417
Some(c) => Ok(c),
417-
None => err!(InvalidChar(val as u128)),
418+
None => err!(Unsupported(InvalidChar(val as u128))),
418419
}
419420
}
420421

@@ -537,7 +538,7 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
537538
pub fn not_undef(self) -> InterpResult<'static, Scalar<Tag>> {
538539
match self {
539540
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
540-
ScalarMaybeUndef::Undef => err!(ReadUndefBytes(Size::from_bytes(0))),
541+
ScalarMaybeUndef::Undef => err!(Unsupported(ReadUndefBytes(Size::from_bytes(0)))),
541542
}
542543
}
543544

0 commit comments

Comments
 (0)