-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mir: add a dedicated IR for types (#1382)
## Summary * implement a dedicated type IR for the MIR and back-end phase * use the new IR in parts of the C code generator * use a new name mangling scheme for types that doesn't rely on signature hashes ## Details The idea behind introducing a dedicated type IR for the MIR and back- end phase is to: * have a simpler and more regular IR during lowering and code generation * decouple type lowering from code generation * make `PType` solely used by `sem` and `transf` The key ideas for the type IR are that: * same ID (`HeaderId`) means same type; there are no duplicates like with `PType` * transformations and code generation have easy access to the various stages of a type's representation (including the `PType`) * lineage to `PType`s is kept track of The 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 in `ccgtypes`. So that the IR is well-tested, all `PType`s entering `mirgen` 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-from `PType` (such as the internal payload type for `seq`s and `string`s), meaning that the `sighash`-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 on `TSym` is obsolete; it's removed. ### Tests * multiple `ccodecheck` test are adjusted to `int` now translating to a sized integer instead of `NI` * due to usage of the to-MIR-type-translation, `tempty_typed_expressions_issues.nim` now also fails for JS --------- Co-authored-by: Saem Ghani <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,921 additions
and
764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.