[runtime] Handle circular references in SRE types
authorAlexander Kyte <alexmkyte@gmail.com>
Wed, 12 Apr 2017 16:25:18 +0000 (12:25 -0400)
committerAlexander Kyte <alexmkyte@gmail.com>
Tue, 18 Apr 2017 15:33:16 +0000 (11:33 -0400)
commita8dfce54660780a583baf1eca4968eb1712102ce
tree4c59da2d8721093555d06e03fdf0de755628fbbb
parentdb95a040654f0407ca8bd8213bd780207e4822c6
[runtime] Handle circular references in SRE types

We previously recursed through the entire directed cyclic graph
of the type passed to SRE. When given a (legal) circular type reference,
we encountered stack overflows. This was particularly easy to trigger
with fsharpi and with FAKE.

By creating everything about the type before searching for the parent,
and by defering all type hierarchy establishment until the type must be
surfaced to manage code, we tease out the data dependencies caught up in
the cycle.

Note the bounded lifetime of the unmanaged object hidden in the SRE
module, which acts as a global reference for all types reachable from
the TypeBuilder passed to the runtime through the icall.
mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mono/metadata/object-internals.h
mono/metadata/sre.c