Skip to content

Commit b3dc6a5

Browse files
authored
Merge branch 'main' into ab/sibling-subgraph-from-node
2 parents a77680b + f3dd145 commit b3dc6a5

File tree

38 files changed

+1063
-1359
lines changed

38 files changed

+1063
-1359
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ target/
1212
# Failing proptest artifacts
1313
proptest-regressions/
1414

15+
# snaphsot test failures
16+
*.snap.new
17+
1518
# Devenv
1619
.devenv*
1720
devenv.local.nix

hugr-core/src/std_extensions/collections/static_array.rs

+34-25
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@
1414
//! * `get<T: Copyable>: [static_array<T>, prelude.usize] -> [[] + [T]]`
1515
//! * `len<T: Copyable>: [static_array<T>] -> [prelude.usize]`
1616
use std::{
17-
hash, iter,
17+
hash::{self, Hash as _},
18+
iter,
1819
sync::{self, Arc},
1920
};
2021

2122
use crate::{
2223
builder::{BuildError, Dataflow},
2324
extension::{
2425
prelude::{option_type, usize_t},
25-
resolution::{ExtensionResolutionError, WeakExtensionRegistry},
26+
resolution::{
27+
resolve_type_extensions, resolve_value_extensions, ExtensionResolutionError,
28+
WeakExtensionRegistry,
29+
},
2630
simple_op::{
2731
try_from_name, HasConcrete, HasDef, MakeExtensionOp, MakeOpDef, MakeRegisteredOp,
2832
OpLoadError,
2933
},
3034
ExtensionId, ExtensionSet, OpDef, SignatureError, SignatureFunc, TypeDef,
3135
},
3236
ops::{
33-
constant::{CustomConst, TryHash, ValueName},
37+
constant::{maybe_hash_values, CustomConst, TryHash, ValueName},
3438
ExtensionOp, NamedOp, OpName, Value,
3539
},
3640
types::{
@@ -41,9 +45,6 @@ use crate::{
4145
Extension, Wire,
4246
};
4347

44-
use super::array::ArrayValue;
45-
46-
use delegate::delegate;
4748
use lazy_static::lazy_static;
4849

4950
/// Reported unique name of the extension
@@ -53,22 +54,25 @@ pub const STATIC_ARRAY_TYPENAME: TypeName = TypeName::new_inline("static_array")
5354
/// Extension version.
5455
pub const VERSION: semver::Version = semver::Version::new(0, 1, 0);
5556

56-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, derive_more::From)]
57+
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, derive_more::From)]
5758
/// Statically sized array of values, all of the same [TypeBound::Copyable]
5859
/// type.
5960
pub struct StaticArrayValue {
60-
/// The contents of the `StaticArrayValue`.
61-
pub value: ArrayValue,
61+
values: Vec<Value>,
62+
typ: Type,
6263
/// The name of the `StaticArrayValue`.
6364
pub name: String,
6465
}
6566

6667
impl StaticArrayValue {
67-
delegate! {
68-
to self.value {
69-
/// Returns the type of values inside the `[StaticArrayValue]`.
70-
pub fn get_element_type(&self) -> &Type;
71-
}
68+
/// Returns the type of values inside the `[StaticArrayValue]`.
69+
pub fn get_element_type(&self) -> &Type {
70+
&self.typ
71+
}
72+
73+
/// Returns the values contained inside the `[StaticArrayValue]`.
74+
pub fn get_contents(&self) -> &[Value] {
75+
&self.values
7276
}
7377

7478
/// Create a new [CustomConst] for an array of values of type `typ`.
@@ -85,7 +89,8 @@ impl StaticArrayValue {
8589
.into());
8690
}
8791
Ok(Self {
88-
value: ArrayValue::new(typ, contents),
92+
typ,
93+
values: contents.into_iter().collect(),
8994
name: name.to_string(),
9095
})
9196
}
@@ -102,9 +107,12 @@ impl StaticArrayValue {
102107
}
103108

104109
impl TryHash for StaticArrayValue {
105-
fn try_hash(&self, st: &mut dyn hash::Hasher) -> bool {
106-
st.write(self.name.as_bytes());
107-
self.value.try_hash(st)
110+
fn try_hash(&self, mut st: &mut dyn hash::Hasher) -> bool {
111+
maybe_hash_values(&self.values, &mut st) && {
112+
self.name.hash(&mut st);
113+
self.typ.hash(&mut st);
114+
true
115+
}
108116
}
109117
}
110118

@@ -123,17 +131,18 @@ impl CustomConst for StaticArrayValue {
123131
}
124132

125133
fn extension_reqs(&self) -> ExtensionSet {
126-
ExtensionSet::union_over(self.value.get_contents().iter().map(Value::extension_reqs))
134+
ExtensionSet::union_over(self.values.iter().map(Value::extension_reqs))
127135
.union(EXTENSION_ID.into())
128136
}
129137

130-
delegate! {
131-
to self.value {
132-
fn update_extensions(
133-
&mut self,
134-
extensions: &WeakExtensionRegistry,
135-
) -> Result<(), ExtensionResolutionError>;
138+
fn update_extensions(
139+
&mut self,
140+
extensions: &WeakExtensionRegistry,
141+
) -> Result<(), ExtensionResolutionError> {
142+
for val in &mut self.values {
143+
resolve_value_extensions(val, extensions)?;
136144
}
145+
resolve_type_extensions(&mut self.typ, extensions)
137146
}
138147
}
139148

hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop@pre-mem2reg@llvm14_2.snap

-168
This file was deleted.

hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop_simple@pre-mem2reg@llvm14_3.snap

-55
This file was deleted.

hugr-llvm/src/emit/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl SimpleHugrConfig {
163163
logic::EXTENSION_ID,
164164
collections::array::EXTENSION_ID,
165165
collections::list::EXTENSION_ID,
166+
collections::static_array::EXTENSION_ID,
166167
]),
167168
),
168169
)

hugr-llvm/src/extension/collections.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
33
pub mod array;
44
pub mod list;
5+
pub mod static_array;

0 commit comments

Comments
 (0)