Jaseci-Labs / jaclang

The Jac Programming Language
https://www.jac-lang.org
22 stars 21 forks source link

Ability to change the Specific Passes in jaclang using Plugin Interface #546

Open chandralegend opened 2 months ago

chandralegend commented 2 months ago

Is your feature request related to a problem? Please describe.

Currently MTLLM is running as a separate repo but the with_llm feature in jaclang only works with mtllm installed. and there is no purpose for that if mttlm is not installed. At the same time developers has to make PRs to the jaclang repo to get language level changes that required to add new functionalities to the mtllm repo. This is counter-productive.

Describe the solution you'd like

Currently we can override add new methods to stuff in plugin folder using pluggy. What if we add the same ability to all the Passes in jaclang. How it will look in the plugin repo will look like this for mtllm

# mtllm/pass.py
from jaclang.compiler.passes.main.pyast_gen_pass import hookmethod

class PyastGenPass:
     @hookmethod
     def needs_mtllm(self) -> None:
        """Add the MTLLM Classes necessary"
        pass

     @hookmethod
     def exit_ability(self, node: ast.Ability) -> None:
        """Sub objects.

        name_ref: NameType,
        is_func: bool,
        is_async: bool,
        is_static: bool,
        is_abstract: bool,
        access: Optional[SubTag[Token]],
        signature: Optional[FuncSignature | ExprType | EventSignature],
        body: Optional[SubNodeList[CodeBlockStmt] | AbilityDef | FuncCall],
        doc: Optional[String],
        decorators: Optional[SubNodeList[ExprType]],
        """
        func_type = ast3.AsyncFunctionDef if node.is_async else ast3.FunctionDef
        body = (
            self.gen_llm_body(node)
            if isinstance(node.body, ast.FuncCall)

        blah blah
# pyproject.toml
[tool.poetry.plugins."jac"]
mtllm = "mtllm.plugin:JacFeature"
pyast_gen_pass = "mtllm.pass.PyastGenPass"

Describe alternatives you've considered

Another option is to have the mtllm inside jaclang. this is not productive as it defeats the purpose of giving developers the ability to create plugins.

marsninja commented 2 months ago

Whats the use case for this, I'm thinking a pattern of having the body of the function make a call into the plugin interface might might make more sense.