New Issue: should extern unions be declared as unions?

17749, "mppf", "should extern unions be declared as unions?", "2021-05-17T14:59:39Z"

After PR #17310, we are documenting in the spec that extern record can be used to declare extern unions. For example:

typedef union _someUnion {      
  float x;
  double y;
} someUnion;
extern record someUnion {
  var x: real(32);
  var y: real(64);
}

While this strategy required no code changes to the compiler, it has some problems.

  1. It is a conceptual mismatch. Since Chapel and C both have unions, why wouldn't we write extern union someUnion instead?
  2. The compiler can't assume that the fields x and y in the extern record don't alias. (Arguably, the Chapel compiler can't assume that anyway since you can have unnamed anonymous unions - see #17748). But in any case, it required some workarounds to function with the LLVM backend since the Chapel compiler is trying to generate type-based alias analysis hints and in doing so it needs to know if a type is a union or not.
  3. Chapel module code might need to know if it is working with a record or a union. In this case, it is not known by the Chapel compiler that someUnion is a union until code generation time (for LLVM compilations) or until the C compiler runs (when using the C backend). In particular, the default I/O implementation for writeln of an extern union should probably not write out each field in turn. Similarly for reading.

So, this issue is proposing that instead of extern record someUnion in this example, we write extern union someUnion. This change would resolve the above 3 problems.