Skip to content

x/tools/internal/refactor/inline: more precise analysis of return conversions in tail-call strategy #63336

@adonovan

Description

@adonovan

This call in callee.go:

				argType := func(i int) types.Type {
					return info.TypeOf(n.Results[i]) // inline
				}

is inlined to

				argType := func(i int) types.Type {
					return func(e ast.Expr) types.Type {
						if t, ok := info.Types[e]; ok {
							return t.Type
						}
						if id, _ := e.(*ast.Ident); id != nil {
							if obj := info.ObjectOf(id); obj != nil {
								return obj.Type()
							}
						}
						return nil
					}(n.Results[i])
				}

I think the only reason is that the final return nil involves a non-trivial conversion from untyped nil to Type(nil), yet TypeOf() is being tailcalled in a Type context, so it's quite safe. It would be nice if this were reduced to this:

				argType := func(i int) types.Type {
					var e ast.Expr = n.Results[i]
					if t, ok := info.Types[e]; ok {
						return t.Type
					}
					if id, _ := e.(*ast.Ident); id != nil {
						if obj := info.ObjectOf(id); obj != nil {
							return obj.Type()
						}
					}
					return nil
				}

(This is a feature request for a [style] optimization, not a bug, in the terms of source-level inliner.)

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions