From 2178961262e464151bb33feeaaae04fb272d4856 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 8 Jun 2016 12:35:15 +0200 Subject: [PATCH] improve the docs of ConstantId --- src/interpreter/mod.rs | 13 ++++++++++--- src/interpreter/stepper.rs | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 774db299db6..1942727e476 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -129,8 +129,14 @@ enum TerminatorTarget { } #[derive(Clone, Debug, Eq, PartialEq, Hash)] +/// Uniquely identifies a specific constant or static struct ConstantId<'tcx> { + /// the def id of the constant/static or in case of promoteds, the def id of the function they belong to def_id: DefId, + /// In case of statics and constants this is `Substs::empty()`, so only promoteds and associated + /// constants actually have something useful here. We could special case statics and constants, + /// but that would only require more branching when working with constants, and not bring any + /// real benefits. substs: &'tcx Substs<'tcx>, kind: ConstantKind, } @@ -138,7 +144,8 @@ struct ConstantId<'tcx> { #[derive(Clone, Debug, Eq, PartialEq, Hash)] enum ConstantKind { Promoted(usize), - Static, + /// Statics, constants and associated constants + Global, } impl<'a, 'tcx> GlobalEvalContext<'a, 'tcx> { @@ -1199,7 +1206,7 @@ fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult { let cid = ConstantId { def_id: def_id, substs: substs, - kind: ConstantKind::Static, + kind: ConstantKind::Global, }; Ok(*self.statics.get(&cid).expect("static should have been cached (rvalue)")) } @@ -1231,7 +1238,7 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult { let cid = ConstantId { def_id: def_id, substs: substs, - kind: ConstantKind::Static, + kind: ConstantKind::Global, }; *self.gecx.statics.get(&cid).expect("static should have been cached (lvalue)") }, diff --git a/src/interpreter/stepper.rs b/src/interpreter/stepper.rs index c0e9249b292..f9bf5c2d3b8 100644 --- a/src/interpreter/stepper.rs +++ b/src/interpreter/stepper.rs @@ -145,7 +145,7 @@ fn static_item(&mut self, def_id: DefId, substs: &'tcx subst::Substs<'tcx>, span let cid = ConstantId { def_id: def_id, substs: substs, - kind: ConstantKind::Static, + kind: ConstantKind::Global, }; if self.gecx.statics.contains_key(&cid) { return; -- 2.44.0