Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#41 closed defect (fixed)

Duplicate function on generic specialisation

Reported by: Thierry Delisle Owned by: Rob Schluntz <rschlunt@…>
Priority: major Component: cfa-cc
Version: 1.0 Keywords: generic
Cc:

Description

forall( dtype T )
struct ptr_t {
	T * ptr;
};

int foo( ptr_t( int ) p ) {
	return 3;
}

int foo( ptr_t( float ) p ) {
	return 4;
}

yields

test.c:10:1 error: duplicate function definition for foo: function
  with parameters
    p: instance of struct ptr_t 
      with parameters
        float

  returning 
    _retval_foo:       Attribute with name: unused
signed int
  with body 
    CompoundStmt
      Return Statement, returning: 
          constant expression (4 4: signed int)

Change History (4)

comment:1 Changed 4 years ago by Thierry Delisle

Priority: blockermajor

comment:2 Changed 4 years ago by a3moss

I looked a little closer at this, didn't manage to solve it, but here's a bit more information:

  • The Indexer relies on the Mangler to disambiguate function overloads (Thierry points out this is actually correct, because the linker will rely on the Mangler to disambiguate function overloads too). Specifically, the Indexer calls Mangler::mangle a couple times inside Indexer::addId.
  • When the Mangler is in typeMode, it includes the type parameters of generic types, otherwise it does not. The Indexer call to the Mangler is not in typeMode, and putting it into typeMode breaks other things, as does having the Mangler unconditionally mangle type parameters. This ought to be fixed, but it has non-trivial interactions with the rest of the compiler, and I have deja vu about trying to fix this before and failing.

comment:3 Changed 4 years ago by Rob Schluntz <rschlunt@…>

Owner: set to Rob Schluntz <rschlunt@…>
Resolution: fixed
Status: newclosed

In e35f30a:

Fix generic type name mangling, add mangleGenericParams mode to name mangler [fixes #41]

comment:4 Changed 4 years ago by Rob Schluntz

I managed to get this to work by following the last approach (unconditionally mangling type parameters) and adding an extra mode that never mangles type parameters (which only needed to be used in one place related to constructors). Thanks for the tips!

Note: See TracTickets for help on using tickets.