Skip to content

cmd/compile: conditional escape analysis (or better synergy with inlining) #77088

@adonovan

Description

@adonovan

(I'm certain this idea is not new, but the only related issues I can find are #72036 and #74364, which are both narrower.)

Inlining and escape analysis are not fully synergistic, presumably due to phase ordering. Thus even when a call is melted away, the conservative judgments of the escape analysis are not refined for the context of the call.

For example, although the compiler eliminates the call to f in this code:

type S struct{ x *int }

func f(ptr *S) {
	ptr.x = new(int)
}

func g() {
	var s S
	f(&s)
	print(s.x)
}

it does not produce object code equivalent to this program:

func g() {
	var s S
	s.x = new(int)
	print(s.x)
}

because the escape analysis of f determined that new(int) escapes, even though it does not escape in the context of the particular call from g.

If the phases of inlining and escape analysis were reversed, the two programs would generate identical code. Alternatively, the phase ordering could be retained but the inliner's summary of function f could be parameterized over a caller-supplied allocator, which in the case of this call would be a stack allocator.

Metadata

Metadata

Assignees

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.Proposalcompiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions