Skip to content

Conversation

radical
Copy link
Member

@radical radical commented Oct 24, 2021

Fixes #60800

@ghost ghost added the area-Build-mono label Oct 24, 2021
@radical radical added the arch-wasm WebAssembly architecture label Oct 24, 2021
@ghost
Copy link

ghost commented Oct 24, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: radical
Assignees: -
Labels:

arch-wasm, area-Build-mono

Milestone: -

@radical radical changed the title [wasm] Fixup symbol names with invalid chars [wasm] PInvokeTableGenerator: Fixup symbol names with invalid chars Oct 24, 2021
Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use an allow-list instead of a deny list. there's a lot of stuff you can technically put in an IL method name, as far as I can tell from ECMA-335.

public string FileWrites { get; private set; } = string.Empty;

private static char[] s_charsToReplace = new[] { '.', '-', };
private static char[] s_charsToReplace = new[] { '.', '-', ',', '|', '<', '>' };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this.

For one thing it's incomplete - for nested classes we also need to replace '/' when it's in a class name. For another thing, C# allows many unicode characters in an identifier (https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/identifier-names). And IL metadata actually doesn't seem to have any restrictions on identifiers - it's just sequences of bytes. I think we should do something like: convert the name to utf8; look at the bytes; for any bytes not in [0-9A-Za-z] replace them by "" or underscore and the byte hex code (ie F☃ will become "F_E2_98_83" https://www.compart.com/en/unicode/U+2603)

private static string SymbolNameForMethod(MethodInfo method)
{
string module_symbol = method.DeclaringType!.Module!.Assembly!.GetName()!.Name!;
string class_name = method.DeclaringType.Name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check method.DeclaringType.IsNested and include the enclosing types' names?

string class_name = method.DeclaringType.Name;
string method_name = method.Name;
string entry_name = $"wasm_native_to_interp_{module_symbol}_{class_name}_{method_name}";
string entry_name = $"wasm_native_to_interp_{SymbolNameForMethod(method)}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're compiling for !aot, we should check if the method UnmanagedCallersOnlyAttribute has an EntryPoint and emit the wasm_native_to_interp callback with the supplied name.

@lambdageek
Copy link
Member

The interpreter runs of the new test are unhappy for some reason.

wasm test]                  
[wasm test]                  
[wasm test] [00:03:37] fail: console.error: RuntimeError: function signature mismatch
[wasm test]                  
[wasm test] [00:03:37] fail: console.error: RuntimeError: function signature mismatch
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[109]:0x6031
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[207]:0x173bc
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[186]:0x16ca8
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[132]:0x78c7
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[131]:0x67f0
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[8069]:0x1a3a53
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[2282]:0x93c92
[wasm test]                  
[wasm test] [00:03:37] fail:     at <anonymous>:wasm-function[2286]:0x943c5
[wasm test]                  
[wasm test] [00:03:37] fail:     at mono_wasm_invoke_method (<anonymous>:wasm-function[9150]:0x1d7100)
[wasm test]                  
[wasm test] [00:03:37] fail:     at Module._mono_wasm_invoke_method (dotnet.js:1:189720)

unclear why

@ghost ghost closed this Nov 26, 2021
@ghost
Copy link

ghost commented Nov 26, 2021

Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it.

radical added a commit that referenced this pull request Dec 4, 2021
Includes:
- Better error logging, and handling
- Add @(NativeFileReference) to up-to-date check items for VS
- Add `WasmBuild.sln`
- Better fix up of symbol names for pinvokes, and callbacks, based on @lambdageek's suggestion in #60814 (comment)

Fixes #60862
@ghost ghost locked as resolved and limited conversation to collaborators Dec 26, 2021
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-Build-mono

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UnmanagedCallersOnly] is not supported on inner functions in Blazor

3 participants