Skip to content

Commit

Permalink
Document the mk_*_eval_cx functions
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 9, 2019
1 parent cea282b commit f174b73
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/librustc_mir/const_eval.rs
Expand Up @@ -35,6 +35,8 @@ const STEPS_UNTIL_DETECTOR_ENABLED: isize = 1_000_000;
/// Should be a power of two for performance reasons.
const DETECTOR_SNAPSHOT_PERIOD: isize = 256;

/// Warning: do not use this function if you expect to start interpreting the given `Mir`.
/// The `EvalContext` is only meant to be used to query values from constants and statics.

This comment has been minimized.

Copy link
@RalfJung

RalfJung Jan 9, 2019

Member

Why is it called "borrowck" then?

This comment has been minimized.

Copy link
@oli-obk

oli-obk Jan 9, 2019

Author Contributor

Because we do this during borrowck, where we can't call load_mir, because we are inside the mir_optimized query or some sub query of that.

This comment has been minimized.

Copy link
@RalfJung

RalfJung Jan 9, 2019

Member

Ah. That makes sense.

Please add it to the comment. :)

pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance: Instance<'tcx>,
Expand All @@ -46,6 +48,8 @@ pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>(
mk_eval_cx_inner(tcx, instance, mir, span, param_env)
}

/// This is just a helper function to reduce code duplication between `mk_borrowck_eval_cx` and
/// `mk_eval_cx`. Do not call this function directly.
fn mk_eval_cx_inner<'a, 'mir, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance: Instance<'tcx>,
Expand All @@ -54,8 +58,9 @@ fn mk_eval_cx_inner<'a, 'mir, 'tcx>(
param_env: ty::ParamEnv<'tcx>,
) -> EvalResult<'tcx, CompileTimeEvalContext<'a, 'mir, 'tcx>> {
let mut ecx = EvalContext::new(tcx.at(span), param_env, CompileTimeInterpreter::new());
// insert a stack frame so any queries have the correct substs
// cannot use `push_stack_frame`; if we do `const_prop` explodes
// Insert a stack frame so any queries have the correct substs.
// We also avoid all the extra work performed by push_stack_frame,
// like initializing local variables
ecx.stack.push(interpret::Frame {
block: mir::START_BLOCK,
locals: IndexVec::new(),
Expand All @@ -70,6 +75,9 @@ fn mk_eval_cx_inner<'a, 'mir, 'tcx>(
Ok(ecx)
}

/// Warning: do not use this function if you expect to start interpreting the given `Mir`.
/// The `EvalContext` is only meant to be used to do field and index projections into constants for
/// `simd_shuffle` and const patterns in match arms.

This comment has been minimized.

Copy link
@RalfJung

RalfJung Jan 9, 2019

Member

Hm, I don't really understand the difference from mk_borrowck_eval_cx. One takes a Mir, the other has a ParamEnv instead... uh, aha?

But that confusion is not new, it doesn't have to be fixed by this PR.

fn mk_eval_cx<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance: Instance<'tcx>,
Expand Down

0 comments on commit f174b73

Please sign in to comment.