Opened 7 years ago

Last modified 6 years ago

#7 new defect

CFA Assertion Error: CodeGenerator visits TypeExpr in trait/genaric type

Reported by: ajbeach Owned by:
Priority: minor Component: cfa-cc
Version: 1.0 Keywords:
Cc: a3moss

Description (last modified by Thierry Delisle)

So I was trying to create a new stack with an implicate error handler and it still is not working. I am getting a failure in code generation. It appears to be trying to generate the code for the trait I created.

A trimmed down version of the code, which still generates the same error, is included:

#include <stdlib.hfa>
extern "C" {
#include <stdbool.h>
}

// (Bug 1 unresolved as of this test.)
forall(otype T)
struct stack_node;

forall(otype T)
struct stack_node {
    stack_node(T) * next;
    T item;
};

forall(otype T)
struct stack {
    stack_node(T) * head;
};

trait stack_errors(otype T) {
    T emptyStackHandler (stack(T) * this);
};

forall(otype T | stack_errors(T))
T pop (stack(T) * this) {
    return (T){};
}

int emptyStackHandler (stack(int) * this) {
    return 0;
}

int main (int argc, char * argv[]) {
    stack(int) stackOfInts;
    pop(&stackOfInts);
    return 0;
}

I did a trace with gdb and it seems to be happening at line 22, which is the body of the trait stack_errors. Here is also a copy of the error message (minus stack trace).

*CFA assertion error* from program "cfa-cpp" in "virtual void CodeGen::CodeGenerator::visit(TypeExpr*)" at line 733 in file "CodeGen/CodeGenerator.cc": TypeExpr should not reach code generation.

Change History (5)

comment:1 Changed 7 years ago by ajbeach

OK, it might not be the trait, because something similar happens if I change it to an explicate function pointer and remove the trait. As in:

forall(otype T)
T pop (stack(T) * this, T (*emptyStackHandler)(stack(T) *)) { // !
    (void)emptyStackHandler;
    return (T){};
}

int emptyStackHandler (stack(int) * this) {
    return 0;
}

int main (int argc, char * argv[]) {
    stack(int) stackOfInts;
    pop(&stackOfInts, emptyStackHandler);
    return 0;
}

! is line 22 which seems to be generating the error again. It may be a separate issues using a function pointer. If it is the same, it seems to be the reference to a generic type within another forall/generic declaration that is causing it.

comment:2 Changed 7 years ago by ajbeach

Summary: CFA Assertion Error: CodeGenerator visits TypeExpr in traitCFA Assertion Error: CodeGenerator visits TypeExpr in genaric type

comment:3 Changed 7 years ago by ajbeach

Summary: CFA Assertion Error: CodeGenerator visits TypeExpr in genaric typeCFA Assertion Error: CodeGenerator visits TypeExpr in trait/genaric type

comment:4 Changed 7 years ago by Rob Schluntz

Cc: a3moss added

This adapter is generated in Box:

void _adapterFi_P6sstack_P_M(void (*_adaptee)(), void *_retval_emptyStackHandler2tT_1, void *thisP6sstack_1){
  ((*((int *)_retval_emptyStackHandler2tT_1))=((int (*)(stack(int ) *thisP6sstack_1))_adaptee)(thisP6sstack_1));
}

In particular, the cast on the adaptee ends up with a generic type, after generics have been instantiated. Considering this is a reoccuring problem, perhaps generic instantiations could be added to the environment so that substitutions can take them into account?

comment:5 Changed 6 years ago by Thierry Delisle

Description: modified (diff)

This assertion appears to be gone but the generated code is wrong:

test.cfa: In function ‘_adapterFi_PS5stack_i__P_M’:
test.cfa:34:104: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
 int main (int argc, char * argv[]) {

test.cfa:34:129: error: expected ‘)’ before ‘_adaptee’
 int main (int argc, char * argv[]) {
Note: See TracTickets for help on using tickets.