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 serializeRelocRecord
I have to make sureEntityRef
of a given function stays the same or things get really dangerous. Doing this is very cumbersome asModuleDeclarations
usePrimaryMap
.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 allocatedEntityRef
to 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 preparationModule
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
inModule
to also acceptEntityRef
the same way asVariable
in 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
EntityRef
they want to allocate their declaration. If I serializeRelocRecord
I have to make sureEntityRef
of a given function stays the same or things get really dangerous. Doing this is very cumbersome asModuleDeclarations
usePrimaryMap
.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 allocatedEntityRef
to 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 preparationModule
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
inModule
to also acceptEntityRef
the same way asVariable
in 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
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.
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 serializeRelocRecord
I have to make sureEntityRef
of a given function stays the same or things get really dangerous. Doing this is very cumbersome asModuleDeclarations
usePrimaryMap
.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 allocatedEntityRef
to 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 preparationModule
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
inModule
to also acceptEntityRef
the same way asVariable
in frontend is used.
Last updated: Dec 23 2024 at 13:07 UTC