docs(tests): correct nominal and native contract scenario boundaries
This commit is contained in:
@@ -62,7 +62,7 @@ fn scoped_allocations_return_one_root_and_clean_up_errors() {
|
||||
/// 返回目标借用身份,由包装载荷 captures 保活,NativeContext 为 Invoke 输出取得拥有根。
|
||||
struct Delegate(ObjectRef);
|
||||
impl NativeCallable for Delegate {
|
||||
/// VM 在 NativeContext 内调用此测试分派器,临时分配与输入由上下文保活,返回/委托后移交输出根。
|
||||
/// VM 分派时原样委托给 captures 保活的目标;参数 clone 仍借用,NativeContext 随后为 Invoke 输出逐项取根。
|
||||
fn invoke(&self, _cx: &mut NativeContext<'_>, args: &[Value]) -> Result<NativeResult, VmError> {
|
||||
Ok(NativeResult::Invoke {
|
||||
function: self.0,
|
||||
@@ -157,7 +157,7 @@ fn native_delegation_shares_budget_and_cleans_owned_arguments() {
|
||||
assert_eq!(vm.ref_count(target).unwrap(), 2);
|
||||
// VM 调用已完成根移交,返回对象应只有一份调用者根。
|
||||
let value = vm.call(delegate, &[]).unwrap();
|
||||
// 归还成功结果,之后只剩函数载荷,临时对象应已自动清理。
|
||||
// 归还 Allocate 返回的独立结果根;delegate、target、arg 的测试根仍在下面分别释放。
|
||||
vm.release_value(value).unwrap();
|
||||
vm.release(delegate).unwrap();
|
||||
vm.release(target).unwrap();
|
||||
@@ -237,6 +237,7 @@ fn notification_overflow_requires_rescan_instead_of_losing_changes_silently() {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// 只读场景的复制器:读输入字段并构造新结果,可选故意改旧输入以验证写屏障及错误退出。
|
||||
struct ReadResult {
|
||||
/// 输入借用身份,包装载荷 captures 负责保活。
|
||||
source: ObjectRef,
|
||||
@@ -381,6 +382,7 @@ fn annotation_reads_remain_dependencies_without_becoming_program_content_reads()
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// 完整签名场景共用分派器,以计数器区分预检/回调/返回检查,支持委托、新分配或回传实参。
|
||||
struct TypedNative {
|
||||
/// 构造时快照的完整签名,包装载荷负责 trace 类型定义。
|
||||
signature: endor_core::CallSignature,
|
||||
@@ -479,7 +481,7 @@ fn delegated_source_results_obey_every_native_contract_without_extra_frames() {
|
||||
let code = vm.new_code(code).unwrap();
|
||||
// 源码环境有分配根,函数持有它的内部边。
|
||||
let globals = vm.new_dict().unwrap();
|
||||
// 源码函数返回文本或 Nil,作为后续返回契约一致/不一致的终点。
|
||||
// 此源码函数固定返回文本;inner 的 String 返回约束可通过,outer 的 Number 约束必须失败。
|
||||
let source = vm
|
||||
.new_function("source", code, globals, vec![], vec![])
|
||||
.unwrap();
|
||||
@@ -705,10 +707,11 @@ fn legacy_native_signatures_check_optional_variadic_types_and_metadata() {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// 移除自身载荷的回归分派器,迫使签名类型在原持边消失后仍由执行检查根保活。
|
||||
struct EraseThenDelegate {
|
||||
/// 构造时快照的完整签名,包装载荷负责 trace 类型定义。
|
||||
signature: endor_core::CallSignature,
|
||||
/// 被委托源码函数,由包装载荷 captures 保活至回调中输出保护接管。
|
||||
/// 被委托源码函数最初有 captures 边;载荷自替换后该边消失,本测试另保留 source 根保护目标。
|
||||
target: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for EraseThenDelegate {
|
||||
@@ -719,6 +722,7 @@ impl NativeCallable for EraseThenDelegate {
|
||||
/// 测试原生分派入口,回调内借用参数/目标,NativeContext 校验并移交 Return 或 Invoke 输出根。
|
||||
fn invoke(&self, cx: &mut NativeContext<'_>, _: &[Value]) -> Result<NativeResult, VmError> {
|
||||
// 将当前函数换为普通 Record,移除签名及捕获边,迫使返回约束靠执行器自己的根存活。
|
||||
// self.target 的存活此时依赖测试未归还的 source 根,Arc 中的 ObjectRef 不构成托管边。
|
||||
cx.replace_payload(cx.callee(), endor_core::Record)?;
|
||||
Ok(NativeResult::Invoke {
|
||||
function: self.target,
|
||||
@@ -758,7 +762,7 @@ fn delegated_return_type_survives_removal_of_the_original_signature_edges() {
|
||||
let code = vm.new_code(code).unwrap();
|
||||
// 源码环境有分配根,函数持有它的内部边。
|
||||
let globals = vm.new_dict().unwrap();
|
||||
// 源码函数返回文本或 Nil,作为后续返回契约一致/不一致的终点。
|
||||
// 此源码函数固定返回 Nil,故意不满足包装器的 Transient | Number 返回联合。
|
||||
let source = vm
|
||||
.new_function("source", code, globals, vec![], vec![])
|
||||
.unwrap();
|
||||
@@ -916,7 +920,7 @@ fn native_union_and_nullable_contracts_accept_each_branch_and_reject_invalid_met
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// Delegated 包装器能进入只读域,但实际目标仍在同域核对效果,目标换为纯函数后可通过。
|
||||
/// Delegated 包装器能进入只读域,但实际目标仍在同域核对效果,目标改为 ReadOnly 声明后可通过。
|
||||
fn delegated_effects_keep_the_original_read_only_scope_and_check_the_actual_target() {
|
||||
use endor_core::{AnnotationType as T, CallEffect, CallSignature};
|
||||
use std::sync::{
|
||||
|
||||
Reference in New Issue
Block a user