Skip to content

Norm 0.13 ​

Norm 0.13 将 Annotation 纳入统一对象模型,并提供定义侧函数、参数与字段生命周期。

语言 ​

  • annotation 是 identity aggregate,可声明字段、显式构造器、普通方法并直接构造;
  • Annotation 通过 std.annotation 的 Target 与 Retention 接口声明策略;
  • FunctionTarget 提供 before、around 和 after 生命周期,适用于函数与具体方法;
  • ParameterTarget<T> 提供可回写的强类型 before 与只观察完成态的 after,适用于函数、方法和构造器参数;
  • FieldTarget<T> 为字段初始化、普通赋值和 ref<T> 间接赋值提供强类型 before 与完成态 after;
  • 拦截器按源码顺序嵌套,动态分派与函数引用保持定义侧行为;
  • 同一个应用在每次 execution 中只构造一个 Annotation 实例,并与 runtime reflection 共享。
  • std.validation 提供复用参数与字段生命周期的强类型内置约束和结构化 ConstraintViolation。

迁移 ​

0.12 的 targets(...) retention(...) 声明改为实现 std.annotation 策略 interface:

norm
import std.annotation.RuntimeRetention
import std.annotation.TypeTarget

annotation Label implements TypeTarget, RuntimeRetention {
  String text
}

Annotation 现在遵循 class 构造规则。需要自定义初始化时声明显式构造器;应用参数使用该构造器的参数名。

工具链 ​

  • Syntax、Semantic、Bound、Core 与 Truffle 共用 aggregate 定义链路;
  • Core callable 参数与 aggregate 字段持有名称、类型和有序 interceptor,身份边界升级为 Schema V9 与 Language Semantics V9;
  • formatter、Language Server、VS Code 语法与跨 package 执行支持新声明模型。

完整规则见 Annotation 规范、Annotation 语法、Validation API 与 Annotation Tour。

Norm 0.25