-
-
Notifications
You must be signed in to change notification settings - Fork 701
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
Improve std.typecons.Unique #3139
Merged
Merged
Commits on Apr 2, 2015
-
Whenever D is brought up to the general programming public, the garbage collector is quickly raised as a point of contention. Regardless of how legitimate or well-informed these concerns are, it would be a massive public relations boon --- and great for the language, to boot --- if we could trot out a solid said of RAII-based smart pointers for those who prefer to use them. We have a solid start in std.typecons.Unique and std.typecons.RefCounted. Unfortunately, these classes seem to be victims of bit rot and compiler bugs of days long gone. An overview of the changes in this commit is as follows: - Unique's underlying data now uses malloc and free instead of the garbage collector. Given that many people use RAII smart pointers to escape the GC, it seems to make more sense to avoid it here. On a related note, isn't delete deprecated? The current destructor uses it. - std.algorithm.move is used instead of a special release member function. Whether by design or by happy accident, move transfers ownership between Unique pointers in a very similar manner to C++'s std::move with std::unique_ptr. Along with being a familiar paradigm to C++ users, using move to transfer ownership makes more intuitive sense and builds consistency with the rest of Phobos. - With std.algorithm.move transferring ownership, release now just frees the underlying pointer and nulls the Unique. - Unique.create is no longer compiled out using version(None). Regardless of whether or not there is language support for checking uniqueness, a utility function that creates a Unique, taking the same arguments as the underlying type's constructor, is extremely useful, as demonstrated by the addition of make_unique to C++14. - Because Unique.create is now in place and Unique is backed with malloc, constructors taking a pointer have been removed. This encourages the use of create as the idiomatic, consistent method to, well, create Unique objects. If one can only get a Unique by calling create or moving another into it, we also ensures uniqueness in one fell swoop. - A new method, get, returns the underlying pointer, for use in functions and code that do not play a role in the life cycle of the object. Smart pointers are as much about ownership semantics as they are about allocating and freeing memory, and non-owning code should continue to refer to data using a raw pointer or a reference.
Configuration menu - View commit details
-
Copy full SHA for f6994ea - Browse repository at this point
Copy the full SHA f6994eaView commit details
Commits on Apr 3, 2015
-
Configuration menu - View commit details
-
Copy full SHA for db544d5 - Browse repository at this point
Copy the full SHA db544d5View commit details -
Configuration menu - View commit details
-
Copy full SHA for a5150a0 - Browse repository at this point
Copy the full SHA a5150a0View commit details -
Use class version of std.conv.emplace for Unique
I picked up the trick of converting a pointer into an array using the [0 .. size] syntax from std/regex/package.d. Unique.create is still segfaulting, but this seems to be an issue with the class version of emplace regardless of this Unique work. The bug can be found here: https://issues.dlang.org/show_bug.cgi?id=14402
Configuration menu - View commit details
-
Copy full SHA for 6d42be9 - Browse repository at this point
Copy the full SHA 6d42be9View commit details
Commits on Apr 5, 2015
-
It is currently impossible (or so it seems) to use malloc and emplace to create a nested class or struct, so we'll return to using the GC for now. We'll also restore the constructors that take a RefT, as using new _inside_ the context of the nested class or struct is apparently the only way to create one currently.
Configuration menu - View commit details
-
Copy full SHA for b3c94c2 - Browse repository at this point
Copy the full SHA b3c94c2View commit details
Commits on Apr 7, 2015
-
From the related pull request (#3139), there seems to be a general consensus that it is more important to do Unique "right", even if that means breaking changes, so long as there is a clean migration path. With that in mind, I have made the following additional changes: - Instead of constructors that take a RefT, Uniques can now be created one of two ways: via .create or .fromNested. See the DDocs of both for details. - opDot is replaced with "alias _p this". A cursorty Google search indicates that opDot is deprecated and that alias this is the preferred method. Like C++'s unique_ptr, Unique now enjoys pointer-like operations (such as dereferencing), but cannot be set to null or assigned from a different pointer due to opAssign and the disabled postblit constructor. - Consequently, isEmpty has been removed. Instead, just use is null as you would with a pointer. - Removal of redundant unit tests - Various comment and unit test cleanup
Configuration menu - View commit details
-
Copy full SHA for dba6bd5 - Browse repository at this point
Copy the full SHA dba6bd5View commit details
Commits on Apr 13, 2015
-
Turn Unique.create into a freestanding unique()
Also cleaned up the Unique documentation a bit. Unfortunately some of the unittests could not be used as documented unittests because placing them in the struct gives an error about RTInfo!(Nested) being recursvely expanded.
Configuration menu - View commit details
-
Copy full SHA for c5605bf - Browse repository at this point
Copy the full SHA c5605bfView commit details
Commits on Apr 17, 2015
-
Marking its various bits as @nogc is still proving to be a challenge since Object.destroy is not @nogc, among other things. We _are_ using GC.addRange and GC.removeRange to handle anything inside the underlying type that uses GC. Why the user would do this in conjunction with Unique is questionable, but until we can explicitly forbid doing so, let's not break garbage collection for them. Note that this also makes nested structs and classes impossible, because there is no way AFAIK to get the frame pointer into unique()
Configuration menu - View commit details
-
Copy full SHA for e112ec9 - Browse repository at this point
Copy the full SHA e112ec9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 836c551 - Browse repository at this point
Copy the full SHA 836c551View commit details -
Configuration menu - View commit details
-
Copy full SHA for d24b738 - Browse repository at this point
Copy the full SHA d24b738View commit details
Commits on Apr 20, 2015
-
Configuration menu - View commit details
-
Copy full SHA for d2289a4 - Browse repository at this point
Copy the full SHA d2289a4View commit details
Commits on Apr 21, 2015
-
Configuration menu - View commit details
-
Copy full SHA for 1cc0b48 - Browse repository at this point
Copy the full SHA 1cc0b48View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1204e04 - Browse repository at this point
Copy the full SHA 1204e04View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5a34389 - Browse repository at this point
Copy the full SHA 5a34389View commit details
Commits on Apr 24, 2015
-
Configuration menu - View commit details
-
Copy full SHA for ad3784f - Browse repository at this point
Copy the full SHA ad3784fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5054c6f - Browse repository at this point
Copy the full SHA 5054c6fView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.