Skip to content

Commit 758750c

Browse files
Fix CreateSpan build failure (#60510)
1 parent 4b28fe9 commit 758750c

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ private void CompileMethodCleanup()
558558
_actualInstructionSetUnsupported = default(InstructionSetFlags);
559559
#endif
560560

561+
_instantiationToJitVisibleInstantiation = null;
562+
561563
_pgoResults.Clear();
562564
}
563565

@@ -644,6 +646,25 @@ private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORIN
644646
return true;
645647
}
646648

649+
private Dictionary<Instantiation, IntPtr[]> _instantiationToJitVisibleInstantiation = null;
650+
private CORINFO_CLASS_STRUCT_** GetJitInstantiation(Instantiation inst)
651+
{
652+
IntPtr [] jitVisibleInstantiation;
653+
if (_instantiationToJitVisibleInstantiation == null)
654+
{
655+
_instantiationToJitVisibleInstantiation = new Dictionary<Instantiation, IntPtr[]>();
656+
}
657+
658+
if (!_instantiationToJitVisibleInstantiation.TryGetValue(inst, out jitVisibleInstantiation))
659+
{
660+
jitVisibleInstantiation = new IntPtr[inst.Length];
661+
for (int i = 0; i < inst.Length; i++)
662+
jitVisibleInstantiation[i] = (IntPtr)ObjectToHandle(inst[i]);
663+
_instantiationToJitVisibleInstantiation.Add(inst, jitVisibleInstantiation);
664+
}
665+
return (CORINFO_CLASS_STRUCT_**)GetPin(jitVisibleInstantiation);
666+
}
667+
647668
private void Get_CORINFO_SIG_INFO(MethodDesc method, CORINFO_SIG_INFO* sig, bool suppressHiddenArgument = false)
648669
{
649670
Get_CORINFO_SIG_INFO(method.Signature, sig);
@@ -668,10 +689,12 @@ private void Get_CORINFO_SIG_INFO(MethodDesc method, CORINFO_SIG_INFO* sig, bool
668689
sig->sigInst.classInstCount = (uint)owningTypeInst.Length;
669690
if (owningTypeInst.Length > 0)
670691
{
671-
var classInst = new IntPtr[owningTypeInst.Length];
672-
for (int i = 0; i < owningTypeInst.Length; i++)
673-
classInst[i] = (IntPtr)ObjectToHandle(owningTypeInst[i]);
674-
sig->sigInst.classInst = (CORINFO_CLASS_STRUCT_**)GetPin(classInst);
692+
sig->sigInst.classInst = GetJitInstantiation(owningTypeInst);
693+
}
694+
695+
if (method.Instantiation.Length != 0)
696+
{
697+
sig->sigInst.methInst = GetJitInstantiation(method.Instantiation);
675698
}
676699
}
677700

src/coreclr/tools/Common/TypeSystem/Common/Instantiation.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Internal.TypeSystem
1111
/// Represents a generic instantiation - a collection of generic parameters
1212
/// or arguments of a generic type or a generic method.
1313
/// </summary>
14-
public struct Instantiation
14+
public struct Instantiation : IEquatable<Instantiation>
1515
{
1616
private TypeDesc[] _genericParameters;
1717

@@ -113,5 +113,33 @@ public bool MoveNext()
113113
return true;
114114
}
115115
}
116+
117+
public bool Equals(Instantiation other)
118+
{
119+
if (_genericParameters.Length != other._genericParameters.Length)
120+
return false;
121+
122+
for (int i = 0; i < _genericParameters.Length; i++)
123+
{
124+
if (_genericParameters[i] != other._genericParameters[i])
125+
return false;
126+
}
127+
return true;
128+
}
129+
public override bool Equals(object o)
130+
{
131+
if (o is Instantiation inst)
132+
return Equals(inst);
133+
return false;
134+
}
135+
public override int GetHashCode()
136+
{
137+
int hashcode = 1;
138+
foreach (var t in _genericParameters)
139+
{
140+
hashcode = (hashcode << 3) ^ t.GetHashCode();
141+
}
142+
return hashcode;
143+
}
116144
}
117145
}

0 commit comments

Comments
 (0)