From 9dddf7b44ef97c874b63fe402a6e7b577bd914a5 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 16 Apr 2024 09:57:35 -0300 Subject: [PATCH 1/5] Add scopeless lambdas and variables readback --- src/term/net_to_term.rs | 30 +++++++- tests/snapshots/cli__debug_list_map.hvm.snap | 72 +++++++++---------- .../readback_lnet__complicated_dup.hvm.snap | 2 +- 3 files changed, 66 insertions(+), 38 deletions(-) diff --git a/src/term/net_to_term.rs b/src/term/net_to_term.rs index 98232d7ea..9d6928cb9 100644 --- a/src/term/net_to_term.rs +++ b/src/term/net_to_term.rs @@ -25,6 +25,8 @@ pub fn net_to_term( namegen: Default::default(), seen: Default::default(), errors: Default::default(), + vars: Default::default(), + unsc_vars: Default::default(), }; let mut term = reader.read_term(net.enter_port(ROOT)); @@ -47,6 +49,19 @@ pub fn net_to_term( debug_assert_eq!(result, None); } + fn switch_lam_to_chn(term: &mut Term, unsc: &HashSet) { + if let Term::Lam { tag, nam: Some(nam), bod } = term { + if unsc.contains(nam) { + *term = Term::Chn { tag: std::mem::take(tag), nam: Some(nam.clone()), bod: std::mem::take(bod) } + } + } + for child in term.children_mut() { + switch_lam_to_chn(child, unsc); + } + } + + switch_lam_to_chn(&mut term, &reader.unsc_vars); + reader.report_errors(diagnostics); term } @@ -65,6 +80,8 @@ pub struct Reader<'a> { seen_fans: Scope, seen: HashSet, errors: Vec, + vars: HashSet, + unsc_vars: HashSet, } impl Reader<'_> { @@ -88,11 +105,22 @@ impl Reader<'_> { // If we're visiting a port 0, then it is a lambda. 0 => { let nam = self.namegen.decl_name(self.net, Port(node, 1)); + if let Some(nam) = &nam { + self.vars.insert(nam.clone()); + } let bod = self.read_term(self.net.enter_port(Port(node, 2))); Term::Lam { tag: self.labels.con.to_tag(*lab), nam, bod: Box::new(bod) } } // If we're visiting a port 1, then it is a variable. - 1 => Term::Var { nam: self.namegen.var_name(next) }, + 1 => { + let nam = self.namegen.var_name(next); + if self.vars.contains(&nam) { + Term::Var { nam } + } else { + self.unsc_vars.insert(nam.clone()); + Term::Lnk { nam } + } + } // If we're visiting a port 2, then it is an application. 2 => { let fun = self.read_term(self.net.enter_port(Port(node, 0))); diff --git a/tests/snapshots/cli__debug_list_map.hvm.snap b/tests/snapshots/cli__debug_list_map.hvm.snap index 29518e9a1..df8165e31 100644 --- a/tests/snapshots/cli__debug_list_map.hvm.snap +++ b/tests/snapshots/cli__debug_list_map.hvm.snap @@ -2,77 +2,77 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/cli/debug_list_map.hvm --- -#List λa #List λ* #List (a b c) +#List λa #List λ* #List (a $b $c) --------------------------------------- -#List λa #List λ* #List (a b c) +#List λa #List λ* #List (a $b $c) --------------------------------------- -#List λa #List λ* #List (a b c) +#List λa #List λ* #List (a $b $c) --------------------------------------- -#List λa #List λ* #List (a b c) +#List λa #List λ* #List (a $b $c) --------------------------------------- -#List λa #List λ* #List (a b c) +#List λa #List λ* #List (a $b $c) --------------------------------------- -#List λa #List λ* #List (a b c) +#List λa #List λ* #List (a $b $c) --------------------------------------- -#List λa #List λ* #List (a b c) +#List λa #List λ* #List (a $b $c) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d e)) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d $e)) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d e)) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d $e)) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d e)) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d $e)) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d e)) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d $e)) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d e)) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d $e)) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d e)) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d $e)) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d e)) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d $e)) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f g))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f $g))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f g))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f $g))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f g))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f $g))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f g))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f $g))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f g))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f $g))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f g))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f $g))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f g))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f $g))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h $i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h $i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h $i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h $i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h $i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h $i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h $i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h #List λ* #List λi i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h #List λ* #List λi i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h #List λ* #List λi i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h #List λ* #List λi i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h #List λ* #List λi i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h #List λ* #List λi i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h #List λ* #List λi i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h #List λ* #List λi i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g h #List λ* #List λi i)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g $h #List λ* #List λi i)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e f #List λg #List λ* #List (g 91 #List λ* #List λh h)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e $f #List λg #List λ* #List (g 91 #List λ* #List λh h)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c d #List λe #List λ* #List (e 256 #List λf #List λ* #List (f 91 #List λ* #List λg g)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c $d #List λe #List λ* #List (e 256 #List λf #List λ* #List (f 91 #List λ* #List λg g)))) --------------------------------------- -#List λa #List λ* #List (a b #List λc #List λ* #List (c 42 #List λd #List λ* #List (d 256 #List λe #List λ* #List (e 91 #List λ* #List λf f)))) +#List λa #List λ* #List (a $b #List λc #List λ* #List (c 42 #List λd #List λ* #List (d 256 #List λe #List λ* #List (e 91 #List λ* #List λf f)))) --------------------------------------- #List λa #List λ* #List (a 2 #List λb #List λ* #List (b 42 #List λc #List λ* #List (c 256 #List λd #List λ* #List (d 91 #List λ* #List λe e)))) --------------------------------------- diff --git a/tests/snapshots/readback_lnet__complicated_dup.hvm.snap b/tests/snapshots/readback_lnet__complicated_dup.hvm.snap index 4164310bd..e10fa7755 100644 --- a/tests/snapshots/readback_lnet__complicated_dup.hvm.snap +++ b/tests/snapshots/readback_lnet__complicated_dup.hvm.snap @@ -2,4 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/readback_lnet/complicated_dup.hvm --- -λa (λb (a (b c)) λc (a (b c))) +λa (λb (a (b $c)) λ$c (a (b c))) From 57ab78dfcd1f5dda6376a1c5cf617cfc18d6bfd7 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 16 Apr 2024 10:38:55 -0300 Subject: [PATCH 2/5] Change readback vars insertion --- src/term/net_to_term.rs | 18 ++++++++++-------- .../readback_lnet__complicated_dup.hvm.snap | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/term/net_to_term.rs b/src/term/net_to_term.rs index 9d6928cb9..a30975557 100644 --- a/src/term/net_to_term.rs +++ b/src/term/net_to_term.rs @@ -26,7 +26,7 @@ pub fn net_to_term( seen: Default::default(), errors: Default::default(), vars: Default::default(), - unsc_vars: Default::default(), + uncoped_vars: Default::default(), }; let mut term = reader.read_term(net.enter_port(ROOT)); @@ -49,18 +49,18 @@ pub fn net_to_term( debug_assert_eq!(result, None); } - fn switch_lam_to_chn(term: &mut Term, unsc: &HashSet) { + fn switch_lam_to_chn(term: &mut Term, uncoped_vars: &HashSet) { if let Term::Lam { tag, nam: Some(nam), bod } = term { - if unsc.contains(nam) { + if uncoped_vars.contains(nam) { *term = Term::Chn { tag: std::mem::take(tag), nam: Some(nam.clone()), bod: std::mem::take(bod) } } } for child in term.children_mut() { - switch_lam_to_chn(child, unsc); + switch_lam_to_chn(child, uncoped_vars); } } - switch_lam_to_chn(&mut term, &reader.unsc_vars); + switch_lam_to_chn(&mut term, &reader.uncoped_vars); reader.report_errors(diagnostics); term @@ -81,7 +81,7 @@ pub struct Reader<'a> { seen: HashSet, errors: Vec, vars: HashSet, - unsc_vars: HashSet, + uncoped_vars: HashSet, } impl Reader<'_> { @@ -106,7 +106,9 @@ impl Reader<'_> { 0 => { let nam = self.namegen.decl_name(self.net, Port(node, 1)); if let Some(nam) = &nam { - self.vars.insert(nam.clone()); + if !self.uncoped_vars.contains(&nam) { + self.vars.insert(nam.clone()); + } } let bod = self.read_term(self.net.enter_port(Port(node, 2))); Term::Lam { tag: self.labels.con.to_tag(*lab), nam, bod: Box::new(bod) } @@ -117,7 +119,7 @@ impl Reader<'_> { if self.vars.contains(&nam) { Term::Var { nam } } else { - self.unsc_vars.insert(nam.clone()); + self.uncoped_vars.insert(nam.clone()); Term::Lnk { nam } } } diff --git a/tests/snapshots/readback_lnet__complicated_dup.hvm.snap b/tests/snapshots/readback_lnet__complicated_dup.hvm.snap index e10fa7755..cd1262a34 100644 --- a/tests/snapshots/readback_lnet__complicated_dup.hvm.snap +++ b/tests/snapshots/readback_lnet__complicated_dup.hvm.snap @@ -2,4 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/readback_lnet/complicated_dup.hvm --- -λa (λb (a (b $c)) λ$c (a (b c))) +λa (λb (a (b $c)) λ$c (a (b $c))) From 40b25ce47465197873af1d07c323d3d141ce51ac Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 16 Apr 2024 10:49:23 -0300 Subject: [PATCH 3/5] Apply clippy suggestions and fix typo --- src/term/net_to_term.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/term/net_to_term.rs b/src/term/net_to_term.rs index a30975557..e2028f201 100644 --- a/src/term/net_to_term.rs +++ b/src/term/net_to_term.rs @@ -26,7 +26,7 @@ pub fn net_to_term( seen: Default::default(), errors: Default::default(), vars: Default::default(), - uncoped_vars: Default::default(), + unscoped_vars: Default::default(), }; let mut term = reader.read_term(net.enter_port(ROOT)); @@ -49,18 +49,18 @@ pub fn net_to_term( debug_assert_eq!(result, None); } - fn switch_lam_to_chn(term: &mut Term, uncoped_vars: &HashSet) { + fn switch_lam_to_chn(term: &mut Term, unscoped_vars: &HashSet) { if let Term::Lam { tag, nam: Some(nam), bod } = term { - if uncoped_vars.contains(nam) { + if unscoped_vars.contains(nam) { *term = Term::Chn { tag: std::mem::take(tag), nam: Some(nam.clone()), bod: std::mem::take(bod) } } } for child in term.children_mut() { - switch_lam_to_chn(child, uncoped_vars); + switch_lam_to_chn(child, unscoped_vars); } } - switch_lam_to_chn(&mut term, &reader.uncoped_vars); + switch_lam_to_chn(&mut term, &reader.unscoped_vars); reader.report_errors(diagnostics); term @@ -81,7 +81,7 @@ pub struct Reader<'a> { seen: HashSet, errors: Vec, vars: HashSet, - uncoped_vars: HashSet, + unscoped_vars: HashSet, } impl Reader<'_> { @@ -106,7 +106,7 @@ impl Reader<'_> { 0 => { let nam = self.namegen.decl_name(self.net, Port(node, 1)); if let Some(nam) = &nam { - if !self.uncoped_vars.contains(&nam) { + if !self.unscoped_vars.contains(nam) { self.vars.insert(nam.clone()); } } @@ -119,7 +119,7 @@ impl Reader<'_> { if self.vars.contains(&nam) { Term::Var { nam } } else { - self.uncoped_vars.insert(nam.clone()); + self.unscoped_vars.insert(nam.clone()); Term::Lnk { nam } } } From 361410dbebcdce0bc424b99ac77d075d1159650d Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 16 Apr 2024 11:59:33 -0300 Subject: [PATCH 4/5] Change unscoped lambda readback approach --- src/term/net_to_term.rs | 73 +++++++++++-------- .../linear_readback__church_mul.hvm.snap | 2 +- .../readback_lnet__complicated_dup.hvm.snap | 2 +- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/term/net_to_term.rs b/src/term/net_to_term.rs index e2028f201..db2dc97a5 100644 --- a/src/term/net_to_term.rs +++ b/src/term/net_to_term.rs @@ -25,8 +25,6 @@ pub fn net_to_term( namegen: Default::default(), seen: Default::default(), errors: Default::default(), - vars: Default::default(), - unscoped_vars: Default::default(), }; let mut term = reader.read_term(net.enter_port(ROOT)); @@ -49,20 +47,13 @@ pub fn net_to_term( debug_assert_eq!(result, None); } - fn switch_lam_to_chn(term: &mut Term, unscoped_vars: &HashSet) { - if let Term::Lam { tag, nam: Some(nam), bod } = term { - if unscoped_vars.contains(nam) { - *term = Term::Chn { tag: std::mem::take(tag), nam: Some(nam.clone()), bod: std::mem::take(bod) } - } - } - for child in term.children_mut() { - switch_lam_to_chn(child, unscoped_vars); - } - } + reader.report_errors(diagnostics); - switch_lam_to_chn(&mut term, &reader.unscoped_vars); + let mut unscoped = HashSet::new(); + let mut scope = Vec::new(); + term.collect_unscoped(&mut unscoped, &mut scope); + term.apply_unscoped(&unscoped); - reader.report_errors(diagnostics); term } @@ -80,8 +71,6 @@ pub struct Reader<'a> { seen_fans: Scope, seen: HashSet, errors: Vec, - vars: HashSet, - unscoped_vars: HashSet, } impl Reader<'_> { @@ -105,24 +94,11 @@ impl Reader<'_> { // If we're visiting a port 0, then it is a lambda. 0 => { let nam = self.namegen.decl_name(self.net, Port(node, 1)); - if let Some(nam) = &nam { - if !self.unscoped_vars.contains(nam) { - self.vars.insert(nam.clone()); - } - } let bod = self.read_term(self.net.enter_port(Port(node, 2))); Term::Lam { tag: self.labels.con.to_tag(*lab), nam, bod: Box::new(bod) } } // If we're visiting a port 1, then it is a variable. - 1 => { - let nam = self.namegen.var_name(next); - if self.vars.contains(&nam) { - Term::Var { nam } - } else { - self.unscoped_vars.insert(nam.clone()); - Term::Lnk { nam } - } - } + 1 => Term::Var { nam: self.namegen.var_name(next) }, // If we're visiting a port 2, then it is an application. 2 => { let fun = self.read_term(self.net.enter_port(Port(node, 0))); @@ -502,3 +478,40 @@ impl std::fmt::Display for ReadbackError { } } } + +impl Term { + pub fn collect_unscoped(&self, unscoped: &mut HashSet, scope: &mut Vec) { + match self { + Term::Var { nam } if !scope.contains(nam) => _ = unscoped.insert(nam.clone()), + _ => {} + } + for (child, binds) in self.children_with_binds() { + let binds: Vec<_> = binds.collect(); + for bind in binds.iter() { + if let Some(nam) = bind { + scope.push(nam.clone()); + } + } + child.collect_unscoped(unscoped, scope); + for bind in binds.into_iter() { + if let Some(_) = bind { + scope.pop(); + } + } + } + } + + pub fn apply_unscoped(&mut self, unscoped: &HashSet) { + match self { + Term::Var { nam } if unscoped.contains(nam) => *self = Term::Lnk { nam: std::mem::take(nam) }, + Term::Lam { tag, nam: Some(nam), bod } if unscoped.contains(nam) => { + *self = + Term::Chn { tag: std::mem::take(tag), nam: Some(std::mem::take(nam)), bod: std::mem::take(bod) }; + } + _ => {} + } + for child in self.children_mut() { + child.apply_unscoped(unscoped); + } + } +} diff --git a/tests/snapshots/linear_readback__church_mul.hvm.snap b/tests/snapshots/linear_readback__church_mul.hvm.snap index 28943046b..e6d241759 100644 --- a/tests/snapshots/linear_readback__church_mul.hvm.snap +++ b/tests/snapshots/linear_readback__church_mul.hvm.snap @@ -2,4 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/linear_readback/church_mul.hvm --- -λa λb let #0{c g} = (let #1{d h} = a; d let #1{e f} = h; (e (f #0{g b}))); c +λa λb let #0{c g} = (let #1{d h} = a; d let #1{e f} = $h; (e (f #0{$g b}))); c diff --git a/tests/snapshots/readback_lnet__complicated_dup.hvm.snap b/tests/snapshots/readback_lnet__complicated_dup.hvm.snap index cd1262a34..d878e9c70 100644 --- a/tests/snapshots/readback_lnet__complicated_dup.hvm.snap +++ b/tests/snapshots/readback_lnet__complicated_dup.hvm.snap @@ -2,4 +2,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/readback_lnet/complicated_dup.hvm --- -λa (λb (a (b $c)) λ$c (a (b $c))) +λa (λ$b (a ($b $c)) λ$c (a ($b $c))) From 5124e82a119e076c5ceac945d66530983442408b Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 16 Apr 2024 12:01:41 -0300 Subject: [PATCH 5/5] Apply clippy suggestions --- src/term/net_to_term.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/term/net_to_term.rs b/src/term/net_to_term.rs index db2dc97a5..c958ded08 100644 --- a/src/term/net_to_term.rs +++ b/src/term/net_to_term.rs @@ -487,16 +487,12 @@ impl Term { } for (child, binds) in self.children_with_binds() { let binds: Vec<_> = binds.collect(); - for bind in binds.iter() { - if let Some(nam) = bind { - scope.push(nam.clone()); - } + for bind in binds.iter().copied().flatten() { + scope.push(bind.clone()); } child.collect_unscoped(unscoped, scope); - for bind in binds.into_iter() { - if let Some(_) = bind { - scope.pop(); - } + for _bind in binds.into_iter().flatten() { + scope.pop(); } } }