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
diff options
context:
space:
mode:
authorSamuel Arzt <arzt.samuel@live.de>2017-10-12 19:13:45 +0300
committerJan Kotas <jkotas@microsoft.com>2017-10-12 19:13:45 +0300
commit3bdaa246efce30d8afe530cd1b63009268d7094a (patch)
tree92cbe0ac216f8efbdccd1d2f790c3460f181f7a3 /src/ILVerify
parentd312715287eddf3d7f75e0fd7815beef6981000f (diff)
[ILVerify] Instantiate constraints of generic parameters used as instantiation (#4641)
* Added test case for generic instantiation with generic constraint instantiated with generic parameter. * Implemented instantiation of generic parameter constraints in constraints check. * Changed GetInstantiatedConstraints to use ArrayBuilder instead of List. * Added recursive constraint instantiation. * Added instantiation context to be able to instantiate generic generic constraints. * Added additional tests for CheckConstraints with InstantiationContext.
Diffstat (limited to 'src/ILVerify')
-rw-r--r--src/ILVerify/src/ILImporter.Verify.cs42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/ILVerify/src/ILImporter.Verify.cs b/src/ILVerify/src/ILImporter.Verify.cs
index f720f6b4d..32ca9b993 100644
--- a/src/ILVerify/src/ILImporter.Verify.cs
+++ b/src/ILVerify/src/ILImporter.Verify.cs
@@ -41,6 +41,7 @@ namespace Internal.IL
readonly MethodDesc _method;
readonly MethodSignature _methodSignature;
readonly TypeSystemContext _typeSystemContext;
+ readonly InstantiationContext _instantiationContext;
readonly TypeDesc _thisType;
@@ -137,18 +138,28 @@ namespace Internal.IL
public ILImporter(MethodDesc method, MethodIL methodIL)
{
- _method = method;
_typeSystemContext = method.Context;
+ // Instantiate method and its owning type
+ var instantiatedType = method.OwningType;
+ var instantiatedMethod = method;
+ if (instantiatedType.HasInstantiation)
+ {
+ instantiatedType = _typeSystemContext.GetInstantiatedType((MetadataType)instantiatedType, instantiatedType.Instantiation);
+ instantiatedMethod = _typeSystemContext.GetMethodForInstantiatedType(instantiatedMethod.GetTypicalMethodDefinition(), (InstantiatedType)instantiatedType);
+ }
+
+ if (instantiatedMethod.HasInstantiation)
+ instantiatedMethod = _typeSystemContext.GetInstantiatedMethod(instantiatedMethod, instantiatedMethod.Instantiation);
+ _method = instantiatedMethod;
+ _methodSignature = _method.Signature;
+ _methodIL = method == instantiatedMethod ? methodIL : new InstantiatedMethodIL(instantiatedMethod, methodIL);
+ _instantiationContext = new InstantiationContext(instantiatedType.Instantiation, instantiatedMethod.Instantiation);
+
+ // Determine this type
if (!_method.Signature.IsStatic)
{
- if (_method.OwningType.HasInstantiation)
- {
- _thisType = _typeSystemContext.GetInstantiatedType((MetadataType)_method.OwningType, _method.OwningType.Instantiation);
- _method = _typeSystemContext.GetMethodForInstantiatedType(_method.GetTypicalMethodDefinition(), (InstantiatedType)_thisType);
- }
- else
- _thisType = _method.OwningType;
+ _thisType = instantiatedType;
// ECMA-335 II.13.3 Methods of value types, P. 164:
// ... By contrast, instance and virtual methods of value types shall be coded to expect a
@@ -157,12 +168,6 @@ namespace Internal.IL
_thisType = _thisType.MakeByRefType();
}
- if (_method.HasInstantiation)
- _method = _typeSystemContext.GetInstantiatedMethod(_method, _method.Instantiation);
-
- _methodSignature = _method.Signature;
- _methodIL = method == _method ? methodIL : new InstantiatedMethodIL(_method, methodIL);
-
_initLocals = _methodIL.IsInitLocals;
_maxStack = _methodIL.MaxStack;
@@ -1073,10 +1078,9 @@ namespace Internal.IL
}
// Check any constraints on the callee's class and type parameters
- var ecmaType = method.OwningType as EcmaType;
- if (!method.OwningType.CheckConstraints())
+ if (!method.OwningType.CheckConstraints(_instantiationContext))
VerificationError(VerifierError.UnsatisfiedMethodParentInst, method.OwningType);
- else if (!method.CheckConstraints())
+ else if (!method.CheckConstraints(_instantiationContext))
VerificationError(VerifierError.UnsatisfiedMethodInst, method);
#if false
// Access verifications
@@ -1190,9 +1194,9 @@ namespace Internal.IL
}
// Check any constraints on the callee's class and type parameters
- if (!method.OwningType.CheckConstraints())
+ if (!method.OwningType.CheckConstraints(_instantiationContext))
VerificationError(VerifierError.UnsatisfiedMethodParentInst, method.OwningType);
- else if (!method.CheckConstraints())
+ else if (!method.CheckConstraints(_instantiationContext))
VerificationError(VerifierError.UnsatisfiedMethodInst, method);
#if false