-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #14873 properly by skipping abi
field in importc type
#17944
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes like these break
nlvm
(which is still our best idea of how to get good debugging support btw).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why single out this type? other types have no guarantee to have all their fields listed in the importc type (unless
{.completeStruct.}
is given), nor being in orderfurthermore, nlvm is heavily behind nim devel: last nim commit that was integrated is Jul 29, 2020, arnetheduck@bf320ed)
and there are other ways to do this without resorting to platform specific conditional fields.
abi/padding fields that aren't used just shouldn't be exposed, which leads to bugs like #14873 etc
more robust ways to query for fields for an importc type
we could query the type using libclang / cling (timotheecour#705), leaving guesswork out of the equation. This could also be done optionally, leaving out uncertain fields by default (as done in this PR)
this approach is actually useful for many problems, including all the importc let variables that are currently hardcoded but could instead be queried (see also nim-lang/RFCs#205). It's not hard to do at least on posix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have a
size
pragma? Can it be used as a replacement forabi
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that would be better than
abi
field, but it still causes the same problems because the ABI for those is not specified and varies by OS/distribution.note that you can still use
sizeof
at RT;{.sizeof: N.}
only makes sense if you need it at CT (unlikely because, well, VM is single threaded).Note also that on osx i get:
even though no nim abi field is there in the definition of
SysLockObj
, which shows how arbitrary this was. Furthermore, it's also wrong for other architectures besides osx (eg: linux and not amd64)Long story short: removing the
abi
, as i did in this PR, makes sense.links
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Araq also you can always do this if you need to access raw bytes:
unlike
abi
field which is fragile and not portable (eg doesn't work on osx etc), this will always work=> timotheecour#722
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The abi field never was about accessing bytes, it was about getting sizeof and alignof right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok; but sizeof and alignof don't need abi fields so long sizeof and alignof are only accessed at RT:
but I think we're agreeing at this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need it for pointer arithmetic, memory allocation, offset arithmetic and a number of other cases - this PR breaks existing code and introduces differences between compile time and runtime that lead to bugs.
The proper fix is to provide the Nim compiler with correct information at compile time - this can indeed be through libclang - or by just spelling it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nlvm is behind mainly because breaking things and moving fast doesn't work for code that actually depends on the standard library to not break their code, ie actual users of the language and the library - it's PR's like this that prevent it from being updated, as well as drive users of it to look for alternative solutions, including forks - the bar of quality must be higher than "works for me, don't care about the rest" - as long as this is not understood (as can be seen by similar PR's recently), it's a hard sell to actually use the code and the end result is a cycle of "I'll make it work for my case now" style back-and-forth PRs. It's not a sustainable approach.