Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upproposal: Go 2: only give special properties to unsafe.Pointer if package imports unsafe #26070
Comments
ianlancetaylor
added
LanguageChange
Go2
Proposal
labels
Jun 26, 2018
ianlancetaylor
added this to the Proposal milestone
Jun 26, 2018
ianlancetaylor
added
the
NeedsDecision
label
Jun 26, 2018
griesemer
referenced this issue
Jun 26, 2018
Open
proposal: Go 2: reflect: return opaque pointer instead of uintptr #24654
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
randall77
Jun 26, 2018
Contributor
Presumably this will also let us redefine reflect.StringHeader and reflect.SliceHeader to use unsafe.Pointer instead of uintptr.
|
Presumably this will also let us redefine |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
I like this one. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bcmills
Jun 26, 2018
Member
Under this proposal, in order to determine whether a conversion expression T(x) may be an unsafe.Pointer conversion, the reader still needs to know three things that may not be locally obvious:
- whether the operand is a pointer or uintptr type,
- whether
Tis an alias forunsafe.Pointer, and - whether the current source file has imported package
unsafe.
(1) and (2) may be arbitrarily distant in the code (even across package boundaries); (3) is fairly easy to find within the source file, but still requires the reader to jump from the current context to the import block and back.
In contrast, with a function-based unsafe API (such as the one @griesemer and I discussed in #20171), I believe all of that information could be present within the conversion expression itself.
(I do agree that this proposal is a strict improvement over the status quo, but in the space of “fixes for unsafe.Pointer” it seems like the low-cost/low-benefit solution. I wonder whether we could get a much larger benefit for an only marginally higher cost.)
|
Under this proposal, in order to determine whether a conversion expression
(1) and (2) may be arbitrarily distant in the code (even across package boundaries); (3) is fairly easy to find within the source file, but still requires the reader to jump from the current context to the import block and back. In contrast, with a function-based (I do agree that this proposal is a strict improvement over the status quo, but in the space of “fixes for |
ianlancetaylor commentedJun 26, 2018
One of the difficulties of
unsafe.Pointeris that if a package gets a value of typeunsafe.Pointerthen it can convert that pointer to other pointer types, oruintptr. This is true even if the package does not itself import "unsafe", but gets theunsafe.Pointervalue by calling some other package. This is the reason thatreflect.Value.Pointerreturnsuintptrrather thanunsafe.Pointer.For Go 2 I propose that we change the language to say that values of type
unsafe.Pointeronly have their special properties in packages that explicitly import "unsafe". If a package does not import "unsafe", then a value of typeunsafe.Pointermay not be converted to other type.If we make that change, then, Go 1 compatibility rules aside, we can safely permit
reflect.Value.Pointerto returnunsafe.Pointer.