Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adonovan opened this issue Oct 2, 2023 · 1 comment
Assignees
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Oct 2, 2023

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.)

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Oct 2, 2023
@gopherbot gopherbot added this to the Unreleased milestone Oct 2, 2023
@prattmic prattmic added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 3, 2023
@adonovan adonovan self-assigned this Oct 5, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/533075 mentions this issue: internal/refactor/inline: permit return conversions in tailcall

@golang golang locked and limited conversation to collaborators Oct 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants