angr/claripy

Over-design for `BackendManager`?

Opened this issue · 3 comments

Description

claripy.backends is originally a submodule of claripy, but in claripy/__init__.py, backends is reassigned by _backend_manager.BackendManager() and used to register other backend.

from . import backend_manager as _backend_manager
backends = _backend_manager.BackendManager()
backends._register_backend(_backends_module.BackendConcrete(), "concrete", True, True)
backends._register_backend(_backends_module.BackendVSA(), "vsa", False, False)

I know that it's for the flexibility to add backends by users themselves, but this name collision between backends:Module and backends:BackendManager really causes some problems in type infering. The language server typically mark it as module other than BackendManager.
image

There is a simple fix without BackendManager:

  1. remove all BackendManager
  2. move class Backend from claripy/backends/__init__.py to claripy/backends/backend.py( avoid recursive import)
  3. In claripy/backends/__init__.py, use from .backend_z3 import BackendZ3 to import correct class
  4. In claripy/backends/__init__.py, use z3 = BackendZ3 , __all__ = ["z3"] to create alias

Alternatives

No response

Additional context

No response

zardus commented

I'm planning to add it. Since the modification overlaps with some part in #352 , so I will do this PR when #352 is merged.

@syheliel I would advise you do it in a separate parallel PR instead of waiting for that one to be merged, as this is a much smaller change that can be reviewed and merged more quickly.