Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-q committed Dec 11, 2024
1 parent efc461a commit 703004e
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 163 deletions.
69 changes: 36 additions & 33 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"lastModified": 1733328505,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
Expand All @@ -51,10 +51,32 @@
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1733665616,
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "d8c02f0ffef0ef39f6063731fc539d8c71eb463a",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"git-hooks",
"nixpkgs"
]
},
Expand Down Expand Up @@ -88,63 +110,44 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1704290814,
"lastModified": 1733730953,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421",
"rev": "7109b680d161993918b0a126f38bc39763e5a709",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1728193676,
"lastModified": 1704290814,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ecbc1ca8ffd6aea8372ad16be9ebbb39889e55b6",
"rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable_2"
},
"locked": {
"lastModified": 1728092656,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "1211305a5b237771e13fcca0c51e60ad47326a9a",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"fenix": "fenix",
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs",
"nixpkgs-stable": "nixpkgs-stable",
"pre-commit-hooks": "pre-commit-hooks"
"nixpkgs-stable": "nixpkgs-stable_2",
"pre-commit-hooks": [
"git-hooks"
]
}
},
"rust-analyzer-src": {
Expand Down
5 changes: 2 additions & 3 deletions hugr-core/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use crate::extension::resolution::{
use std::borrow::Cow;

use crate::extension::simple_op::MakeExtensionOp;
use crate::extension::{ExtensionId, ExtensionSet};
use crate::extension::{ExtensionId, ExtensionSet, ExtensionRegistry};
use crate::types::{EdgeKind, Signature, Substitution};
use crate::extension::{ExtensionId, ExtensionRegistry, ExtensionSet};
use crate::{Direction, OutgoingPort, Port};
use crate::{IncomingPort, PortIndex};
use derive_more::Display;
Expand Down Expand Up @@ -437,7 +436,7 @@ pub trait OpTrait: Sized + Clone {

/// Apply a type-level substitution to this OpType, i.e. replace
/// [type variables](crate::types::TypeArg::new_var_use) with new types.
fn substitute(&self, _subst: &Substitution) -> Self {
fn substitute(&self, _subst: &Substitution, _reg: &ExtensionRegistry) -> Self {
self.clone()
}
}
Expand Down
54 changes: 28 additions & 26 deletions hugr-core/src/ops/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::borrow::Cow;

use crate::extension::ExtensionSet;
use crate::extension::{ExtensionRegistry, ExtensionSet};
use crate::types::{EdgeKind, Signature, Type, TypeRow};
use crate::Direction;

Expand Down Expand Up @@ -42,11 +42,11 @@ impl DataflowOpTrait for TailLoop {
)
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
Self {
just_inputs: self.just_inputs.substitute(subst),
just_outputs: self.just_outputs.substitute(subst),
rest: self.rest.substitute(subst),
just_inputs: self.just_inputs.substitute(subst, reg),
just_outputs: self.just_outputs.substitute(subst, reg),
rest: self.rest.substitute(subst, reg),
extension_delta: self.extension_delta.substitute(subst),
}
}
Expand Down Expand Up @@ -121,11 +121,11 @@ impl DataflowOpTrait for Conditional {
)
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
Self {
sum_rows: self.sum_rows.iter().map(|r| r.substitute(subst)).collect(),
other_inputs: self.other_inputs.substitute(subst),
outputs: self.outputs.substitute(subst),
sum_rows: self.sum_rows.iter().map(|r| r.substitute(subst, reg)).collect(),
other_inputs: self.other_inputs.substitute(subst, reg),
outputs: self.outputs.substitute(subst, reg),
extension_delta: self.extension_delta.substitute(subst),
}
}
Expand Down Expand Up @@ -159,9 +159,9 @@ impl DataflowOpTrait for CFG {
Cow::Borrowed(&self.signature)
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
Self {
signature: self.signature.substitute(subst),
signature: self.signature.substitute(subst, reg),
}
}
}
Expand Down Expand Up @@ -248,11 +248,11 @@ impl OpTrait for DataflowBlock {
}
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
Self {
inputs: self.inputs.substitute(subst),
other_outputs: self.other_outputs.substitute(subst),
sum_rows: self.sum_rows.iter().map(|r| r.substitute(subst)).collect(),
inputs: self.inputs.substitute(subst, reg),
other_outputs: self.other_outputs.substitute(subst, reg),
sum_rows: self.sum_rows.iter().map(|r| r.substitute(subst, reg)).collect(),
extension_delta: self.extension_delta.substitute(subst),
}
}
Expand Down Expand Up @@ -282,9 +282,9 @@ impl OpTrait for ExitBlock {
}
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
Self {
cfg_outputs: self.cfg_outputs.substitute(subst),
cfg_outputs: self.cfg_outputs.substitute(subst, reg),
}
}
}
Expand Down Expand Up @@ -351,9 +351,9 @@ impl OpTrait for Case {
<Self as StaticTag>::TAG
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
Self {
signature: self.signature.substitute(subst),
signature: self.signature.substitute(subst, reg),
}
}
}
Expand All @@ -372,6 +372,8 @@ impl Case {

#[cfg(test)]
mod test {
use std::borrow::Borrow;

use crate::{
extension::{
prelude::{qb_t, usize_t, PRELUDE_ID},
Expand Down Expand Up @@ -399,9 +401,9 @@ mod test {
TypeArg::Extensions {
es: PRELUDE_ID.into(),
},
],
]),
&PRELUDE_REGISTRY,
));
);
let st = Type::new_sum(vec![vec![usize_t()], vec![qb_t(); 2]]);
assert_eq!(
dfb2.inner_signature(),
Expand All @@ -425,9 +427,9 @@ mod test {
elems: vec![usize_t().into(); 3],
},
qb_t().into(),
],
]),
&PRELUDE_REGISTRY,
));
);
let st = Type::new_sum(vec![usize_t(), qb_t()]); //both single-element variants
assert_eq!(
cond2.signature(),
Expand All @@ -453,12 +455,12 @@ mod test {
TypeArg::Extensions {
es: PRELUDE_ID.into(),
},
],
]),
&PRELUDE_REGISTRY,
));
);
assert_eq!(
tail2.signature(),
Signature::new(
ow r::new(
vec![qb_t(), usize_t(), usize_t()],
vec![usize_t(), qb_t(), usize_t()]
)
Expand Down
14 changes: 7 additions & 7 deletions hugr-core/src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ impl DataflowOpTrait for ExtensionOp {
Cow::Borrowed(&self.signature)
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
let args = self
.args
.iter()
.map(|ta| ta.substitute(subst))
.map(|ta| ta.substitute(subst, reg))
.collect::<Vec<_>>();
let signature = self.signature.substitute(subst);
let signature = self.signature.substitute(subst, reg);
debug_assert_eq!(
self.def
.compute_signature(&args, subst.extension_registry())
.compute_signature(&args, reg)
.as_ref(),
Ok(&signature)
);
Expand Down Expand Up @@ -280,10 +280,10 @@ impl DataflowOpTrait for OpaqueOp {
Cow::Borrowed(&self.signature)
}

fn substitute(&self, subst: &crate::types::Substitution) -> Self {
fn substitute(&self, subst: &crate::types::Substitution, reg: &ExtensionRegistry) -> Self {
Self {
args: self.args.iter().map(|ta| ta.substitute(subst)).collect(),
signature: self.signature.substitute(subst),
args: self.args.iter().map(|ta| ta.substitute(subst, reg)).collect(),
signature: self.signature.substitute(subst, reg),
..self.clone()
}
}
Expand Down
Loading

0 comments on commit 703004e

Please sign in to comment.