Skip to content

Commit d740618

Browse files
committed
Export interpreter macros so they can be used with use crate::interpret::*.
1 parent b2b6c26 commit d740618

File tree

18 files changed

+57
-21
lines changed

18 files changed

+57
-21
lines changed

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::interpret::{self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic};
1+
use crate::interpret::{
2+
self, throw_machine_stop, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic,
3+
};
24
use rustc_middle::mir::interpret::{AllocId, ConstAllocation, InterpResult};
35
use rustc_middle::mir::*;
46
use rustc_middle::query::TyCtxtAt;
57
use rustc_middle::ty;
68
use rustc_middle::ty::layout::TyAndLayout;
7-
use rustc_middle::{bug, span_bug, throw_machine_stop};
9+
use rustc_middle::{bug, span_bug};
810
use rustc_span::def_id::DefId;
911

1012
/// Macro for machine-specific `InterpError` without allocation.

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use rustc_middle::mir::AssertKind;
77
use rustc_middle::query::TyCtxtAt;
88
use rustc_middle::ty::TyCtxt;
99
use rustc_middle::ty::{layout::LayoutError, ConstInt};
10-
use rustc_middle::{err_inval, err_machine_stop};
1110
use rustc_span::{Span, Symbol};
1211

1312
use super::CompileTimeInterpreter;
1413
use crate::errors::{self, FrameNote, ReportErrorExt};
14+
use crate::interpret::{err_inval, err_machine_stop};
1515
use crate::interpret::{ErrorHandled, Frame, InterpError, InterpErrorInfo, MachineStopType};
1616

1717
/// The CTFE machine has some custom error kinds.

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use std::sync::atomic::Ordering::Relaxed;
33
use either::{Left, Right};
44

55
use rustc_hir::def::DefKind;
6+
use rustc_middle::bug;
67
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo};
78
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
89
use rustc_middle::query::TyCtxtAt;
910
use rustc_middle::traits::Reveal;
1011
use rustc_middle::ty::layout::LayoutOf;
1112
use rustc_middle::ty::print::with_no_trimmed_paths;
1213
use rustc_middle::ty::{self, Ty, TyCtxt};
13-
use rustc_middle::{bug, throw_exhaust};
1414
use rustc_session::lint;
1515
use rustc_span::def_id::LocalDefId;
1616
use rustc_span::{Span, DUMMY_SP};
@@ -25,7 +25,7 @@ use crate::interpret::{
2525
InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking,
2626
StackPopCleanup,
2727
};
28-
use crate::interpret::{eval_nullary_intrinsic, InternResult};
28+
use crate::interpret::{eval_nullary_intrinsic, throw_exhaust, InternResult};
2929
use crate::CTRL_C_RECEIVED;
3030

3131
// Returns a pointer to where the result lives

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::DefId;
1111
use rustc_hir::def_id::LocalDefId;
1212
use rustc_hir::LangItem;
13+
use rustc_middle::bug;
1314
use rustc_middle::mir;
1415
use rustc_middle::mir::AssertMessage;
1516
use rustc_middle::query::TyCtxtAt;
1617
use rustc_middle::ty;
1718
use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout};
18-
use rustc_middle::{bug, err_ub, throw_exhaust, throw_inval, throw_ub_custom, throw_unsup_format};
1919
use rustc_session::lint::builtin::WRITES_THROUGH_IMMUTABLE_POINTER;
2020
use rustc_span::symbol::{sym, Symbol};
2121
use rustc_span::Span;
@@ -25,8 +25,9 @@ use rustc_target::spec::abi::Abi as CallAbi;
2525
use crate::errors::{LongRunning, LongRunningWarn};
2626
use crate::fluent_generated as fluent;
2727
use crate::interpret::{
28-
self, compile_time_machine, AllocId, AllocRange, ConstAllocation, CtfeProvenance, FnArg, FnVal,
29-
Frame, ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic, Scalar,
28+
self, compile_time_machine, err_ub, throw_exhaust, throw_inval, throw_ub_custom,
29+
throw_unsup_format, AllocId, AllocRange, ConstAllocation, CtfeProvenance, FnArg, FnVal, Frame,
30+
ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic, Scalar,
3031
};
3132

3233
use super::error::*;

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::mir::CastKind;
77
use rustc_middle::ty::adjustment::PointerCoercion;
88
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, TyAndLayout};
99
use rustc_middle::ty::{self, FloatTy, Ty};
10-
use rustc_middle::{bug, err_inval, span_bug, throw_ub, throw_ub_custom};
10+
use rustc_middle::{bug, span_bug};
1111
use rustc_target::abi::Integer;
1212
use rustc_type_ir::TyKind::*;
1313

@@ -16,6 +16,7 @@ use super::{
1616
};
1717

1818
use crate::fluent_generated as fluent;
19+
use crate::interpret::{err_inval, throw_ub, throw_ub_custom};
1920

2021
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2122
pub fn cast(

compiler/rustc_const_eval/src/interpret/discriminant.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
//! Functions for reading and writing discriminants of multi-variant layouts (enums and coroutines).
22
33
use rustc_middle::mir;
4+
use rustc_middle::span_bug;
45
use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt};
56
use rustc_middle::ty::{self, ScalarInt, Ty};
6-
use rustc_middle::{err_ub, span_bug, throw_ub};
77
use rustc_target::abi::{self, TagEncoding};
88
use rustc_target::abi::{VariantIdx, Variants};
99

1010
use super::{ImmTy, InterpCx, InterpResult, Machine, Readable, Scalar, Writeable};
1111

12+
use crate::interpret::{err_ub, throw_ub};
13+
1214
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1315
/// Writes the discriminant of the given variant.
1416
///

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{
1717
TyAndLayout,
1818
};
1919
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, Variance};
20-
use rustc_middle::{bug, err_inval, span_bug, throw_inval, throw_ub, throw_ub_custom, throw_unsup};
20+
use rustc_middle::{bug, span_bug};
2121
use rustc_mir_dataflow::storage::always_storage_live_locals;
2222
use rustc_session::Limit;
2323
use rustc_span::Span;
@@ -29,6 +29,7 @@ use super::{
2929
Provenance, Scalar, StackPopJump,
3030
};
3131
use crate::errors;
32+
use crate::interpret::{err_inval, throw_inval, throw_ub, throw_ub_custom, throw_unsup};
3233
use crate::util;
3334
use crate::{fluent_generated as fluent, ReportErrorExt};
3435

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use hir::def::DefKind;
1717
use rustc_ast::Mutability;
1818
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1919
use rustc_hir as hir;
20-
use rustc_middle::err_ub;
2120
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2221
use rustc_middle::mir::interpret::{ConstAllocation, CtfeProvenance, InterpResult};
2322
use rustc_middle::query::TyCtxtAt;
@@ -28,6 +27,7 @@ use rustc_span::sym;
2827
use super::{AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceTy};
2928
use crate::const_eval;
3029
use crate::errors::NestedStaticInThreadLocal;
30+
use crate::interpret::err_ub;
3131

3232
pub trait CompileTimeMachine<'mir, 'tcx: 'mir, T> = Machine<
3333
'mir,

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_middle::mir;
1212
use rustc_middle::query::TyCtxtAt;
1313
use rustc_middle::ty;
1414
use rustc_middle::ty::layout::TyAndLayout;
15-
use rustc_middle::{throw_unsup, throw_unsup_format};
1615
use rustc_span::def_id::DefId;
1716
use rustc_span::Span;
1817
use rustc_target::abi::{Align, Size};
@@ -24,6 +23,8 @@ use super::{
2423
Pointer, Provenance,
2524
};
2625

26+
use crate::interpret::{throw_unsup, throw_unsup_format};
27+
2728
/// Data returned by Machine::stack_pop,
2829
/// to provide further control over the popping of the stack frame
2930
#[derive(Eq, PartialEq, Debug, Copy, Clone)]

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::interpret::ScalarSizeMismatch;
1010
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1111
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter};
1212
use rustc_middle::ty::{ConstInt, ScalarInt, Ty, TyCtxt};
13-
use rustc_middle::{bug, err_ub, span_bug, throw_ub};
13+
use rustc_middle::{bug, span_bug};
1414
use rustc_middle::{mir, ty};
1515
use rustc_target::abi::{self, Abi, HasDataLayout, Size};
1616

@@ -20,6 +20,8 @@ use super::{
2020
Provenance, Scalar,
2121
};
2222

23+
use crate::interpret::{err_ub, throw_ub};
24+
2325
/// An `Immediate` represents a single immediate self-contained Rust value.
2426
///
2527
/// For optimization of a few very common cases, there is also a representation for a pair of

compiler/rustc_const_eval/src/interpret/operator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ use rustc_middle::mir;
33
use rustc_middle::mir::interpret::{InterpResult, Scalar};
44
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
55
use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty};
6-
use rustc_middle::{bug, err_ub, span_bug, throw_ub, throw_ub_custom};
6+
use rustc_middle::{bug, span_bug};
77
use rustc_span::symbol::sym;
88
use rustc_target::abi::Abi;
99

1010
use super::{ImmTy, Immediate, InterpCx, Machine, PlaceTy};
1111

1212
use crate::fluent_generated as fluent;
13+
use crate::interpret::{err_ub, throw_ub, throw_ub_custom};
1314

1415
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1516
/// Applies the binary operation `op` to the two operands and writes a tuple of the result

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir;
1111
use rustc_middle::ty;
1212
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1313
use rustc_middle::ty::Ty;
14-
use rustc_middle::{bug, span_bug, throw_ub};
14+
use rustc_middle::{bug, span_bug};
1515
use rustc_target::abi::{Abi, Align, HasDataLayout, Size};
1616

1717
use super::{
@@ -20,6 +20,8 @@ use super::{
2020
Operand, Pointer, PointerArithmetic, Projectable, Provenance, Readable, Scalar,
2121
};
2222

23+
use crate::interpret::throw_ub;
24+
2325
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
2426
/// Information required for the sound usage of a `MemPlace`.
2527
pub enum MemPlaceMeta<Prov: Provenance = CtfeProvenance> {

compiler/rustc_const_eval/src/interpret/projection.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ use rustc_middle::mir;
1414
use rustc_middle::ty;
1515
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1616
use rustc_middle::ty::Ty;
17-
use rustc_middle::{bug, span_bug, throw_ub, throw_unsup_format};
17+
use rustc_middle::{bug, span_bug};
1818
use rustc_target::abi::Size;
1919
use rustc_target::abi::{self, VariantIdx};
2020

2121
use super::{InterpCx, InterpResult, MPlaceTy, Machine, MemPlaceMeta, OpTy, Provenance, Scalar};
2222

23+
use crate::interpret::{throw_ub, throw_unsup_format};
24+
2325
/// Describes the constraints placed on offset-projections.
2426
#[derive(Copy, Clone, Debug)]
2527
pub enum OffsetMode {

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::borrow::Cow;
22

33
use either::Either;
44

5+
use rustc_middle::span_bug;
56
use rustc_middle::{
67
mir,
78
ty::{
@@ -10,7 +11,6 @@ use rustc_middle::{
1011
AdtDef, Instance, Ty,
1112
},
1213
};
13-
use rustc_middle::{span_bug, throw_ub, throw_ub_custom, throw_unsup_format};
1414
use rustc_span::{source_map::Spanned, sym};
1515
use rustc_target::abi::{self, FieldIdx};
1616
use rustc_target::abi::{
@@ -24,6 +24,7 @@ use super::{
2424
Projectable, Provenance, Scalar, StackPopCleanup,
2525
};
2626
use crate::fluent_generated as fluent;
27+
use crate::interpret::{throw_ub, throw_ub_custom, throw_unsup_format};
2728

2829
/// An argment passed to a function.
2930
#[derive(Clone, Debug)]

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::interpret::{MemPlaceMeta, MemoryKind};
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_middle::mir;
55
use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer};
6-
use rustc_middle::throw_inval;
76
use rustc_middle::ty::layout::TyAndLayout;
87
use rustc_middle::ty::{
98
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
@@ -12,6 +11,8 @@ use std::ops::ControlFlow;
1211

1312
use super::{InterpCx, MPlaceTy};
1413

14+
use crate::interpret::throw_inval;
15+
1516
/// Checks whether a type contains generic parameters which must be instantiated.
1617
///
1718
/// In case it does, returns a `TooGeneric` const eval error. Note that due to polymorphization

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use hir::def::DefKind;
1313
use rustc_ast::Mutability;
1414
use rustc_data_structures::fx::FxHashSet;
1515
use rustc_hir as hir;
16+
use rustc_middle::bug;
1617
use rustc_middle::mir::interpret::{
1718
ExpectedKind, InterpError, InvalidMetaKind, Misalignment, PointerKind, Provenance,
1819
ValidationErrorInfo, ValidationErrorKind, ValidationErrorKind::*,
1920
};
2021
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
2122
use rustc_middle::ty::{self, Ty};
22-
use rustc_middle::{bug, err_ub, throw_ub};
2323
use rustc_span::symbol::{sym, Symbol};
2424
use rustc_target::abi::{
2525
Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
@@ -39,6 +39,8 @@ use super::InterpError::Unsupported as Unsup;
3939
use super::UndefinedBehaviorInfo::*;
4040
use super::UnsupportedOpInfo::*;
4141

42+
use crate::interpret::{err_ub, throw_ub};
43+
4244
macro_rules! throw_validation_failure {
4345
($where:expr, $kind: expr) => {{
4446
let where_ = &$where;

compiler/rustc_const_eval/src/interpret/visitor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
use rustc_index::IndexVec;
55
use rustc_middle::mir::interpret::InterpResult;
6-
use rustc_middle::throw_inval;
76
use rustc_middle::ty::{self, Ty};
87
use rustc_target::abi::FieldIdx;
98
use rustc_target::abi::{FieldsShape, VariantIdx, Variants};
@@ -12,6 +11,8 @@ use std::num::NonZero;
1211

1312
use super::{InterpCx, MPlaceTy, Machine, Projectable};
1413

14+
use crate::interpret::throw_inval;
15+
1516
/// How to traverse a value and what to do when we are at the leaves.
1617
pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
1718
type V: Projectable<'tcx, M::Provenance> + From<MPlaceTy<'tcx, M::Provenance>>;

0 commit comments

Comments
 (0)