motoko icon indicating copy to clipboard operation
motoko copied to clipboard

feat: parenthetical syntax for `cycles` etc.

Open ggreif opened this issue 1 year ago • 1 comments

ICCallPrim (and friends) should carry the fragment to set the SystemCyclesAddPrim while the call is being set up towards the replica.

Parentheticals

  • now: (with cycles = 42_000_000) Actor.call(param)
  • later: (with timeout = 10) ic0.call_with_best_effort_response : (timeout_seconds : i32) -> ()
  • maybe: (with receiveMax = 50_000) (to limit the response size)
  • maybe: (with resend = true; resendDelay = 3) when SYS_TRANSIENT reject response (like Unix EINTR)
  • support https://github.com/dfinity/ic/pull/1158
  • usecase (with memoryLimit = 1G) ActorClass(<args>)

TODOs:

  • test one-ways
  • typecheck
    • warn when an attribute is moot
    • cycles : Nat for canister sends (self and raw sends too)
  • async blocks
  • ICCallPrim, see top

ggreif avatar Jul 10 '24 11:07 ggreif

Notes:

// foo.mo
actor class Foo() {}

translates too something like:

module {
  type Foo = actor { .. }
  func Foo() : async Foo = async {
    let p = await* Internals.create_helper() {
      let available = Cycles.availabe();
      Cycles.add(availabe);
      let p = await IC.create_cansiter();
      let _ = await IC.install_code(p,...);
      p
   };
   actor (..p..) : Foo
};

// test
import Lib "foo"
public func test() : async () {
       addCycles(10);
       let a : Lib.Foo = Lib.Foo();
       ();
  }
}

crusso avatar Jul 12 '24 10:07 crusso

@Mergifyio refresh

ggreif avatar Dec 03 '24 11:12 ggreif

refresh

✅ Pull request refreshed

mergify[bot] avatar Dec 03 '24 11:12 mergify[bot]

@oggy-dfin This is the PR.

ggreif avatar Dec 03 '24 15:12 ggreif

Comparing from 3c59a0e2f8441063410959deb187214f7c9c2765 to c3b7baa4b64405f02f0fa9ebebd3303a6a6b1404: In terms of gas, 3 tests regressed, 2 tests improved and the mean change is -0.0%. In terms of size, 4 tests regressed, 1 tests improved and the mean change is +0.0%.

github-actions[bot] avatar Dec 03 '24 18:12 github-actions[bot]

So I think I've finally understood what is bugging me about this approach.

For a given context, the parenthetical is allowed to have one of several types and the semantics depends on typing in a weird way. If it's a record type with a cycles field do this, if it's a record type with a timeout field do this, etc.

I think this would all be easier to type and describe if we just said that a parenthetical has some expected type depending on its context, and the annotation is just a record extension of a default base.

So for async and messages, the default base would be { cycles = 0 (or @cycles); timeout = null } and extension allows you to override one, both or zero fields. For async/send we would just check the (desugared) migration expression has type { cycles : Nat; timeout : ?Nat32 }. Note the option to allow the timeout to be null be default.

For migration, the default would be {} and the expected type { migration : func {...} - {...} }, forcing the user to add a migration field if we declares a parenthetical. For migration, we would not check but infer the parenthical's type and check it is a record of the correct form since there is no fixed type for the migration field.

I can live with what we have, since it works, just wanted to write down what was bugging me.

crusso avatar Feb 20 '25 14:02 crusso

I can live with what we have, since it works, just wanted to write down what was bugging me.

Yeah, it feels somewhat ad-hoc. But we still don't know where this is ultimately heading to, and whether parentheticals can (always) be encompassed by a record type as we move forward. We can still have timeout = -1 for no timeout if we really want a common type, so I am concerned too much. And breaking the current schema is also an option if we figure all out.

ggreif avatar Feb 20 '25 14:02 ggreif

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks:

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

mergify[bot] avatar Feb 26 '25 15:02 mergify[bot]