]> git.lizzy.rs Git - rust.git/commitdiff
improve the docs of ConstantId
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 8 Jun 2016 10:35:15 +0000 (12:35 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 8 Jun 2016 10:35:15 +0000 (12:35 +0200)
src/interpreter/mod.rs
src/interpreter/stepper.rs

index 774db299db6f477a84001f983cf4ae4084cb276d..1942727e47694613f79269b889eb0c4efa6147e0 100644 (file)
@@ -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<Pointer> {
                             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<Lvalue> {
                 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)")
             },
index c0e9249b29250b8c19480ab8658779400ce1369a..f9bf5c2d3b85314cdfaaa1cf5b01c454afdc5bef 100644 (file)
@@ -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;