-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
add Placement New #17057
base: master
Are you sure you want to change the base?
add Placement New #17057
Conversation
Thanks for your pull request, @WalterBright! 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 run digger -- build "master + dmd#17057" |
29a5064
to
4db86a4
Compare
311f2cb
to
fd23a02
Compare
I got it to work for some basic cases. Next comes extending it to more complex ones. |
6456c9a
to
c1d3813
Compare
Placement new for structs seem to be working now! |
5f00e37
to
49f4a4c
Compare
If i'm reading this right, this will allow classes in betterC, using a kind of "allocator argument" like in $OTHER_LANGUAGES? Once upon a time I made my own internal fork of dmd that forced betterC on all D code but of course that didn't last long because it couldn't compile Phobos. (I should clarify, my usecase is making a kernel with betterC and so far I have had to use a hacky mixin and alias this in order to use inheritance. Also, will this unlock the door for interfaces?) |
16cdbd6
to
448abed
Compare
I realised what you meant here... this situation naturally occurs when you want to new an array though, so the case still has to be handled? |
efb517c
to
606be08
Compare
I am catching up after 4 days without internet or power. Seattle is a technologically advanced city with a primitive electric grid.
I'm sorry you got that impression. I've provided a rationale for each decision.
You did indeed propose The first line of the first post of the DIP in the n.g. on Oct 30: "Based on a suggestion by Manu Evans:" The dip is about passing an lvalue rather than a pointer.
It's a good thing we're friends, Manu! If you want things verbatim, write the DIP the way you want it. I wrote it the way I thought would work best. I've never seen an idea that survived into a specification without modification, like the replacement of void* with void[]. I've also never seen a specification that survived into an implementation without modification. (I rewrote the DIP after this implementation.) You've wanted 3 things, and I want them too:
The first two now have implementations and will work for your use cases. The other aspect of placement new works for my use cases. We should be both happy about this.
I didn't see the more, other than what I mentioned earlier. I know placement new from C++, having implemented it. I also implemented that in an earlier version of D: https://dlang.org/deprecate.html#Class%20allocators%20and%20deallocators and the implementation code for it is still present (and I made some use of it!).
Ok, but you've also made it clear it is not what you proposed :-) The hinge of our disagreement is placement new cannot be made |
Not at all, the hinge of our disagreement is that accepting a By writing: T x;
new(x) T; There's nothing you could do to make it look more like a value of I think if you were going to design this API, it's not possible to make the API worse than that; it communicates exactly the wrong thing, and I don't think you could inspire misunderstanding and user error more confidently if you tried. Before Yes I know you can write |
Could the current semantics of C++'s " Placement new" described in https://en.cppreference.com/w/cpp/language/new give insights on what type(s) that should be allowed to be passed as argument to |
C++ accepts |
The trouble with the function apparently accepting |
Oh no! void f(int* p) @nogc
{
new(*p) int;
}
Seems that placement new is not |
override void visit(NewExp e)
{
+++ if (e.placement)
+++ return; // placement new
if (e.member && !e.member.isNogc() && f.setGC(e.loc, null))
{
// @nogc-ness is already checked in NewExp::semantic
return;
}
if (e.onstack)
return;
if (global.params.ehnogc && e.thrownew)
return; // separate allocator is called for this, not the GC
if (setGC(e, "cannot use `new` in `@nogc` %s `%s`"))
return;
f.printGCUsage(e.loc, "`new` causes a GC allocation");
} This worked for me locally... |
606be08
to
45f59a5
Compare
@TurkeyMan Added your fix |
Is it correct though? |
45f59a5
to
04b3fd4
Compare
yes |
shall we merge this too? |
Actually, I still vehemently object to the API... can we get some 3rd parties to add their opinions? |
Let me talk to @WalterBright first. |
da96448
to
36c8611
Compare
Documentation PR: dlang/dlang.org#4161 |
Note: I have not added the |
36c8611
to
58bcca2
Compare
I presume this is no longer WIP? If so please remove the label |
This implements Placement New, described in https://github.com/WalterBright/documents/blob/master/placementnew.md