diff --git a/oracle/describe.go b/oracle/describe.go index 5607a9c61d..162085d3ed 100644 --- a/oracle/describe.go +++ b/oracle/describe.go @@ -639,10 +639,22 @@ func describeType(o *Oracle, qpos *QueryPos, path []ast.Node) (*describeTypeResu return nil, fmt.Errorf("unexpected AST for type: %T", n) } + description = description + "type " + qpos.TypeString(t) + + // Show sizes for structs and named types (it's fairly obvious for others). + switch t.(type) { + case *types.Named, *types.Struct: + // TODO(adonovan): use o.imp.Config().TypeChecker.Sizes when + // we add the Config() method (needs some thought). + szs := types.StdSizes{8, 8} + description = fmt.Sprintf("%s (size %d, align %d)", description, + szs.Sizeof(t), szs.Alignof(t)) + } + return &describeTypeResult{ qpos: qpos, node: path[0], - description: description + "type " + qpos.TypeString(t), + description: description, typ: t, methods: accessibleMethods(t, qpos.info.Pkg), }, nil diff --git a/oracle/testdata/src/main/describe-json.golden b/oracle/testdata/src/main/describe-json.golden index 230c255fb0..48b85f0b68 100644 --- a/oracle/testdata/src/main/describe-json.golden +++ b/oracle/testdata/src/main/describe-json.golden @@ -133,7 +133,7 @@ { "mode": "describe", "describe": { - "desc": "definition of type C", + "desc": "definition of type C (size 8, align 8)", "pos": "testdata/src/main/describe-json.go:27:6", "detail": "type", "type": { diff --git a/oracle/testdata/src/main/describe.golden b/oracle/testdata/src/main/describe.golden index 41230c0e91..b586169197 100644 --- a/oracle/testdata/src/main/describe.golden +++ b/oracle/testdata/src/main/describe.golden @@ -50,13 +50,13 @@ reference to interface method func (I).f() defined here -------- @describe type-D -------- -reference to type D +reference to type D (size 0, align 1) defined as struct{} Method set: method (D) f() -------- @describe type-I -------- -reference to type I +reference to type I (size 16, align 8) defined as interface{f()} Method set: method (I) f() @@ -140,11 +140,11 @@ reference to const localpi untyped float of constant value 3141/1000 defined here -------- @describe type-def-T -------- -definition of type T +definition of type T (size 8, align 8) No methods. -------- @describe type-ref-T -------- -reference to type T +reference to type T (size 8, align 8) defined as int No methods. @@ -186,7 +186,7 @@ definition of var b *int no points-to information: PTA did not encounter this expression (dead code?) -------- @describe def-iface-I -------- -definition of type I +definition of type I (size 16, align 8) Method set: method (I) f() diff --git a/oracle/testdata/src/main/imports.golden b/oracle/testdata/src/main/imports.golden index cf9d881f33..b1173961ca 100644 --- a/oracle/testdata/src/main/imports.golden +++ b/oracle/testdata/src/main/imports.golden @@ -19,7 +19,7 @@ reference to var lib.Var int defined here -------- @describe ref-type -------- -reference to type lib.Type +reference to type lib.Type (size 8, align 8) defined as int Method set: method (lib.Type) Method(x *int) *int