go/types: support for customizable Alignof, Sizeof
(Offsetof is a function of Alignof and Sizeof.)
- removed IntSize, PtrSize from Context (set Sizeof instead)
- GcImporter needs a Context now (it needs to have
access to Sizeof/Alignof)
- removed exported Size field from Basic (use Sizeof)
- added Offset to Field
- added Alignment, Size to Struct
https://codereview.appspot.com/7357046/diff/6002/src/pkg/exp/ssa/builder.go File src/pkg/exp/ssa/builder.go (right): https://codereview.appspot.com/7357046/diff/6002/src/pkg/exp/ssa/builder.go#newcode165 src/pkg/exp/ssa/builder.go:165: // TODO(adonovan): permit the client to specify these On ...
*** Submitted as https://code.google.com/p/go/source/detail?r=abd0feffdac3 *** go/types: support for customizable Alignof, Sizeof (Offsetof is a function ...
*** Submitted as https://code.google.com/p/go/source/detail?r=abd0feffdac3 ***
go/types: support for customizable Alignof, Sizeof
(Offsetof is a function of Alignof and Sizeof.)
- removed IntSize, PtrSize from Context (set Sizeof instead)
- GcImporter needs a Context now (it needs to have
access to Sizeof/Alignof)
- removed exported Size field from Basic (use Sizeof)
- added Offset to Field
- added Alignment, Size to Struct
R=adonovan
CC=golang-dev
https://codereview.appspot.com/7357046
LGTM (pair-reviewed) https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go File src/pkg/go/types/builtins.go (right): https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go#newcode325 src/pkg/go/types/builtins.go:325: case _Offsetof: On 2013/02/20 18:16:13, gri wrote: ...
11 years, 10 months ago
(2013-05-09 21:53:58 UTC)
#5
Message was sent while issue was closed.
LGTM
(pair-reviewed)
https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go
File src/pkg/go/types/builtins.go (right):
https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go...
src/pkg/go/types/builtins.go:325: case _Offsetof:
On 2013/02/20 18:16:13, gri wrote:
> On 2013/02/20 15:41:22, adonovan wrote:
> > Curious: when this is so clearly a special form, why do we try to make it
look
> > it library function? Also, I can see that using it is potentially
> nonportable,
> > but is it really unsafe?
>
> Built-in functions are the mechanism we have in Go for special situations.
It's
> non-portable, and perhaps not unsafe, but still, the very same program using
> unsafe.Offsetof may compile on one platform, and not on the other (say, the
> result constant could be used in a expression that results in a div-zero
compile
> time error dep. on offset value). Package unsafe seems as good as any other
> special case, and unsafe we have.
Well, I can determine sizeof(x) even in the supposedly portable (safe) parts of
the language. :)
My point was that the operands to sizeof, offsetof and alignof are not values
but types (or struct/fieldname pairs) so they are even more special than append,
which could in principle have a (polymorphic) type in some hypothetical future
release. So these things need compiler support, yet are not in the global
namespace.
Is putting them in "unsafe" a namespace pollution issue?
https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go File src/pkg/go/types/builtins.go (right): https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go#newcode325 src/pkg/go/types/builtins.go:325: case _Offsetof: On 2013/05/09 21:53:58, adonovan wrote: > On ...
11 years, 10 months ago
(2013-05-09 22:05:21 UTC)
#6
Message was sent while issue was closed.
https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go
File src/pkg/go/types/builtins.go (right):
https://codereview.appspot.com/7357046/diff/6002/src/pkg/go/types/builtins.go...
src/pkg/go/types/builtins.go:325: case _Offsetof:
On 2013/05/09 21:53:58, adonovan wrote:
> On 2013/02/20 18:16:13, gri wrote:
> > On 2013/02/20 15:41:22, adonovan wrote:
> > > Curious: when this is so clearly a special form, why do we try to make it
> look
> > > it library function? Also, I can see that using it is potentially
> > nonportable,
> > > but is it really unsafe?
> >
> > Built-in functions are the mechanism we have in Go for special situations.
> It's
> > non-portable, and perhaps not unsafe, but still, the very same program using
> > unsafe.Offsetof may compile on one platform, and not on the other (say, the
> > result constant could be used in a expression that results in a div-zero
> compile
> > time error dep. on offset value). Package unsafe seems as good as any other
> > special case, and unsafe we have.
>
> Well, I can determine sizeof(x) even in the supposedly portable (safe) parts
of
> the language. :)
>
> My point was that the operands to sizeof, offsetof and alignof are not values
> but types (or struct/fieldname pairs) so they are even more special than
append,
> which could in principle have a (polymorphic) type in some hypothetical future
> release. So these things need compiler support, yet are not in the global
> namespace.
>
> Is putting them in "unsafe" a namespace pollution issue?
Not really. It's just a design decision. In some sense, all the size operations
are "safe" but at the same time they are (likely) not often used unless in
conjunction with unsafe pointer operations. Arguably, it would be nice to have
sizeof w/o the need to import unsafe. One argument one might make that it
exposes implementation details and thus makes code non-portable (I am aware that
this is not a very sharp argument).
Issue 7357046: code review 7357046: go/types: support for customizable Alignof, Sizeof
(Closed)
Created 12 years ago by gri
Modified 11 years, 10 months ago
Reviewers: adonovan
Base URL:
Comments: 14