Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,29 @@ protected virtual TypeCode GetTypeCodeImpl()
return TypeCode.Object;
}

#if !CORECLR
[Intrinsic]
public static bool operator ==(Type? left, Type? right)
{
if (object.ReferenceEquals(left, right))
return true;

if (left is null || right is null)
return false;

// CLR-compat: runtime types are never equal to non-runtime types
// If `left` is a non-runtime type with a weird Equals implementation
// this is where operator `==` would differ from `Equals` call.
if (left.IsRuntimeImplemented() || right.IsRuntimeImplemented())
return false;

return left.Equals(right);
}

[Intrinsic]
public static bool operator !=(Type? left, Type? right) => !(left == right);
#endif

public abstract Guid GUID { get; }

[SupportedOSPlatform("windows")]
Expand Down
8 changes: 0 additions & 8 deletions src/mono/System.Private.CoreLib/src/System/Type.Mono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,5 @@ internal virtual FieldInfo GetField(FieldInfo fromNoninstanciated)

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern Type internal_from_handle(IntPtr handle);

[Intrinsic]
public static bool operator ==(Type? left, Type? right) => left == right;

public static bool operator !=(Type? left, Type? right)
{
return !(left == right);
}
}
}
2 changes: 0 additions & 2 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -2417,8 +2417,6 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
} else if (in_corlib && !strcmp (klass_name_space, "System") && !strcmp (klass_name, "RuntimeMethodHandle") && !strcmp (tm, "GetFunctionPointer") && csignature->param_count == 1) {
// We must intrinsify this method on interp so we don't return a pointer to native code entering interpreter
*op = MINT_LDFTN_DYNAMIC;
} else if (in_corlib && target_method->klass == mono_defaults.systemtype_class && !strcmp (target_method->name, "op_Equality")) {
*op = MINT_CEQ_P;
} else if (in_corlib && target_method->klass == mono_defaults.object_class) {
if (!strcmp (tm, "InternalGetHashCode"))
*op = MINT_INTRINS_GET_HASHCODE;
Expand Down
7 changes: 0 additions & 7 deletions src/mono/mono/mini/intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1798,13 +1798,6 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
return ins;
}
}
} else if (cmethod->klass == mono_defaults.systemtype_class && !strcmp (cmethod->name, "op_Equality")) {
EMIT_NEW_BIALU (cfg, ins, OP_COMPARE, -1, args [0]->dreg, args [1]->dreg);
MONO_INST_NEW (cfg, ins, OP_PCEQ);
ins->dreg = alloc_preg (cfg);
ins->type = STACK_I4;
MONO_ADD_INS (cfg->cbb, ins);
return ins;
} else if (((!strcmp (cmethod_klass_image->assembly->aname.name, "MonoMac") ||
!strcmp (cmethod_klass_image->assembly->aname.name, "monotouch")) &&
!strcmp (cmethod_klass_name_space, "XamCore.ObjCRuntime") &&
Expand Down