chore: initialize standalone UPM package
Publish UPM package / publish (push) Failing after 1s

This commit is contained in:
2026-08-26 02:49:58 +08:00
commit 6eebb8e8e4
50 changed files with 3458 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#nullable enable
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
namespace ShrinkContext
{
/// <summary>
/// 组件 = (inject 依赖键集合 d, provide 供给键集合 p, apply 效应函数 e)(论文定义 43)。
/// apply 内部通过 ctx.Set 提供依赖、ctx.Get 消费依赖、ctx.Effect 注册可逆效应;
/// 组件的拆卸由运行时按已追踪的逆操作自动推导,无需手写卸载路径。
/// </summary>
public interface IShrinkComponent
{
string Name { get; }
/// <summary>声明的依赖键集合(论文 d):全部可用时组件才激活。</summary>
IReadOnlyList<string> Inject { get; }
/// <summary>供给键集合(论文 p):apply 的效应不应写入 p 之外的键。</summary>
IReadOnlyList<string> Provide { get; }
/// <summary>效应函数(论文 e):激活时执行;其中注册的效应在停用时按 LIFO 回滚。</summary>
UniTask ApplyAsync(ShrinkCtx ctx, object? config);
}
/// <summary>
/// 分步效应组件(论文 𝔈iterΓ):apply 以步进器逐步产出逆操作。
/// 目标在步进边界发生变化时中断迭代并回滚已执行步骤(部分回滚,论文 4.3.2 / 定理 64)。
/// 使用自定义 UniTask 步进协议而非 IAsyncEnumerable
/// Mono 的 ValueTask 迭代器恢复经同步上下文调度,会破坏同步内联的确定性语义。
/// </summary>
public interface IShrinkIterativeComponent : IShrinkComponent
{
IShrinkStepEffectEnumerator ApplySteps(ShrinkCtx ctx, object? config);
}
/// <summary>分步效应步进器:MoveNextAsync 执行该步前向并使 Current 指向其逆操作。</summary>
public interface IShrinkStepEffectEnumerator
{
/// <summary>推进到下一步;返回 false 表示迭代结束。前向在该调用内执行完毕。</summary>
UniTask<bool> MoveNextAsync();
/// <summary>最近一次 MoveNextAsync 成功后该步的逆操作。</summary>
Func<UniTask> Current { get; }
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc9d2e1bcf849da42a70c6c720e1c770
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+68
View File
@@ -0,0 +1,68 @@
#nullable enable
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
namespace ShrinkContext
{
public enum ShrinkFiberState
{
Inactive = 0,
Loading = 1,
Active = 2,
Unloading = 3,
}
/// <summary>
/// 纤程(论文定义 44):组件的一次运行时实例化。
/// 生命周期由 Target(期望提供者集合,null 即 ⊥)与惯性状态机驱动:
/// 一旦进入转换即运行至完成,之后才响应新的目标变化(算法 5)。
/// </summary>
public sealed class ShrinkFiber
{
internal ShrinkFiber(long uid, IShrinkComponent component, ShrinkFiber? parent, object? config)
{
Uid = uid;
Component = component;
Parent = parent;
Config = config;
InjectSet = new HashSet<string>(component.Inject ?? Array.Empty<string>(), StringComparer.Ordinal);
ProvideSet = new HashSet<string>(component.Provide ?? Array.Empty<string>(), StringComparer.Ordinal);
}
public long Uid { get; }
public string Name => Component.Name;
public IShrinkComponent Component { get; }
/// <summary>实例化该纤程时的父纤程(根级为 null);父纤程卸载会级联到本纤程。</summary>
public ShrinkFiber? Parent { get; }
/// <summary>本纤程运行所在的派生子上下文。</summary>
public ShrinkCtx Ctx { get; internal set; } = null!;
public object? Config { get; }
public ShrinkFiberState State { get; internal set; } = ShrinkFiberState.Inactive;
/// <summary>是否到达过 Active(用于断言“从未激活”)。</summary>
public bool EverActive { get; internal set; }
/// <summary>最近一次 apply 抛出的异常;成功激活后清空。</summary>
public Exception? LastError { get; internal set; }
/// <summary>已提交视图(算法 5 reload 提交 / 算法 6 读取):依赖键 → 绑定快照。</summary>
public IReadOnlyDictionary<string, ShrinkBinding>? Committed => _committed;
/// <summary>进行中转换的句柄;任务在纤程到达静止态(Active 或 Inactive)时完成。</summary>
public UniTask Inertia { get; internal set; }
internal Dictionary<string, ShrinkBinding>? _committed;
internal long[]? Target;
internal bool InTransition;
internal bool Retired;
internal HashSet<string> InjectSet { get; }
internal HashSet<string> ProvideSet { get; }
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 812996226a7accb44b00963f89ff15fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: