modular / modular/modular

[Feature Request] Allow parametric materialization

Open
#2,100 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement mojo mojo-repo
Dominant language
Mojo
Stars
29.8k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

Review Mojo's priorities
What is your request?

Allow parametric materialization of nonmaterializable types.

Currently, i'm not aware of any way to get the following behavior:

@nonmaterializable(MyVal[param])
struct MyLit[param: Bool]:
  ...


struct MyVal[param: Bool]:
  ...

Or alternatively, a required __materialize__() method when no arguments to @nonmaterializable are given:

@nonmaterializable
struct MyLit[param: Bool]:

  fn __materialize__(self) -> MyVal[param]:
    return self
  ...


struct MyVal[param: Bool]:
  ...
What is your motivation for this change?

I have some use cases for something like this, such as custom generalized complex literals.
I don't know the inner workings, so i'm not sure if this would fit into the compilation flow, but if not that's okay.

Any other details?

if something already exists like this, or you think there's a better way to go about it, let me know :]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by searching the Mojo compiler for handling of @nonmaterializable and materialization, then trace how parameterized types and generalized literals are represented. The issue provides no file or test entry point, so first identify the relevant compiler tests. Done means a parametric MyLit can materialize to MyVal[param], with coverage for the example behavior.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.