Closed zerbina closed 2 months ago
It's easier to not mess with tuple equality for the moment, so I went with using sighashes
to unify generic object instantiations. This restores the original behaviour of Generic[(int,)]
and Generic[tuple[x: int]]
translating to the same nominal C type.
Okay, that fixed it. The sighashes
-based approach merged types that the MIR considered to be different, since sighashes
is unable to produce unique hashes for tyObject
types in some cases (e.g., two object types with the same content in adjacent scopes).
Merging instantiations of generic object types is now based on the MIR representation, meaning that there can be no disagreements.
Many thanks for the review, @saem.
/merge
Merge requested by: @zerbina
Contents after the first section break of the PR description has been removed and preserved below:
## To-Do * [x] make a separate PR with a fix for the IC-related issue * [x] ~make a separate PR with a fix for generic type equality and remove the workaround~ * [x] write a proper commit message ## Notes for Reviewers * the type IR is a requirement for much of the remaining mid-/back-end work * given the breadth and complexity of the change, it's possible that some untested behaviour ceases to work (although not intentionally) * review is likely easier by going through the commits one-by-one
Summary
Details
The idea behind introducing a dedicated type IR for the MIR and back- end phase is to:
PType
solely used bysem
andtransf
The key ideas for the type IR are that:
HeaderId
) means same type; there are no duplicates like withPType
PType
)PType
s is kept track ofThe current design likely covers more ground than it ultimately needs to, but this was a deliberate choice in order to ease the transition to the new IR.
Translation
The lowering and or fixes performed by
mirtypes
during the translation of types intends to exactly match what was previously implemented inccgtypes
.So that the IR is well-tested, all
PType
s enteringmirgen
are translated to the IR representation.Code generation
Most of the existing is still oblivious to the new type IR, with only the type emission in the C code generation. Some analysis that was previously performed on
PType
s is ported to operate on MIR type descriptions.The
mangling
module implements a semi-stable, reversible name mangling for types. It's necessary since not all MIR types have an originating-fromPType
(such as the internal payload type forseq
s andstring
s), meaning that thesighash
-based mangling cannot be used there.AST
Associating fields with names in the C code generator is now done via the new type IR, meaning that the
locId
field onTSym
is obsolete; it's removed.Tests
ccodecheck
test are adjusted toint
now translating to a sized integer instead ofNI
tempty_typed_expressions_issues.nim
now also fails for JS