Closed Skydev0h closed 4 years ago
Ref: #230 (implementation / fix)
(Almost) fixed in commit 493ae2410cda47dffc7e793d5db28fa84c4f88a5, where unused non-external functions are also often removed from dictionary.
But if function f()
calls g()
, and both f()
and g()
are not called from anywhere else, then only f()
will be removed from the dictionary.
Yeah, good point, now I understand that my suggestion would suffer from the same problem. Tracking down reference counts of each call and analyzing body upon exclusion would be really difficult and bug-prone. It may be possible to track invocations of each method in separate dict and manipulate counters from there.
I hope I would come out with a good idea and implementation sometime.
Well, the current solution (as well as the solution suggested by you) solves the original problem - correctly removes all inline procedures from the dictionary. Tracking the graph of dependencies between all functions is better done by the FunC compiler.
Yeah, well, good idea. Sounds like a challenge for ... sometime. I agree that the original technical problem is now solved.
Inline functions are emitted into methods dictionary despite the fact that they are not ever called from that dictionary.
An example that demonstrates what I mean:
inltest.fc
inltest.fif
inlassess.fif
result
At least several cells are wasted and tree complexity is unneccessarily increased. This is especially important if many inline functions are used (i spotted tens of those in some contest 1 and contest 2 entries).
As for
inline_ref
there is following result:That way the function cell itself is not completely wasted (because it is referenced later as-is when called, but still, several cells are wasted as part of dictionary itself and complexity is still unneccessarily increased.
Therefore, it should be safe to remove (do not put into) those functions from procs-methods dict because they are not referenced directly by id in code (they are body-inlined or ref-inlined). It may be neccessary only if for some reason function cannot be inlined (such as recursive calls).
And of course it would be wise not to touch methods with defined id, only procs (with autogenerated id), however it would be strange pattern to have inline methods.
More broadly speaking, fift assembler can keep track of used procs (that are called by dict id) plus root functions (0, -1, -2, -3) and getter methods and throw out the rest.