Skip to content

cmd/compile: rewrite f(g()) to use OAS2FUNC earlier #29197

@mdempsky

Description

@mdempsky

Currently, there's a bunch of complexity from handling f(g()) where g is multi-valued.

For example, there's #15992, where it doesn't work when f is copy or delete. Until 1602e49 it didn't work with complex either.

It makes variadic functions and implicit conversions to interface type more complicated too. For example, given

//go:noescape
func f(a, b interface{})
func g() (a, b [4]int)

it should be possible to stack allocate the [4]int boxes for f(g()), but the OCONVIFACE nodes aren't even introduced until order.go, so esc.go has no way to mark them as non-escaping and currently they're heap allocated.

order.go (callArgs/copyRet) already rewrites f(g()) into t1, t2, .., tn := g(); f(t1, t2, ..., tn). I think we should do that during type checking instead.

A side benefit will be that we can also rewrite calls to variadic functions to always use a slice parameter (i.e., the ... call form), which should simplify various call-site logic too.

I feel like there have been other subtleties around multi-value and variadic functions, so I expect this should help improve compiler robustness.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions