Stream: git-wasmtime

Topic: wasmtime / issue #4122 Improving `Module` API to allow ea...


view this post on Zulip Wasmtime GitHub notifications bot (May 10 2022 at 19:23):

jakubDoka opened issue #4122:

Feature

Allow pre-allocating function declaration inside the modules.

Benefit

This is useful because it allows reconstructing the module declaration to a previous state when incrementally compiling and also gives user a choice to which EntityRef they want to allocate their declaration. If I serialize RelocRecord I have to make sure EntityRef of a given function stays the same or things get really dangerous. Doing this is very cumbersome as ModuleDeclarations use PrimaryMap.

Implementation

Implementation should be simple. Main change will happen inside ModuleDeclarations where you have to add ne method that will just push a default value of module Item and return newly allocated EntityRef to caller. Another method that is needed will accept the EntityRef, name, signature, and linkage. Upon invocation, declaration gets replaced, name inserted into hash map and symbols or whatever preparation Module has to do gets done.

Calling method on already declared item will result into panic! and probably requires preserving some state on debug builds for this to work.

Alternatives

You could of course allocate anon Func with empty body and signature to manipulate FuncId but this can add useles data into final object file and you cannot reuse the allocated FuncId as different signature would not get accepted.

Another alternative is breaking the API compatibility by changing declare_function in Module to also accept EntityRef the same way as Variable in frontend is used.

view this post on Zulip Wasmtime GitHub notifications bot (May 10 2022 at 21:05):

cfallin labeled issue #4122:

Feature

Allow pre-allocating function declaration inside the modules.

Benefit

This is useful because it allows reconstructing the module declaration to a previous state when incrementally compiling and also gives user a choice to which EntityRef they want to allocate their declaration. If I serialize RelocRecord I have to make sure EntityRef of a given function stays the same or things get really dangerous. Doing this is very cumbersome as ModuleDeclarations use PrimaryMap.

Implementation

Implementation should be simple. Main change will happen inside ModuleDeclarations where you have to add ne method that will just push a default value of module Item and return newly allocated EntityRef to caller. Another method that is needed will accept the EntityRef, name, signature, and linkage. Upon invocation, declaration gets replaced, name inserted into hash map and symbols or whatever preparation Module has to do gets done.

Calling method on already declared item will result into panic! and probably requires preserving some state on debug builds for this to work.

Alternatives

You could of course allocate anon Func with empty body and signature to manipulate FuncId but this can add useles data into final object file and you cannot reuse the allocated FuncId as different signature would not get accepted.

Another alternative is breaking the API compatibility by changing declare_function in Module to also accept EntityRef the same way as Variable in frontend is used.

view this post on Zulip Wasmtime GitHub notifications bot (May 10 2022 at 21:47):

bjorn3 commented on issue #4122:

When referencing a function or data object inside a function the full declaration needs to be known in advance.

I think when serializing you should map from FuncId back to symbol name and when deserializing declare the function with the known decalaration and symbol name and then use the returned FuncId.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 05:10):

jakubDoka commented on issue #4122:

When referencing a function or data object inside a function the full declaration needs to be known in advance.

Yes, blanc functions are not supposed to be imported by anything. When you use incremental data, some functions are invalidated, possibly removed and that implies all dependent constructs are also recompiled so by the time I compile any function depending of FuncId the declaration is present, otherwise I am doing things wrongly.

I think when serializing you should map from FuncId back to symbol name and when deserializing declare the function with the known decalaration and symbol name and then use the returned FuncId.

I have not think of this option. It seems the right solution, I'll try it out, thanks.

Closing the issue for now.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 05:10):

jakubDoka closed issue #4122:

Feature

Allow pre-allocating function declaration inside the modules.

Benefit

This is useful because it allows reconstructing the module declaration to a previous state when incrementally compiling and also gives user a choice to which EntityRef they want to allocate their declaration. If I serialize RelocRecord I have to make sure EntityRef of a given function stays the same or things get really dangerous. Doing this is very cumbersome as ModuleDeclarations use PrimaryMap.

Implementation

Implementation should be simple. Main change will happen inside ModuleDeclarations where you have to add ne method that will just push a default value of module Item and return newly allocated EntityRef to caller. Another method that is needed will accept the EntityRef, name, signature, and linkage. Upon invocation, declaration gets replaced, name inserted into hash map and symbols or whatever preparation Module has to do gets done.

Calling method on already declared item will result into panic! and probably requires preserving some state on debug builds for this to work.

Alternatives

You could of course allocate anon Func with empty body and signature to manipulate FuncId but this can add useles data into final object file and you cannot reuse the allocated FuncId as different signature would not get accepted.

Another alternative is breaking the API compatibility by changing declare_function in Module to also accept EntityRef the same way as Variable in frontend is used.


Last updated: Dec 23 2024 at 13:07 UTC