@@ -126,16 +126,16 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
126
126
/// of `self`.
127
127
///
128
128
/// The returned port will be in `replacement`, unless the wire in the
129
- /// replacement is empty and `return_invalid ` is
130
- /// [`BoundaryMode::SnapToHost`] (the default), in which case it
131
- /// will be another `host` port. If [`BoundaryMode::IncludeIO`] is
132
- /// passed, the returned port will always be in `replacement` even if it
133
- /// is invalid (i.e. it is an IO node in the replacement).
129
+ /// replacement is empty and `boundary ` is [`BoundaryMode::SnapToHost`] (the
130
+ /// default), in which case it will be another `host` port. If
131
+ /// [`BoundaryMode::IncludeIO`] is passed, the returned port will always
132
+ /// be in `replacement` even if it is invalid (i.e. it is an IO node in
133
+ /// the replacement).
134
134
pub fn linked_replacement_output (
135
135
& self ,
136
136
port : impl Into < HostPort < HostNode , IncomingPort > > ,
137
137
host : & impl HugrView < Node = HostNode > ,
138
- return_invalid : BoundaryMode ,
138
+ boundary : BoundaryMode ,
139
139
) -> Option < BoundaryPort < HostNode , OutgoingPort > > {
140
140
let HostPort ( node, port) = port. into ( ) ;
141
141
let pos = self
@@ -144,7 +144,7 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
144
144
. iter ( )
145
145
. position ( move |& ( n, p) | host. linked_inputs ( n, p) . contains ( & ( node, port) ) ) ?;
146
146
147
- Some ( self . linked_replacement_output_by_position ( pos, host, return_invalid ) )
147
+ Some ( self . linked_replacement_output_by_position ( pos, host, boundary ) )
148
148
}
149
149
150
150
/// The outgoing port linked to the i-th output boundary edge of `subgraph`.
@@ -155,7 +155,7 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
155
155
& self ,
156
156
pos : usize ,
157
157
host : & impl HugrView < Node = HostNode > ,
158
- return_invalid : BoundaryMode ,
158
+ boundary : BoundaryMode ,
159
159
) -> BoundaryPort < HostNode , OutgoingPort > {
160
160
debug_assert ! ( pos < self . subgraph( ) . signature( host) . output_count( ) ) ;
161
161
@@ -166,7 +166,7 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
166
166
. single_linked_output ( repl_out, pos)
167
167
. expect ( "valid dfg wire" ) ;
168
168
169
- if out_node != repl_inp || return_invalid == BoundaryMode :: IncludeIO {
169
+ if out_node != repl_inp || boundary == BoundaryMode :: IncludeIO {
170
170
BoundaryPort :: Replacement ( out_node, out_port)
171
171
} else {
172
172
let ( in_node, in_port) = * self . subgraph . incoming_ports ( ) [ out_port. index ( ) ]
@@ -213,17 +213,16 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
213
213
/// of `self`.
214
214
///
215
215
/// The returned ports will be in `replacement`, unless the wires in the
216
- /// replacement are empty and `return_invalid` is
217
- /// [`BoundaryMode::SnapToHost`] (the default), in which case they
218
- /// will be other `host` ports. If [`BoundaryMode::IncludeIO`] is
219
- /// passed, the returned ports will always be in
220
- /// `replacement` even if they are invalid (i.e. they are an IO node in
221
- /// the replacement).
216
+ /// replacement are empty and `boundary` is [`BoundaryMode::SnapToHost`]
217
+ /// (the default), in which case they will be other `host` ports. If
218
+ /// [`BoundaryMode::IncludeIO`] is passed, the returned ports will
219
+ /// always be in `replacement` even if they are invalid (i.e. they are
220
+ /// an IO node in the replacement).
222
221
pub fn linked_replacement_inputs < ' a > (
223
222
& ' a self ,
224
223
port : impl Into < HostPort < HostNode , OutgoingPort > > ,
225
224
host : & ' a impl HugrView < Node = HostNode > ,
226
- return_invalid : BoundaryMode ,
225
+ boundary : BoundaryMode ,
227
226
) -> impl Iterator < Item = BoundaryPort < HostNode , IncomingPort > > + ' a {
228
227
let HostPort ( node, port) = port. into ( ) ;
229
228
let positions = self
@@ -235,25 +234,24 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
235
234
host. single_linked_output ( n, p) . expect ( "valid dfg wire" ) == ( node, port)
236
235
} ) ;
237
236
238
- positions. flat_map ( move |pos| {
239
- self . linked_replacement_inputs_by_position ( pos, host, return_invalid)
240
- } )
237
+ positions
238
+ . flat_map ( move |pos| self . linked_replacement_inputs_by_position ( pos, host, boundary) )
241
239
}
242
240
243
241
/// The incoming ports linked to the i-th input boundary edge of `subgraph`.
244
242
fn linked_replacement_inputs_by_position (
245
243
& self ,
246
244
pos : usize ,
247
245
host : & impl HugrView < Node = HostNode > ,
248
- return_invalid : BoundaryMode ,
246
+ boundary : BoundaryMode ,
249
247
) -> impl Iterator < Item = BoundaryPort < HostNode , IncomingPort > > {
250
248
debug_assert ! ( pos < self . subgraph( ) . signature( host) . input_count( ) ) ;
251
249
252
250
let [ repl_inp, repl_out] = self . get_replacement_io ( ) ;
253
251
self . replacement
254
252
. linked_inputs ( repl_inp, pos)
255
253
. flat_map ( move |( in_node, in_port) | {
256
- if in_node != repl_out || return_invalid == BoundaryMode :: IncludeIO {
254
+ if in_node != repl_out || boundary == BoundaryMode :: IncludeIO {
257
255
Either :: Left ( std:: iter:: once ( BoundaryPort :: Replacement ( in_node, in_port) ) )
258
256
} else {
259
257
let ( out_node, out_port) = self . subgraph . outgoing_ports ( ) [ in_port. index ( ) ] ;
@@ -552,8 +550,8 @@ impl<HostNode: HugrNode> PatchVerification for SimpleReplacement<HostNode> {
552
550
}
553
551
}
554
552
555
- /// In [`SimpleReplacement`], some nodes in the replacement may not be valid
556
- /// after the replacement is applied.
553
+ /// In [`SimpleReplacement::replacement `], IO nodes marking the boundary will
554
+ /// not be valid nodes in the host after the replacement is applied.
557
555
///
558
556
/// This enum allows specifying whether these invalid nodes on the boundary
559
557
/// should be returned or should be resolved to valid nodes in the host.
0 commit comments