Skip to content

feat: Add llvm codegen for collections.static_array #2003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 20, 2025

Conversation

doug-q
Copy link
Collaborator

@doug-q doug-q commented Mar 19, 2025

No description provided.

Copy link

codecov bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 84.06170% with 62 lines in your changes missing coverage. Please review.

Project coverage is 83.82%. Comparing base (6bd7665) to head (d4a8cf9).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ugr-llvm/src/extension/collections/static_array.rs 85.47% 24 Missing and 29 partials ⚠️
...ore/src/std_extensions/collections/static_array.rs 65.00% 7 Missing ⚠️
hugr-py/src/hugr/std/collections/static_array.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2003      +/-   ##
==========================================
+ Coverage   83.73%   83.82%   +0.08%     
==========================================
  Files         209      210       +1     
  Lines       39266    39645     +379     
  Branches    35937    36315     +378     
==========================================
+ Hits        32879    33232     +353     
+ Misses       4541     4537       -4     
- Partials     1846     1876      +30     
Flag Coverage Δ
python 92.01% <33.33%> (-0.03%) ⬇️
rust 83.07% <84.45%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@doug-q doug-q marked this pull request as ready for review March 19, 2025 15:17
@doug-q doug-q requested a review from a team as a code owner March 19, 2025 15:17
@doug-q doug-q requested a review from acl-cqc March 19, 2025 15:17
@doug-q
Copy link
Collaborator Author

doug-q commented Mar 19, 2025

I've deleted some old unusued snapshots (via cargo insta test --unrefeferenced delete)

@cqc-alec cqc-alec requested review from cqc-alec and removed request for acl-cqc March 20, 2025 08:43
check_emission!(hugr, llvm_ctx);
}

#[rstest]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we handle zero-length static arrays? Can we add a test to prove it?

#[case(1, StaticArrayValue::try_new("b", float64_type(), (0..10).map(|x| ConstF64::new(x as f64).into())).unwrap())]
#[case(2, StaticArrayValue::try_new("c", bool_t(), (0..10).map(|x| Value::from_bool(x % 2 == 0))).unwrap())]
#[case(3, StaticArrayValue::try_new("d", option_type(usize_t()).into(), (0..10).map(|x| Value::some([ConstUsize::new(x)]))).unwrap())]
fn static_array_const_codegen(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the following test fail when I run

cargo test --all-features --workspace

with the error

thread 'extension::collections::static_array::test::static_array_const_codegen::case_1' panicked at hugr-llvm/src/emit/test.rs:177:48:
Parent node Node(1) has extensions [arithmetic.conversions, arithmetic.float, arithmetic.float.types, arithmetic.int, arithmetic.int.types, collections.array, collections.list, logic, prelude] that are too restrictive for child node Node(4), they must include child extensions [collections.static_array, prelude]

I guess we need to annotate them so that they don't run with the extension_inference feature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I will fix it so that it works

});
assert_eq!(expected, exec_ctx.exec_hugr_u64(hugr, "main"));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a test with arrays of arrays would also be good.

@doug-q doug-q requested a review from cqc-alec March 20, 2025 14:19
@doug-q
Copy link
Collaborator Author

doug-q commented Mar 20, 2025

@alec I think I've addressed all your comments, thank you. Note that we should merge #2009 (which I've merged in here) first

@hugrbot
Copy link
Collaborator

hugrbot commented Mar 20, 2025

This PR contains breaking changes to the public Rust API.
Please deprecate the old API instead (if possible), or mark the PR with a ! to indicate a breaking change.

cargo-semver-checks summary

--- failure constructible_struct_adds_private_field: struct no longer constructible due to new private field ---

Description:
A struct constructible with a struct literal has a new non-public field. It can no longer be constructed using a struct literal outside of its crate.
      ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/constructible_struct_adds_private_field.ron

Failed in:
field StaticArrayValue.values in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/std_extensions/collections/static_array.rs:61
field StaticArrayValue.typ in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/std_extensions/collections/static_array.rs:62

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/struct_pub_field_missing.ron

Failed in:
field value of struct StaticArrayValue, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/std_extensions/collections/static_array.rs:61

Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but this is now breaking -- are we OK with that?

@doug-q
Copy link
Collaborator Author

doug-q commented Mar 20, 2025

LGTM, but this is now breaking -- are we OK with that?

The PR that I merged in is breaking, and we are OK with that because we have not released the breaking apis.

@doug-q doug-q added this pull request to the merge queue Mar 20, 2025
Merged via the queue into main with commit f3dd145 Mar 20, 2025
24 of 25 checks passed
@doug-q doug-q deleted the doug/static-arrays-llvm branch March 20, 2025 16:11
This was referenced Mar 20, 2025
github-merge-queue bot pushed a commit that referenced this pull request Mar 21, 2025
## 🤖 New release

* `hugr-model`: 0.18.0 -> 0.18.1 (✓ API compatible changes)
* `hugr-core`: 0.15.0 -> 0.16.0 (✓ API compatible changes)
* `hugr-llvm`: 0.15.0 -> 0.16.0 (✓ API compatible changes)
* `hugr-passes`: 0.15.0 -> 0.16.0 (✓ API compatible changes)
* `hugr`: 0.15.0 -> 0.16.0 (✓ API compatible changes)
* `hugr-cli`: 0.15.0 -> 0.16.0 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `hugr-model`

<blockquote>

##
[0.18.0](hugr-model-v0.17.1...hugr-model-v0.18.0)
- 2025-03-14

### Bug Fixes

- Hugr-model using undeclared derive_more features
([#1940](#1940))

### New Features

- *(hugr-model)* [**breaking**] Add `read_from_reader` and
`write_to_writer` for streaming reads and writes.
([#1871](#1871))
- `hugr-model` AST ([#1953](#1953))

### Refactor

- *(hugr-model)* Reexport `bumpalo` from `hugr-model`
([#1870](#1870))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.16.0](hugr-core-v0.15.0...hugr-core-v0.16.0)
- 2025-03-21

### Bug Fixes

- correct `CallIndirect` tag from `FnCall` to `DataflowChild`
([#2006](#2006))
- StaticArrayValue serialisation
([#2009](#2009))

### New Features

- traits for transforming Types/TypeArgs/etc.
([#1991](#1991))
- add exit operation to prelude
([#2008](#2008))
- Add llvm codegen for collections.static_array
([#2003](#2003))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.16.0](hugr-llvm-v0.15.0...hugr-llvm-v0.16.0)
- 2025-03-21

### Bug Fixes

- Remove return from val_or_panic
([#1999](#1999))

### New Features

- add exit operation to prelude
([#2008](#2008))
- Add llvm codegen for collections.static_array
([#2003](#2003))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.16.0](hugr-passes-v0.15.0...hugr-passes-v0.16.0)
- 2025-03-21

### Bug Fixes

- correct `CallIndirect` tag from `FnCall` to `DataflowChild`
([#2006](#2006))
</blockquote>

## `hugr`

<blockquote>

##
[0.16.0](hugr-v0.15.0...hugr-v0.16.0)
- 2025-03-21

### Bug Fixes

- correct `CallIndirect` tag from `FnCall` to `DataflowChild`
([#2006](#2006))
- StaticArrayValue serialisation
([#2009](#2009))

### New Features

- traits for transforming Types/TypeArgs/etc.
([#1991](#1991))
- add exit operation to prelude
([#2008](#2008))
- Add llvm codegen for collections.static_array
([#2003](#2003))
- *(hugr-py)* Support envelope compression
([#1994](#1994))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.16.0](hugr-cli-v0.15.0...hugr-cli-v0.16.0)
- 2025-03-21

### New Features

- *(hugr-cli)* Nicer error when passing a non-envelope file
([#2007](#2007))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: Douglas Wilson <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Mar 21, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.11.2](hugr-py-v0.11.1...hugr-py-v0.11.2)
(2025-03-21)


### Features

* add exit operation to prelude
([#2008](#2008))
([6bd7665](6bd7665))
* Add llvm codegen for collections.static_array
([#2003](#2003))
([f3dd145](f3dd145))
* **hugr-py:** Add `StaticArray` to standard extensions
([#1985](#1985))
([cf860f3](cf860f3)),
closes [#1984](#1984)
* **hugr-py:** Support envelope compression
([#1994](#1994))
([434c563](434c563))


### Bug Fixes

* StaticArrayValue serialisation
([#2009](#2009))
([3fe6bf8](3fe6bf8))


### Reverts

* Revert breaking change to StaticArrayValue
([33a2b49](33a2b49))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: hugrbot <[email protected]>
@hugrbot hugrbot mentioned this pull request Mar 21, 2025
github-merge-queue bot pushed a commit that referenced this pull request Mar 21, 2025
## 🤖 New release

* `hugr-core`: 0.15.1 -> 0.15.2 (✓ API compatible changes)
* `hugr-llvm`: 0.15.1 -> 0.15.2
* `hugr-passes`: 0.15.1 -> 0.15.2
* `hugr`: 0.15.1 -> 0.15.2 (✓ API compatible changes)
* `hugr-cli`: 0.15.1 -> 0.15.2

<details><summary><i><b>Changelog</b></i></summary><p>

## `hugr-core`

<blockquote>

##
[0.15.2](hugr-core-v0.15.1...hugr-core-v0.15.2)
- 2025-03-21

### Bug Fixes

- Don't enable envelope compression by default (yet)
([#2014](#2014))
- Inconsistent behaviour in `SiblingSubgraph::from_nodes`
([#2011](#2011))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.15.1](hugr-llvm-v0.15.0...hugr-llvm-v0.15.1)
- 2025-03-21

### Bug Fixes

- Remove return from val_or_panic
([#1999](#1999))

### New Features

- add exit operation to prelude
([#2008](#2008))
- Add llvm codegen for collections.static_array
([#2003](#2003))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.15.1](hugr-passes-v0.15.0...hugr-passes-v0.15.1)
- 2025-03-21

### Bug Fixes

- correct `CallIndirect` tag from `FnCall` to `DataflowChild`
([#2006](#2006))
</blockquote>

## `hugr`

<blockquote>

##
[0.15.2](hugr-v0.15.1...hugr-v0.15.2)
- 2025-03-21

### Bug Fixes

- Don't enable envelope compression by default (yet)
([#2014](#2014))
- Inconsistent behaviour in `SiblingSubgraph::from_nodes`
([#2011](#2011))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.15.1](hugr-cli-v0.15.0...hugr-cli-v0.15.1)
- 2025-03-21

### New Features

- *(hugr-cli)* Nicer error when passing a non-envelope file
([#2007](#2007))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
@hugrbot hugrbot mentioned this pull request Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants