Difference between revisions of "DIP29"
WalterBright (talk | contribs) (Created page with "== Abstract == Currently, pointers cannot be converted to and from shared and immutable without an explicit and unsafe cast. Unique pointers can be implicitly cast to and from...") |
WalterBright (talk | contribs) |
||
Line 1: | Line 1: | ||
+ | {| class="wikitable" | ||
+ | !Title: | ||
+ | !'''Unique Pointers''' | ||
+ | |- | ||
+ | |DIP: | ||
+ | |29 | ||
+ | |- | ||
+ | |Version: | ||
+ | |1 | ||
+ | |- | ||
+ | |Status: | ||
+ | |'''Draft''' | ||
+ | |- | ||
+ | |Created: | ||
+ | |2013-02-28 | ||
+ | |- | ||
+ | |Last Modified: | ||
+ | |2013-02-28 | ||
+ | |- | ||
+ | |Language: | ||
+ | |D2 | ||
+ | |- | ||
+ | |Breaks: | ||
+ | |Nothing, it enables code that doesn't compile at the moment | ||
+ | |- | ||
+ | |Links: | ||
+ | |[https://github.com/D-Programming-Language/dmd/pull/1700 Discussion on github] | ||
+ | [http://www.digitalmars.com/d/archives/digitalmars/D/bugs/Issue_8993_New_Implement_unique_references_isolated_memory_44371.html Discussion on n.g.] | ||
+ | [http://www.digitalmars.com/d/archives/digitalmars/D/Immutable_and_unique_in_C_180572.html More Discussion on n.g.] | ||
+ | |} | ||
+ | |||
== Abstract == | == Abstract == | ||
Currently, pointers cannot be converted to and from shared and immutable without an explicit and unsafe cast. Unique pointers can be implicitly cast to and from shared and immutable in safety. A unique pointer can be discovered by examining the expression that generated the pointer. | Currently, pointers cannot be converted to and from shared and immutable without an explicit and unsafe cast. Unique pointers can be implicitly cast to and from shared and immutable in safety. A unique pointer can be discovered by examining the expression that generated the pointer. | ||
+ | |||
+ | == Rationale == | ||
+ | Requiring switching to unsafe code to do routine things like create immutable references is a glaring problem. By recognizing unique pointers much of this can be done safely. More advanced analysis can uncover more cases that can be done safely. | ||
+ | |||
+ | == Expression Case 1: ptr+offset == | ||
+ | |||
+ | If an expression ptr+offset yields a pointer, that expression is convertible iff ptr is convertible. | ||
+ | |||
+ | == Expression Case 2: ptr-offset == | ||
+ | |||
+ | If an expression ptr-offset yields a pointer, that expression is convertible iff ptr is convertible. | ||
+ | |||
+ | == Expression Case 3: new T == | ||
+ | |||
+ | This is convertible if T is convertible. (Not sure this is completely true.) | ||
+ | |||
+ | A lot more work is needed to enumerate all the cases. | ||
+ | |||
+ | == Copyright == | ||
+ | This document has been placed in the Public Domain. | ||
+ | |||
+ | [[Category: DIP]] |
Revision as of 01:11, 1 March 2013
Title: | Unique Pointers |
---|---|
DIP: | 29 |
Version: | 1 |
Status: | Draft |
Created: | 2013-02-28 |
Last Modified: | 2013-02-28 |
Language: | D2 |
Breaks: | Nothing, it enables code that doesn't compile at the moment |
Links: | Discussion on github |
Contents
Abstract
Currently, pointers cannot be converted to and from shared and immutable without an explicit and unsafe cast. Unique pointers can be implicitly cast to and from shared and immutable in safety. A unique pointer can be discovered by examining the expression that generated the pointer.
Rationale
Requiring switching to unsafe code to do routine things like create immutable references is a glaring problem. By recognizing unique pointers much of this can be done safely. More advanced analysis can uncover more cases that can be done safely.
Expression Case 1: ptr+offset
If an expression ptr+offset yields a pointer, that expression is convertible iff ptr is convertible.
Expression Case 2: ptr-offset
If an expression ptr-offset yields a pointer, that expression is convertible iff ptr is convertible.
Expression Case 3: new T
This is convertible if T is convertible. (Not sure this is completely true.)
A lot more work is needed to enumerate all the cases.
Copyright
This document has been placed in the Public Domain.