Skip to content

Commit 4b93524

Browse files
committed
More mono updates
1 parent e83db73 commit 4b93524

File tree

7 files changed

+122
-30
lines changed

7 files changed

+122
-30
lines changed

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorOnTypeBuilderInstantiation.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Globalization;
67

78
namespace System.Reflection.Emit
@@ -30,11 +31,29 @@ internal ConstructorOnTypeBuilderInstantiation(ConstructorInfo constructor, Type
3031
}
3132
#endregion
3233

34+
#region Internal Overrides
3335
internal override Type[] GetParameterTypes()
3436
{
3537
return _ctor.GetParameterTypes();
3638
}
3739

40+
#if MONO
41+
// Called from the runtime to return the corresponding finished ConstructorInfo object
42+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern",
43+
Justification = "Reflection.Emit is not subject to trimming")]
44+
internal ConstructorInfo RuntimeResolve()
45+
{
46+
Type type = _type.InternalResolve();
47+
return type.GetConstructor(_ctor);
48+
}
49+
50+
internal override int GetParametersCount()
51+
{
52+
return _ctor.GetParametersCount();
53+
}
54+
#endif
55+
#endregion
56+
3857
#region MemberInfo Overrides
3958
public override MemberTypes MemberType => _ctor.MemberType;
4059
public override string Name => _ctor.Name;

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/FieldOnTypeBuilderInstantiation.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,14 @@ public override object GetValueDirect(TypedReference obj)
8787
public override void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, CultureInfo? culture) { throw new InvalidOperationException(); }
8888
public override FieldAttributes Attributes => _field.Attributes;
8989
#endregion
90+
91+
#if MONO
92+
// Called from the runtime to return the corresponding finished FieldInfo object
93+
internal FieldInfo RuntimeResolve()
94+
{
95+
Type type = _type.RuntimeResolve();
96+
return type.GetField(_field);
97+
}
98+
#endif
9099
}
91100
}

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInstantiation.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ private static MethodInfo ExtractBaseMethod(MethodInfo info)
7070
return (MethodInfo)t.Module.ResolveMethod(info.MetadataToken)!;
7171
}
7272

73-
internal override Type[] GetParameterTypes()
74-
{
75-
return _method.GetParameterTypes();
76-
}
77-
7873
#region MemberInfo Overrides
7974
public override MemberTypes MemberType => _method.MemberType;
8075
public override string Name => _method.Name;
@@ -98,7 +93,7 @@ public override object Invoke(object? obj, BindingFlags invokeAttr, Binder? bind
9893
public override CallingConventions CallingConvention => _method.CallingConvention;
9994
public override Type[] GetGenericArguments()
10095
{
101-
#if MONO_FEATURE_SRE
96+
#if MONO
10297
if (!_method.IsGenericMethodDefinition)
10398
return Type.EmptyTypes;
10499
Type[] source = _typeArguments ?? _method.GetGenericArguments();
@@ -115,7 +110,7 @@ public override bool ContainsGenericParameters
115110
{
116111
get
117112
{
118-
#if MONO_FEATURE_SRE
113+
#if MONO
119114
if (_method.ContainsGenericParameters)
120115
return true;
121116
if (!_method.IsGenericMethodDefinition)
@@ -137,7 +132,7 @@ public override bool ContainsGenericParameters
137132
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
138133
public override MethodInfo MakeGenericMethod(params Type[] typeArgs)
139134
{
140-
#if MONO_FEATURE_SRE
135+
#if MONO
141136
if (!_method.IsGenericMethodDefinition || (_typeArguments != null))
142137
throw new InvalidOperationException("Method is not a generic method definition");
143138

@@ -170,5 +165,38 @@ public override MethodInfo MakeGenericMethod(params Type[] typeArgs)
170165
public override ICustomAttributeProvider ReturnTypeCustomAttributes => throw new NotSupportedException();
171166
public override MethodInfo GetBaseDefinition() { throw new NotSupportedException(); }
172167
#endregion
168+
169+
#region Internal overrides
170+
internal override Type[] GetParameterTypes()
171+
{
172+
return _method.GetParameterTypes();
173+
}
174+
175+
#if MONO
176+
// Called from the runtime to return the corresponding finished MethodInfo object
177+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod",
178+
Justification = "MethodOnTypeBuilderInst is Reflection.Emit's underlying implementation of MakeGenericMethod. " +
179+
"Callers of the outer calls to MakeGenericMethod will be warned as appropriate.")]
180+
internal MethodInfo RuntimeResolve()
181+
{
182+
Type type = _type.InternalResolve();
183+
MethodInfo m = type.GetMethod(_method);
184+
if (_typeArguments != null)
185+
{
186+
var args = new Type[_typeArguments.Length];
187+
for (int i = 0; i < _typeArguments.Length; ++i)
188+
args[i] = _typeArguments[i].InternalResolve();
189+
m = m.MakeGenericMethod(args);
190+
}
191+
return m;
192+
}
193+
194+
internal override int GetParametersCount()
195+
{
196+
return _method.GetParametersCount();
197+
}
198+
#endif
199+
#endregion
200+
173201
}
174202
}

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ namespace System.Reflection.Emit
1313
/*
1414
* TypeBuilderInstantiation represents an instantiation of a generic TypeBuilder.
1515
*/
16-
#if MONO_FEATURE_SRE
16+
#if MONO
1717
[StructLayout(LayoutKind.Sequential)]
1818
#endif
1919
internal sealed partial class TypeBuilderInstantiation : TypeInfo
2020
{
21-
#region Keep in sync with object-internals.h MonoReflectionGenericClass
21+
#region Keep in sync with object-internals.h MonoReflectionGenericClass
2222
private Type generic_type;
2323
private Type[] type_arguments;
24-
#endregion
24+
#endregion
2525
private string? _strFullQualName;
2626
internal Hashtable _hashtable;
2727

@@ -32,7 +32,7 @@ public override bool IsAssignableFrom([NotNullWhen(true)] TypeInfo? typeInfo)
3232
return IsAssignableFrom(typeInfo.AsType());
3333
}
3434

35-
#region Static Members
35+
#region Static Members
3636
internal static Type MakeGenericType(Type type, Type[] typeArguments)
3737
{
3838
Debug.Assert(type != null, "this is only called from RuntimeType.MakeGenericType and TypeBuilder.MakeGenericType so 'type' cannot be null");
@@ -49,35 +49,35 @@ internal static Type MakeGenericType(Type type, Type[] typeArguments)
4949

5050
return new TypeBuilderInstantiation(type, typeArguments);
5151
}
52-
#endregion
52+
#endregion
5353

54-
#region Constructor
54+
#region Constructor
5555
internal TypeBuilderInstantiation(Type type, Type[] inst)
5656
{
5757
generic_type = type;
5858
type_arguments = inst;
5959
_hashtable = new Hashtable();
6060
}
61-
#endregion
61+
#endregion
6262

63-
#region Object Overrides
63+
#region Object Overrides
6464
public override string ToString()
6565
{
6666
return TypeNameBuilder.ToString(this, TypeNameBuilder.Format.ToString)!;
6767
}
68-
#endregion
68+
#endregion
6969

70-
#region MemberInfo Overrides
70+
#region MemberInfo Overrides
7171
public override Type? DeclaringType => generic_type.DeclaringType;
7272

7373
public override Type? ReflectedType => generic_type.ReflectedType;
7474

7575
public override string Name => generic_type.Name;
7676

7777
public override Module Module => generic_type.Module;
78-
#endregion
78+
#endregion
7979

80-
#region Type Overrides
80+
#region Type Overrides
8181
public override Type MakePointerType()
8282
{
8383
return SymbolType.FormCompoundType("*", this, 0)!;
@@ -264,7 +264,45 @@ public override bool IsSubclassOf(Type c)
264264
throw new NotSupportedException();
265265
}
266266

267-
#if MONO_FEATURE_SRE
267+
#if MONO
268+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:UnrecognizedReflectionPattern",
269+
Justification = "Reflection.Emit is not subject to trimming")]
270+
internal override Type InternalResolve()
271+
{
272+
Type gtd = generic_type.InternalResolve();
273+
Type[] args = new Type[type_arguments.Length];
274+
for (int i = 0; i < type_arguments.Length; ++i)
275+
args[i] = type_arguments[i].InternalResolve();
276+
return gtd.MakeGenericType(args);
277+
}
278+
279+
// Called from the runtime to return the corresponding finished Type object
280+
internal override Type RuntimeResolve()
281+
{
282+
if (generic_type is TypeBuilder tb && !tb.IsCreated())
283+
throw new NotImplementedException();
284+
for (int i = 0; i < type_arguments.Length; ++i)
285+
{
286+
Type t = type_arguments[i];
287+
if (t is TypeBuilder ttb && !ttb.IsCreated())
288+
throw new NotImplementedException();
289+
}
290+
return InternalResolve();
291+
}
292+
293+
internal override bool IsUserType
294+
{
295+
get
296+
{
297+
foreach (Type t in type_arguments)
298+
{
299+
if (t.IsUserType)
300+
return true;
301+
}
302+
return false;
303+
}
304+
}
305+
268306
internal override MethodInfo GetMethod(MethodInfo fromNoninstanciated)
269307
{
270308
return new MethodOnTypeBuilderInstantiation(fromNoninstanciated, this);
@@ -280,14 +318,14 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated)
280318
return FieldOnTypeBuilderInstantiation.GetField(fromNoninstanciated, this);
281319
}
282320
#endif
283-
#endregion
321+
#endregion
284322

285323
#region ICustomAttributeProvider Implementation
286324
public override object[] GetCustomAttributes(bool inherit) { throw new NotSupportedException(); }
287325

288326
public override object[] GetCustomAttributes(Type attributeType, bool inherit) { throw new NotSupportedException(); }
289327

290328
public override bool IsDefined(Type attributeType, bool inherit) { throw new NotSupportedException(); }
291-
#endregion
329+
#endregion
292330
}
293331
}

src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<EnableDefaultItems>false</EnableDefaultItems>
44
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
@@ -253,7 +253,7 @@
253253
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\NativeLibrary.Mono.cs" />
254254
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\SafeHandle.Mono.cs" />
255255
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ObjectiveCMarshal.Mono.cs"
256-
Condition="'$(FeatureObjCMarshal)' == 'true'" />
256+
Condition="'$(FeatureObjCMarshal)' == 'true'"/>
257257
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\X86\X86Base.Mono.cs" />
258258
<Compile Include="$(BclSourcesRoot)\System\Runtime\Loader\AssemblyLoadContext.Mono.cs" />
259259
<Compile Include="$(BclSourcesRoot)\System\Security\DynamicSecurityMethodAttribute.cs" />

src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,11 @@ internal static object RuntimeResolve(object obj)
717717
if (obj is RuntimeGenericTypeParameterBuilder gtpb)
718718
return gtpb.RuntimeResolve();
719719
if (obj is FieldOnTypeBuilderInstantiation fotbi)
720-
return fotbi.DeclaringType!.RuntimeResolve();
720+
return fotbi.RuntimeResolve();
721721
if (obj is MethodOnTypeBuilderInstantiation motbi)
722-
return motbi.DeclaringType!.RuntimeResolve();
722+
return motbi.RuntimeResolve();
723723
if (obj is ConstructorOnTypeBuilderInstantiation cotbi)
724-
return cotbi.DeclaringType!.RuntimeResolve();
724+
return cotbi.RuntimeResolve();
725725
if (obj is Type t)
726726
return t.RuntimeResolve();
727727
throw new NotImplementedException(obj.GetType().FullName);

src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3535
//
3636

37-
#if MONO_FEATURE_SRE
3837
using System.Collections.Generic;
3938
using System.Diagnostics;
4039
using System.Diagnostics.CodeAnalysis;
@@ -1953,4 +1952,3 @@ private static void throw_argument_ConstantDoesntMatch()
19531952
public override bool IsByRefLike => false;
19541953
}
19551954
}
1956-
#endif

0 commit comments

Comments
 (0)