Skip to content

Commit

Permalink
[runtime] Remove the is_mb_open field from MonoMethod, it doesn't see…
Browse files Browse the repository at this point in the history
…m to be needed, inflated MethodBuilders are represented by MethodOnTypeBuilderInst objects.
  • Loading branch information
vargaz committed Aug 24, 2015
1 parent 0700303 commit 1da119b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 42 deletions.
2 changes: 0 additions & 2 deletions mono/metadata/class-internals.h
Expand Up @@ -82,8 +82,6 @@ struct _MonoMethod {
unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
unsigned int verification_success:1; /* whether this method has been verified successfully.*/
/* TODO we MUST get rid of this field, it's an ugly hack nobody is proud of. */
unsigned int is_mb_open : 1; /* This is the fully open instantiation of a generic method_builder. Worse than is_tb_open, but it's temporary */
signed int slot : 16;

/*
Expand Down
37 changes: 0 additions & 37 deletions mono/metadata/class.c
Expand Up @@ -1009,7 +1009,6 @@ mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *k
MonoMethodInflated *iresult, *cached;
MonoMethodSignature *sig;
MonoGenericContext tmp_context;
gboolean is_mb_open = FALSE;

mono_error_init (error);

Expand Down Expand Up @@ -1041,44 +1040,9 @@ mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *k
(method->klass->generic_container && context->class_inst)))
return method;

/*
* The reason for this hack is to fix the behavior of inflating generic methods that come from a MethodBuilder.
* What happens is that instantiating a generic MethodBuilder with its own arguments should create a diferent object.
* This is opposite to the way non-SRE MethodInfos behave.
*
* This happens, for example, when we want to emit a recursive generic method. Given the following C# code:
*
* void Example<T> () {
* Example<T> ();
* }
*
* In Example, the method token must be encoded as: "void Example<!!0>()"
*
* The reference to the first generic argument, "!!0", must be explicit otherwise it won't be inflated
* properly. To get that we need to inflate the MethodBuilder with its own arguments.
*
* On the other hand, inflating a non-SRE generic method with its own arguments should
* return itself. For example:
*
* MethodInfo m = ... //m is a generic method definition
* MethodInfo res = m.MakeGenericMethod (m.GetGenericArguments ());
* res == m
*
* To allow such scenarios we must allow inflation of MethodBuilder to happen in a diferent way than
* what happens with regular methods.
*
* There is one last touch to this madness, once a TypeBuilder is finished, IOW CreateType() is called,
* everything should behave like a regular type or method.
*
*/
is_mb_open = method->is_generic &&
image_is_dynamic (method->klass->image) && !method->klass->wastypebuilder && /* that is a MethodBuilder from an unfinished TypeBuilder */
context->method_inst == mono_method_get_generic_container (method)->context.method_inst; /* and it's been instantiated with its own arguments. */

iresult = g_new0 (MonoMethodInflated, 1);
iresult->context = *context;
iresult->declaring = method;
iresult->method.method.is_mb_open = is_mb_open;

if (!context->method_inst && method->is_generic)
iresult->context.method_inst = mono_method_get_generic_container (method)->context.method_inst;
Expand Down Expand Up @@ -1129,7 +1093,6 @@ mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *k
result->is_generic = FALSE;
result->sre_method = FALSE;
result->signature = NULL;
result->is_mb_open = is_mb_open;

if (!context->method_inst) {
/* Set the generic_container of the result to the generic_container of method */
Expand Down
4 changes: 1 addition & 3 deletions mono/metadata/metadata.c
Expand Up @@ -2150,16 +2150,14 @@ inflated_method_equal (gconstpointer a, gconstpointer b)
const MonoMethodInflated *mb = b;
if (ma->declaring != mb->declaring)
return FALSE;
if (ma->method.method.is_mb_open != mb->method.method.is_mb_open)
return FALSE;
return mono_metadata_generic_context_equal (&ma->context, &mb->context);
}

static guint
inflated_method_hash (gconstpointer a)
{
const MonoMethodInflated *ma = a;
return (mono_metadata_generic_context_hash (&ma->context) ^ mono_aligned_addr_hash (ma->declaring)) + ma->method.method.is_mb_open;
return (mono_metadata_generic_context_hash (&ma->context) ^ mono_aligned_addr_hash (ma->declaring));
}

static gboolean
Expand Down

0 comments on commit 1da119b

Please sign in to comment.