Skip to content

cmd/compile: endless compilation for code that cannot be monomorphised #48018

@griesemer

Description

@griesemer

This code corresponds to Fig. 10 in the paper "Featherweight Go" ("FGG"); it's an example of a program that cannot be monomorphised.

The type checker (types2, go/types) accept this fine, but the compiler runs "forever".

package main

type Box[A any] struct {
	value A
}

func Nest[A any](b Box[A], n int) interface{} {
	if n == 0 {
		return b
	}
	return Nest(Box[Box[A]]{b}, n-1)
}

func main() {
	Nest(Box[int]{0}, 10)
}

The FGG paper suggests a check to detect such cases. We may want to implement that eventually. For 1.18, maybe we can have some sort of "time-out" with a suitable error message for now.

cc: @randall77

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.genericsIssue is related to genericsokay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions