|
| 1 | +# Flux Repository - Copilot Coding Agent Instructions |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Flux is a refinement type checker for Rust. This is a Rust workspace with multiple crates, requiring specific dependencies (Z3, fixpoint) and custom build tooling through `cargo xtask`. |
| 6 | + |
| 7 | +**Languages & Frameworks:** Rust (edition 2024), custom rustc integration |
| 8 | +**Repository Size:** ~15 crates in workspace + 4 library packages + test suites |
| 9 | + |
| 10 | +**Note:** Required dependencies (fixpoint and Z3 4.12.1) are automatically installed in the Copilot coding agent environment via `.github/workflows/copilot-setup-steps.yml`. For local development, developers need to install these dependencies manually (see CI workflow for installation steps). |
| 11 | + |
| 12 | +## Build & Test Instructions |
| 13 | + |
| 14 | +### Test Commands |
| 15 | + |
| 16 | +1. **Run all regression tests**: |
| 17 | + ```bash |
| 18 | + cargo xtask test |
| 19 | + ``` |
| 20 | + This runs tests from `tests/pos/` (should pass) and `tests/neg/` (should fail with specific errors) |
| 21 | + |
| 22 | +2. **Run specific tests** (filtered by substring): |
| 23 | + ```bash |
| 24 | + cargo xtask test <filter> |
| 25 | + # Example: cargo xtask test impl_trait |
| 26 | + ``` |
| 27 | + |
| 28 | +3. **Test on a single file**: |
| 29 | + ```bash |
| 30 | + cargo xtask run <file.rs> |
| 31 | + # Example: cargo xtask run tests/pos/surface/impl_trait00.rs |
| 32 | + ``` |
| 33 | + This automatically sets up proper flags for Flux attributes and debugging |
| 34 | + |
| 35 | +### Linting & Formatting |
| 36 | + |
| 37 | +1. **Format code**: |
| 38 | + ```bash |
| 39 | + cargo fmt --check # Check only |
| 40 | + cargo fmt # Auto-format |
| 41 | + ``` |
| 42 | + Uses `rustfmt.toml` configuration |
| 43 | + |
| 44 | +2. **Run clippy**: |
| 45 | + ```bash |
| 46 | + cargo clippy |
| 47 | + ``` |
| 48 | + Uses `clippy.toml` with custom lints defined in `Cargo.toml` workspace section |
| 49 | + |
| 50 | +## Project Layout |
| 51 | + |
| 52 | +### Directory Structure |
| 53 | + |
| 54 | +``` |
| 55 | +/ |
| 56 | +├── crates/ - Main Flux implementation crates |
| 57 | +│ ├── flux-bin/ - CLI binary (flux, cargo-flux) |
| 58 | +│ ├── flux-driver/ - Rustc driver integration |
| 59 | +│ ├── flux-middle/ - Core type system and refinement types |
| 60 | +│ ├── flux-refineck/ - Refinement type checker |
| 61 | +│ ├── flux-syntax/ - Parsing Flux surface syntax |
| 62 | +│ ├── flux-errors/ - Error reporting |
| 63 | +│ └── ... - Other supporting crates |
| 64 | +├── lib/ - User-facing Flux libraries |
| 65 | +│ ├── flux-rs/ - Main library with macros (#[flux::sig], etc.) |
| 66 | +│ ├── flux-core/ - Extern specs for std library |
| 67 | +│ ├── flux-attrs/ - Attribute proc macros |
| 68 | +│ └── flux-alloc/ - Extern specs for alloc |
| 69 | +├── tests/ - Regression test suite |
| 70 | +│ ├── pos/ - Tests that should type check |
| 71 | +│ └── neg/ - Tests that should fail with errors |
| 72 | +├── xtask/ - Build system implementation |
| 73 | +├── book/ - User documentation (mdBook). |
| 74 | +├── .github/ |
| 75 | +│ └── workflows/ |
| 76 | +│ ├── ci.yml - Main CI: tests, vtock, lean-demo, rustfmt, clippy |
| 77 | +│ └── ... |
| 78 | +└── Configuration files (see below) |
| 79 | +``` |
| 80 | + |
| 81 | +### Key Files |
| 82 | + |
| 83 | +- **Cargo.toml**: Workspace configuration with all crates, dependencies, and lints |
| 84 | +- **rust-toolchain.toml**: Specifies Rust toolchain (edition 2024, nightly features) |
| 85 | +- **clippy.toml**: Clippy configuration (allowed/denied lints) |
| 86 | +- **rustfmt.toml**: Code formatting rules |
| 87 | +- **typos.toml**: Spell checking configuration |
| 88 | +- **book/src/guide/develop.md**: Detailed developer guide |
| 89 | + |
| 90 | +### Architecture Notes |
| 91 | + |
| 92 | +- **Flux is a rustc driver**: It integrates with the Rust compiler as a custom driver |
| 93 | +- **Two-stage execution**: |
| 94 | + 1. Build flux-driver and cargo-flux binaries |
| 95 | + 2. Use cargo-flux to build libraries with refinement types |
| 96 | +- **Custom test framework**: Uses `cargo xtask test` which invokes the test harness in `tests/` package |
| 97 | + |
| 98 | +## CI Pipeline |
| 99 | + |
| 100 | +The `.github/workflows/ci.yml` runs on push/PR to main: |
| 101 | + |
| 102 | +1. **tests job**: Runs `cargo xtask test` on ubuntu/macos/windows |
| 103 | +2. **vtock job**: Tests Flux on the Tock OS kernel (verification use case) |
| 104 | +3. **lean-demo job**: Tests Flux-to-Lean translation feature |
| 105 | +4. **rustfmt job**: Checks code formatting |
| 106 | +5. **clippy job**: Runs `cargo check` and `cargo clippy` |
| 107 | + |
| 108 | +All jobs (except formatting/clippy) require fixpoint and Z3 to be installed first. In the Copilot coding agent environment, these dependencies are automatically installed via `.github/workflows/copilot-setup-steps.yml`. |
| 109 | + |
| 110 | +## Validation Steps |
| 111 | + |
| 112 | +Before submitting changes: |
| 113 | + |
| 114 | +1. **Format code**: `cargo fmt` |
| 115 | +2. **Run regression tests**: `cargo xtask test` |
| 116 | + |
| 117 | +## Important Conventions |
| 118 | + |
| 119 | +- **Error reporting**: Use `bug!`, `span_bug!`, `tracked_span_bug!`, or `QueryErr::bug` for unreachable code paths |
| 120 | +- **Debugging flags**: `-Ztrack-diagnostics=y` to show where errors are emitted (enabled by `cargo xtask run`) |
| 121 | +- **Backtraces**: Set `RUST_BACKTRACE=1`; dev profile gives better traces |
| 122 | + |
| 123 | +## Development Workflow |
| 124 | + |
| 125 | +1. Make changes to relevant crates in `crates/` or `lib/` |
| 126 | +2. Test specific functionality: `cargo xtask test <filter>` |
| 127 | +3. Or test single file: `cargo xtask run <file.rs>` |
| 128 | +4. Run formatter: `cargo fmt` |
| 129 | +5. Run full test suite: `cargo xtask test` |
| 130 | + |
| 131 | +## Trust These Instructions |
| 132 | + |
| 133 | +The information above has been validated against the repository structure, CI configuration, and developer documentation. When you need to build, test, or understand Flux: |
| 134 | + |
| 135 | +- **ALWAYS use `cargo xtask`** for building and testing |
| 136 | +- **NEVER run `cargo test`** directly on the workspace |
| 137 | +- Refer to these instructions first before searching the codebase for build/test commands |
0 commit comments