SMAT-Lab / Scalpel

Scalpel: The Python Static Analysis Framework
Apache License 2.0
286 stars 43 forks source link

Framework for organizing passes #126

Open tristanlatr opened 4 months ago

tristanlatr commented 4 months ago

Hello static analysis enthousiastes,

I believe this proposal could be interesting for the work you’re doing in this repository.

https://github.com/twisted/twisted/issues/12176

Basically I’m trying to describe an infrastructure that would allow to hook any analysis or transformation into a system in charge of ensuring optimizations and consistency of analysis results when a transformation happen.

It’s currently unclear where this code will be hosted for the long term. I’m opening this issue to gather feedbacks and see if there are potential contributors here that could help me finish the implementation and maintain this over time.

thanks,

tristanlatr commented 4 months ago

@pawamoy ça pourrait t’intéresser

pawamoy commented 4 months ago

Hey @tristanlatr, thanks for mentioning me :slightly_smiling_face:

It's cool to see that you're still working on static analysis. @TusharSadhwani has created a Discord channel on the static analysis topic, if you'd like to join and share this there: https://discord.gg/fZCBfm4r :slightly_smiling_face:

I've read the mentioned issue. It looks very serious and promising :+1: However I do have to say I have trouble understanding why and how I would use this passmanager (by the way, I understand that "passmanager" is the name used in LLVM, GCC and Pythran, but I can't help but think of "password manager" when I read it :sweat_smile:).

For ignorant devs like myself, I would expect to see the following things explained:

Without this it's hard for me to see how I could use such package for my own static analysis needs. How would I plug it into existing AST visitors? Would I have to migrate all of my visitor's code, or could I just use the passmanager in specific places to infer the values of __all__ or expand wildcard imports?

I found the Pythran docs to be the most readable ones, if that helps :slightly_smiling_face:

tristanlatr commented 4 months ago

Thanks for your feedback, I'll try to improve these points.

In the meantime, there is this docstring full of doctest that could be more or less what your looking for: https://github.com/tristanlatr/libstatic/blob/passmanager/libstatic/_lib/passmanager/__init__.py

Would I have to migrate all of my visitor's code, or could I just use the passmanager in specific places to infer the values of all or expand wildcard imports?

It's aimed to be flexible, so you should be able to use it once at specific places, for instance to transform from x import * into from x importa,b,c,d,e,f,...

pawamoy commented 4 months ago

The docstring is great, thanks!