Skip to content

Commit fc48f3e

Browse files
committed
more grouping of the variants in InterpError
1 parent 01859bb commit fc48f3e

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

src/librustc/mir/interpret/error.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ impl<'tcx> ConstEvalErr<'tcx> {
137137
message: &str,
138138
lint_root: Option<hir::HirId>,
139139
) -> Result<DiagnosticBuilder<'tcx>, ErrorHandled> {
140+
use InvalidProgramInfo::*;
140141
match self.error {
141-
InterpError::Layout(LayoutError::Unknown(_)) |
142-
InterpError::InvalidProgram(InvalidProgramMessage::TooGeneric) =>
142+
InterpError::InvalidProgram(Layout(LayoutError::Unknown(_))) |
143+
InterpError::InvalidProgram(TooGeneric) =>
143144
return Err(ErrorHandled::TooGeneric),
144145
InterpError::Layout(LayoutError::SizeOverflow(_)) |
145-
InterpError::InvalidProgram(InvalidProgramMessage::TypeckError) =>
146+
InterpError::InvalidProgram(TypeckError) =>
146147
return Err(ErrorHandled::Reported),
147148
_ => {},
148149
}
@@ -312,42 +313,74 @@ impl<O: fmt::Debug> fmt::Debug for PanicMessage<O> {
312313
}
313314

314315
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
315-
pub enum InvalidProgramMessage {
316+
pub enum InvalidProgramInfo<'tcx> {
316317
/// Resolution can fail if we are in a too generic context
317318
TooGeneric,
318319
/// Cannot compute this constant because it depends on another one
319320
/// which already produced an error
320321
ReferencedConstant,
321322
/// Abort in case type errors are reached
322323
TypeckError,
324+
Layout(layout::LayoutError<'tcx>),
323325
}
324326

325327
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
326-
pub enum UndefinedBehaviourMessage {
328+
pub enum UndefinedBehaviourInfo {
329+
Unreachable,
327330
}
328331

329332
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
330-
pub enum UnsupportedMessage {
333+
pub enum UnsupportedInfo<'tcx> {
334+
FunctionAbiMismatch(Abi, Abi),
335+
FunctionArgMismatch(Ty<'tcx>, Ty<'tcx>),
336+
FunctionRetMismatch(Ty<'tcx>, Ty<'tcx>),
337+
FunctionArgCountMismatch,
338+
UnterminatedCString(Pointer),
339+
DanglingPointerDeref,
340+
DoubleFree,
341+
InvalidMemoryAccess,
342+
InvalidFunctionPointer,
343+
InvalidBool,
344+
InvalidDiscriminant(ScalarMaybeUndef),
345+
PointerOutOfBounds {
346+
ptr: Pointer,
347+
msg: CheckInAllocMsg,
348+
allocation_size: Size,
349+
},
350+
InvalidNullPointerUsage,
351+
ReadPointerAsBytes,
352+
ReadBytesAsPointer,
353+
ReadForeignStatic,
354+
InvalidPointerMath,
355+
ReadUndefBytes(Size),
356+
DeadLocal,
357+
InvalidBoolOp(mir::BinOp),
358+
InlineAsm,
359+
UnimplementedTraitSelection,
360+
CalledClosureAsFunction,
361+
NoMirFor(String),
331362
}
332363

333364
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
334-
pub enum ResourceExhaustionMessage {
365+
pub enum ResourceExhaustionInfo {
366+
StackFrameLimitReached,
367+
InfiniteLoop,
335368
}
336369

337370
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
338371
pub enum InterpError<'tcx> {
339372
/// The program panicked.
340373
Panic(PanicMessage<u64>),
341374
/// The program caused undefined behavior.
342-
UndefinedBehaviour(UndefinedBehaviourMessage),
375+
UndefinedBehaviour(UndefinedBehaviourInfo),
343376
/// The program did something the interpreter does not support (some of these *might* be UB
344377
/// but the interpreter is not sure).
345-
Unsupported(UnsupportedMessage),
378+
Unsupported(UnsupportedInfo<'tcx>),
346379
/// The program was invalid (ill-typed, not sufficiently monomorphized, ...).
347-
InvalidProgram(InvalidProgramMessage),
380+
InvalidProgram(InvalidProgramInfo<'tcx>),
348381
/// The program exhausted the interpreter's resources (stack/heap too big,
349382
/// execution takes too long, ..).
350-
ResourceExhaustion(ResourceExhaustionMessage),
383+
ResourceExhaustion(ResourceExhaustionInfo),
351384

352385
/// THe above 5 variants are what we want to group all the remaining InterpError variants into
353386
@@ -359,37 +392,11 @@ pub enum InterpError<'tcx> {
359392
/// with the given status code. Used by Miri, but not by CTFE.
360393
Exit(i32),
361394

362-
FunctionAbiMismatch(Abi, Abi),
363-
FunctionArgMismatch(Ty<'tcx>, Ty<'tcx>),
364-
FunctionRetMismatch(Ty<'tcx>, Ty<'tcx>),
365-
FunctionArgCountMismatch,
366-
NoMirFor(String),
367-
UnterminatedCString(Pointer),
368-
DanglingPointerDeref,
369-
DoubleFree,
370-
InvalidMemoryAccess,
371-
InvalidFunctionPointer,
372-
InvalidBool,
373-
InvalidDiscriminant(ScalarMaybeUndef),
374-
PointerOutOfBounds {
375-
ptr: Pointer,
376-
msg: CheckInAllocMsg,
377-
allocation_size: Size,
378-
},
379-
InvalidNullPointerUsage,
380-
ReadPointerAsBytes,
381-
ReadBytesAsPointer,
382-
ReadForeignStatic,
383-
InvalidPointerMath,
384-
ReadUndefBytes(Size),
385-
DeadLocal,
386-
InvalidBoolOp(mir::BinOp),
387395
Unimplemented(String),
388396
DerefFunctionPointer,
389397
ExecuteMemory,
390398
Intrinsic(String),
391399
InvalidChar(u128),
392-
StackFrameLimitReached,
393400
OutOfTls,
394401
TlsOutOfBounds,
395402
AbiViolation(String),
@@ -398,25 +405,20 @@ pub enum InterpError<'tcx> {
398405
has: Align,
399406
},
400407
ValidationFailure(String),
401-
CalledClosureAsFunction,
402408
VtableForArgumentlessMethod,
403409
ModifiedConstantMemory,
404410
ModifiedStatic,
405411
AssumptionNotHeld,
406-
InlineAsm,
407412
TypeNotPrimitive(Ty<'tcx>),
408413
ReallocatedWrongMemoryKind(String, String),
409414
DeallocatedWrongMemoryKind(String, String),
410415
ReallocateNonBasePtr,
411416
DeallocateNonBasePtr,
412417
IncorrectAllocationInformation(Size, Size, Align, Align),
413-
Layout(layout::LayoutError<'tcx>),
414418
HeapAllocZeroBytes,
415419
HeapAllocNonPowerOfTwoAlignment(u64),
416-
Unreachable,
417420
ReadFromReturnPointer,
418421
PathNotFound(Vec<String>),
419-
UnimplementedTraitSelection,
420422
}
421423

422424
pub type InterpResult<'tcx, T = ()> = Result<T, InterpErrorInfo<'tcx>>;

0 commit comments

Comments
 (0)