Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] Attempt to make FEP selection at compile time #13425

Open
wants to merge 3 commits into
base: emitMSIL
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 257 additions & 56 deletions src/Engine/EmitMSIL/CodeGenIL.cs

Large diffs are not rendered by default.

94 changes: 81 additions & 13 deletions src/Engine/EmitMSIL/Replication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,28 @@ internal static List<object> UnmarshalFunctionArguments(List<CLRFunctionEndPoint
return values;
}

private static CLRFunctionEndPoint SelectFinalFep(List<CLRFunctionEndPoint> functionEndPoint,
private static CLRFunctionEndPoint SelectFinalFep(List<CLRFunctionEndPoint> functionEndPoints,
List<CLRStackValue> formalParameters, MSILRuntimeCore runtimeCore)
{
List<ReplicationInstruction> replicationControl = new List<ReplicationInstruction>();
//We're never going to replicate so create an empty structure to allow us to use
//the existing utility methods

//Filter for exact matches

List<CLRFunctionEndPoint> exactTypeMatchingCandindates = new List<CLRFunctionEndPoint>();

foreach (CLRFunctionEndPoint possibleFep in functionEndPoint)
foreach (CLRFunctionEndPoint possibleFep in functionEndPoints)
{
if (possibleFep.DoesTypeDeepMatch(formalParameters, runtimeCore))
{
exactTypeMatchingCandindates.Add(possibleFep);
}
}


//There was an exact match, so dispath to it
//There was an exact match, so dispatch to it
if (exactTypeMatchingCandindates.Count > 0)
{
CLRFunctionEndPoint fep = null;

CLRFunctionEndPoint fep;
if (exactTypeMatchingCandindates.Count == 1)
{
fep = exactTypeMatchingCandindates[0];
Expand All @@ -131,24 +128,24 @@ private static CLRFunctionEndPoint SelectFinalFep(List<CLRFunctionEndPoint> func
// TODO_MSIL: implement SelectFEPFromMultiple
//fep = SelectFEPFromMultiple(stackFrame, runtimeCore, exactTypeMatchingCandindates, formalParameters);
}

return fep;
}
else
{
Dictionary<CLRFunctionEndPoint, int> candidatesWithDistances = new Dictionary<CLRFunctionEndPoint, int>();
Dictionary<CLRFunctionEndPoint, int> candidatesWithCastDistances = new Dictionary<CLRFunctionEndPoint, int>();

foreach (CLRFunctionEndPoint fep in functionEndPoint)
foreach (CLRFunctionEndPoint fep in functionEndPoints)
{
//@TODO(Luke): Is this value for allow array promotion correct?
int distance = fep.ComputeTypeDistance(formalParameters, runtimeCore, false);
if (distance !=
(int)ProcedureDistance.InvalidDistance)
if (distance != (int)ProcedureDistance.InvalidDistance)
{
candidatesWithDistances.Add(fep, distance);
}
}

foreach (CLRFunctionEndPoint fep in functionEndPoint)
foreach (CLRFunctionEndPoint fep in functionEndPoints)
{
int dist = fep.ComputeCastDistance(formalParameters);
candidatesWithCastDistances.Add(fep, dist);
Expand All @@ -163,9 +160,80 @@ private static CLRFunctionEndPoint SelectFinalFep(List<CLRFunctionEndPoint> func
Resources.kAmbigousMethodDispatch);
return null;
}
CLRFunctionEndPoint compliantTarget = GetCompliantTarget(formalParameters, replicationControl,
runtimeCore, candidatesWithCastDistances,
candidateFunctions, candidatesWithDistances);

return compliantTarget;
}
}

CLRFunctionEndPoint compliantTarget = GetCompliantTarget(formalParameters, replicationControl,
internal static CLRFunctionEndPoint SelectFinalFep(IEnumerable<CLRFunctionEndPoint> functionEndPoints,
List<ProtoCore.AST.AssociativeAST.AssociativeNode> formalParameters,
List<System.Type> argTypes, MSILRuntimeCore runtimeCore)
{
List<ReplicationInstruction> replicationControl = new List<ReplicationInstruction>();
//We're never going to replicate so create an empty structure to allow us to use
//the existing utility methods

//Filter for exact matches
List<CLRFunctionEndPoint> exactTypeMatchingCandindates = new List<CLRFunctionEndPoint>();

foreach (CLRFunctionEndPoint possibleFep in functionEndPoints)
{
if (possibleFep.DoesTypeDeepMatch(formalParameters, argTypes, runtimeCore))
{
exactTypeMatchingCandindates.Add(possibleFep);
}
}

//There was an exact match, so dispatch to it
if (exactTypeMatchingCandindates.Count > 0)
{
CLRFunctionEndPoint fep;
if (exactTypeMatchingCandindates.Count == 1)
{
fep = exactTypeMatchingCandindates[0];
}
else
{
fep = exactTypeMatchingCandindates[0];
// TODO_MSIL: implement SelectFEPFromMultiple
//fep = SelectFEPFromMultiple(stackFrame, runtimeCore, exactTypeMatchingCandindates, formalParameters);
}
return fep;
}
else
{
Dictionary<CLRFunctionEndPoint, int> candidatesWithDistances = new Dictionary<CLRFunctionEndPoint, int>();
Dictionary<CLRFunctionEndPoint, int> candidatesWithCastDistances = new Dictionary<CLRFunctionEndPoint, int>();

foreach (CLRFunctionEndPoint fep in functionEndPoints)
{
//@TODO(Luke): Is this value for allow array promotion correct?
int distance = fep.ComputeTypeDistance(formalParameters, argTypes, runtimeCore, false);
if (distance != (int)ProcedureDistance.InvalidDistance)
{
candidatesWithDistances.Add(fep, distance);
}
}

foreach (CLRFunctionEndPoint fep in functionEndPoints)
{
int dist = fep.ComputeCastDistance(argTypes, runtimeCore);
candidatesWithCastDistances.Add(fep, dist);
}

// TODO_MSIL: implement GetCandidateFunctions;
List<CLRFunctionEndPoint> candidateFunctions = candidatesWithDistances.Keys.ToList(); //GetCandidateFunctions(candidatesWithDistances);

if (candidateFunctions.Count == 0)
{
runtimeCore.LogWarning(ProtoCore.Runtime.WarningID.AmbiguousMethodDispatch,
Resources.kAmbigousMethodDispatch);
return null;
}
CLRFunctionEndPoint compliantTarget = GetCompliantTarget(null, null,
runtimeCore, candidatesWithCastDistances,
candidateFunctions, candidatesWithDistances);

Expand Down
Loading