[Feature Request] [mojo-lang] Reflection capabilities for functions in parameter space
Nobody has claimed this yet.
- Dominant language
- Mojo
- Stars
- 29.8k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Review Mojo's priorities
- I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
I don't know if this is viable to implement in the compiler, but I thought I'd write this up in case it can.
# a trait that all functions conform to
trait AnyDef: ...
def do_something[func: AnyDef]():
comptime for type in parameter_types(func): ...
comptime for type in argument_types(func): ...
comptime ret_type = return_type(func)
...
Bonus, if we could even treat effects as traits we could maybe build generic code around things like
def do_something[func: AnyDef]():
comptime if conforms_to(func, thin): ...
What is your motivation for this change?
- modular/modular#6521, part of the problem is that we don't have a way to know when a function's arguments or return type can be trivially converted from cpython directly to Mojo and do a roundtrip through the Python representation
- The potential for this to change how we do generic functional code
Any other details?
I don't have enough examples off the top of by head, but this feels like a feature that will prove very powerful in several applications
I'll add @owenhilyard and @soraros in case they have some input
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Mojo roadmap and the existing compiler support for parameter-space functions, traits, effects, and compile-time introspection; no files or tests are named in the request. Define the supported reflection model and identify the relevant compiler entry points and tests before implementation, with completion requiring agreed behavior for parameter types, argument types, return types, and effects.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100