GC Config: initialization method does not need access to the outer scope - #23507
GC Config: initialization method does not need access to the outer scope#23507denizzzka wants to merge 1 commit into
Conversation
thewilsonator
left a comment
There was a problem hiding this comment.
also would making _initialized a static member of Config help for what you want to do here?
|
|
||
| private __gshared bool _initialized; | ||
|
|
||
| package(core) bool initialize(ref Config cfg) nothrow @nogc |
There was a problem hiding this comment.
marking this package(core) means regular users cannot call this function. Is this intended?
There was a problem hiding this comment.
Yes: by the time regular users can call it it's already been called and tryToInitialize() won't be executed a second time because _initialized == true
| @nogc nothrow: | ||
|
|
||
| bool initialize() | ||
| private bool tryToInitialize() |
There was a problem hiding this comment.
I made it private here because method name changed anyway.
If we need to be able initialize it somewhere externally (a second instance of Config, for example) we can change that in the future. But I think this is not needed
This is impossible, because adding static members to (Besides, I think it is architecturally correct to do it as I suggested in this PR) |
|
@schveiguy Hi! Tell your opinion about this PR? |
Can you elaborate on this? I.e. what is the problem this PR is fixing. |
I'm planning to add the ability to use other config structs (literally a different structs with the same field names) declared in other modules. This is necessary to be able to replace defaults, implement other ways to configure or remove configurability altogether because this is not necessary everywhere and may be incompatible with baremetal targets. But this access from struct itself to external |
|
So is there a further plan to accept a config struct as a template parameter? I don't see how this change enables using a different config struct. |
I don't know yet, maybe. I used to make the switching by static if previously.
Structure from another module haven't access to |
|
OK, but if you are are editing druntime to effect your fix anyway, then why not just make this change locally? And then when you want to make the change to druntime to allow alternative configuration structs, then you make this change at the same time. I'm not saying we don't want to do this. What I'm saying is that this change by itself doesn't seem to give you any ability to change the
It still does not. |
Yes, I just decided to state my intentions: seems, there will be a lot tied to this change
If this PR is accepted, access to this variable will become unnecessary |
|
It's just that this change doesn't enable anything except a different editing of druntime. What about a way to replace the Something similar to dmd/druntime/src/core/internal/gc/proxy.d Line 42 in f047a03 I'd suggest something like this: @weak extern(C) bool initialize_gc_options(Config *config) {
return config.tryToInitialize();
}
void initialize(ref Config config) {
if (!_initialized)
_initialized = initialize_gc_options(&config);
return _initialized;
}And then your change makes sense. Because now you can replace that call with your own. See if something like this works with your changes that you are trying (and makes it so you don't have to edit druntime). |
|
In my PR I can also replace |
I.e.,
Configisn't need to touch outer_initializeddirectlyHaving such access prohibits replaceable configuration structs