Skip to content

Commit 953d981

Browse files
committed
Add documentation of src/analyze/{annot,crate_,did_cache,local_def}.rs
1 parent 3492f9d commit 953d981

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/analyze/annot.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Supporting implementation for parsing Thrust annotations.
2+
13
use rustc_ast::ast::Attribute;
24
use rustc_ast::tokenstream::TokenStream;
35
use rustc_index::IndexVec;
@@ -31,6 +33,10 @@ pub fn callable_path() -> [Symbol; 2] {
3133
[Symbol::intern("thrust"), Symbol::intern("callable")]
3234
}
3335

36+
/// A [`Resolver`] implementation for resolving function parameters.
37+
///
38+
/// The parameter names and their sorts needs to be configured via
39+
/// [`ParamResolver::push_param`] before use.
3440
#[derive(Debug, Clone, Default)]
3541
pub struct ParamResolver {
3642
params: IndexVec<rty::FunctionParamIdx, (Symbol, chc::Sort)>,
@@ -52,6 +58,10 @@ impl ParamResolver {
5258
}
5359
}
5460

61+
/// A [`Resolver`] implementation for resolving the special identifier `result`.
62+
///
63+
/// The `result` identifier is used to refer to [`rty::RefinedTypeVar::Value`] in postconditions, denoting
64+
/// the return value of a function.
5565
#[derive(Debug, Clone)]
5666
pub struct ResultResolver {
5767
result_symbol: Symbol,

src/analyze/crate_.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Analyze a local crate.
2+
13
use std::collections::HashSet;
24

35
use rustc_hir::def::DefKind;
@@ -12,6 +14,16 @@ use crate::chc;
1214
use crate::refine::{self, TemplateTypeGenerator, UnrefinedTypeGenerator};
1315
use crate::rty::{self, ClauseBuilderExt as _};
1416

17+
/// An implementation of local crate analysis.
18+
///
19+
/// The entry point is [`Analyzer::run`], which performs the following steps in order:
20+
///
21+
/// 1. Register enum definitions found in the crate.
22+
/// 2. Give initial refinement types to local function definitions based on their signatures and
23+
/// annotations. This generates template refinement types with predicate variables for parameters and
24+
/// return types that are not known via annotations.
25+
/// 3. Type local function definition bodies via [`local_def::Analyzer`] using the refinement types
26+
/// generated in the previous step.
1527
pub struct Analyzer<'tcx, 'ctx> {
1628
tcx: TyCtxt<'tcx>,
1729
ctx: &'ctx mut analyze::Analyzer<'tcx>,

src/analyze/did_cache.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Retrieves and caches well-known [`DefId`]s.
2+
13
use std::cell::OnceCell;
24

35
use rustc_middle::ty::TyCtxt;
@@ -10,6 +12,10 @@ struct DefIds {
1012
nonnull: OnceCell<Option<DefId>>,
1113
}
1214

15+
/// Retrieves and caches well-known [`DefId`]s.
16+
///
17+
/// [`DefId`]s of some well-known types can be retrieved as lang items or via the definition of
18+
/// lang items. This struct implements that logic and caches the results.
1319
#[derive(Clone)]
1420
pub struct DefIdCache<'tcx> {
1521
tcx: TyCtxt<'tcx>,

src/analyze/local_def.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Analyze a local definition.
2+
13
use std::collections::{HashMap, HashSet};
24

35
use rustc_index::bit_set::BitSet;
@@ -12,6 +14,10 @@ use crate::pretty::PrettyDisplayExt as _;
1214
use crate::refine::{BasicBlockType, TemplateTypeGenerator};
1315
use crate::rty;
1416

17+
/// An implementation of the typing of local definitions.
18+
///
19+
/// The current implementation only applies to function definitions. The entry point is
20+
/// [`Analyzer::run`], which generates constraints during typing, given the expected type of the function.
1521
pub struct Analyzer<'tcx, 'ctx> {
1622
ctx: &'ctx mut analyze::Analyzer<'tcx>,
1723
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)