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

Compilation errors when enabling debug in WriterContext.extract #805

Open
jubnzv opened this issue Sep 10, 2024 · 0 comments
Open

Compilation errors when enabling debug in WriterContext.extract #805

jubnzv opened this issue Sep 10, 2024 · 0 comments
Labels
bug Something isn't working or isn't right scope: codegen Code generation, a.k.a. compiler backend
Milestone

Comments

@jubnzv
Copy link
Member

jubnzv commented Sep 10, 2024

If we turn on debug mode in the WriterContext.extract function, incorrect FunC code will be generated. That feature might be quite useful for the compiler development, in particular for differential testing between backends (#559).

Steps to reproduce

  1. Enforce debug-mode here:
    extract(debug: boolean = false) {
  2. Compile a simple Tact contract, e.g.:
trait T {
    a: Int = 42;
    get fun getA(): Int {
        return self.a;
    }
}
contract Test with T {
    a: Int = 19;
}
  1. See the error output:
💼 Compiling project sample ...
   > Test: tact compiler
   > Test: func compiler
Func compilation error ./sources/output/sample_Test.stdlib.fc:1238:36: error: cannot apply function $Test$_fun_reply : (int, cell) -> (int, ()) to arguments of type int: cannot unify type int with (int, cell)
      return $self~$Test$_fun_reply();

Problem description

The issue appears because of return types mismatch between these functions: $Test$_fun_reply and $Test$_fun_reply$not_mut.

Generated code:

((int), ()) $Test$_fun_reply((int) $self, cell $body) impure inline {
    var (($self'a)) = $self;
    ($self'a)~$Test$_fun_forward(__tact_context_get_sender(), $body, true, null());
    return (($self'a), ());
}

() $Test$_fun_reply$not_mut((int) $self, cell $body) impure inline {
    return $self~$Test$_fun_reply();
}

The relevant code in backend:

const nonMutName = ops.nonModifying(name);
.

@jubnzv jubnzv added the bug Something isn't working or isn't right label Sep 10, 2024
@anton-trunov anton-trunov added the scope: codegen Code generation, a.k.a. compiler backend label Sep 10, 2024
@anton-trunov anton-trunov added this to the v1.6.0 milestone Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or isn't right scope: codegen Code generation, a.k.a. compiler backend
Projects
None yet
Development

No branches or pull requests

2 participants