"trap" 相对于整数 underflow/overflow 的含义是什么?

What is the meaning of "trap" in relation to integer underflow/overflow?

正在阅读 Internet Computer 的 Motoko 的文档:

https://sdk.dfinity.org/docs/languages/motoko-at-a-glance.html#_bounded_numbers_trapping

我意识到我没有一个很好的模型来理解“诱捕”这个词在这里的含义:

Bounded numbers (trapping) Nat8, Nat16, Nat32, Nat64, Int8, Int16, Int32, Int64

trap on over- and underflow

need type annotations specified

literals: 13, 0xf4, -20, 1_000_000

这是否意味着如果尝试写入一个会导致 overflow/underflow 的数字,整数将保持固定在 maximum/minimum?

在这种情况下,“陷阱”一词的来源是什么?它在这里的确切含义是什么?

此上下文中的陷阱导致执行中止。罐子仍然可以正常工作,但对罐子的调用将失败。参见 this part of the manual.

作为演示,我设置了一个来自 one of these templates 的 Nat8 类型的计数器容器,因此它应该支持值 0..255(含),并将其初始化为 250:

$ cat counter-canister/main.mo 
actor {
    stable var currentValue: Nat8 = 250;

    public func increment(): async () {
        currentValue += 1;
    };

    public query func getValue(): async Nat8 {
        currentValue;
    };
};

然后我点击了“增加”按钮。它按预期从 250 增加到 255,然后在下一次点击时,这显示在浏览器控制台中:

vendor.e49a5b15.js:831 Uncaught (in promise) Error: Call was rejected:
  Request ID: 0f549a49b80b31831e423196d086e36c12df51896ffaaa59e99bae7fa66047aa
  Reject code: 5
  Reject text: Canister ryjl3-tyaaa-aaaaa-aaaba-cai trapped explicitly: arithmetic overflow

    at pollForResponse (vendor.e49a5b15.js:831)
    at async n (vendor.e49a5b15.js:838)
    at async HTMLButtonElement.n (index.4a11dcea.js:5)

重新加载页面显示该值仍为最大值 255。

罐子仍然可以正常使用。如果我也懒得在那里放一个递减按钮,我可以倒数一点,然后增加值,直到我再次达到极限。