Skip to content

Commit

Permalink
[metadata] Replace uses of MonoType:byref by a getter (#60313)
Browse files Browse the repository at this point in the history
* [metadata] Replace uses of MonoType:byref by a getter

Call `mono_type_is_byref_internal` instead of accessing the byref bit directly.

No functional change. (I hope).

This is in preparation for exploring alternative representations of ref types.

* Change mono_type_is_byref_internal to take a const argument

* Missed a couple byref reads

* rename mono_type_is_byref_internal -> m_type_is_byref [NFC]

* more missed byrefs

* revert unintended change
  • Loading branch information
lambdageek committed Oct 14, 2021
1 parent dac1290 commit f77e586
Show file tree
Hide file tree
Showing 44 changed files with 343 additions and 343 deletions.
18 changes: 9 additions & 9 deletions src/mono/mono/component/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -5023,7 +5023,7 @@ buffer_add_value_full (Buffer *buf, MonoType *t, void *addr, MonoDomain *domain,
MonoObject *obj;
gboolean boxed_vtype = FALSE;

if (t->byref) {
if (m_type_is_byref (t)) {
if (!(*(void**)addr)) {
/* This can happen with compiler generated locals */
//PRINT_MSG ("%s\n", mono_type_full_name (t));
Expand Down Expand Up @@ -5699,7 +5699,7 @@ set_var (MonoType *t, MonoDebugVarInfo *var, MonoContext *ctx, MonoDomain *domai
host_mgreg_t v;
gboolean is_signed = FALSE;

if (t->byref) {
if (m_type_is_byref (t)) {
addr = (guint8 *)mono_arch_context_get_int_reg (ctx, reg);

if (addr) {
Expand All @@ -5709,7 +5709,7 @@ set_var (MonoType *t, MonoDebugVarInfo *var, MonoContext *ctx, MonoDomain *domai
break;
}

if (!t->byref && (t->type == MONO_TYPE_I1 || t->type == MONO_TYPE_I2 || t->type == MONO_TYPE_I4 || t->type == MONO_TYPE_I8))
if (!m_type_is_byref (t) && (t->type == MONO_TYPE_I1 || t->type == MONO_TYPE_I2 || t->type == MONO_TYPE_I4 || t->type == MONO_TYPE_I8))
is_signed = TRUE;

switch (size) {
Expand Down Expand Up @@ -5754,7 +5754,7 @@ set_var (MonoType *t, MonoDebugVarInfo *var, MonoContext *ctx, MonoDomain *domai

//PRINT_MSG ("[R%d+%d] = %p\n", reg, var->offset, addr);

if (t->byref) {
if (m_type_is_byref (t)) {
addr = *(guint8**)addr;

if (!addr)
Expand Down Expand Up @@ -6103,7 +6103,7 @@ mono_do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, gu
if (args [i] && ((MonoObject*)args [i])->vtable->domain != domain)
NOT_IMPLEMENTED;

if (sig->params [i]->byref) {
if (m_type_is_byref (sig->params [i])) {
arg_buf [i] = g_newa (guint8, sizeof (gpointer));
*(gpointer*)arg_buf [i] = args [i];
args [i] = arg_buf [i];
Expand Down Expand Up @@ -6178,7 +6178,7 @@ mono_do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, gu
buffer_add_value (buf, mono_get_void_type_dbg (), NULL, domain);
}
} else if (MONO_TYPE_IS_REFERENCE (sig->ret)) {
if (sig->ret->byref) {
if (m_type_is_byref (sig->ret)) {
MonoType* ret_byval = m_class_get_byval_arg (mono_class_from_mono_type_internal (sig->ret));
buffer_add_value (buf, ret_byval, &res, domain);
} else {
Expand All @@ -6195,7 +6195,7 @@ mono_do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, gu
} else {
g_assert (res);

if (sig->ret->byref) {
if (m_type_is_byref (sig->ret)) {
MonoType* ret_byval = m_class_get_byval_arg (mono_class_from_mono_type_internal (sig->ret));
buffer_add_value (buf, ret_byval, mono_object_unbox_internal (res), domain);
} else {
Expand All @@ -6213,7 +6213,7 @@ mono_do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, gu
for (i = 0; i < nargs; ++i) {
if (MONO_TYPE_IS_REFERENCE (sig->params [i]))
buffer_add_value (buf, sig->params [i], &args [i], domain);
else if (sig->params [i]->byref)
else if (m_type_is_byref (sig->params [i]))
/* add_value () does an indirection */
buffer_add_value (buf, sig->params [i], &arg_buf [i], domain);
else
Expand Down Expand Up @@ -7892,7 +7892,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
b |= (1 << 0);
if (type->type == MONO_TYPE_PTR || type->type == MONO_TYPE_FNPTR)
b |= (1 << 1);
if (!type->byref && (((type->type >= MONO_TYPE_BOOLEAN) && (type->type <= MONO_TYPE_R8)) || (type->type == MONO_TYPE_I) || (type->type == MONO_TYPE_U)))
if (!m_type_is_byref (type) && (((type->type >= MONO_TYPE_BOOLEAN) && (type->type <= MONO_TYPE_R8)) || (type->type == MONO_TYPE_I) || (type->type == MONO_TYPE_U)))
b |= (1 << 2);
if (type->type == MONO_TYPE_VALUETYPE)
b |= (1 << 3);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/component/debugger-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ mono_de_set_interp_var (MonoType *t, gpointer addr, guint8 *val_buf)
{
int size;

if (t->byref) {
if (m_type_is_byref (t)) {
addr = *(gpointer*)addr;
if (!addr)
return ERR_INVALID_OBJECT;
Expand Down
18 changes: 9 additions & 9 deletions src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError

if (mono_metadata_token_table (parent_token) == MONO_TABLE_TYPESPEC) {
/*WARNING: this must satisfy mono_metadata_type_hash*/
klass->this_arg.byref = 1;
klass->this_arg.byref__ = 1;
klass->this_arg.data.klass = klass;
klass->this_arg.type = MONO_TYPE_CLASS;
klass->_byval_arg.data.klass = klass;
Expand Down Expand Up @@ -846,7 +846,7 @@ mono_class_create_generic_inst (MonoGenericClass *gclass)
klass->_byval_arg.type = MONO_TYPE_GENERICINST;
klass->this_arg.type = m_class_get_byval_arg (klass)->type;
klass->this_arg.data.generic_class = klass->_byval_arg.data.generic_class = gclass;
klass->this_arg.byref = TRUE;
klass->this_arg.byref__ = TRUE;
klass->enumtype = gklass->enumtype;
klass->valuetype = gklass->valuetype;

Expand Down Expand Up @@ -1148,7 +1148,7 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound
klass->_byval_arg.data.klass = eclass;
}
klass->this_arg = klass->_byval_arg;
klass->this_arg.byref = 1;
klass->this_arg.byref__ = 1;

if (rank > 32) {
ERROR_DECL (prepared_error);
Expand Down Expand Up @@ -1321,7 +1321,7 @@ make_generic_param_class (MonoGenericParam *param)
klass->this_arg.type = t;
CHECKED_METADATA_WRITE_PTR ( klass->this_arg.data.generic_param , param );
CHECKED_METADATA_WRITE_PTR ( klass->_byval_arg.data.generic_param , param );
klass->this_arg.byref = TRUE;
klass->this_arg.byref__ = TRUE;

/* We don't use type_token for VAR since only classes can use it (not arrays, pointer, VARs, etc) */
klass->sizes.generic_param_token = !is_anonymous ? pinfo->token : 0;
Expand Down Expand Up @@ -1464,7 +1464,7 @@ mono_class_create_ptr (MonoType *type)

result->this_arg.type = result->_byval_arg.type = MONO_TYPE_PTR;
result->this_arg.data.type = result->_byval_arg.data.type = m_class_get_byval_arg (el_class);
result->this_arg.byref = TRUE;
result->this_arg.byref__ = TRUE;

mono_class_setup_supertypes (result);

Expand Down Expand Up @@ -1529,7 +1529,7 @@ mono_class_create_fnptr (MonoMethodSignature *sig)
result->cast_class = result->element_class = result;
result->this_arg.type = result->_byval_arg.type = MONO_TYPE_FNPTR;
result->this_arg.data.method = result->_byval_arg.data.method = sig;
result->this_arg.byref = TRUE;
result->this_arg.byref__ = TRUE;
result->blittable = TRUE;
result->inited = TRUE;

Expand Down Expand Up @@ -1805,7 +1805,7 @@ type_has_references (MonoClass *klass, MonoType *ftype)
{
if (MONO_TYPE_IS_REFERENCE (ftype) || IS_GC_REFERENCE (klass, ftype) || ((MONO_TYPE_ISSTRUCT (ftype) && class_has_references (mono_class_from_mono_type_internal (ftype)))))
return TRUE;
if (!ftype->byref && (ftype->type == MONO_TYPE_VAR || ftype->type == MONO_TYPE_MVAR)) {
if (!m_type_is_byref (ftype) && (ftype->type == MONO_TYPE_VAR || ftype->type == MONO_TYPE_MVAR)) {
MonoGenericParam *gparam = ftype->data.generic_param;

if (gparam->gshared_constraint)
Expand Down Expand Up @@ -1974,7 +1974,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_
if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
continue;
if (blittable) {
if (field->type->byref || MONO_TYPE_IS_REFERENCE (field->type)) {
if (m_type_is_byref (field->type) || MONO_TYPE_IS_REFERENCE (field->type)) {
blittable = FALSE;
} else if (mono_type_is_generic_parameter (field->type) &&
mono_class_is_gparam_with_nonblittable_parent (mono_class_from_mono_type_internal (field->type))) {
Expand Down Expand Up @@ -3102,7 +3102,7 @@ mono_class_setup_mono_type (MonoClass *klass)
const char *nspace = klass->name_space;
gboolean is_corlib = mono_is_corlib_image (klass->image);

klass->this_arg.byref = 1;
klass->this_arg.byref__ = 1;
klass->this_arg.data.klass = klass;
klass->this_arg.type = MONO_TYPE_CLASS;
klass->_byval_arg.data.klass = klass;
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/class-setup-vtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,10 +1421,10 @@ vtable_slot_has_preserve_base_overrides_attribute (MonoClass *klass, int slot, M
static gboolean
is_ok_for_covariant_ret (MonoType *type_impl, MonoType *type_decl)
{
if (type_impl->byref ^ type_decl->byref)
if (m_type_is_byref (type_impl) ^ m_type_is_byref (type_decl))
return FALSE;

if (type_impl->byref) {
if (m_type_is_byref (type_impl)) {
return mono_byref_type_is_assignable_from (type_decl, type_impl, TRUE);
}

Expand Down
16 changes: 8 additions & 8 deletions src/mono/mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ _mono_type_get_assembly_name (MonoClass *klass, GString *str)
static void
mono_type_name_check_byref (MonoType *type, GString *str)
{
if (type->byref)
if (m_type_is_byref (type))
g_string_append_c (str, '&');
}

Expand Down Expand Up @@ -575,9 +575,9 @@ mono_type_get_name (MonoType *type)
MonoType*
mono_type_get_underlying_type (MonoType *type)
{
if (type->type == MONO_TYPE_VALUETYPE && m_class_is_enumtype (type->data.klass) && !type->byref)
if (type->type == MONO_TYPE_VALUETYPE && m_class_is_enumtype (type->data.klass) && !m_type_is_byref (type))
return mono_class_enum_basetype_internal (type->data.klass);
if (type->type == MONO_TYPE_GENERICINST && m_class_is_enumtype (type->data.generic_class->container_class) && !type->byref)
if (type->type == MONO_TYPE_GENERICINST && m_class_is_enumtype (type->data.generic_class->container_class) && !m_type_is_byref (type))
return mono_class_enum_basetype_internal (type->data.generic_class->container_class);
return type;
}
Expand Down Expand Up @@ -708,7 +708,7 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont
* ->byref and ->attrs from @type are propagated to the returned type.
*/
nt = mono_metadata_type_dup_with_cmods (image, inst->type_argv [num], type);
nt->byref = type->byref;
nt->byref__ = type->byref__;
nt->attrs = type->attrs;
return nt;
}
Expand Down Expand Up @@ -750,7 +750,7 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont
#endif

nt = mono_metadata_type_dup_with_cmods (image, inst->type_argv [num], type);
nt->byref = type->byref || inst->type_argv[num]->byref;
nt->byref__ = type->byref__ || inst->type_argv[num]->byref__;
nt->attrs = type->attrs;
#ifdef DEBUG_INFLATE_CMODS
if (append_cmods) {
Expand Down Expand Up @@ -1691,7 +1691,7 @@ MonoType*
mono_type_get_basic_type_from_generic (MonoType *type)
{
/* When we do generic sharing we let type variables stand for reference/primitive types. */
if (!type->byref && (type->type == MONO_TYPE_VAR || type->type == MONO_TYPE_MVAR) &&
if (!m_type_is_byref (type) && (type->type == MONO_TYPE_VAR || type->type == MONO_TYPE_MVAR) &&
(!type->data.generic_param->gshared_constraint || type->data.generic_param->gshared_constraint->type == MONO_TYPE_OBJECT))
return mono_get_object_type ();
return type;
Expand Down Expand Up @@ -3782,8 +3782,8 @@ mono_type_get_underlying_type_ignore_byref (MonoType *type)
gboolean
mono_byref_type_is_assignable_from (MonoType *type, MonoType *ctype, gboolean signature_assignment)
{
g_assert (type->byref);
g_assert (ctype->byref);
g_assert (m_type_is_byref (type));
g_assert (m_type_is_byref (ctype));
MonoType *t = mono_type_get_underlying_type_ignore_byref (type);
MonoType *ot = mono_type_get_underlying_type_ignore_byref (ctype);

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/debug-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ mono_type_get_desc (GString *res, MonoType *type, gboolean include_namespace)
if (type->has_cmods) {
mono_custom_modifiers_get_desc (res, type, include_namespace);
}
if (type->byref)
if (m_type_is_byref (type))
g_string_append_c (res, '&');
}

Expand Down
Loading

0 comments on commit f77e586

Please sign in to comment.