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: compiler crash when compiling for iOS #1441

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Aug 30, 2024

Summary

Fix a compiler crash when compiling any program for iOS with threading
enabled. Only the iOS target was affected.

Details

Due to StrTab ordering, within the system module, all calls to
sizeof outside of generic routines resolve to the sizeof(x: T)
symbol, foregoing overload resolution since sizeof is an "eager"
magic.

If called with the symbol of a type that has an unknown size (which
happens in a when defined(ios) guarded part of syslocks), the first
parameter's type of the callee reaching mirgen is a tyGenericParam,
and thus mirgen.genArgs attempts to translate the skType symbol
like a normal expression, triggering an assertion.

Always using overload resolution for sizeof would result in
unnecessary generic instantiations, so mirgen now uses dedicated
handling for the mSizeOf magic, always translating argument as a
type, thus fixing the crash.

Fixes #1436.

Summary
=======

Fix a compiler crash when compiling any program for iOS with threading
enabled. Only the iOS target was affected.

Details
=======

Due to `StrTab` ordering, within the `system` module, all calls to
`sizeof` outside of generic routines resolve to the `sizeof(x: T)`
symbol, foregoing overload resolution since `sizeof` is an "eager"
magic.

If called with the symbol of a type that has an unknown size (which
happens in a `when defined(ios)` guarded part of `syslocks`), the first
parameter's type of the callee reaching `mirgen` is a `tyGenericParam`,
and thus `mirgen.genArgs` attempts to translate the `skType` symbol
like a normal expression, triggering an assertion.

Always using overload resolution for `sizeof` would result in
unnecessary generic instantiations, so `mirgen` now uses dedicated
handling for the `mSizeOf` magic, always translating argument as a
type, thus fixing the crash.
@zerbina zerbina added bug Something isn't working compiler/backend Related to backend system of the compiler labels Aug 30, 2024
@zerbina zerbina added this to the MIR phase milestone Aug 30, 2024
@saem
Copy link
Collaborator

saem commented Aug 30, 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

  • the issues only occurred for sizeof call within the system module, so no standalone regression test is possible

@chore-runner chore-runner bot enabled auto-merge August 30, 2024 21:32
@chore-runner chore-runner bot added this pull request to the merge queue Aug 30, 2024
Merged via the queue into nim-works:devel with commit fd9dbe5 Aug 30, 2024
35 checks passed
@zerbina zerbina deleted the fix-sizeof-magic-crash branch August 30, 2024 23:10
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
None yet
Development

Successfully merging this pull request may close these issues.

Compiler crashes when compiling for iOS with threads on
2 participants