Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context.getVar failing compilation (and likely can't be deserialized) #978

Open
kushti opened this issue May 10, 2024 · 3 comments
Open
Assignees

Comments

@kushti
Copy link
Member

kushti commented May 10, 2024

test for method-call version of getVar (you can put it in BasicOpsSpecification) is failing compilation

property("getVar") {
    test("getVar", env, ext,
      "{ allOf(Coll(CONTEXT.getVar[Boolean](trueVar).get, true, true)) }",
      AND(GetVarBoolean(booleanVar).get, TrueLeaf, TrueLeaf).toSigmaProp
    )
  }

(and all the method calls with parametrized types as well)

Also, after fixing compilation serialization will be failed for Context.getVar[T] , as MethodCallSerializer is not serializing and so not able to restore T

@aslesarenko aslesarenko self-assigned this May 12, 2024
@kushti kushti changed the title Context.getVar failing compilation (and likely can't be deserialized Context.getVar failing compilation (and likely can't be deserialized) May 13, 2024
@aslesarenko
Copy link
Member

This is a limitation of MethodCall (see this ScalaDoc)

Specifically for this use case, since CONTEXT is singleton, every CONTEXT.getVar method call can be (and should be) compiled down to GetVar node, thus eliminating this specific MethodCall.
Other method calls would still be supported.

The elimination would even work in lambdas like def f(ctx: Context) = ctx.getVar[Int](1).get, because every Context instance is the same object reference, so the lambda will be transformed to
def f(ctx: Context) = GetVar[Int](1).get where ctx is just ignored.

Added a new issue #980

@kushti
Copy link
Member Author

kushti commented May 13, 2024

This is limitation of MethodCall, because we cannot use it to represent for example
* def Box.getReg[T](id: Int): Option[T], which require serialization of expected type T
* However it can be implemented using separate node type (new type code) and can be added via soft-fork.

Not necessary, see deserializeRaw implementation

Specifically for this use case, since CONTEXT is singleton, every CONTEXT.getVar method call can be (and should be) compiled down to GetVar node, thus eliminating this specific MethodCall.

You can replace method call with GetVar in compiler, but then what to do with the method itself, it is still available.

@aslesarenko
Copy link
Member

aslesarenko commented May 13, 2024

You can replace method call with GetVar in compiler, but then what to do with the method itself, it is still available.

Well, if we will have either PolyMethodCall of just generalized MethodCall itself supporing types serialization then we can have CONTEXT.getVar as MethodCall in the ErgoTree and execute it at runtime. So lowering will be a compilation option (on or off).

In such case this issue can be fixed completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants