{"id":22444346,"url":"https://github.com/mlir-rs/melior","last_synced_at":"2025-05-14T15:07:23.645Z","repository":{"id":39744410,"uuid":"496668214","full_name":"mlir-rs/melior","owner":"mlir-rs","description":"The rustic MLIR bindings in Rust","archived":false,"fork":false,"pushed_at":"2025-05-08T16:22:24.000Z","size":183856,"stargazers_count":399,"open_issues_count":28,"forks_count":46,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-11T10:14:02.593Z","etag":null,"topics":["llvm","mlir","rust"],"latest_commit_sha":null,"homepage":"https://mlir-rs.github.io/melior/melior/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlir-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-05-26T15:12:11.000Z","updated_at":"2025-05-10T19:34:38.000Z","dependencies_parsed_at":"2024-04-04T00:22:32.016Z","dependency_job_id":"73fc0c28-2be3-472d-b011-4bf68a23a438","html_url":"https://github.com/mlir-rs/melior","commit_stats":{"total_commits":543,"total_committers":9,"mean_commits":"60.333333333333336","dds":0.3664825046040515,"last_synced_commit":"103daad71e03f5ed3f8d953cc2c40cbfe4ee3ed3"},"previous_names":["mlir-rs/melior"],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlir-rs%2Fmelior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlir-rs%2Fmelior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlir-rs%2Fmelior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlir-rs%2Fmelior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlir-rs","download_url":"https://codeload.github.com/mlir-rs/melior/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169641,"owners_count":22026213,"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","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-12-06T03:00:57.538Z","updated_at":"2025-05-14T15:07:23.624Z","avatar_url":"https://github.com/mlir-rs.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Melior\n\n[![GitHub Action](https://img.shields.io/github/actions/workflow/status/mlir-rs/melior/test.yaml?branch=main\u0026style=flat-square)](https://github.com/mlir-rs/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/mlir-rs/melior.svg?style=flat-square)](https://github.com/mlir-rs/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::{DialectRegistry, arith, func},\n    ir::{\n        attribute::{StringAttribute, TypeAttribute},\n        operation::OperationLike,\n        r#type::FunctionType,\n        *,\n    },\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(\n        FunctionType::new(\u0026context, \u0026[index_type, index_type], \u0026[index_type]).into(),\n    ),\n    {\n        let block = Block::new(\u0026[(index_type, location), (index_type, location)]);\n\n        let sum = block\n            .append_operation(arith::addi(\n                block.argument(0).unwrap().into(),\n                block.argument(1).unwrap().into(),\n                location,\n            ))\n            .result(0)\n            .unwrap();\n\n        block.append_operation(func::r#return(\u0026[sum.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 20](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@20\n```\n\n## Documentation\n\nOn [GitHub Pages](https://mlir-rs.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 [mlir-rs/mlir-sys](https://github.com/mlir-rs/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/mlir-rs/melior/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlir-rs%2Fmelior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlir-rs%2Fmelior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlir-rs%2Fmelior/lists"}