架构优化

This commit is contained in:
2026-08-11 12:40:28 +08:00
parent e91f134f16
commit 8d4714f691
17 changed files with 210 additions and 107 deletions
+7 -2
View File
@@ -100,8 +100,11 @@ static_assert(Property::writable);
static_assert(Property::runtime_copy_writable);
using Value = Property::value_type;
using Accessor = Property::accessor_type;
using Dependencies = Property::dependency_spec;
```
Every custom `Property_Accessor` must declare `using dependency_spec = ...`. Use `No_Property_Dependencies` when it has no dependencies; there is no implicit fallback.
A `read_only` field reports:
```cpp
@@ -513,7 +516,7 @@ computed_property<Device, int>(depends_on<&Device::min_speed, &Device::max_speed
}, key<"speed_span">)
```
`depends_on<...>` makes dependencies explicit Schema facts. `depends_on_keys<"a", "b">` is available when key-based declaration is more appropriate. A computed view can read only its declared direct dependencies.
`depends_on<...>` makes dependencies explicit Schema facts. `depends_on_keys<"a", "b">` is available when key-based declaration is more appropriate. `depends_on<>` is a valid explicit zero-dependency declaration. A computed view can read only its declared direct dependencies.
Writable dependencies that must form one snapshot should share a synchronization domain with each other:
@@ -526,7 +529,9 @@ synchronization(
Do not put the computed property itself in a synchronization rule. Its read slot is derived from the dependency graph; a schema or per-instance topology is rejected when synchronized dependencies do not resolve to one domain. Read-only stored dependencies need no lock slot.
`schema_property_dependency_indices<Schema, Index>()` exposes the direct dependency indices for schema consumers.
`schema_property_dependency_indices<Schema, Index>()` exposes the direct dependency indices for schema consumers. `schema_dependency_graph_acyclic<Schema>()` exposes the DAG invariant; `object_schema(...)` rejects cyclic dependency graphs at compile time.
A descriptor stores Attributes and Constraints in one metadata tuple. `for_each_metadata()` traverses both kinds, `for_each_attribute()` traverses only Attributes, and `for_each_constraint()` traverses only Constraints.
## 21. Trusted accessor properties
+7 -2
View File
@@ -98,8 +98,11 @@ static_assert(Property::writable);
static_assert(Property::runtime_copy_writable);
using Value = Property::value_type;
using Accessor = Property::accessor_type;
using Dependencies = Property::dependency_spec;
```
所有自定义 `Property_Accessor` 都必须显式声明 `using dependency_spec = ...`。无依赖时使用 `No_Property_Dependencies`,不再存在隐式 fallback。
`read_only` 字段:
```cpp
@@ -505,7 +508,7 @@ computed_property<Device, int>(depends_on<&Device::min_speed, &Device::max_speed
}, key<"speed_span">)
```
`depends_on<...>` 把 dependency 变成 Schema 的显式结构事实。也可以通过 `depends_on_keys<"a", "b">` 按 key 声明。Computed view 只能读取已声明的直接 dependency。
`depends_on<...>` 把 dependency 变成 Schema 的显式结构事实。也可以通过 `depends_on_keys<"a", "b">` 按 key 声明。`depends_on<>` 是合法的显式零依赖声明。Computed view 只能读取已声明的直接 dependency。
如果 writable dependency 需要同一快照,只需要让这些 writable dependency 共享 synchronization domain
@@ -518,7 +521,9 @@ synchronization(
Computed Property 自身不要加入 synchronization rule。它的读取 slot 根据 dependency graph 自动推导;如果需要同步的 dependency 不在同一个 domainSchema/实例 synchronization topology 会被拒绝。Read-only stored dependency 不需要 lock slot。
Schema 可通过 `schema_property_dependency_indices<Schema, Index>()` 读取某个 Property 的直接 dependency index。
Schema 可通过 `schema_property_dependency_indices<Schema, Index>()` 读取某个 Property 的直接 dependency index`schema_dependency_graph_acyclic<Schema>()` 暴露 DAG invariant`object_schema(...)` 会在编译期拒绝 dependency cycle
Descriptor 使用一份 metadata tuple 同时保存 Attribute 与 Constraint。`for_each_metadata()` 遍历两者,`for_each_attribute()` 只遍历 Attribute`for_each_constraint()` 只遍历 Constraint。
## 21. Trusted Accessor Property
+7 -6
View File
@@ -46,6 +46,7 @@ Structive has two architectural layers.
- intrinsic readable/writable capability;
- Attributes;
- Constraints;
- dependency graph;
- default synchronization description.
This information belongs to the type.
@@ -213,7 +214,7 @@ A computed property may itself be read-only while depending on writable fields.
The computed property does not contain writable storage. However, its read may require a stable snapshot of mutable dependencies.
Dependencies must be explicit Schema facts. The `Synchronized_Computed_Accessor` read view can access only declared direct dependencies, and the computed property's read slot is derived from the dependency graph instead of requiring its key to be repeated in a synchronization group.
Dependencies must be explicit Schema facts. Every Property Accessor declares a `dependency_spec`; no-dependency accessors use `No_Property_Dependencies` explicitly. The `Synchronized_Computed_Accessor` read view can access only declared direct dependencies, and the computed property's read slot is derived from the dependency graph instead of requiring its key to be repeated in a synchronization group. The dependency graph is a DAG invariant and cycles are rejected at compile time when the Schema is formed.
Writable dependencies that require one atomic snapshot must share one synchronization domain with each other. Read-only stored dependencies are safe to read directly through the synchronized view because they have no managed writer.
@@ -221,17 +222,17 @@ Writable dependencies that require one atomic snapshot must share one synchroniz
Do not give a read-only stored field a mutex. A computed read uses synchronization only for mutable dependencies that require consistency.
## 12. One Attribute protocol
## 12. One property metadata store
Core and extensions share one Attribute mechanism.
A Property Descriptor has one metadata store. Its entries are either Attributes or Constraints.
An Attribute owns a category and may define whether it is single-valued and inheritable.
Core and extensions share one Attribute mechanism for descriptive metadata. An Attribute owns a category and declares whether it is single-valued and inheritable. Constraints use the validation protocol but live in the same descriptor metadata store.
Core must not create parallel metadata systems for UI, serialization, diagnostics or domain-specific features.
Core must not create parallel metadata storage systems for UI, serialization, diagnostics or domain-specific features.
### Rule
New metadata domains should extend the Attribute protocol instead of adding a second metadata framework.
New descriptive metadata domains should extend the Attribute protocol; new validation rules should extend the Constraint protocol. Both remain entries in the same Property metadata store.
## 13. Category ownership must be clear
+7 -6
View File
@@ -46,6 +46,7 @@ Structive 有两层架构。
- intrinsic readable/writable
- Attribute
- Constraint
- dependency graph
- 默认 synchronization 描述。
这些属于类型。
@@ -211,7 +212,7 @@ Computed Property 自身可以只读,但它可能依赖可写字段。
Computed value 本身没有可写存储,但读取它时可能需要 mutable dependency 的一致快照。
Dependency 必须显式进入 Schema。`Synchronized_Computed_Accessor` 的 read view 只能读取声明过的直接 dependencycomputed property 的读取 slot 从 dependency graph 推导,而不是由调用方再次把 computed key 写进 synchronization group。
Dependency 必须显式进入 Schema。每个 Property Accessor 都必须声明 `dependency_spec`,无依赖 Accessor 显式使用 `No_Property_Dependencies``Synchronized_Computed_Accessor` 的 read view 只能读取声明过的直接 dependencycomputed property 的读取 slot 从 dependency graph 推导,而不是由调用方再次把 computed key 写进 synchronization group。Dependency graph 是 DAG invariantSchema 形成时在编译期拒绝 cycle。
需要原子一致性的 writable dependency 应彼此处于同一个同步域。Read-only stored dependency 没有 managed writer,所以可以直接读取而无需锁。
@@ -219,17 +220,17 @@ Dependency 必须显式进入 Schema。`Synchronized_Computed_Accessor` 的 read
不要给 read-only stored field 创建 mutex。Computed read 的同步只服务于需要一致性的 mutable dependency。
## 12. 只有一套 Attribute 协议
## 12. 只有一份 Property Metadata Storage
Core 与 Extension 共用同一套 Attribute mechanism
Property Descriptor 只有一份 metadata storage,其中的条目只能是 Attribute 或 Constraint
Attribute 拥有 category,并可以声明 single-valued 与 inheritable 语义。
Core 与 Extension 的描述性 metadata 共用 Attribute mechanism。Attribute 拥有 category,并声明 single-valued 与 inheritable 语义Constraint 使用 validation protocol,但与 Attribute 保存在同一份 descriptor metadata storage 中
UI、serialization、诊断等新领域不应该另起第二套 metadata system
UI、serialization、诊断等新领域不应该另起第二套 metadata storage
### 原则
新的 metadata domain 应扩展 Attribute protocol而不是创造另一套框架
新的描述性 metadata 扩展 Attribute protocol新的校验规则扩展 Constraint protocol;两者都作为同一份 Property metadata 的条目存在
## 13. Category 必须有明确所有者