Skip to content

Commit 1b94d45

Browse files
authored
feat: git subtree move in hugr-llvm
Due to the LLVM dependency the package is excluded from default CI runs, except check which does not require llvm. A separate job for building and testing is added that runs on push to main.
2 parents 649589c + 010f5cf commit 1b94d45

File tree

158 files changed

+11478
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+11478
-15
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/snapshots/*.snap -diff

.github/change-filters.yml

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ python:
1818
- "uv.lock"
1919
- "specification/schema/**"
2020
- ".github/workflows/ci-py.yml"
21+
22+
23+
llvm:
24+
- "hugr-llvm/**"

.github/workflows/ci-rs.yml

+50-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77
pull_request:
88
branches:
9-
- main
9+
- '*'
1010
merge_group:
1111
types: [checks_requested]
1212
workflow_dispatch: {}
@@ -23,7 +23,7 @@ env:
2323

2424
jobs:
2525
# Check if changes were made to the relevant files.
26-
# Always returns true if running on the default branch, to ensure all changes are throughly checked.
26+
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked.
2727
changes:
2828
name: Check for changes
2929
runs-on: ubuntu-latest
@@ -35,6 +35,7 @@ jobs:
3535
outputs:
3636
rust: ${{ steps.filter.outputs.rust == 'true' || steps.override.outputs.out == 'true' }}
3737
python: ${{ steps.filter.outputs.python == 'true' || steps.override.outputs.out == 'true' }}
38+
llvm: ${{ steps.filter.outputs.llvm == 'true' || steps.override.outputs.out == 'true' }}
3839
steps:
3940
- uses: actions/checkout@v4
4041
- name: Override label
@@ -91,9 +92,9 @@ jobs:
9192
- name: Install CapnProto
9293
run: sudo apt-get install -y capnproto
9394
- name: Build benchmarks with no features
94-
run: cargo bench --verbose --no-run --workspace --no-default-features
95+
run: cargo bench --verbose --no-run --no-default-features
9596
- name: Build benchmarks with all features
96-
run: cargo bench --verbose --no-run --workspace --all-features
97+
run: cargo bench --verbose --no-run --all-features
9798

9899
# Run tests on Rust stable
99100
tests-stable-no-features:
@@ -110,12 +111,13 @@ jobs:
110111
toolchain: "stable"
111112
- name: Configure default rust toolchain
112113
run: rustup override set ${{steps.toolchain.outputs.name}}
114+
113115
- name: Install CapnProto
114116
run: sudo apt-get install -y capnproto
115117
- name: Build with no features
116-
run: cargo test --verbose --workspace --no-default-features --no-run
118+
run: cargo test --verbose --no-default-features --no-run
117119
- name: Tests with no features
118-
run: cargo test --verbose --workspace --no-default-features
120+
run: cargo test --verbose --no-default-features
119121

120122
# Run tests on Rust stable
121123
tests-stable-all-features:
@@ -132,12 +134,13 @@ jobs:
132134
toolchain: "stable"
133135
- name: Configure default rust toolchain
134136
run: rustup override set ${{steps.toolchain.outputs.name}}
137+
135138
- name: Install CapnProto
136139
run: sudo apt-get install -y capnproto
137140
- name: Build with all features
138-
run: cargo test --verbose --workspace --all-features --no-run
141+
run: cargo test --verbose --all-features --no-run
139142
- name: Tests with all features
140-
run: cargo test --verbose --workspace --all-features
143+
run: cargo test --verbose --all-features
141144
- name: Build HUGR binary
142145
run: cargo build -p hugr-cli
143146
- name: Upload the binary to the artifacts
@@ -170,13 +173,13 @@ jobs:
170173
- name: Install CapnProto
171174
run: sudo apt-get install -y capnproto
172175
- name: Build with no features
173-
run: cargo test --verbose --workspace --no-default-features --no-run
176+
run: cargo test --verbose --no-default-features --no-run
174177
- name: Tests with no features
175-
run: cargo test --verbose --workspace --no-default-features
178+
run: cargo test --verbose --no-default-features
176179
- name: Build with all features
177-
run: cargo test --verbose --workspace --all-features --no-run
180+
run: cargo test --verbose --all-features --no-run
178181
- name: Tests with all features
179-
run: cargo test --verbose --workspace --all-features
182+
run: cargo test --verbose --all-features
180183

181184
# Ensure that serialized extensions match rust implementation
182185
std-extensions:
@@ -225,8 +228,8 @@ jobs:
225228
- name: Run tests with coverage instrumentation
226229
run: |
227230
cargo llvm-cov clean --workspace
228-
cargo llvm-cov --no-report --workspace --no-default-features --doctests
229-
cargo llvm-cov --no-report --workspace --all-features --doctests
231+
cargo llvm-cov --no-report --no-default-features --doctests
232+
cargo llvm-cov --no-report --all-features --doctests
230233
- name: Generate coverage report
231234
run: cargo llvm-cov --all-features report --codecov --output-path coverage.json
232235
- name: Upload coverage to codecov.io
@@ -237,6 +240,39 @@ jobs:
237240
flags: rust
238241
token: ${{ secrets.CODECOV_TOKEN }}
239242

243+
tests-stable-llvm:
244+
needs: changes
245+
if: ${{ ( needs.changes.outputs.llvm == 'true' && github.event_name == 'push' ) || needs.changes.outputs.override == 'true' }}
246+
runs-on: ubuntu-latest
247+
name: tests hugr-llvm
248+
strategy:
249+
matrix:
250+
llvm-version:
251+
# different strings for install action and feature name
252+
# adapted from https://github.com/TheDan64/inkwell/blob/master/.github/workflows/test.yml
253+
- ["14.0", "14-0"]
254+
255+
steps:
256+
- uses: actions/checkout@v4
257+
- uses: mozilla-actions/[email protected]
258+
- id: toolchain
259+
uses: dtolnay/rust-toolchain@master
260+
with:
261+
toolchain: "stable"
262+
- name: Configure default rust toolchain
263+
run: rustup override set ${{steps.toolchain.outputs.name}}
264+
- name: Install CapnProto
265+
run: sudo apt-get install -y capnproto
266+
- name: Install LLVM and Clang
267+
uses: KyleMayes/install-llvm-action@v2
268+
with:
269+
version: ${{ matrix.llvm-version[0] }}
270+
env: true
271+
- name: Build
272+
run: cargo test -p hugr-llvm --verbose --features llvm${{ matrix.llvm-version[1] }} --no-run
273+
- name: Tests with no features
274+
run: cargo test -p hugr-llvm --verbose --features llvm${{ matrix.llvm-version[1] }}
275+
240276
rs-semver-checks:
241277
needs: [changes, check]
242278
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name == 'pull_request' }}

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ lto = "thin"
33

44
[workspace]
55
resolver = "2"
6-
members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]
6+
members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model", "hugr-llvm"]
7+
default-members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]
78

89
[workspace.package]
910
rust-version = "1.75"
@@ -64,6 +65,7 @@ predicates = "3.1.0"
6465
indexmap = "2.3.0"
6566
fxhash = "0.2.1"
6667
bumpalo = { version = "3.16.0" }
68+
pathsearch = "0.2.0"
6769

6870
[profile.dev.package]
6971
insta.opt-level = 3

DEVELOPMENT.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ To setup the environment manually you will need:
3232
- Rust `>=1.75`: https://www.rust-lang.org/tools/install
3333
- uv `>=0.3`: docs.astral.sh/uv/getting-started/installation
3434
- capnproto `>=1.0`: https://capnproto.org/install.html
35+
- Optional: llvm `== 14.0`. The "llvm" feature (backed by the sub-crate `hugr-llvm`)
36+
requires LLVM installed. We use the rust bindings
37+
[llvm-sys](https://crates.io/crates/llvm-sys) to [llvm](https://llvm.org/),
3538

3639
Once you have these installed, you can install the required python dependencies and setup pre-commit hooks with:
3740

devenv.nix

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ in
99
default = true;
1010
description = "run `just setup` on entering shell";
1111
};
12+
13+
llvmVersion = lib.mkOption {
14+
type = lib.types.str;
15+
default = "14";
16+
};
1217
};
1318

1419
config = {
@@ -23,6 +28,10 @@ in
2328
pkgs.graphviz
2429
pkgs.cargo-insta
2530
pkgs.capnproto
31+
32+
# These are required for hugr-llvm to be able to link to llvm.
33+
pkgs.libffi
34+
pkgs.libxml2
2635
] ++ lib.optionals
2736
pkgs.stdenv.isDarwin
2837
(with pkgs.darwin.apple_sdk; [
@@ -32,6 +41,11 @@ in
3241
frameworks.SystemConfiguration
3342
]);
3443

44+
env = {
45+
"LLVM_SYS_${cfg.llvmVersion}0_PREFIX" = "${pkgs."llvmPackages_${cfg.llvmVersion}".libllvm.dev}";
46+
};
47+
48+
3549
# https://devenv.sh/scripts/
3650
scripts.hello.exec = "echo Welcome to hugr dev shell!";
3751

hugr-llvm/CHANGELOG.md

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
## [0.13.3](https://github.com/CQCL/hugr-llvm/compare/v0.6.0...v0.6.1) - 2024-11-25
9+
No changes - version bump to catch up with other hugr crates in repository move.
10+
11+
## [0.6.1](https://github.com/CQCL/hugr-llvm/compare/v0.6.0...v0.6.1) - 2024-10-23
12+
13+
### Bug Fixes
14+
15+
- don't normalise half turns ([#137](https://github.com/CQCL/hugr-llvm/pull/137))
16+
17+
## [0.6.0](https://github.com/CQCL/hugr-llvm/compare/v0.5.1...v0.6.0) - 2024-10-21
18+
19+
### Bug Fixes
20+
21+
- Conversion operations having poison results ([#131](https://github.com/CQCL/hugr-llvm/pull/131))
22+
23+
### New Features
24+
25+
- [**breaking**] Allow extension callbacks to have non-`'static` lifetimes ([#128](https://github.com/CQCL/hugr-llvm/pull/128))
26+
- [**breaking**] Support `tket2.rotation.from_halfturns_unchecked` ([#133](https://github.com/CQCL/hugr-llvm/pull/133))
27+
28+
### Refactor
29+
30+
- [**breaking**] remove trait emit op ([#104](https://github.com/CQCL/hugr-llvm/pull/104))
31+
- [**breaking**] rework extensions interface ([#119](https://github.com/CQCL/hugr-llvm/pull/119))
32+
- [**breaking**] move packaged extensions from `crate::custom` to `crate::extension` ([#126](https://github.com/CQCL/hugr-llvm/pull/126))
33+
34+
## [0.5.1](https://github.com/CQCL/hugr-llvm/compare/v0.5.0...v0.5.1) - 2024-09-23
35+
36+
### New Features
37+
38+
- provide `inline_constant_functions` ([#108](https://github.com/CQCL/hugr-llvm/pull/108))
39+
40+
## [0.5.0](https://github.com/CQCL/hugr-llvm/compare/v0.4.0...v0.5.0) - 2024-09-16
41+
42+
### New Features
43+
44+
- Add emitters for int <-> float/usize conversions ([#94](https://github.com/CQCL/hugr-llvm/pull/94))
45+
- [**breaking**] array ops ([#96](https://github.com/CQCL/hugr-llvm/pull/96))
46+
- Add conversions itobool, ifrombool ([#101](https://github.com/CQCL/hugr-llvm/pull/101))
47+
- Add `tket2` feature and lowerings for `tket2.rotation` extension ([#100](https://github.com/CQCL/hugr-llvm/pull/100))
48+
49+
### Testing
50+
51+
- Add execution test framework ([#97](https://github.com/CQCL/hugr-llvm/pull/97))
52+
53+
## [0.3.1](https://github.com/CQCL/hugr-llvm/compare/v0.3.0...v0.3.1) - 2024-08-28
54+
55+
### New Features
56+
- Emit more int operations ([#87](https://github.com/CQCL/hugr-llvm/pull/87))
57+
58+
## [0.3.0](https://github.com/CQCL/hugr-llvm/compare/v0.2.1...v0.3.0) - 2024-08-27
59+
60+
### New Features
61+
- [**breaking**] Lower string, print, and panic ([#78](https://github.com/CQCL/hugr-llvm/pull/78))
62+
- Lower float operations ([#83](https://github.com/CQCL/hugr-llvm/pull/83))
63+
- Lower logic extension ([#81](https://github.com/CQCL/hugr-llvm/pull/81))
64+
- Lower arrays ([#82](https://github.com/CQCL/hugr-llvm/pull/82))
65+
66+
## [0.2.1](https://github.com/CQCL/hugr-llvm/compare/v0.2.0...v0.2.1) - 2024-08-19
67+
68+
### Documentation
69+
- Remove fixed crate version in usage instructions ([#68](https://github.com/CQCL/hugr-llvm/pull/68))
70+
71+
### New Features
72+
- Add lowering for LoadFunction ([#65](https://github.com/CQCL/hugr-llvm/pull/65))
73+
- Emission for CallIndirect nodes ([#73](https://github.com/CQCL/hugr-llvm/pull/73))
74+
75+
## [0.2.0](https://github.com/CQCL/hugr-llvm/compare/v0.1.0...v0.2.0) - 2024-07-31
76+
77+
### New Features
78+
- make EmitFuncContext::iw_context pub ([#55](https://github.com/CQCL/hugr-llvm/pull/55))
79+
80+
### Refactor
81+
- use HugrFuncType/HugrType/HugrSumType ([#56](https://github.com/CQCL/hugr-llvm/pull/56))
82+
- remove unneeded `HugrView` constraints ([#59](https://github.com/CQCL/hugr-llvm/pull/59))
83+
- [**breaking**] add `LLVMSumValue` ([#63](https://github.com/CQCL/hugr-llvm/pull/63))
84+
85+
### Testing
86+
- Add test for LoadFunction Op ([#60](https://github.com/CQCL/hugr-llvm/pull/60))
87+
88+
## [0.1.0](https://github.com/CQCL/hugr-llvm/releases/tag/v0.1.0) - 2024-07-10
89+
90+
### Bug Fixes
91+
- Syntax error
92+
- sum type tag elision logic reversed
93+
- [**breaking**] Allow Const and FuncDecl as children of Modules, Dataflow Parents, and CFG nodes ([#46](https://github.com/CQCL/hugr-llvm/pull/46))
94+
95+
### Documentation
96+
- fix bad grammar ([#34](https://github.com/CQCL/hugr-llvm/pull/34))
97+
98+
### New Features
99+
- Emission for Call nodes
100+
- Support values
101+
- add `get_extern_func` ([#28](https://github.com/CQCL/hugr-llvm/pull/28))
102+
- lower CFGs ([#26](https://github.com/CQCL/hugr-llvm/pull/26))
103+
- Add initial codegen extension for `prelude` ([#29](https://github.com/CQCL/hugr-llvm/pull/29))
104+
- [**breaking**] `Namer` optionally appends node index to mangled names. ([#32](https://github.com/CQCL/hugr-llvm/pull/32))
105+
- Implement lowerings for ieq,ilt_s,sub in int codegen extension ([#33](https://github.com/CQCL/hugr-llvm/pull/33))
106+
- Add initial `float` extension ([#31](https://github.com/CQCL/hugr-llvm/pull/31))
107+
- Emit more int comparison operators ([#47](https://github.com/CQCL/hugr-llvm/pull/47))
108+
109+
### Refactor
110+
- clean up fat.rs ([#38](https://github.com/CQCL/hugr-llvm/pull/38))
111+
112+
### Testing
113+
- add a test for sum type tags
114+
- Add integration tests lowering guppy programs ([#35](https://github.com/CQCL/hugr-llvm/pull/35))

hugr-llvm/Cargo.toml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "hugr-llvm"
3+
version = "0.13.3"
4+
description = "A general and extensible crate for lowering HUGRs into LLVM IR"
5+
6+
edition.workspace = true
7+
rust-version.workspace = true
8+
9+
readme = "README.md"
10+
license.workspace = true
11+
homepage.workspace = true
12+
repository.workspace = true
13+
documentation = "https://docs.rs/hugr-llvm"
14+
authors = ["TKET development team <[email protected]>"]
15+
keywords = ["Quantum", "Quantinuum"]
16+
categories = ["compilers"]
17+
18+
[features]
19+
default = ["llvm14-0"]
20+
llvm14-0 = ["inkwell/llvm14-0"]
21+
22+
[dependencies]
23+
inkwell = { version = "0.4.0", default-features = false }
24+
hugr-core = { path = "../hugr-core", version = "0.13.3"}
25+
anyhow = "1.0.83"
26+
itertools.workspace = true
27+
delegate.workspace = true
28+
petgraph.workspace = true
29+
lazy_static.workspace = true
30+
downcast-rs.workspace = true
31+
strum.workspace = true
32+
33+
[dev-dependencies]
34+
insta.workspace = true
35+
rstest.workspace = true
36+
portgraph.workspace = true
37+
pathsearch.workspace = true
38+
serde_json.workspace = true
39+
serde.workspace = true
40+
typetag.workspace = true

0 commit comments

Comments
 (0)