Skip to content

cmd/compile: apparent infinite expansion of recursive function #48711

@findleyr

Description

@findleyr

The following program type-checks, but appears to grow unbounded during compilation:

package main

func f[T interface{~[]P}, P any](t T) {
	if t == nil {
		return
	}
	f[[]T,T]([]T{t})
}

func main() {
	f[[]int](nil)
}

This is not surprising: the program was constructed to require an infinitely growing number of function instances. See also #48098 and #48703: infinitely expanding instances are generally problematic.

Not sure where it is best to handle this. It seems like something that could be detected by the type-checker, but there can be an arbitrary number of functions involved in this infinite expansion. Maybe it would be easier for the compiler to enforce a limit on recursive instantiation.

CC @griesemer @danscales @randall77 @timothy-king

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions