Skip to content

Generics propagation inside functions #642

Open
@kyleheadley

Description

@kyleheadley

Capability of the recent generics PR (#639) was limited because of the inability to propagate generic indexes (the base type of a generic variable). For example:

void* wrap_malloc(unsigned int size) {
  void* p_ret;
  p_ret = malloc(size);
  return p_ret;
}

This function cannot be rewritten to generic because of the declaration of a void* parameter p_ret. We would like to back-propagate the void* in the function's return to p_ret, mark the cast from malloc as safe, and rewrite the declaration as _Ptr<T> p_ret. But 3C has constraint propagation for pointer types only, not generic indexes (the "T"), which are more like base types. How to do this is still unclear.

We could make new atoms and reuse the constraint resolution code. This would require heuristics in cases where an expression consumes a generic type and produces a void* type. Should we propagate the generic? Or should we only propagate with direct assignment, which is likely uncommon except for function calls.

We could write our own type checker, but this is likely to be more work than we are prepared to put in now.

We could use existing atoms in new ways with added resolution code for generics.

This will all become more complex when we introduce multiple generic parameters per rewritten function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions