There was a hard to see misalignment between types accepted as
representable in C languages defined in `BuiltinMappedTypes.def` and
those with an associated C type name defined in `PrimitiveTypeMapping`.
While `BuiltinMappedTypes` looked through typealiases,
`PrimitiveTypeMapping` didn't and instead referred only to types by
their identifier. So even when both files defined the same types by
name, their underlying type were only partially handled. An affected
type was `Unicode.Scalar` which is the underlying type of `CWideChar`
and `CChar32`. `Unicode.Scalar` was accepted as a C representable type
but was not printed using a corresponding C type name, breaking the
generated compatibility header.
Another issue with the use of identifiers in the PrimitiveTypeMapping
logic was a limited support for nested types. It would track
`Unicode.Scalar` only as `Scalar`.
This change updates `PrimitiveTypeMapping` to keep track of TypeDecls
instead of identifiers and look through typealiases. This fixes the
issue with `Unicode.Scalar`, allowing it to be printed using the type
defined by an alias and avoid matching an unrelated Scalar. It should
also prevent future types behind typealiases to trigger this same kind
of misalignment.
rdar://157332446
Fix crash when printing references to Unicode.Scalar in the
compatibility header.
Unicode.Scalar should not be printed in the first place, it's a Swift
struct. It should either be considered non-representable or printed as a
C / Objective-C type if that's the intent.
rdar://157120538