{"id":48591052,"url":"https://github.com/coord-e/thrust","last_synced_at":"2026-04-08T19:31:49.227Z","repository":{"id":289982905,"uuid":"799919835","full_name":"coord-e/thrust","owner":"coord-e","description":"Refinement type checking and inference tool for Rust","archived":false,"fork":false,"pushed_at":"2026-03-30T15:34:47.000Z","size":613,"stargazers_count":20,"open_issues_count":9,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-03-30T16:37:20.398Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coord-e.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-05-13T11:07:18.000Z","updated_at":"2026-03-30T15:28:49.000Z","dependencies_parsed_at":"2025-10-25T06:45:13.410Z","dependency_job_id":null,"html_url":"https://github.com/coord-e/thrust","commit_stats":null,"previous_names":["coord-e/thrust"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/coord-e/thrust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coord-e%2Fthrust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coord-e%2Fthrust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coord-e%2Fthrust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coord-e%2Fthrust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coord-e","download_url":"https://codeload.github.com/coord-e/thrust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coord-e%2Fthrust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31571600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-04-08T19:31:48.640Z","updated_at":"2026-04-08T19:31:49.218Z","avatar_url":"https://github.com/coord-e.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Thrust\n\nThrust is a refinement type checking and inference tool for Rust.\n\n## Getting Started\n\n- Make sure [Z3](https://github.com/Z3Prover/z3) is installed.\n- The main binary, `thrust-rustc`, behaves like `rustc` but includes Thrust's verification.\n- In the following instructions, we assume the Thrust source code is cloned locally and commands are executed within it.\n\nTake the following Rust code (`gcd.rs`):\n\n```rust\nfn gcd(mut a: i32, mut b: i32) -\u003e i32 {\n    while a != b {\n        let (l, r) = if a \u003c b {\n            (\u0026mut a, \u0026b)\n        } else {\n            (\u0026mut b, \u0026a)\n        };\n        *l -= *r;\n    }\n    a\n}\n\n#[thrust::callable]\nfn check_gcd(a: i32, b: i32) {\n    assert!(gcd(a, b) \u003c= a);\n}\n\nfn main() {}\n```\n\nLet Thrust verify that the program is correct. Here, we use `cargo run` in the Thrust source tree to build and run `thrust-rustc`. Note that you need to disable the debug overflow assertions in rustc, as they are currently not supported in Thrust.\n\n```console\n$ cargo run -- -Adead_code -C debug-assertions=false gcd.rs \u0026\u0026 echo 'safe'\n   Compiling thrust v0.1.0 (/home/coord_e/rust-refinement/thrust)\n    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s\n     Running `target/debug/thrust-rustc -Adead_code -C debug-assertions=false gcd.rs`\nerror: verification error: Unsat\n\nerror: aborting due to 1 previous error\n```\n\nThrust says the program is not safe (possible to panic). In fact, we have a bug in our `gcd` function:\n\n```diff\n fn gcd(mut a: i32, mut b: i32) -\u003e i32 {\n     while a != b {\n-        let (l, r) = if a \u003c b {\n+        let (l, r) = if a \u003e b {\n             (\u0026mut a, \u0026b)\n         } else {\n             (\u0026mut b, \u0026a)\n```\n\nNow Thrust verifies the program is actually safe.\n\n```console\n$ cargo run -- -Adead_code -C debug-assertions=false gcd_fixed.rs \u0026\u0026 echo 'safe'\n    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s\n     Running `target/debug/thrust-rustc -Adead_code -C debug-assertions=false gcd.rs`\nsafe\n```\n\nIntegration test examples are located under `tests/ui/` and can be executed using `cargo test`. You can review these examples to understand what the current Thrust implementation can handle.\n\n## Annotation\n\nThrust can verify a wide range of programs without explicit annotations, but you can use `#[thrust::requires(expr)]` and `#[thrust::ensures(expr)]` to annotate the precondition and postcondition of a function, aiding in verification or specifying the specification. Here, `expr` is a logical expression that supports basic integer, boolean, and reference operations.\n\n```rust\n#[thrust::requires(n \u003e= 0)]\n#[thrust::ensures((result * 2) == n * (n + 1))]\nfn sum(n: i32) -\u003e i32 {\n    if n == 0 {\n        0\n    } else {\n        n + sum(n - 1)\n    }\n}\n```\n\nYou can use the `^` unary operator to denote the value of a mutable reference after the function is called. Note that in the current implementation, you need to specify both `requires` and `ensures` when using either one.\n\n```rust\n#[thrust::requires(true)]\n#[thrust::ensures(^ma == *ma + a)]\nfn add(ma: \u0026mut i32, a: i32) {\n    *ma += a;\n}\n```\n\nThe conditions on `thrust::requires` and `thrust::ensures` are internally encoded as refinement types for the parameter and return types. You can also specify these refinement types directly using `#[thrust::param(param: type)]` and `#[thrust::ret(type)]`.\n\n```rust\n#[thrust::param(n: { x: int | x \u003e= 0 })]\n#[thrust::ret({ x: int | (x * 2) == n * (n + 1) })]\nfn sum(n: i32) -\u003e i32 {\n    if n == 0 {\n        0\n    } else {\n        n + sum(n - 1)\n    }\n}\n```\n\nThe bodies of functions marked with `#[thrust::trusted]` are not analyzed by Thrust. Additionally, `#[thrust::callable]` is an alias for `#[thrust::requires(true)]` and `#[thrust::ensures(true)]`.\n\n```rust\n#[thrust::trusted]\n#[thrust::callable]\nfn rand() -\u003e i32 { unimplemented!() }\n```\n\n## Configuration\n\nSeveral environment variables are used by Thrust to configure its behavior:\n\n- `THRUST_SOLVER`: A CHC solver command used to solve CHC constraints generated by Thrust. Default: `z3`\n- `THRUST_SOLVER_ARGS`: Whitespace-separated command-line flags passed to the solver. The default is `fp.spacer.global=true fp.validate=true` when the solver is `z3`.\n- `THRUST_SOLVER_TIMEOUT_SECS`: Timeout for waiting on results from the solver. Default: `30`\n- `THRUST_OUTPUT_DIR`: When configured, Thrust outputs intermediate smtlib2 files into this directory.\n- `THRUST_ENUM_EXPANSION_DEPTH_LIMIT`: When Thrust works with enums, it \"expands\" the structure of the enum value onto its environment. This configuration value sets the limit on the depth of recursion during this expansion to handle enums that are defined recursively. It is our future work to discover a sensible value for this automatically. Default: `2`\n\n## Development\n\nThe implementation of the Thrust is largely divided into the following modules.\n\n- `analyze`: MIR analysis. Further divided into the modules corresponding to the program units: `analyze::crate_`, `analyze::local_def`, and `analyze::basic_block`.\n- `refine`: Typing environment and related implementations.\n- `rty`: Refinement type primitives.\n- `chc`: CHC and logic primitives, and it also implements an invocation of the underlying CHC solver.\n- `annot`: Refinement type annotation parser.\n\nThe implementation generates subtyping constraints in the form of CHCs (`chc::System`). The entry point is `analyze::crate_::Analyzer::run`, followed by `analyze::local_def::Analyzer::run` and `analyze::basic_block::Analyzer::run`, while accumulating the necessary information in `analyze::Analyzer`. Once `chc::System` is collected for the entire input, it invokes an external CHC solver via the `chc::solver` module and subsequently reports the result.\n\n## Publication\n\nHiromi Ogawa, Taro Sekiyama, and Hiroshi Unno. Thrust: A Prophecy-based Refinement Type System for Rust. PLDI 2025.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoord-e%2Fthrust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoord-e%2Fthrust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoord-e%2Fthrust/lists"}