nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
275 stars 39 forks source link

fix regression with imported `distinct` types #1418

Closed zerbina closed 1 month ago

zerbina commented 1 month ago

Summary

Marking a distinct T type as imported resulted in multiple C definitions for T, if T is a non-numeric, non-pointer type. This is now fixed.

Fixes https://github.com/nim-works/nimskull/issues/1417.

Details

When translating imported types, mirtypes always created a new type symbol for the imported type's underlying type. For tyAlias and tyDistinct types (or any other type kind in the Skip set), this resulted in a duplicate of the underlying type symbol being created. Since MIR types are identified by ID, both look separate to cgen, and thus a C definition is emitted for each.

handleImportedTypes now goes through the caching mechanism for the underlying type if its not the type marked with .importc, fixing the issue.

saem commented 1 month ago

/merge

github-actions[bot] commented 1 month ago

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


## Notes for Reviewers * a regression introduced by #1382 * the fix is simple, and restoring what previously worked makes sense even if `type T {.importc.} = distinct U` becomes an error