| @@ -27,6 +27,7 @@ |
| 27 | 27 | //! Derived impls are lowered in [`derive`], HTML literals in [`html`], |
| 28 | 28 | //! template literals in [`template`], and patterns in [`pattern`]. |
| 29 | 29 | |
| 30 | +mod closed; |
| 30 | 31 | mod derive; |
| 31 | 32 | mod html; |
| 32 | 33 | mod pattern; |
| @@ -59,9 +60,6 @@ enum Key { |
| 59 | 60 | /// The `i`-th dictionary stored in the value a refined constructor |
| 60 | 61 | /// pattern matched (ADR 0041). |
| 61 | 62 | Stored(PatId, u32), |
| 62 | | − /// A plain variable captured by a partial application's closure |
| 63 | | − /// (ADR 0062), by its id. |
| 64 | | − Capture(VarId), |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | 65 | fn cap_key(instance: &Ty) -> Option<Key> { |
| @@ -219,6 +217,8 @@ pub fn lower(hir: &Hir, typeck: &TypeckOutput) -> Program { |
| 219 | 217 | l.declare(); |
| 220 | 218 | l.lower_all(); |
| 221 | 219 | l.program.actor_caps = l.actor_caps(); |
| 220 | + #[cfg(debug_assertions)] |
| 221 | + closed::assert_closed(&l.program); |
| 222 | 222 | l.program |
| 223 | 223 | } |
| 224 | 224 | |
| @@ -271,6 +271,33 @@ fn falls_through(e: &Expr) -> bool { |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | +/// A partial application's slots as which are placed, and the placed |
| 275 | +/// arguments in order. |
| 276 | +fn split_slots(slots: Vec<Option<Atom>>) -> (Vec<bool>, Vec<Atom>) { |
| 277 | + let placed = slots.iter().map(Option::is_some).collect(); |
| 278 | + (placed, slots.into_iter().flatten().collect()) |
| 279 | +} |
| 280 | + |
| 281 | +fn holes(placed: &[bool]) -> usize { |
| 282 | + placed.iter().filter(|p| !**p).count() |
| 283 | +} |
| 284 | + |
| 285 | +/// The arrow's arguments: the placed ones from `given`, in order, and a |
| 286 | +/// hole for each parameter not placed. |
| 287 | +fn fill(placed: &[bool], mut given: impl Iterator<Item = Atom>, holes: Vec<Atom>) -> Vec<Atom> { |
| 288 | + let mut holes = holes.into_iter(); |
| 289 | + placed |
| 290 | + .iter() |
| 291 | + .map(|p| { |
| 292 | + if *p { |
| 293 | + given.next().expect("one per placed argument") |
| 294 | + } else { |
| 295 | + holes.next().expect("one per hole") |
| 296 | + } |
| 297 | + }) |
| 298 | + .collect() |
| 299 | +} |
| 300 | + |
| 274 | 301 | fn bool_value(b: bool) -> Value { |
| 275 | 302 | Value::Construct { |
| 276 | 303 | tag: u32::from(b), |
| @@ -578,53 +605,67 @@ impl<'a> Lowerer<'a> { |
| 578 | 605 | self.frame().vars.insert(key, v); |
| 579 | 606 | } |
| 580 | 607 | |
| 581 | | − /// `v` as a variable of the current frame, captured into it and every |
| 582 | | − /// frame between it and its owner (a partial application's closure, |
| 583 | | − /// ADR 0062). Keyed unlike a local: a variable is captured by identity. |
| 584 | | − fn lookup_var(&mut self, v: VarId) -> VarId { |
| 585 | | − let top = self.frames.len() - 1; |
| 586 | | − if self.frames[top].vars.values().any(|&id| id == v) { |
| 587 | | − return v; |
| 588 | | − } |
| 589 | | − let Some(owner) = (0..top) |
| 590 | | − .rev() |
| 591 | | − .find(|i| self.frames[*i].vars.values().any(|&id| id == v)) |
| 592 | | − else { |
| 593 | | − // A global (a definition's frame): visible as is. |
| 594 | | − return v; |
| 595 | | − }; |
| 596 | | − let mut out = v; |
| 597 | | − for i in owner + 1..=top { |
| 598 | | − let frame = &mut self.frames[i]; |
| 599 | | − out = frame.fresh(); |
| 600 | | − frame.vars.insert(Key::Capture(v), out); |
| 601 | | − frame.captures.push((Key::Capture(v), out)); |
| 602 | | − } |
| 603 | | − out |
| 604 | | − } |
| 605 | | − |
| 606 | | − /// The atom captured into the current frame's closure: a variable is |
| 607 | | − /// threaded through the frames; a literal is recomputed. |
| 608 | | − fn capture_atom(&mut self, a: Atom) -> Atom { |
| 609 | | − match a { |
| 610 | | − Atom::Var(v) => Atom::Var(self.lookup_var(v)), |
| 611 | | − // Atoms are values (a literal or unit is pure). |
| 612 | | − other => other, |
| 613 | | − } |
| 614 | | − } |
| 615 | | − |
| 616 | | − /// The outer atom a `Key::Capture` of the frame's captures names. |
| 617 | | − fn captured_atom(&mut self, key: Key) -> Atom { |
| 618 | | − match key { |
| 619 | | − Key::Capture(v) => { |
| 620 | | − if self.frame().vars.values().any(|&id| id == v) { |
| 621 | | − Atom::Var(v) |
| 622 | | − } else { |
| 623 | | − Atom::Var(self.lookup(key)) |
| 608 | + /// A closure over `outer`, atoms of the current frame, taking `holes` |
| 609 | + /// more arguments (a partial application, ADR 0062, issue #321). Each |
| 610 | + /// distinct variable of `outer` is captured once, as a parameter of |
| 611 | + /// the new function; a literal is used as is. `body` builds the result |
| 612 | + /// from `outer` as the new frame sees it, then the holes. |
| 613 | + fn closure_over( |
| 614 | + &mut self, |
| 615 | + outer: Vec<Atom>, |
| 616 | + holes: usize, |
| 617 | + body: impl FnOnce(&mut Self, std::vec::IntoIter<Atom>, Vec<Atom>) -> Atom, |
| 618 | + ) -> Atom { |
| 619 | + let parent = self.frame(); |
| 620 | + parent.lambdas += 1; |
| 621 | + let name = format!("{}$partial{}", parent.name, parent.lambdas); |
| 622 | + let fid = self.placeholder(name.clone()); |
| 623 | + self.frames.push(Frame::new(name)); |
| 624 | + let mut captured: Vec<(VarId, VarId)> = Vec::new(); |
| 625 | + let inner: Vec<Atom> = outer |
| 626 | + .into_iter() |
| 627 | + .map(|a| match a { |
| 628 | + Atom::Var(v) => { |
| 629 | + let own = match captured.iter().find(|(o, _)| *o == v) { |
| 630 | + Some((_, own)) => *own, |
| 631 | + None => { |
| 632 | + let own = self.fresh(); |
| 633 | + captured.push((v, own)); |
| 634 | + own |
| 635 | + } |
| 636 | + }; |
| 637 | + Atom::Var(own) |
| 624 | 638 | } |
| 625 | | − } |
| 626 | | − other => Atom::Var(self.lookup(other)), |
| 627 | | − } |
| 639 | + other => other, |
| 640 | + }) |
| 641 | + .collect(); |
| 642 | + let holes: Vec<VarId> = (0..holes).map(|_| self.fresh()).collect(); |
| 643 | + let hole_atoms = holes.iter().map(|v| Atom::Var(*v)).collect(); |
| 644 | + let body = self.block_value(|this| body(this, inner.into_iter(), hole_atoms)); |
| 645 | + let frame = self.frames.pop().expect("pushed"); |
| 646 | + let mut params: Vec<VarId> = captured.iter().map(|(_, own)| *own).collect(); |
| 647 | + params.extend(holes); |
| 648 | + self.define( |
| 649 | + fid, |
| 650 | + FnDecl { |
| 651 | + name: frame.name, |
| 652 | + params, |
| 653 | + body, |
| 654 | + n_vars: frame.n_vars, |
| 655 | + borrowed: Default::default(), |
| 656 | + span: self.span, |
| 657 | + module: None, |
| 658 | + shapes: Default::default(), |
| 659 | + fip: false, |
| 660 | + cpr_arity: None, |
| 661 | + unbox_sig: None, |
| 662 | + }, |
| 663 | + ); |
| 664 | + let captures = captured |
| 665 | + .iter() |
| 666 | + .map(|(outer, _)| Atom::Var(*outer)) |
| 667 | + .collect(); |
| 668 | + self.emit(Value::Closure(fid, captures)) |
| 628 | 669 | } |
| 629 | 670 | |
| 630 | 671 | // ---- functions --------------------------------------------------------- |
| @@ -1655,7 +1696,7 @@ impl<'a> Lowerer<'a> { |
| 1655 | 1696 | args, |
| 1656 | 1697 | }) |
| 1657 | 1698 | } |
| 1658 | | − DefKind::Op(_) if !complete => self.partial_perform(def, slots, caps, callee), |
| 1699 | + DefKind::Op(_) if !complete => self.partial_perform(def, slots, caps), |
| 1659 | 1700 | DefKind::Op(_) => { |
| 1660 | 1701 | let (effect, op) = self.effect_and_op(def); |
| 1661 | 1702 | let cap = caps.into_iter().next().unwrap_or(Atom::Unit); |
| @@ -1754,7 +1795,7 @@ impl<'a> Lowerer<'a> { |
| 1754 | 1795 | _ => (Vec::new(), args.len(), Ty::Error), |
| 1755 | 1796 | }; |
| 1756 | 1797 | let chunk: Vec<LabelledAtom> = args.drain(..n.min(args.len())).collect(); |
| 1757 | | − let slots: Vec<Option<Atom>> = if chunk.iter().all(|(l, _)| l.is_none()) { |
| 1798 | + let mut slots: Vec<Option<Atom>> = if chunk.iter().all(|(l, _)| l.is_none()) { |
| 1758 | 1799 | chunk.into_iter().map(|(_, a)| Some(a)).collect() |
| 1759 | 1800 | } else { |
| 1760 | 1801 | let arg_labels: Vec<Option<String>> = |
| @@ -1771,7 +1812,11 @@ impl<'a> Lowerer<'a> { |
| 1771 | 1812 | Err(_) => chunk.into_iter().map(|(_, a)| Some(a)).collect(), |
| 1772 | 1813 | } |
| 1773 | 1814 | }; |
| 1774 | | − let full = slots.len() == n && slots.iter().all(Option::is_some); |
| 1815 | + // The parameters not given are the closure's holes. |
| 1816 | + if slots.len() < n { |
| 1817 | + slots.resize(n, None); |
| 1818 | + } |
| 1819 | + let full = slots.iter().all(Option::is_some); |
| 1775 | 1820 | if full { |
| 1776 | 1821 | let atoms: Vec<Atom> = std::mem::take(&mut caps) |
| 1777 | 1822 | .into_iter() |
| @@ -1780,7 +1825,7 @@ impl<'a> Lowerer<'a> { |
| 1780 | 1825 | cur = self.emit(Value::Call(cur, atoms)); |
| 1781 | 1826 | } else { |
| 1782 | 1827 | // Partial: a closure of the parameters left. |
| 1783 | | − cur = self.eta(cur, slots, std::mem::take(&mut caps), n); |
| 1828 | + cur = self.eta(cur, slots, std::mem::take(&mut caps)); |
| 1784 | 1829 | } |
| 1785 | 1830 | ty = ret; |
| 1786 | 1831 | } |
| @@ -1791,62 +1836,16 @@ impl<'a> Lowerer<'a> { |
| 1791 | 1836 | /// a value (ADR 0062). The callee, the capabilities and the placed |
| 1792 | 1837 | /// arguments are captured; `slots` are the arrow's parameters, the |
| 1793 | 1838 | /// placed ones `Some`. |
| 1794 | | − fn eta( |
| 1795 | | − &mut self, |
| 1796 | | − callee: Atom, |
| 1797 | | − slots: Vec<Option<Atom>>, |
| 1798 | | − caps: Vec<Atom>, |
| 1799 | | − _arity: usize, |
| 1800 | | − ) -> Atom { |
| 1801 | | − let parent = self.frame(); |
| 1802 | | − parent.lambdas += 1; |
| 1803 | | − let name = format!("{}$partial{}", parent.name, parent.lambdas); |
| 1804 | | − let fid = self.placeholder(name.clone()); |
| 1805 | | − self.frames.push(Frame::new(name)); |
| 1806 | | − let callee = self.capture_atom(callee); |
| 1807 | | − let caps: Vec<Atom> = caps.into_iter().map(|c| self.capture_atom(c)).collect(); |
| 1808 | | − let slots: Vec<Option<Atom>> = slots |
| 1809 | | − .into_iter() |
| 1810 | | − .map(|s| s.map(|a| self.capture_atom(a))) |
| 1811 | | − .collect(); |
| 1812 | | − let vars: Vec<VarId> = slots |
| 1813 | | − .iter() |
| 1814 | | − .filter(|s| s.is_none()) |
| 1815 | | − .map(|_| self.fresh()) |
| 1816 | | − .collect(); |
| 1817 | | − let body = self.block_value(|this| { |
| 1818 | | − let mut vars = vars.iter(); |
| 1819 | | − let args: Vec<Atom> = slots |
| 1820 | | − .into_iter() |
| 1821 | | − .map(|s| s.unwrap_or_else(|| Atom::Var(*vars.next().expect("one per hole")))) |
| 1822 | | − .collect(); |
| 1839 | + fn eta(&mut self, callee: Atom, slots: Vec<Option<Atom>>, caps: Vec<Atom>) -> Atom { |
| 1840 | + let n_caps = caps.len(); |
| 1841 | + let (placed, outer) = split_slots(slots); |
| 1842 | + let outer = std::iter::once(callee).chain(caps).chain(outer).collect(); |
| 1843 | + self.closure_over(outer, holes(&placed), |this, mut inner, holes| { |
| 1844 | + let callee = inner.next().expect("the callee"); |
| 1845 | + let caps: Vec<Atom> = inner.by_ref().take(n_caps).collect(); |
| 1846 | + let args = fill(&placed, inner, holes); |
| 1823 | 1847 | this.emit(Value::Call(callee, caps.into_iter().chain(args).collect())) |
| 1824 | | − }); |
| 1825 | | − let frame = self.frames.pop().expect("pushed"); |
| 1826 | | − let mut params: Vec<VarId> = frame.captures.iter().map(|(_, v)| *v).collect(); |
| 1827 | | − params.extend(&vars); |
| 1828 | | − self.define( |
| 1829 | | − fid, |
| 1830 | | − FnDecl { |
| 1831 | | − name: frame.name, |
| 1832 | | − params, |
| 1833 | | − body, |
| 1834 | | − n_vars: frame.n_vars, |
| 1835 | | − borrowed: Default::default(), |
| 1836 | | − span: self.span, |
| 1837 | | − module: None, |
| 1838 | | − shapes: Default::default(), |
| 1839 | | − fip: false, |
| 1840 | | − cpr_arity: None, |
| 1841 | | − unbox_sig: None, |
| 1842 | | − }, |
| 1843 | | − ); |
| 1844 | | − let captures = frame |
| 1845 | | − .captures |
| 1846 | | − .iter() |
| 1847 | | − .map(|(key, _)| self.captured_atom(*key)) |
| 1848 | | − .collect(); |
| 1849 | | − self.emit(Value::Closure(fid, captures)) |
| 1848 | + }) |
| 1850 | 1849 | } |
| 1851 | 1850 | |
| 1852 | 1851 | /// `def` with some arguments given: a closure of the rest (ADR 0062). |
| @@ -1859,152 +1858,63 @@ impl<'a> Lowerer<'a> { |
| 1859 | 1858 | caps: Vec<Atom>, |
| 1860 | 1859 | site: ExprId, |
| 1861 | 1860 | ) -> Atom { |
| 1862 | | − let parent = self.frame(); |
| 1863 | | − parent.lambdas += 1; |
| 1864 | | − let name = format!("{}$partial{}", parent.name, parent.lambdas); |
| 1865 | | − let fid = self.placeholder(name.clone()); |
| 1866 | 1861 | // Dictionaries are found where the partial application is written. |
| 1867 | 1862 | let ev: Vec<Atom> = self |
| 1868 | 1863 | .evidence(site) |
| 1869 | 1864 | .iter() |
| 1870 | 1865 | .map(|e| self.materialize(e)) |
| 1871 | 1866 | .collect(); |
| 1872 | | − self.frames.push(Frame::new(name)); |
| 1873 | | − let caps: Vec<Atom> = caps.into_iter().map(|c| self.capture_atom(c)).collect(); |
| 1874 | | − let ev: Vec<Atom> = ev.into_iter().map(|e| self.capture_atom(e)).collect(); |
| 1875 | | − let slots: Vec<Option<Atom>> = slots |
| 1876 | | − .into_iter() |
| 1877 | | − .map(|s| s.map(|a| self.capture_atom(a))) |
| 1878 | | − .collect(); |
| 1879 | | − let vars: Vec<VarId> = slots |
| 1880 | | − .iter() |
| 1881 | | − .filter(|s| s.is_none()) |
| 1882 | | − .map(|_| self.fresh()) |
| 1883 | | − .collect(); |
| 1884 | | − let body = self.block_value(|this| { |
| 1885 | | − let mut vars = vars.iter(); |
| 1886 | | − let args: Vec<Atom> = slots |
| 1887 | | − .into_iter() |
| 1888 | | − .map(|s| s.unwrap_or_else(|| Atom::Var(*vars.next().expect("one per hole")))) |
| 1889 | | − .collect(); |
| 1890 | | − match &this.hir.def(def).kind { |
| 1891 | | − DefKind::Fn(f) => { |
| 1892 | | − if let Some(sym) = this.extern_symbol(def) { |
| 1893 | | − return this.emit(Value::CallExtern(sym, args)); |
| 1894 | | − } |
| 1895 | | − let args: Vec<Atom> = caps.into_iter().chain(args).collect(); |
| 1896 | | − if let Some(owner) = f.owner |
| 1897 | | − && matches!(this.hir.def(owner).kind, DefKind::Trait(_)) |
| 1898 | | − { |
| 1899 | | − let Some((first, extra)) = ev.split_first() else { |
| 1900 | | − return Atom::Unit; |
| 1901 | | − }; |
| 1902 | | − let index = this.method_index(owner, &this.hir.def(def).name); |
| 1903 | | − return this.method_call( |
| 1904 | | − first.clone(), |
| 1905 | | − index, |
| 1906 | | − extra.iter().cloned().chain(args).collect(), |
| 1907 | | − ); |
| 1908 | | − } |
| 1909 | | − this.emit(Value::CallFn( |
| 1910 | | − this.fn_ids[&def], |
| 1911 | | − ev.into_iter().chain(args).collect(), |
| 1912 | | − )) |
| 1913 | | − } |
| 1914 | | − _ => Atom::Unit, |
| 1867 | + let (n_caps, n_ev) = (caps.len(), ev.len()); |
| 1868 | + let (placed, outer) = split_slots(slots); |
| 1869 | + let outer = caps.into_iter().chain(ev).chain(outer).collect(); |
| 1870 | + self.closure_over(outer, holes(&placed), |this, mut inner, holes| { |
| 1871 | + let caps: Vec<Atom> = inner.by_ref().take(n_caps).collect(); |
| 1872 | + let ev: Vec<Atom> = inner.by_ref().take(n_ev).collect(); |
| 1873 | + let args = fill(&placed, inner, holes); |
| 1874 | + let DefKind::Fn(f) = &this.hir.def(def).kind else { |
| 1875 | + return Atom::Unit; |
| 1876 | + }; |
| 1877 | + if let Some(sym) = this.extern_symbol(def) { |
| 1878 | + return this.emit(Value::CallExtern(sym, args)); |
| 1915 | 1879 | } |
| 1916 | | − }); |
| 1917 | | − let frame = self.frames.pop().expect("pushed"); |
| 1918 | | − let mut params: Vec<VarId> = frame.captures.iter().map(|(_, v)| *v).collect(); |
| 1919 | | − params.extend(&vars); |
| 1920 | | − self.define( |
| 1921 | | − fid, |
| 1922 | | − FnDecl { |
| 1923 | | − name: frame.name, |
| 1924 | | − params, |
| 1925 | | − body, |
| 1926 | | − n_vars: frame.n_vars, |
| 1927 | | − borrowed: Default::default(), |
| 1928 | | − span: self.span, |
| 1929 | | − module: None, |
| 1930 | | − shapes: Default::default(), |
| 1931 | | − fip: false, |
| 1932 | | − cpr_arity: None, |
| 1933 | | − unbox_sig: None, |
| 1934 | | − }, |
| 1935 | | − ); |
| 1936 | | − let captures = frame |
| 1937 | | − .captures |
| 1938 | | − .iter() |
| 1939 | | − .map(|(key, _)| self.captured_atom(*key)) |
| 1940 | | − .collect(); |
| 1941 | | − self.emit(Value::Closure(fid, captures)) |
| 1880 | + let args: Vec<Atom> = caps.into_iter().chain(args).collect(); |
| 1881 | + if let Some(owner) = f.owner |
| 1882 | + && matches!(this.hir.def(owner).kind, DefKind::Trait(_)) |
| 1883 | + { |
| 1884 | + let Some((first, extra)) = ev.split_first() else { |
| 1885 | + return Atom::Unit; |
| 1886 | + }; |
| 1887 | + let index = this.method_index(owner, &this.hir.def(def).name); |
| 1888 | + return this.method_call( |
| 1889 | + first.clone(), |
| 1890 | + index, |
| 1891 | + extra.iter().cloned().chain(args).collect(), |
| 1892 | + ); |
| 1893 | + } |
| 1894 | + this.emit(Value::CallFn( |
| 1895 | + this.fn_ids[&def], |
| 1896 | + ev.into_iter().chain(args).collect(), |
| 1897 | + )) |
| 1898 | + }) |
| 1942 | 1899 | } |
| 1943 | 1900 | |
| 1944 | 1901 | /// An operation with some arguments given: a closure performing it |
| 1945 | 1902 | /// once the rest arrive (ADR 0062). |
| 1946 | | − fn partial_perform( |
| 1947 | | − &mut self, |
| 1948 | | − def: DefId, |
| 1949 | | − slots: Vec<Option<Atom>>, |
| 1950 | | − caps: Vec<Atom>, |
| 1951 | | − _site: ExprId, |
| 1952 | | − ) -> Atom { |
| 1953 | | − let parent = self.frame(); |
| 1954 | | − parent.lambdas += 1; |
| 1955 | | − let name = format!("{}$partial{}", parent.name, parent.lambdas); |
| 1956 | | − let fid = self.placeholder(name.clone()); |
| 1957 | | − self.frames.push(Frame::new(name)); |
| 1958 | | − let caps: Vec<Atom> = caps.into_iter().map(|c| self.capture_atom(c)).collect(); |
| 1959 | | − let slots: Vec<Option<Atom>> = slots |
| 1960 | | − .into_iter() |
| 1961 | | − .map(|s| s.map(|a| self.capture_atom(a))) |
| 1962 | | − .collect(); |
| 1963 | | − let vars: Vec<VarId> = slots |
| 1964 | | − .iter() |
| 1965 | | − .filter(|s| s.is_none()) |
| 1966 | | − .map(|_| self.fresh()) |
| 1967 | | − .collect(); |
| 1968 | | − let body = self.block_value(|this| { |
| 1969 | | − let mut vars = vars.iter(); |
| 1970 | | − let args: Vec<Atom> = slots |
| 1971 | | − .into_iter() |
| 1972 | | − .map(|s| s.unwrap_or_else(|| Atom::Var(*vars.next().expect("one per hole")))) |
| 1973 | | − .collect(); |
| 1903 | + fn partial_perform(&mut self, def: DefId, slots: Vec<Option<Atom>>, caps: Vec<Atom>) -> Atom { |
| 1904 | + let n_caps = caps.len(); |
| 1905 | + let (placed, outer) = split_slots(slots); |
| 1906 | + let outer = caps.into_iter().chain(outer).collect(); |
| 1907 | + self.closure_over(outer, holes(&placed), |this, mut inner, holes| { |
| 1908 | + let cap = inner.by_ref().take(n_caps).next().unwrap_or(Atom::Unit); |
| 1909 | + let args = fill(&placed, inner, holes); |
| 1974 | 1910 | let (effect, op) = this.effect_and_op(def); |
| 1975 | | − let cap = caps.into_iter().next().unwrap_or(Atom::Unit); |
| 1976 | 1911 | this.emit(Value::Perform { |
| 1977 | 1912 | cap, |
| 1978 | 1913 | effect, |
| 1979 | 1914 | op, |
| 1980 | 1915 | args, |
| 1981 | 1916 | }) |
| 1982 | | − }); |
| 1983 | | − let frame = self.frames.pop().expect("pushed"); |
| 1984 | | − let mut params: Vec<VarId> = frame.captures.iter().map(|(_, v)| *v).collect(); |
| 1985 | | − params.extend(&vars); |
| 1986 | | − self.define( |
| 1987 | | − fid, |
| 1988 | | − FnDecl { |
| 1989 | | − name: frame.name, |
| 1990 | | − params, |
| 1991 | | − body, |
| 1992 | | − n_vars: frame.n_vars, |
| 1993 | | − borrowed: Default::default(), |
| 1994 | | − span: self.span, |
| 1995 | | − module: None, |
| 1996 | | − shapes: Default::default(), |
| 1997 | | − fip: false, |
| 1998 | | − cpr_arity: None, |
| 1999 | | − unbox_sig: None, |
| 2000 | | − }, |
| 2001 | | − ); |
| 2002 | | − let captures = frame |
| 2003 | | − .captures |
| 2004 | | − .iter() |
| 2005 | | − .map(|(key, _)| self.captured_atom(*key)) |
| 2006 | | − .collect(); |
| 2007 | | − self.emit(Value::Closure(fid, captures)) |
| 1917 | + }) |
| 2008 | 1918 | } |
| 2009 | 1919 | |
| 2010 | 1920 | fn binary(&mut self, e: ExprId, op: hb::BinOp, lhs: ExprId, rhs: ExprId) -> Atom { |