#model

    职责:公共事件、消息键、证据来源与基础差分约束。

    #已实现接口

    类型契约
    EventKindSend、Receive 两种消息事件
    MessageKey(trace_id, message_id, attempt),可作为 Map 键,重试和不同 trace 相互隔离
    SourceLocation来源路径与从 1 开始的行号
    Event事件 ID、时钟 ID、消息键、种类、Int64 微秒时间戳及可选来源
    ConstraintOrigin消息事件引用,或用户先验的标签
    DifferenceConstraintoffset(left_clock) - offset(right_clock) <= upper_bound_us
    ModelError空白标识、负重试索引、非法来源行号

    记录类型通过 new 构造,并提供同名字段访问方法。构造器拒绝空白标识,但保留合法标识的原始字符,不会自动去掉首尾空格或改写大小写。消息事件引用是否存在、事件 ID 是否重复等集合级校验由后续输入与关联功能负责。

    时间戳和约束权重均为完整范围的有符号 Int64 微秒数;模型允许负值。当前仅保存数值,后续计算需要独立检查算术溢出。

    约束的图边方向固定为 right_clock -> left_clock,对应 edge_from() 与 edge_to()。同一时钟的负上界约束也允许构造,由后续求解器判断冲突。

    #调用示例

    调用方需在包配置中导入 Mitsuha11zz/chronolens/model 并使用别名 model。

    let key = @model.MessageKey::new(
    trace_id="t1", message_id="request-1", attempt=0,
    )
    let event = @model.Event::new(
    event_id="a1", clock_id="A", key~, kind=@model.Send,
    timestamp_us=1000000L,
    )
    let constraint = @model.DifferenceConstraint::new(
    left_clock="A", right_clock="B", upper_bound_us=-100000L,
    origin=@model.Message(send_event_id="a1", receive_event_id="b1"),
    )

    示例需放在允许传播 ModelError 的函数或测试中;生产调用方也可捕获该错误。

    #验证

    model_test.mbt 包含 9 项黑盒契约测试,覆盖标识校验、重试隔离、Map 键、完整时间戳范围、可选来源、证据引用和约束边方向。

    运行 moon test model --target all。本阶段已通过 wasm、wasm-gc、js、native 四个后端,各 9/9。

    ModelError

    pub(all) suberror ModelError {
    EmptyIdentifier(String)
    InvalidAttempt(Int)
    InvalidSourceLine(Int)
    } derive(Eq,
    Debug
    )

    Invalid data supplied to a model constructor.

    ModelError::equal

    #deprecated("`ModelError::equal` is deprecated, use `Eq::equal` instead.")
    fn ModelError::equal(ModelError, ModelError) -> Bool
    automatically derived

    ModelError::not_equal

    #deprecated("`ModelError::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn ModelError::not_equal(x : ModelError, y : ModelError) -> Bool
    automatically derived

    ModelError::to_repr

    #deprecated("`ModelError::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn ModelError::to_repr(ModelError) ->
    Repr
    automatically derived

    ConstraintOrigin

    pub(all) enum ConstraintOrigin {
    Message(send_event_id~ : String, receive_event_id~ : String)
    Prior(label~ : String)
    } derive(Eq,
    Debug
    )

    Evidence behind a constraint. Message references identify source events; a prior label identifies a user-supplied assumption.

    ConstraintOrigin::equal

    #deprecated("`ConstraintOrigin::equal` is deprecated, use `Eq::equal` instead.")
    fn ConstraintOrigin::equal(ConstraintOrigin, ConstraintOrigin) -> Bool
    automatically derived

    ConstraintOrigin::not_equal

    #deprecated("`ConstraintOrigin::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn ConstraintOrigin::not_equal(x : ConstraintOrigin, y : ConstraintOrigin) -> Bool
    automatically derived

    ConstraintOrigin::to_repr

    #deprecated("`ConstraintOrigin::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn ConstraintOrigin::to_repr(ConstraintOrigin) ->
    Repr
    automatically derived

    DifferenceConstraint

    pub struct DifferenceConstraint {
    left_clock : String
    right_clock : String
    upper_bound_us : Int64
    origin : ConstraintOrigin
    } derive(Eq,
    Debug
    )

    The inequality is offset(left_clock) - offset(right_clock) <= upper_bound_us. Its graph edge goes from right_clock to left_clock.

    DifferenceConstraint::edge_from

    fn DifferenceConstraint::edge_from(self : DifferenceConstraint) -> String

    DifferenceConstraint::edge_to

    fn DifferenceConstraint::edge_to(self : DifferenceConstraint) -> String

    DifferenceConstraint::equal

    #deprecated("`DifferenceConstraint::equal` is deprecated, use `Eq::equal` instead.")
    fn DifferenceConstraint::equal(DifferenceConstraint, DifferenceConstraint) -> Bool
    automatically derived

    DifferenceConstraint::left_clock

    fn DifferenceConstraint::left_clock(self : DifferenceConstraint) -> String

    DifferenceConstraint::new

    fn DifferenceConstraint::new(left_clock~ : String, right_clock~ : String, upper_bound_us~ : Int64, origin~ : ConstraintOrigin) -> DifferenceConstraint raise ModelError

    Negative bounds and same-clock constraints are valid model inputs. Feasibility is evaluated by the solver in a later stage.

    DifferenceConstraint::not_equal

    #deprecated("`DifferenceConstraint::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn DifferenceConstraint::not_equal(x : DifferenceConstraint, y : DifferenceConstraint) -> Bool
    automatically derived

    DifferenceConstraint::origin

    DifferenceConstraint::right_clock

    fn DifferenceConstraint::right_clock(self : DifferenceConstraint) -> String

    DifferenceConstraint::to_repr

    #deprecated("`DifferenceConstraint::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn DifferenceConstraint::to_repr(DifferenceConstraint) ->
    Repr
    automatically derived

    DifferenceConstraint::upper_bound_us

    fn DifferenceConstraint::upper_bound_us(self : DifferenceConstraint) -> Int64

    Event

    pub struct Event {
    event_id : String
    clock_id : String
    key : MessageKey
    kind : EventKind
    timestamp_us : Int64
    source : SourceLocation?
    } derive(Eq,
    Debug
    )

    An immutable observation. Timestamp units are signed integer microseconds. Event-id uniqueness is a dataset-level responsibility.

    Event::clock_id

    fn Event::clock_id(self : Event) -> String

    Event::equal

    #deprecated("`Event::equal` is deprecated, use `Eq::equal` instead.")
    fn Event::equal(Event, Event) -> Bool
    automatically derived

    Event::event_id

    fn Event::event_id(self : Event) -> String

    Event::key

    fn Event::key(self : Event) -> MessageKey

    Event::kind

    fn Event::kind(self : Event) -> EventKind

    Event::new

    fn Event::new(event_id~ : String, clock_id~ : String, key~ : MessageKey, kind~ : EventKind, timestamp_us~ : Int64, source? : SourceLocation) -> Event raise ModelError

    Create an observation without changing its timestamp or identifier text. Negative timestamps are valid; timestamp arithmetic belongs to later stages.

    Event::not_equal

    #deprecated("`Event::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn Event::not_equal(x : Event, y : Event) -> Bool
    automatically derived

    Event::source

    fn Event::source(self : Event) -> SourceLocation?

    Event::timestamp_us

    fn Event::timestamp_us(self : Event) -> Int64

    Event::to_repr

    #deprecated("`Event::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn Event::to_repr(Event) ->
    Repr
    automatically derived

    EventKind

    pub(all) enum EventKind {
    Send
    Receive
    } derive(Eq,
    Debug
    )

    Direction of a single, explicitly identified message event.

    EventKind::equal

    #deprecated("`EventKind::equal` is deprecated, use `Eq::equal` instead.")
    fn EventKind::equal(EventKind, EventKind) -> Bool
    automatically derived

    EventKind::not_equal

    #deprecated("`EventKind::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn EventKind::not_equal(x : EventKind, y : EventKind) -> Bool
    automatically derived

    EventKind::to_repr

    #deprecated("`EventKind::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn EventKind::to_repr(EventKind) ->
    Repr
    automatically derived

    MessageKey

    pub struct MessageKey {
    trace_id : String
    message_id : String
    attempt : Int
    } derive(Eq, Hash,
    Debug
    )

    A message attempt is identified by all three fields.

    MessageKey::attempt

    fn MessageKey::attempt(self : MessageKey) -> Int

    MessageKey::equal

    #deprecated("`MessageKey::equal` is deprecated, use `Eq::equal` instead.")
    fn MessageKey::equal(MessageKey, MessageKey) -> Bool
    automatically derived

    MessageKey::hash

    #deprecated("`MessageKey::hash` is deprecated, use `Hash::hash` instead.")
    fn MessageKey::hash(self : MessageKey) -> Int
    automatically derived

    MessageKey::hash_combine

    #deprecated("`MessageKey::hash_combine` is deprecated, use `Hash::hash_combine` instead.")
    fn MessageKey::hash_combine(MessageKey, Hasher) -> Unit
    automatically derived

    MessageKey::message_id

    fn MessageKey::message_id(self : MessageKey) -> String

    MessageKey::new

    fn MessageKey::new(trace_id~ : String, message_id~ : String, attempt~ : Int) -> MessageKey raise ModelError

    Validate identifiers and retry index without normalizing identifier text.

    MessageKey::not_equal

    #deprecated("`MessageKey::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn MessageKey::not_equal(x : MessageKey, y : MessageKey) -> Bool
    automatically derived

    MessageKey::to_repr

    #deprecated("`MessageKey::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn MessageKey::to_repr(MessageKey) ->
    Repr
    automatically derived

    MessageKey::trace_id

    fn MessageKey::trace_id(self : MessageKey) -> String

    SourceLocation

    pub struct SourceLocation {
    path : String
    line : Int
    } derive(Eq,
    Debug
    )

    Optional evidence location; line numbers are one-based.

    SourceLocation::equal

    #deprecated("`SourceLocation::equal` is deprecated, use `Eq::equal` instead.")
    fn SourceLocation::equal(SourceLocation, SourceLocation) -> Bool
    automatically derived

    SourceLocation::line

    fn SourceLocation::line(self : SourceLocation) -> Int

    SourceLocation::new

    fn SourceLocation::new(path~ : String, line~ : Int) -> SourceLocation raise ModelError

    SourceLocation::not_equal

    #deprecated("`SourceLocation::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn SourceLocation::not_equal(x : SourceLocation, y : SourceLocation) -> Bool
    automatically derived

    SourceLocation::path

    fn SourceLocation::path(self : SourceLocation) -> String

    SourceLocation::to_repr

    #deprecated("`SourceLocation::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn SourceLocation::to_repr(SourceLocation) ->
    Repr
    automatically derived