-
-
Notifications
You must be signed in to change notification settings - Fork 694
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
Make GCAllocator usable in pure functions #6432
Conversation
Thanks for your pull request and interest in making D better, @nordlow! 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 + phobos#6432" |
@@ -1,6 +1,6 @@ | |||
// Written in the D programming language. | |||
/** | |||
D's built-in garbage-collected allocator. | |||
D's built-in garbage-collected allocator. |
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.
Unrelated
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.
Fixed.
2e6008b
to
056b644
Compare
Had to update a |
@@ -117,31 +117,31 @@ struct GCAllocator | |||
are `shared`. | |||
*/ | |||
|
|||
static shared GCAllocator instance; | |||
static shared const GCAllocator instance; |
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.
Why not immutable? Does it matter one way or the other?
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.
No, AFAICT. An immutable
data is automatically shared
, but since GCAllocator
contains no data members I don't think it matters in this case.
Update: Apparently, it must be const
. Changing to immutable
fails as
std/experimental/allocator/building_blocks/segregator.d(377): Error: non-shared method std.experimental.allocator.building_blocks.segregator.Segregator!(128LU, GCAllocator, GCAllocator).Segregator.Impl!().goodAllocSize is not callable using a shared object
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.
That's bizarre.
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.
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 issue seems to be that when you have static immutable GCAllocator instance
the following
is(typeof(GCAllocator.instance) == shared)
is false
, which is odd.
If you have a look at Segregator it compares the small and large allocators against shared
in order to decide how to mixin
the Impl
template struct.
With immutable
, the is expression is false
and thus the shared
attribute is not applied.
I don't know why it's false; maybe a compiler bug? @andralex
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.
Probably a new PR would be better
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, I'll try that.
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.
@edi33416, can you have a go at this? My time is currently very spare.
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.
@nordlow I'll have at it after DConf
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.
Thanks.
2df3cb1
to
3c438cd
Compare
std/experimental/allocator/typed.d
Outdated
@@ -22,7 +22,7 @@ import std.traits : isPointer, hasElaborateDestructor; | |||
import std.typecons : Flag, Yes, No; | |||
|
|||
/** | |||
Allocation-related flags dictated by type characteristics. `TypedAllocator` | |||
Allocation-related flags dictated by type characteristics. `TypedAllocator` |
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.
No reason for indent
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.
Fixed.
3c438cd
to
d0adf13
Compare
Thanks. |
Sorry for being away over the weekend, but I thought we couldn't do this:
(I tried the same ~ two years ago) |
Thanks, anyway. |
In case I wasn't clear: I was trying to say that except @andralex changed his mind, I think we need to revert this :/ |
After working on allocators and collection for a good while, I got to the conclusion the allocation funcs must be pure, so let's keep this in. |
Great, |
Qualify members of
GCAllocator
asconst
to make it usable in pure contexts.Because
new
can be used in pure contexts I see no reason whyGCAllocator
shouldn't be that aswell.