Decouple Stack Context#2797
Decouple Stack Context#2797baziotis wants to merge 13 commits intodlang:masterfrom baziotis:thread_ctx
Conversation
|
Thanks for your pull request and interest in making D better, @baziotis! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. 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 + druntime#2797" |
Yes, but the operations only require the data members of
I think I was trying to factorise the horrible mess of globals somewhat. See the low level thread stuff at the bottom of
I don't think so, as its kind of the point to make it obvious that the variable being accessed is global (and therefore synchronisation may be required, and should be suspicious if absent). |
Yes, but if we put them in
Yes, I'll see if I have something when the tests pass. Which btw, fail currently. If you happen to have any suggestion, in this unittest calling the So.. the hard part on these refactorings is that something can break with 0 chances of finding why. :p
Ok great, interesting.
Ok, clear. -- Edit -- |
Due to changing the number of fields in Fiber (and moving them in a base class), the indexing on .tupleof had to change.
Even if Fiber doesn't need it, having the stuff related solely to StackContext management all in one place is good practice.
Please do. |
|
|
||
| // Thread / Fiber entry point. Invokes the function or delegate passed on | ||
| // construction (if any). | ||
| final void run() |
There was a problem hiding this comment.
note that somehow this has triggered
../.dub/packages/gtk-d-3.3.1/gtk-d/src/glib/Spawn.d(204,15): Error: function `glib.Spawn.Spawn.ReadFile.run` cannot override `final` function `core.thread.context.StackContextExecutor.run`
ae:sys-net-test 0.0.2444: building configuration "ae-sys-net-test-test-library"...
--
| sys/file.d(2020,8): Error: function `ae.sys.file.writeFileAsync.Writer.run` cannot override `final` function `core.thread.context.StackContextExecutor.run`
in build kite, why I'm not sure.
There was a problem hiding this comment.
I can't find the source of either of these files but the error most probably is something like here. Note that the private was not there before. I put it to fix an identical error (following the example of other unittests).
So, the point is that this is user code and it's not a problem of Fiber's code.
But this may lead to breaking change in existing code.
There was a problem hiding this comment.
Yeah its probably a visibility/protection issue, you can ask on the forums for an explanation if you can't find a solution. (Alternately you could call it something else that won't cause a collision)
There was a problem hiding this comment.
Well, the problem is that a final function cannot be overriden, unless it is also private.
Previously: run was member of Fiber but it was private so overriding in e.g. DerivedFiber was ok.
Now: run is a member of StackContextExecutor and it can't be private as it has to be used by Fiber. Because of that, overriding it causes a problem.
I think of a couple solutions to that, of which the simplest is the one you said - chaning the name.
There was a problem hiding this comment.
Hmm, perhaps doing #2797 (comment) and having it as the opCall in this PR would be worth doing then. Saves having to come up with a name that won't collide. Or just move run back to Fiber for the time being and do that when you address #2797 (comment) in a future PR. Up to you.
There was a problem hiding this comment.
Ok, I'll see if there are any simple things left and do that.
| */ | ||
| class Fiber | ||
|
|
||
| import core.thread.context : StackContext, StackContextExecutor; |
There was a problem hiding this comment.
You have multiple import of the same module just collapse them into one, and the public import for Rethrow just do alias Rethrow = .Rethow; (or alias Rethrow = core.thread.context.Rethrow; if that doesn't work)
There was a problem hiding this comment.
Yes, the imports are a little bad at the moment, along with the versioning. The last one is good thought, thanks.
|
This was supposed to be a follow-up to #2821, |
Continuing from #2689
This PR decouples
Context(nowStackContext) fromThread / Fiberin the form of a super class for both.Also, it adds a
GlobalStackContextfor commonly used global data.@thewilsonator I did it kind of quickly, tell me what you think. I did not follow your diff precisely as some things seemed not necessary. One example is
push/popContextetc. which seem to be relevant only toThread.Also, you seem to want a
LockGuardedBlockfor which I found no use and so it's not added yet.Finally, it may be good to alias
GlobalStackContextas it is used very much and it is a little verbose.