{"id":13667946,"url":"https://github.com/raviqqe/melior","last_synced_at":"2025-07-22T03:31:04.883Z","repository":{"id":267421142,"uuid":"901187770","full_name":"raviqqe/melior","owner":"raviqqe","description":"The rustic MLIR bindings in Rust","archived":false,"fork":true,"pushed_at":"2025-06-03T00:38:06.000Z","size":183941,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-03T15:09:06.810Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mlir-rs.github.io/melior/melior/","language":"Rust","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mlir-rs/melior","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raviqqe.png","metadata":{},"created_at":"2024-12-10T07:46:42.000Z","updated_at":"2024-12-27T05:17:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/raviqqe/melior","commit_stats":null,"previous_names":["raviqqe/melior-1"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/raviqqe/melior","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raviqqe%2Fmelior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raviqqe%2Fmelior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raviqqe%2Fmelior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raviqqe%2Fmelior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raviqqe","download_url":"https://codeload.github.com/raviqqe/melior/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raviqqe%2Fmelior/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266419202,"owners_count":23925709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llvm","mlir","rust"],"created_at":"2024-08-02T07:00:55.453Z","updated_at":"2025-07-22T03:31:04.874Z","avatar_url":"https://github.com/raviqqe.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Melior\n\n[![GitHub Action](https://img.shields.io/github/actions/workflow/status/raviqqe/melior/test.yaml?branch=main\u0026style=flat-square)](https://github.com/raviqqe/melior/actions?query=workflow%3Atest)\n[![Crate](https://img.shields.io/crates/v/melior.svg?style=flat-square)](https://crates.io/crates/melior)\n[![License](https://img.shields.io/github/license/raviqqe/melior.svg?style=flat-square)](https://github.com/raviqqe/melior/blob/main/LICENSE)\n\nMelior is the MLIR bindings for Rust. It aims to provide a simple,\nsafe, and complete API for MLIR with a reasonably sane ownership model\nrepresented by the type system in Rust.\n\nThis crate is a wrapper of [the MLIR C API](https://mlir.llvm.org/docs/CAPI/).\n\n## Examples\n\n### Building a function to add integers\n\n```rust\nuse melior::{\n    Context,\n    dialect::{arith, DialectRegistry, func},\n    ir::{*, attribute::{StringAttribute, TypeAttribute}, r#type::FunctionType},\n    utility::register_all_dialects,\n};\n\nlet registry = DialectRegistry::new();\nregister_all_dialects(\u0026registry);\n\nlet context = Context::new();\ncontext.append_dialect_registry(\u0026registry);\ncontext.load_all_available_dialects();\n\nlet location = Location::unknown(\u0026context);\nlet module = Module::new(location);\n\nlet index_type = Type::index(\u0026context);\n\nmodule.body().append_operation(func::func(\n    \u0026context,\n    StringAttribute::new(\u0026context, \"add\"),\n    TypeAttribute::new(FunctionType::new(\u0026context, \u0026[index_type, index_type], \u0026[index_type]).into()),\n    {\n        let block = Block::new(\u0026[(index_type, location), (index_type, location)]);\n\n        let sum = block.append_operation(arith::addi(\n            block.argument(0).unwrap().into(),\n            block.argument(1).unwrap().into(),\n            location\n        ));\n\n        block.append_operation(func::r#return( \u0026[sum.result(0).unwrap().into()], location));\n\n        let region = Region::new();\n        region.append_block(block);\n        region\n    },\n    \u0026[],\n    location,\n));\n\nassert!(module.as_operation().verify());\n```\n\n## Install\n\n```sh\ncargo add melior\n```\n\n### Dependencies\n\n[LLVM/MLIR 19](https://llvm.org/) needs to be installed on your system. On Linux and macOS, you can install it via [Homebrew](https://brew.sh).\n\n```sh\nbrew install llvm@19\n```\n\n## Documentation\n\nOn [GitHub Pages](https://raviqqe.github.io/melior/melior/).\n\n## Contribution\n\nContribution is welcome! But, Melior is still in the alpha stage as well as the MLIR C API. Note that the API is unstable and can have breaking changes in the future.\n\n### Technical notes\n\n- We always use `\u0026T` for MLIR objects instead of `\u0026mut T` to mitigate the intricacy of representing a loose ownership model of the MLIR C API in Rust.\n- Only UTF-8 is supported as string encoding.\n  - Most string conversion between Rust and C is cached internally.\n\n### Naming conventions\n\n- `Mlir\u003cX\u003e` objects are named `\u003cX\u003e` if they have no destructor. Otherwise, they are named `\u003cX\u003e` for owned objects and `\u003cX\u003eRef` for borrowed references.\n- `mlir\u003cX\u003eCreate` functions are renamed as `\u003cX\u003e::new`.\n- `mlir\u003cX\u003eGet\u003cY\u003e` functions are renamed as follows:\n  - If the resulting objects refer to `\u0026self`, they are named `\u003cX\u003e::as_\u003cY\u003e`.\n  - Otherwise, they are named just `\u003cX\u003e::\u003cY\u003e` and may have arguments, such as position indices.\n\n### Safety\n\nAlthough Melior aims to be completely type safe, some part of the current API is\nnot.\n\n- Access to operations, types, or attributes that belong to dialects not\n  loaded in contexts can lead to runtime errors or segmentation faults in\n  the worst case.\n  - Fix plan: Load all dialects by default on creation of contexts, and\n    provide unsafe constructors of contexts for advanced users.\n- IR object references returned from functions that move ownership of\n  arguments might get invalidated later.\n  - This is because we need to borrow `\u0026self` rather than `\u0026mut self` to\n    return such references.\n  - e.g. `Region::append_block()`\n  - Fix plan: Use dynamic check, such as `RefCell`, for the objects.\n\n## References\n\n- The raw C binding generation depends on [femtomc/mlir-sys](https://github.com/femtomc/mlir-sys).\n- The overall design is inspired by [TheDan64/inkwell](https://github.com/TheDan64/inkwell).\n\n## License\n\n[Apache 2.0](https://github.com/raviqqe/melior/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraviqqe%2Fmelior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraviqqe%2Fmelior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraviqqe%2Fmelior/lists"}