Add ability to use interfaces and classes without the runtime if they only contain static members#8204
Add ability to use interfaces and classes without the runtime if they only contain static members#8204dlang-bot merged 1 commit intodlang:masterfrom JinShil:minimal_runtime_with_classes
Conversation
|
Thanks for your pull request, @JinShil! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#8204" |
|
There might some confusion around which part of a feature can be used where. |
|
@jacob-carlborg Are you a Mac user? If so, any chance I can persuade you to look into the Darwin failure? I'm mostly concerned with why it behaves differently from Linux, and would like to reduce the discrepancies. |
|
I’ll have a look. |
|
@JinShil macOS 32-bit is using a custom implementation of TLS. For every access to a TLS variable, the compiler generates a call to the This does not occur on macOS 64-bit since it's using the system provided functionality for TLS (implemented in the dynamic loader). The reason why it's not used on 32-bit is because it did not work out of the box (I don't see a reason why it wouldn't, they both use the same system). Because macOS 32-bit is a dead platform we felt it wasn't worth spending time trying to fix the issue. I suspect it's a simple fix to get the native TLS working on 32-bit, once someone manage to find the issue. |
|
Thank you @jacob-carlborg, very helpful. I've disabled the runnable test for osx32 and added a compilable test. See my comments in the test files for justification. @rainers Do you have any insight to offer for the Win32_64 error? The exit code is 5, which, based on what I could find, is an access denied error. |
@JinShil an alternative would be to not use TLS variables, or do you want to explicitly test that? Or a third option. Add the implementation of extern(D) void* ___tls_get_addr( void* p )
{
return p;
} |
I specifically want to test TLS members as I think that is the most common usage. |
@JinShil 5 seems an abbreviation of 0xc0000005 which is an access violation. The crash happens in the TLS seems broken: the first entry points to the tls_array table itself, so the assignemnt before overwrites the pointer. I guess it misses some of the magic from druntime/src/rt/msvct_stub.c Edit: sorry, that file only exists on my disk, it has made its way into the installer repo as https://github.com/dlang/installer/blob/build-mingw-libs/windows/mingw/msvcrt_data.c |
|
@jacob-carlborg and @rainers, Thank you for your help. OSX32 and Windows have at least part of their TLS implementation in the D runtime, so if users opt into using TLS variables and are not using a runtime, or creating their own runtime, they will need to link to an existing TLS implementation or build their own. I've, therefore, moved the TLS test to the compilable folder and modified the runnable test so it executes only for I would prefer to emit a compile-time error if a TLS implementation is not found, but that would require reworking a lot of code, and probably be too disruptive to support this niche use case. With this PR, users will at least no longer be obstructed with an irrelevant TypeInfo error. It's all green now, and ready to go.. |
jacob-carlborg
left a comment
There was a problem hiding this comment.
There’s no changelog entry.
test/runnable/minimal2.d
Outdated
|
|
||
| // This test ensures that interfaces and classes can be used in a minimal | ||
| // runtime as long as they only contain shared static members. Non-shared | ||
| // static members would a thread-local storage (TLS) implementation. |
There was a problem hiding this comment.
The last sentence sounds a bit weird. Is it missing a “required”?
|
The necessary TLS magic for Windows is in the C runtime, too. What is missing is a reference to the respective symbols, but it is optimized away under the assumption that the code ends up in the executable image. If you compile it separately, |
That symbol is available in the [1] https://github.com/dlang/dmd/pull/8204/files#diff-26f06e2cdfaed27b14b8a004281f0798R2 |
Right, so using that |
|
For macOS 32-bit you can add a dummy implementation: extern(D) void* ___tls_get_addr( void* p )
{
return p;
}It won't be a true TLS but you're not using threads so... |
|
I have just added COMPILE_SEPARATELY to the test, but that didn't pick up object.obj (for obvious reasons). There doesn't seem to be a simple way to add it to the link command line. |
|
@jacob-carlborg and @rainers, are you concerned about having a runnable test for osx32 and Windows? |
No. |
You add the |
Yes, that works with COMPILE_SEPARATELY and runs successfully. |
Not really ;-) |
changelog/min_runtime_classes.dd
Outdated
| ) | ||
|
|
||
| Non-shared static members can also be used, but will require a thread-local storage (TLS) implementation. | ||
| For Linux, the TLS implementation is already supplied by the C runtime and C |
There was a problem hiding this comment.
Don't we know that there are only two platforms where it doesn't work out of the box?
There was a problem hiding this comment.
All the platforms in the auto-tester passed except osx32 and Win32_64. So those are the only supported platforms I know of that don't work out of the box.
There was a problem hiding this comment.
Exactly, so why only mentioning Linux?
There was a problem hiding this comment.
I'm just using Linux and an illustrative example. How else should I say it? "For *nix platforms..."?
There was a problem hiding this comment.
I'll add "For example.."
|
Do we want/is there a need to test static methods as well? |
Added a method to the runtime test. |
|
Wait hold on, does this mean it's possible for determine the attributes for destroy at compile time because of this? |
I don't see how it would. |
This is a followup to the PRs previously released in 2.079 that enable users to use D without the runtime in a pay-as-you-go fashion
ModuleInfoThrowableis not declared #7786 forThrowableTypeInfoCurrently, even with the above PRs, the following code will cause the compiler to emit an error about
TypeInfoif compiled without the runtime. However,TypeInfois in no way required for such code because all interface/class members are static.This PR removes this arbitrary limitation enabling more features of D to be used without the runtime.