docs(objects): clarify type capability and effect query contracts

This commit is contained in:
2026-11-15 19:39:21 +08:00
parent 4880547e66
commit ca61378c92
2 changed files with 40 additions and 17 deletions
+6 -2
View File
@@ -1,5 +1,6 @@
//! Store::call_effect 的当前快照证明;None 表示无法证明,不代表确定有副作用。
//! 查询经过 Store 读取追踪,但不执行源码或分配托管对象;所有身份仅借用。
//! 返回效果不会保留目标或冻结全局/Cell/方法表;缓存者需在追踪作用域收集观察并在使用前重验。
//! Snapshot proof of read-only call graphs. All identities are borrowed and all
//! traversals iterative; analysis neither executes code nor allocates VM objects.
use super::{AttributeLookup, BoundMethod};
@@ -10,8 +11,11 @@ use crate::{
use std::collections::{BTreeSet, VecDeque};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
/// infer_call_effect 队列与去重集合中的借用调用身份,read_only_callees 识别直接/绑定调用后构造。
struct Target {
/// 底层被调函数身份;队列本身不新增拥有根。
function: ObjectRef,
/// 已知的首个接收者,可用于解析 LoadFast(0) 和方法;未知时保持 None。
receiver: Option<ObjectRef>,
}
#[derive(Clone, Copy, PartialEq, Eq)]
@@ -26,7 +30,7 @@ enum Fact {
Method(Target),
}
impl Fact {
// 把实际值降为抽象身份事实,直接标量不保留其内容。
// read_only_callees 对常量、全局值及 Cell 内容降为身份事实,直接标量不保留其内容。
fn value(value: Value) -> Self {
// 对象保留借用身份,标量统一变成 Unknown;不把抽象事实当作实际求值结果。
match value {
@@ -34,7 +38,7 @@ impl Fact {
_ => Self::Unknown,
}
}
// 只从普通对象事实提取身份,不把方法对当作对象。
// read_only_callees 的属性接收者/调用参数识别只提取普通对象身份,不把方法对当作对象。
fn object(self) -> Option<ObjectRef> {
// 仅 Object 事实可用于属性接收者或调用身份,Unknown/Null/Method 都不冒充普通对象。
match self {