File: sizeoffset.txt

package info (click to toggle)
golang-golang-x-tools 1%3A0.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,724 kB
  • sloc: javascript: 2,027; asm: 1,645; sh: 166; yacc: 155; makefile: 49; ansic: 8
file content (117 lines) | stat: -rw-r--r-- 2,187 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
This test checks that hover reports the sizes of vars/types,
and the offsets of struct fields.

Notes:
- this only works on the declaring identifier, not on refs.
- the size of a type is undefined if it depends on type parameters.
- the offset of a field is undefined if it or any preceding field
  has undefined size/alignment.
- the test's size expectations assumes a 64-bit machine.
- requires go1.22 because size information was inaccurate before.

-- flags --
-skip_goarch=386,arm
-min_go=go1.22

-- go.mod --
module example.com

go 1.18
-- a.go --
package a

type T struct {         //@ hover("T", "T", T)
	a int		//@ hover("a", "a", a)
	U U		//@ hover("U", "U", U)
	y, z int	//@ hover("y", "y", y), hover("z", "z", z)
}

type U struct {
	slice []string
}

type G[T any] struct {
	p T		//@ hover("p", "p", p)
	q int		//@ hover("q", "q", q)
}

var _ struct {
	Gint    G[int]    //@ hover("Gint",    "Gint",    Gint)
	Gstring G[string] //@ hover("Gstring", "Gstring", Gstring)
}

type wasteful struct { //@ hover("wasteful", "wasteful", wasteful)
	a bool
	b [2]string
	c bool
}

-- @T --
```go
type T struct { // size=48 (0x30)
	a    int //@ hover("a", "a", a)
	U    U   //@ hover("U", "U", U)
	y, z int //@ hover("y", "y", y), hover("z", "z", z)
}
```

[`a.T` on pkg.go.dev](https://pkg.go.dev/example.com#T)
-- @wasteful --
```go
type wasteful struct { // size=48 (0x30) (29% wasted)
	a bool
	b [2]string
	c bool
}
```
-- @a --
```go
field a int // size=8, offset=0
```

@ hover("a", "a", a)
-- @U --
```go
field U U // size=24 (0x18), offset=8
```

@ hover("U", "U", U)


[`(a.T).U` on pkg.go.dev](https://pkg.go.dev/example.com#T.U)
-- @y --
```go
field y int // size=8, offset=32 (0x20)
```

@ hover("y", "y", y), hover("z", "z", z)
-- @z --
```go
field z int // size=8, offset=40 (0x28)
```

@ hover("y", "y", y), hover("z", "z", z)
-- @p --
```go
field p T
```

@ hover("p", "p", p)
-- @q --
```go
field q int // size=8
```

@ hover("q", "q", q)
-- @Gint --
```go
field Gint G[int] // size=16 (0x10), offset=0
```

@ hover("Gint",    "Gint",    Gint)
-- @Gstring --
```go
field Gstring G[string] // size=24 (0x18), offset=16 (0x10)
```

@ hover("Gstring", "Gstring", Gstring)