Skip to content

Commit 99ae45a

Browse files
authored
cleanup some inacurrate or out-of-date code docs (#2802)
1 parent ac22632 commit 99ae45a

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

source/vir/src/ast.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ pub struct Visibility {
117117

118118
#[derive(Clone, Debug, Serialize, Deserialize, ToDebugSNode, PartialEq, Eq)]
119119
pub enum BodyVisibility {
120+
/// Function is declared uninterpreted (i.e., "visible nowhere")
120121
Uninterpreted,
121-
/// None for pub
122-
/// Some(path) means visible to path and path's descendents
122+
/// Body is visible at the given visibility.
123123
Visibility(Visibility),
124124
}
125125

@@ -190,12 +190,12 @@ pub enum IntRange {
190190
/// In some places, the decoration of a Typ cannot be considered meaningful due to these
191191
/// implicit 'identity' coercions:
192192
/// - `expr.typ`
193-
/// - `place.typ`
194193
/// - `pattern.typ`
195194
/// - `exp.typ` (SST nodes)
196195
/// But in other places, types must be exactly correct, *including* decoration:
197196
/// - type arguments for a Call
198197
/// - `pattern_binding.typ` (type of a local variable declaration)
198+
/// - `place.typ` (See docs for `Place`)
199199
/// - Most places where `Typ` is given as an explicit field of a node
200200
#[derive(
201201
Debug,
@@ -249,8 +249,6 @@ pub enum TypDecoration {
249249
pub enum Primitive {
250250
Array,
251251
Slice,
252-
/// StrSlice type. Currently the vstd StrSlice struct is "seen" as this type
253-
/// despite the fact that it is in fact a datatype
254252
StrSlice,
255253
Ptr, // Mut ptr, unless Const decoration is applied
256254
Global,
@@ -353,7 +351,8 @@ pub enum ModeCoercion {
353351
/// This operation behaves like a datatype constructor with a mode annotation
354352
/// `from_mode` on its field.
355353
/// (e.g., Tracked(...) is proof -> exec, Ghost(...) is spec -> exec.
356-
/// Like with ordinary constructors, the input can be spec and if so, the whole thing is spec.
354+
/// Note that `Tracked` behaves like an exec datatype with a proof-mode field, meaning
355+
/// if the input is 'spec', then the whole thing is 'spec'.
357356
Constructor,
358357
/// This behaves like a field-getter,
359358
/// returning the contents of the Tracked or Ghost value.
@@ -574,18 +573,17 @@ pub enum BoundsCheck {
574573

575574
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, ToDebugSNode)]
576575
pub enum OverflowBehavior {
577-
/// Return an int. This is the only value allowed in SST.
576+
/// Return an unbounded int, the exact value of the arithmetic expression.
578577
Allow,
579-
/// Truncate to the given range
578+
/// Truncate to the given range.
580579
Truncate(IntRange),
581-
/// Error if the result is outside the given range
580+
/// Error if the result is outside the given range.
582581
Error(IntRange),
583582
}
584583

585584
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, ToDebugSNode)]
586585
pub enum Div0Behavior {
587586
/// Return the (unspecified) result of divide- or mod-by-0.
588-
/// This is the only value allowed in SST.
589587
Allow,
590588
/// Error if the dividend is 0.
591589
Error,

source/vir/src/resolution_inference.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ In order to resolve the field of an enum (e.g., `opt->Some_0` for a varible `opt
102102
the resolution needs to be conditional on the variant:
103103
104104
```
105-
assume(opt is Some ==> has_resolved(opt->Some_0)
105+
assume(opt is Some ==> has_resolved(opt->Some_0))
106106
```
107107
108108
Since resolution is explicitly conditional, we don't need to account for variants
@@ -253,7 +253,8 @@ use air::scope_map::ScopeMap;
253253
use std::collections::{HashMap, VecDeque};
254254
use std::sync::Arc;
255255

256-
/// Updates the given function body to include AssumeResolved nodes at the appropriate places.
256+
/// Updates the given function body to include assume(has_resolved(...)) nodes
257+
/// at the appropriate places.
257258
/// On the side, also handles some work related to user_defined_type_invariants.
258259
///
259260
/// This relies on the AstIds of the given Expr being unique, but it also destroys this property
@@ -1329,7 +1330,6 @@ impl<'a> Builder<'a> {
13291330
}
13301331
}
13311332

1332-
/// Returns Err(()) if the place expression never returns (can happen if it's a temporary)
13331333
fn build_place_typed(
13341334
&mut self,
13351335
place: &Place,
@@ -1572,6 +1572,17 @@ impl<'a> Builder<'a> {
15721572
}
15731573
}
15741574

1575+
/// Get all moves and mutations for the given pattern, using `ByRef::No` for moves
1576+
/// and `ByRef::MutRef` for mutations.
1577+
///
1578+
/// Example:
1579+
///
1580+
/// ```
1581+
/// let (a, _, ref mut b) = x.1;
1582+
/// ```
1583+
///
1584+
/// Returns `[(x.1.0, ByRef::No), (x.1.2, ByRef::MutRef)]` if `x.1.0` is a non-Copy type.
1585+
/// Otherwise just returns `[(x.1.2, ByRef::MutRef)]`.
15751586
fn moves_and_muts_for_place_being_matched(
15761587
&mut self,
15771588
pattern: &Pattern,
@@ -1970,7 +1981,7 @@ pub struct BoundVar {
19701981
pub typ: Typ,
19711982
}
19721983

1973-
/// Same as above, but takes a Pattern as input
1984+
/// Get all non-spec vars bound by the pattern.
19741985
pub fn pattern_all_bound_vars_with_ownership(
19751986
pattern: &Pattern,
19761987
modes: &HashMap<VarIdent, Mode>,
@@ -2017,6 +2028,7 @@ pub fn pattern_all_bound_vars_with_ownership(
20172028
v
20182029
}
20192030

2031+
/// See `moves_and_muts_for_place_being_matched`
20202032
fn moves_and_muts_for_pattern(
20212033
pattern: &Pattern,
20222034
datatypes: &HashMap<Path, Datatype>,
@@ -3845,8 +3857,6 @@ fn add_decls_for_temps(
38453857
// Declare all temp vars at the beginning of the function body
38463858
// (There doesn't seem to be any point in minimizing the scope of such variables,
38473859
// but maybe we should restrict them to individual loops?)
3848-
// We mark them all mut, though in principle, some of them don't need to be mut,
3849-
// e.g., the ones that are only here so we can call `assume(HasResolved(...))`.
38503860
let mut stmts = vec![];
38513861
for local in cfg.locals.locals.iter() {
38523862
if let LocalName::Temporary(ast_id, temp_id) = &local.name {

0 commit comments

Comments
 (0)