Skip to content

Commit

Permalink
[wasm] IcallTableGenerator: For unsupported types, log a warning instead
Browse files Browse the repository at this point in the history
.. of throwing an exception.

```
 The "IcallTableGenerator" task failed unexpectedly. [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
 System.NotImplementedException: System.Enum [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
    at IcallTableGenerator.AppendType(StringBuilder sb, Type t) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
    at IcallTableGenerator.ProcessType(Type type) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
    at IcallTableGenerator.GenIcallTable(String runtimeIcallTableFile, String[] assemblies) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
    at IcallTableGenerator.Execute() [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj]
```

becomes:

```
C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\7.0.0-alpha.1.21551.1\Sdk\WasmApp.Native.targets(258,5):
    warning : Failed to generate icall function for [System.Private.CoreLib]System.Enum::InternalHasFlag because type System.Enum is not supported for parameter named flags. Ignoring. [C:\Users\Ankit Jain\bl0\bl0.csproj]
```

Prompted by dotnet#61053
  • Loading branch information
radical committed Nov 7, 2021
1 parent 7e433fb commit 421bd1d
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions src/tasks/WasmAppBuilder/IcallTableGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ public class IcallTableGenerator : Task

public override bool Execute()
{
GenIcallTable(RuntimeIcallTableFile!, Assemblies!.Select(item => item.ItemSpec).ToArray());
return true;
try
{
GenIcallTable(RuntimeIcallTableFile!, Assemblies!.Select(item => item.ItemSpec).ToArray());
return !Log.HasLoggedErrors;
}
catch (LogAsErrorException laee)
{
Log.LogError(laee.Message);
return false;
}
}

//
Expand Down Expand Up @@ -152,20 +160,9 @@ private void ProcessType (Type type)
icallClass.Icalls.TryGetValue (method.Name, out icall);
if (icall == null)
{
// Then with signature
var sig = new StringBuilder (method.Name + "(");
int pindex = 0;
foreach (var par in method.GetParameters())
{
if (pindex > 0)
sig.Append (',');
var t = par.ParameterType;
AppendType (sig, t);
pindex++;
}
sig.Append (')');
if (icallClass.Icalls.ContainsKey (sig.ToString ()))
icall = icallClass.Icalls [sig.ToString ()];
string? methodSig = BuildSignature(method, className);
if (methodSig != null && icallClass.Icalls.ContainsKey (methodSig))
icall = icallClass.Icalls [methodSig];
}
if (icall == null)
// Registered at runtime
Expand All @@ -178,6 +175,33 @@ private void ProcessType (Type type)

foreach (var nestedType in type.GetNestedTypes())
ProcessType(nestedType);

string? BuildSignature(MethodInfo method, string className)
{
// Then with signature
var sig = new StringBuilder (method.Name + "(");
int pindex = 0;
foreach (var par in method.GetParameters())
{
if (pindex > 0)
sig.Append (',');
var t = par.ParameterType;
try
{
AppendType (sig, t);
}
catch (NotImplementedException nie)
{
Log.LogWarning($"Failed to generate icall function for '[{method.DeclaringType!.Assembly.GetName().Name}] {className}::{method.Name}'" +
$" because type '{nie.Message}' is not supported for parameter named '{par.Name}'. Ignoring.");
return null;
}
pindex++;
}
sig.Append (')');

return sig.ToString();
}
}

// Append the type name used by the runtime icall tables
Expand Down

0 comments on commit 421bd1d

Please sign in to comment.