{"id":14991220,"url":"https://github.com/edg-l/melior","last_synced_at":"2025-10-06T04:31:38.360Z","repository":{"id":128114081,"uuid":"611292322","full_name":"edg-l/melior","owner":"edg-l","description":"The rustic MLIR bindings in Rust, continued","archived":false,"fork":true,"pushed_at":"2025-01-16T11:42:26.000Z","size":3351,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-16T13:00:33.789Z","etag":null,"topics":["llvm","llvm-ir","mlir","rust"],"latest_commit_sha":null,"homepage":"","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/edg-l.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}},"created_at":"2023-03-08T14:24:55.000Z","updated_at":"2025-01-16T11:42:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"8885c73b-b466-4637-95f1-7009c28eff5d","html_url":"https://github.com/edg-l/melior","commit_stats":{"total_commits":120,"total_committers":4,"mean_commits":30.0,"dds":0.4833333333333333,"last_synced_commit":"0a4b0c34457e81adc61609a805e87bd26545b529"},"previous_names":["edg-l/melior","edg-l/melior-next"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edg-l%2Fmelior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edg-l%2Fmelior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edg-l%2Fmelior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edg-l%2Fmelior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edg-l","download_url":"https://codeload.github.com/edg-l/melior/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235494957,"owners_count":18999388,"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","llvm-ir","mlir","rust"],"created_at":"2024-09-24T14:21:53.096Z","updated_at":"2025-10-06T04:31:37.946Z","avatar_url":"https://github.com/edg-l.png","language":"Rust","funding_links":[],"categories":["Starchart"],"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::{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://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%2Fedg-l%2Fmelior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedg-l%2Fmelior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedg-l%2Fmelior/lists"}