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

nimscript: fix compiler crash with .header procs #800

Merged
merged 1 commit into from
Jul 16, 2023

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Jul 16, 2023

Summary

Fix the compiler crashing when running NimScript files that directly
contain procedure definitions using the .header or .dynlib pragma.

Details

The module of a NimScript didn't use its own IdGenerator, but instead
re-used the IdGenerator instance belonging to the ModuleGraph. Apart
from leading to all symbols created as part of semantically analysing
the module being not attached to any module, this also caused an
IndexDefect when processing a .header/.dynlib pragma, as there the
module ID provided by the IdGenerator (which is -1 for the
ModuleGraph's) is used as an index into to the TLib storage.

A dedicated IdGenerator is now created for a NimScript file, both
fixing the crash and guaranteeing that the module ID provided by a
PContext's ID generator is a valid FileIndex.

Summary
=======

Fix the compiler crashing when running NimScript files that directly
contain procedure definitions using the `.header` or `.dynlib` pragma.

Details
=======

The module of a NimScript didn't use its own `IdGenerator`, but instead
re-used the `IdGenerator` instance belonging to the `ModuleGraph`. Apart
from leading to all symbols created as part of semantically analysing
the module being not attached to any module, this also caused an
`IndexDefect` when processing a `.header`/`.dynlib` pragma, as there the
module ID provided by the `IdGenerator` (which is -1 for the
`ModuleGraph`'s) is used as an index into to the `TLib` storage.

A dedicated `IdGenerator` is now created for a NimScript file, both
fixing the crash and guara the invariant that the module ID provided
by a `PContext`'s ID generator is a valid `FileIndex`.
@zerbina zerbina added bug Something isn't working compiler General compiler tag labels Jul 16, 2023
@saem
Copy link
Collaborator

saem commented Jul 16, 2023

/merge

@github-actions
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 Jul 16, 2023
Merged via the queue into nim-works:devel with commit 0311f88 Jul 16, 2023
18 checks passed
@zerbina zerbina deleted the nimscript-fix-compiler-crash branch July 16, 2023 17:54
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 General compiler tag
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants