Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Strehovsky <michals@microsoft.com>2018-08-02 16:57:58 +0300
committerMichal Strehovsky <michals@microsoft.com>2018-08-02 16:57:58 +0300
commit684bb89d4abeaf71a291414d0b960c2a333c4428 (patch)
tree442c482357eb26b4a5d6b0acf756d489d175b115 /src
parent476627a87b0e348dab5872f6a4da59ff8dca3ca1 (diff)
Allow illegal custom modifiers on generic constraints
Roslyn decided to do a breaking change to the ECMA-335 file format by generating an illegal custom modifier for the `unmanaged` constraint. The purpose of the modifier is to poison such types for old versions of the C# compiler (the modifier otherwise isn't necessary for the feature to work). This also poisons a lot of the .NET ecosystem too (breaking everything ranging from Mono to the C++/CLI compiler). We need to update our stack to support this and unblock our customers. [tfs-changeset: 1709243]
Diffstat (limited to 'src')
-rw-r--r--src/Common/src/Internal/Metadata/NativeFormat/Generator/SchemaDef.cs2
-rw-r--r--src/Common/src/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs2
-rw-r--r--src/ILCompiler.MetadataWriter/src/Internal/Metadata/NativeFormat/Writer/NativeFormatWriterGen.cs3
-rw-r--r--src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs18
-rw-r--r--src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs6
5 files changed, 27 insertions, 4 deletions
diff --git a/src/Common/src/Internal/Metadata/NativeFormat/Generator/SchemaDef.cs b/src/Common/src/Internal/Metadata/NativeFormat/Generator/SchemaDef.cs
index d5da54db8..a6bb922ee 100644
--- a/src/Common/src/Internal/Metadata/NativeFormat/Generator/SchemaDef.cs
+++ b/src/Common/src/Internal/Metadata/NativeFormat/Generator/SchemaDef.cs
@@ -644,7 +644,7 @@ class SchemaDef
new MemberDef("Flags", "GenericParameterAttributes"),
new MemberDef("Kind", "GenericParameterKind"),
new MemberDef("Name", "ConstantStringValue", MemberDefFlags.RecordRef | MemberDefFlags.Child),
- new MemberDef("Constraints", TypeDefOrRefOrSpec, MemberDefFlags.List | MemberDefFlags.RecordRef | MemberDefFlags.EnumerateForHashCode),
+ new MemberDef("Constraints", TypeDefOrRefOrSpecOrMod, MemberDefFlags.List | MemberDefFlags.RecordRef | MemberDefFlags.EnumerateForHashCode),
new MemberDef("CustomAttributes", "CustomAttribute", MemberDefFlags.List | MemberDefFlags.RecordRef | MemberDefFlags.Child),
}
),
diff --git a/src/Common/src/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs b/src/Common/src/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs
index f068f31f9..9ade71970 100644
--- a/src/Common/src/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs
+++ b/src/Common/src/Internal/Metadata/NativeFormat/NativeFormatReaderGen.cs
@@ -4314,7 +4314,7 @@ namespace Internal.Metadata.NativeFormat
} // Name
internal ConstantStringValueHandle _name;
- /// One of: TypeDefinition, TypeReference, TypeSpecification
+ /// One of: TypeDefinition, TypeReference, TypeSpecification, ModifiedType
public HandleCollection Constraints
{
diff --git a/src/ILCompiler.MetadataWriter/src/Internal/Metadata/NativeFormat/Writer/NativeFormatWriterGen.cs b/src/ILCompiler.MetadataWriter/src/Internal/Metadata/NativeFormat/Writer/NativeFormatWriterGen.cs
index d503e858e..d4e199c70 100644
--- a/src/ILCompiler.MetadataWriter/src/Internal/Metadata/NativeFormat/Writer/NativeFormatWriterGen.cs
+++ b/src/ILCompiler.MetadataWriter/src/Internal/Metadata/NativeFormat/Writer/NativeFormatWriterGen.cs
@@ -2807,7 +2807,8 @@ namespace Internal.Metadata.NativeFormat.Writer
Debug.Assert(Constraints.TrueForAll(handle => handle == null ||
handle.HandleType == HandleType.TypeDefinition ||
handle.HandleType == HandleType.TypeReference ||
- handle.HandleType == HandleType.TypeSpecification));
+ handle.HandleType == HandleType.TypeSpecification ||
+ handle.HandleType == HandleType.ModifiedType));
writer.Write(Constraints);
writer.Write(CustomAttributes);
} // Save
diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs
index 901d0f4ba..5896aa812 100644
--- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs
+++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/MetadataReaderExtensions.NativeFormat.cs
@@ -162,6 +162,24 @@ namespace System.Reflection.Runtime.General
return customModifiers.ToArray();
}
+ public static Handle SkipCustomModifiers(this Handle handle, MetadataReader reader)
+ {
+ HandleType handleType = handle.HandleType;
+ Debug.Assert(handleType == HandleType.TypeDefinition || handleType == HandleType.TypeReference || handleType == HandleType.TypeSpecification || handleType == HandleType.ModifiedType);
+ if (handleType != HandleType.ModifiedType)
+ return handle;
+
+ do
+ {
+ ModifiedType modifiedType = handle.ToModifiedTypeHandle(reader).GetModifiedType(reader);
+ handle = modifiedType.Type;
+ handleType = handle.HandleType;
+ }
+ while (handleType == HandleType.ModifiedType);
+
+ return handle;
+ }
+
public static MethodSignature ParseMethodSignature(this Handle handle, MetadataReader reader)
{
return handle.ToMethodSignatureHandle(reader).GetMethodSignature(reader);
diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs
index 678577135..f027f9caa 100644
--- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs
+++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfo.cs
@@ -81,7 +81,11 @@ namespace System.Reflection.Runtime.TypeInfos.NativeFormat
LowLevelList<QTypeDefRefOrSpec> constraints = new LowLevelList<QTypeDefRefOrSpec>();
foreach (Handle constraintHandle in _genericParameter.Constraints)
{
- constraints.Add(new QTypeDefRefOrSpec(reader, constraintHandle));
+ // We're skipping custom modifiers here because Roslyn generates
+ // a modifier for the "unmanaged" constraint. This doesn't conform to the
+ // ECMA-335 spec, but we need to deal with it. The modifier is not visible
+ // to reflection.
+ constraints.Add(new QTypeDefRefOrSpec(reader, constraintHandle.SkipCustomModifiers(reader)));
}
return constraints.ToArray();
}