Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regression with imported distinct types #1418

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Aug 15, 2024

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 #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.

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.

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.
@zerbina zerbina added bug Something isn't working compiler/backend Related to backend system of the compiler labels Aug 15, 2024
@zerbina zerbina added this to the MIR phase milestone Aug 15, 2024
@saem
Copy link
Collaborator

saem commented Aug 15, 2024

/merge

Copy link

Merge requested by: @saem

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


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue Aug 15, 2024
Merged via the queue into nim-works:devel with commit 4a02aaa Aug 15, 2024
35 checks passed
@zerbina zerbina deleted the mirtypes-fix-importc-handling branch August 25, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler/backend Related to backend system of the compiler
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

cgen generates the same struct twice when importing a distinct object
2 participants