Skip to content

Commit

Permalink
Revert "Add annotations to System.Private.DataContractSerialization (#…
Browse files Browse the repository at this point in the history
…73337)" (#73878)

This reverts commit c4ea2ca.
  • Loading branch information
StephenMolloy authored Aug 13, 2022
1 parent 339a6bc commit bff7c3d
Show file tree
Hide file tree
Showing 53 changed files with 7 additions and 688 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<NoWarn>$(NoWarn);1634;1691;649</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Too much private reflection. Do not bother with trimming -->
<ILLinkTrimAssembly>false</ILLinkTrimAssembly>
<EnableAOTAnalyzer>true</EnableAOTAnalyzer>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ internal static class FastInvokerBuilder

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod",
Justification = "The call to MakeGenericMethod is safe due to the fact that we are preserving the constructors of type which is what Make() is doing.")]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
public static Func<object> GetMakeNewInstanceFunc(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Type type)
Expand Down Expand Up @@ -67,9 +66,7 @@ public static Getter CreateGetter(MemberInfo memberInfo)
// Only JIT if dynamic code is supported.
if (RuntimeFeature.IsDynamicCodeSupported || (!declaringType.IsValueType && !propertyType.IsValueType))
{
#pragma warning disable IL3050 // AOT compiling should recognize that this call is gated by RuntimeFeature.IsDynamicCodeSupported
var createGetterGeneric = s_createGetterInternal.MakeGenericMethod(declaringType, propertyType).CreateDelegate<Func<PropertyInfo, Getter>>();
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
return createGetterGeneric(propInfo);
}
else
Expand Down Expand Up @@ -124,9 +121,7 @@ public static Setter CreateSetter(MemberInfo memberInfo)
// Only JIT if dynamic code is supported.
if (RuntimeFeature.IsDynamicCodeSupported || (!declaringType.IsValueType && !propertyType.IsValueType))
{
#pragma warning disable IL3050 // AOT compiling should recognize that this call is gated by RuntimeFeature.IsDynamicCodeSupported
var createSetterGeneric = s_createSetterInternal.MakeGenericMethod(propInfo.DeclaringType!, propInfo.PropertyType).CreateDelegate<Func<PropertyInfo, Setter>>();
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
return createSetterGeneric(propInfo);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ internal sealed class ClassDataContract : DataContract
DynamicallyAccessedMemberTypes.PublicProperties;

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal ClassDataContract(Type type) : base(new ClassDataContractCriticalHelper(type))
{
InitClassDataContract();
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private ClassDataContract(Type type, XmlDictionaryString ns, string[] memberNames) : base(new ClassDataContractCriticalHelper(type, ns, memberNames))
{
InitClassDataContract();
Expand Down Expand Up @@ -77,7 +75,6 @@ internal List<DataMember>? Members
public XmlDictionaryString?[]? ChildElementNamespaces
{
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
get
{
if (_childElementNamespaces == null)
Expand Down Expand Up @@ -136,7 +133,6 @@ internal MethodInfo? ExtensionDataSetMethod
public override DataContractDictionary? KnownDataContracts
{
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
get
{ return _helper.KnownDataContracts; }
}
Expand Down Expand Up @@ -208,8 +204,6 @@ internal MethodInfo? GetKeyValuePairMethodInfo
}

private Func<object>? _makeNewInstance;
[UnconditionalSuppressMessage("AOT Analysis", "IL3050:RequiresDynamicCode",
Justification = "Cannot annotate a field, annotating the usage instead")]
private Func<object> MakeNewInstance => _makeNewInstance ??= FastInvokerBuilder.GetMakeNewInstanceFunc(UnderlyingType);

internal bool CreateNewInstanceViaDefaultConstructor([NotNullWhen(true)] out object? obj)
Expand All @@ -235,7 +229,6 @@ internal bool CreateNewInstanceViaDefaultConstructor([NotNullWhen(true)] out obj
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private XmlFormatClassWriterDelegate CreateXmlFormatWriterDelegate()
{
return new XmlFormatWriterGenerator().GenerateClassWriter(this);
Expand All @@ -244,7 +237,6 @@ private XmlFormatClassWriterDelegate CreateXmlFormatWriterDelegate()
internal XmlFormatClassWriterDelegate XmlFormatWriterDelegate
{
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
get
{
if (_helper.XmlFormatWriterDelegate == null)
Expand All @@ -267,7 +259,6 @@ internal XmlFormatClassWriterDelegate XmlFormatWriterDelegate
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private XmlFormatClassReaderDelegate CreateXmlFormatReaderDelegate()
{
return new XmlFormatReaderGenerator().GenerateClassReader(this);
Expand All @@ -276,7 +267,6 @@ private XmlFormatClassReaderDelegate CreateXmlFormatReaderDelegate()
internal XmlFormatClassReaderDelegate XmlFormatReaderDelegate
{
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
get
{
if (_helper.XmlFormatReaderDelegate == null)
Expand All @@ -299,7 +289,6 @@ internal XmlFormatClassReaderDelegate XmlFormatReaderDelegate
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal static ClassDataContract CreateClassDataContractForKeyValue(Type type, XmlDictionaryString ns, string[] memberNames)
{
ClassDataContract? cdc = (ClassDataContract?)DataContract.GetDataContractFromGeneratedAssembly(type);
Expand Down Expand Up @@ -334,7 +323,6 @@ internal static void CheckAndAddMember(List<DataMember> members, DataMember memb
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal static XmlDictionaryString? GetChildNamespaceToDeclare(DataContract dataContract, Type childType, XmlDictionary dictionary)
{
childType = DataContract.UnwrapNullableType(childType);
Expand Down Expand Up @@ -458,7 +446,6 @@ internal static bool IsNonSerializedMember(Type type, string memberName)
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private XmlDictionaryString?[]? CreateChildElementNamespaces()
{
if (Members == null)
Expand Down Expand Up @@ -487,7 +474,6 @@ private void EnsureMethodsImported()
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext? context)
{
Debug.Assert(context != null);
Expand All @@ -500,7 +486,6 @@ public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, Xml
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
public override object? ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext? context)
{
if (_isScriptObject)
Expand Down Expand Up @@ -708,8 +693,6 @@ private sealed class ClassDataContractCriticalHelper : DataContract.DataContract
{
private static Type[]? s_serInfoCtorArgs;
private static readonly MethodInfo s_getKeyValuePairMethod = typeof(KeyValuePairAdapter<,>).GetMethod("GetKeyValuePair", Globals.ScanAllMembers)!;
[UnconditionalSuppressMessage("AOT Analysis", "IL3050:RequiresDynamicCode",
Justification = "Cannot annotate a field, annotating the method that uses the field instead")]
private static readonly ConstructorInfo s_ctorGenericMethod = typeof(KeyValuePairAdapter<,>).GetConstructor(Globals.ScanAllMembers, new Type[] { typeof(KeyValuePair<,>).MakeGenericType(typeof(KeyValuePairAdapter<,>).GetGenericArguments()) })!;

private ClassDataContract? _baseContract;
Expand Down Expand Up @@ -742,7 +725,6 @@ private sealed class ClassDataContractCriticalHelper : DataContract.DataContract
public XmlDictionaryString[]? MemberNamespaces;

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal ClassDataContractCriticalHelper([DynamicallyAccessedMembers(DataContractPreserveMemberTypes)]
Type type) : base(type)
{
Expand Down Expand Up @@ -857,7 +839,6 @@ internal ClassDataContractCriticalHelper([DynamicallyAccessedMembers(DataContrac
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal ClassDataContractCriticalHelper(
[DynamicallyAccessedMembers(DataContractPreserveMemberTypes)]
Type type, XmlDictionaryString ns, string[] memberNames) : base(type)
Expand Down Expand Up @@ -934,7 +915,6 @@ private void EnsureIsReferenceImported(Type type)
[MemberNotNull(nameof(_members))]
[MemberNotNull(nameof(Members))]
[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private void ImportDataMembers()
{
Type type = this.UnderlyingType;
Expand Down Expand Up @@ -1113,7 +1093,6 @@ private static bool CanSerializeMember(FieldInfo? field)
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private static bool SetIfGetOnlyCollection(DataMember memberContract)
{
//OK to call IsCollection here since the use of surrogated collection types is not supported in get-only scenarios
Expand Down Expand Up @@ -1188,7 +1167,6 @@ private void SetIfMembersHaveConflict(List<DataMember> members)
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private XmlQualifiedName GetStableNameAndSetHasDataContract(Type type)
{
return DataContract.GetStableName(type, out _hasDataContract);
Expand Down Expand Up @@ -1359,7 +1337,6 @@ internal override DataContractDictionary? KnownDataContracts
{

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
get
{
if (_knownDataContracts != null)
Expand Down Expand Up @@ -1409,7 +1386,6 @@ internal bool IsNonAttributedType
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private void SetKeyValuePairAdapterFlags(
[DynamicallyAccessedMembers(DataContractPreserveMemberTypes)]
Type type)
Expand Down Expand Up @@ -1534,7 +1510,6 @@ public int Compare(Member x, Member y)
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal ClassDataContractCriticalHelper Clone()
{
ClassDataContractCriticalHelper clonedHelper = new ClassDataContractCriticalHelper(this.UnderlyingType);
Expand Down Expand Up @@ -1597,7 +1572,6 @@ internal Type ObjectType
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal ClassDataContract Clone()
{
ClassDataContract clonedDc = new ClassDataContract(this.UnderlyingType);
Expand All @@ -1612,7 +1586,6 @@ internal ClassDataContract Clone()
}

[RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal void UpdateNamespaceAndMembers(Type type, XmlDictionaryString ns, string[] memberNames)
{
this.StableName = new XmlQualifiedName(GetStableName(type).Name, ns.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ internal void BeginMethod(DynamicMethod dynamicMethod, Type delegateType, string
InitILGeneration(methodName, argTypes);
}

[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
internal void BeginMethod(string methodName, Type delegateType, bool allowPrivateMemberAccess)
{
MethodInfo signature = JsonFormatWriterGenerator.GetInvokeMethod(delegateType);
Expand All @@ -133,7 +132,6 @@ internal void BeginMethod(string methodName, Type delegateType, bool allowPrivat
_delegateType = delegateType;
}

[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
private void BeginMethod(Type returnType, string methodName, Type[] argTypes, bool allowPrivateMemberAccess)
{
_dynamicMethod = new DynamicMethod(methodName, returnType, argTypes, SerializationModule, allowPrivateMemberAccess);
Expand Down
Loading

0 comments on commit bff7c3d

Please sign in to comment.