[Mono-dev] [PATCH] Handle more gracefully invalid generic instantiations

Raja R Harinath harinath at hurrynot.org
Tue Jun 30 10:30:32 EDT 2009


Hi,

On Tue, Jun 30, 2009 at 19:16, Rodrigo Kumpera<kumpera at gmail.com> wrote:
> Hi,
>
> On Sat, Jun 27, 2009 at 2:49 AM, Raja R Harinath <harinath at hurrynot.org>
> wrote:
>>
>> Hi,
>>
>> Rodrigo Kumpera <kumpera at gmail.com> writes:
>>
>> > The attached patch changes class.c/inflate_generic_type to not abort the
>> > runtime when facing a bad instantiation.
[snip]
>> I think the issue is that we're forced to intertwine this particular
>> error check in the middle of code dealing with the mechanics of
>> inflating.  It'd be much nicer for inflate_generic_type to have the
>> precondition that no VAR or MVAR in 'type' will be out-of-bounds WRT
>> 'context'.
>>
>> The problem is that this precondition check is currently expensive, as
>> it would duplicate the same recursive traversal.  However, we _can_ and
>> _should_ make it non-recursive -- we can replace the field and
>> computation of MonoGenericInst::is_open with something like
>> MonoGenericInst::min_context_size (yeah that name is horribly bad.  I've
>> been putting of writing that code since I couldn't get a better name).
[snip]
> Hari, I fail to see how changing MonoGenericInst::is_open would help here.
> The type received by inflate_generic_type can be anything such as "!T[]",
> which requires a recursive transversal to check for errors as there is no
> MonoGenericInst involved.

I guess it's easiest to explain with code.  The basic idea is to
pre-compute more information when a MonoGenericInst is created.  It's
very easy to compute the context size constraints for any context that
MonoGenericInst would be expanded in: it turns out that it can be
computed pretty much the same non-recursive way that 'is_open' is.
Now, given such a context size constraint, it's easy to check the
pre-condition upfront, in a non-recursive manner.

- Hari


More information about the Mono-devel-list mailing list