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
EntityRefthey want to allocate their declaration. If I serializeRelocRecordI have to make sureEntityRefof a given function stays the same or things get really dangerous. Doing this is very cumbersome asModuleDeclarationsusePrimaryMap.Implementation
Implementation should be simple. Main change will happen inside
ModuleDeclarationswhere you have to add ne method that will just push a default value of module Item and return newly allocatedEntityRefto caller. Another method that is needed will accept theEntityRef,name,signature, andlinkage. Upon invocation, declaration gets replaced, name inserted into hash map and symbols or whatever preparationModulehas 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
FuncIdas different signature would not get accepted.Another alternative is breaking the API compatibility by changing
declare_functioninModuleto also acceptEntityRefthe same way asVariablein frontend is used.
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
EntityRefthey want to allocate their declaration. If I serializeRelocRecordI have to make sureEntityRefof a given function stays the same or things get really dangerous. Doing this is very cumbersome asModuleDeclarationsusePrimaryMap.Implementation
Implementation should be simple. Main change will happen inside
ModuleDeclarationswhere you have to add ne method that will just push a default value of module Item and return newly allocatedEntityRefto caller. Another method that is needed will accept theEntityRef,name,signature, andlinkage. Upon invocation, declaration gets replaced, name inserted into hash map and symbols or whatever preparationModulehas 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
FuncIdas different signature would not get accepted.Another alternative is breaking the API compatibility by changing
declare_functioninModuleto also acceptEntityRefthe same way asVariablein frontend is used.
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.
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
FuncIdthe 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.
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
EntityRefthey want to allocate their declaration. If I serializeRelocRecordI have to make sureEntityRefof a given function stays the same or things get really dangerous. Doing this is very cumbersome asModuleDeclarationsusePrimaryMap.Implementation
Implementation should be simple. Main change will happen inside
ModuleDeclarationswhere you have to add ne method that will just push a default value of module Item and return newly allocatedEntityRefto caller. Another method that is needed will accept theEntityRef,name,signature, andlinkage. Upon invocation, declaration gets replaced, name inserted into hash map and symbols or whatever preparationModulehas 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
FuncIdas different signature would not get accepted.Another alternative is breaking the API compatibility by changing
declare_functioninModuleto also acceptEntityRefthe same way asVariablein frontend is used.
Last updated: Dec 13 2025 at 21:03 UTC