code garbage collector

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

code garbage collector

Joe Armstrong-2
Has anybody written a code garbage collector?

The root set would be a given module.

I want to statically extract all code that is reachable (recursively)
from the module and examine it.

I want the *opposite* of "including a dependency" but rather a tool that
garbage collects code reducing it to a minimal program.

/Joe
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: code garbage collector

Jesper Louis Andersen-2
Replies inline

On Wed, Oct 5, 2016 at 9:54 AM Joe Armstrong <[hidden email]> wrote:

I want the *opposite* of "including a dependency" but rather a tool that
garbage collects code reducing it to a minimal program.


Isn't this just dead-code-elimination? For each function, you can put it into SSA-form, reverse the SSA dominator graph and everything not reachable is dead code which can be eliminated. You can then improve on this approximation to shave off more code.

For it to really work, you need to have global knowledge of all the modules in the system. And you can't in Erlang due to its lack of proper bundling support for modules.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: code garbage collector

Dmytro Lytovchenko
In reply to this post by Joe Armstrong-2

Modern IDE are able to detect and highlight some (many of) unused symbols and functions. Also: What you want can be done. But wouldn't it be better to have function-level selective code loading? I can foresee some trouble re-linking labels from loaded code to memory addresses.


Den 5 okt. 2016 09:54 skrev "Joe Armstrong" <[hidden email]>:
Has anybody written a code garbage collector?

The root set would be a given module.

I want to statically extract all code that is reachable (recursively)
from the module and examine it.

I want the *opposite* of "including a dependency" but rather a tool that
garbage collects code reducing it to a minimal program.

/Joe
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: code garbage collector

Kostis Sagonas-2
In reply to this post by Joe Armstrong-2
On 10/05/2016 09:54 AM, Joe Armstrong wrote:
> I want the *opposite* of "including a dependency" but rather a tool that
> garbage collects code reducing it to a minimal program.

I doubt that something like that exists.  Note that Erlang is not just a
higher-order language where you need to do a complicated analysis, but
it is also language that also allows something along the lines of:

   % foo/3 is an exported function (called with some constructed lists)

   foo(L1, L2, Args) ->
     M = list_to_atom(L1), F = list_to_atom(L2), apply(M, F, Args).

Of course, writing an analysis that is effective if no such cases exist
or a conservative analysis that protects itself from such cases is
doable.  But you need to base it on a "closed-world assumption" of some
sort.

Kostis
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: code garbage collector

Joe Armstrong-2
On Wed, Oct 5, 2016 at 10:09 AM, Kostis Sagonas <[hidden email]> wrote:

> On 10/05/2016 09:54 AM, Joe Armstrong wrote:
>>
>> I want the *opposite* of "including a dependency" but rather a tool that
>> garbage collects code reducing it to a minimal program.
>
>
> I doubt that something like that exists.  Note that Erlang is not just a
> higher-order language where you need to do a complicated analysis, but it is
> also language that also allows something along the lines of:
>
>   % foo/3 is an exported function (called with some constructed lists)
>
>   foo(L1, L2, Args) ->
>     M = list_to_atom(L1), F = list_to_atom(L2), apply(M, F, Args).
>
> Of course, writing an analysis that is effective if no such cases exist or a
> conservative analysis that protects itself from such cases is doable.  But
> you need to base it on a "closed-world assumption" of some sort.

Agreed - but code like the above should really not be hidden away in the
middle of a module but be in a special module reserved for foul smelling code.

All I want to do is extract all the callable code from a given start point
and stop the extraction when I hit OTP library code, or nasty smelling code.

/Joe

>
> Kostis
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions