-
-
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
Revert "fix #14873 properly by skipping abi
field in importc type"
#17992
Conversation
that's too vague to justify a revert, what code specifically breaks? Note that #17944 fixes code that was broken because of those abi fields. That message also doesn't address the points in the PR:
I suggest writing an RFC to discuss this as well as what exactly breaks (reproducible, minimized code) and discussing alternative options before reverting this. |
We can and should do it differently after such an RFC has been accepted... |
code that uses the sizes and offsets at compile time - for example memory pools and serialization libraries - I'm not sure how to be more specific - it also breaks Removing the ABI markers also introduces risk of hard-to-detect bugs where the Nim and C compiler don't agree on the ABI which can't easily be detected until the application crashes - you're aware of this issue already though.
The std lib has been growing organically and is larger than can be maintained at a consistent quality level - it's not surprising that it's not complete in this regard - if I were to pick a reason, most likely these types are the ones that actually have some unit test coverage.
indeed they don't -
to the best of my knowledge, there is none implemented today - when it gets implemented, it will be appropriate to remove the fields (in that order) - until then, typing them out is a pragmatic solution that works surprisingly well - fortunately, C ABI:s don't change usually, since C programmers tend to be intimately familiar with the difficulties that this causes in the C compilation model - once the ABI types have been typed out correctly, they become non-problems that don't really need alternative approaches. In general, this is an example of how Nim at the Nim level must have some knowledge of the target environment it's compiling for in order to support systems programming features that exist in the language - this includes knowing details like the size of a float and a long, the alignment requirements of an MMX register and so on - without this, some Nim features simply can't work. There have been some improvements suggested to deal with this - in particular, having a low-level
I would suggest that as a general approach, the onus of writing an RFC would be on those that knowingly introduce breaking changes - we agree that such are sometimes necessary and an RFC is a good place to hash them out. In this case, you've already analyzed yourself what code breaks -
If the answer is yes to any of these questions, the std lib is not a good place for it most likely. |
just replying on 1st point for now:
how so? when true:
import std/locks
let a = Lock.sizeof # ok
const b = Lock.sizeof # CT error again, can you please show minimized code that breaks? |
You're right, apologies. I forgot that Nim prevents people from using these types with all features of the language, which means that the change will indeed not break existing working code. The way the fields are formed right now, it also doesn't make debugging worse, though the times that do correctly include all fields (even private ones) are somewhat easier to debug - ie the windows lock contains owner thread and counter - glibc likewise, if one were to dig. It does prevent An actual improvement here would be to make the ABI fields match libc exactly for the platforms where they are known - that would help debugging, printing and enable them to be used with the things I wrongly thought would break (systems programming). |
I still like the custom $ for locks better anyway. |
that's not an argument in support of a revert though, this PR could've simply added back just the Since you've reverted #14873, you should re-open #14873 which was fixed by that PR... Why can't nlvm use sizeof at RT instead of CT? In future work, we can integrate cling and clang's |
To use any size at all,
There's nothing fragile about putting the information in Nim - for the C library, the type sizes are part of the ABI in the vast majority of cases and cannot change on the C side, except when new platforms are added. There is very little complexity to this solution and it makes the std library easier to use on Nim with fewer moving parts, without more complex features that don't exist.
the proper fix here would be to add it on osx as well - as is, because of |
…c type (nim-lang#17944)" (nim-lang#17992) This reverts commit 98c29c0.
Reverts #17944