MCPcopy Index your code
hub / github.com/python/mypy / Unborrow

Class Unborrow

mypyc/ir/ops.py:1870–1913  ·  view source on GitHub ↗

A no-op op to create a regular reference from a borrowed one. Borrowed references can only be used temporarily and the reference counts won't be managed. This value will be refcounted normally. This is mainly useful if you split an aggregate value, such as a tuple, into components

Source from the content-addressed store, hash-verified

1868
1869@final
1870class Unborrow(RegisterOp):
1871 """A no-op op to create a regular reference from a borrowed one.
1872
1873 Borrowed references can only be used temporarily and the reference
1874 counts won't be managed. This value will be refcounted normally.
1875
1876 This is mainly useful if you split an aggregate value, such as
1877 a tuple, into components using borrowed values (to avoid increfs),
1878 and want to treat the components as sharing the original managed
1879 reference. You'll also need to use KeepAlive with steal=True to
1880 "consume" the original tuple reference:
1881
1882 # t is a 2-tuple
1883 r0 = borrow t[0]
1884 r1 = borrow t[1]
1885 keep_alive steal t
1886 r2 = unborrow r0
1887 r3 = unborrow r1
1888 # now (r2, r3) represent the tuple as separate items, that are
1889 # managed again. (Note we need to steal before unborrow, to avoid
1890 # refcount briefly touching zero if r2 or r3 are unused.)
1891
1892 Be careful with this -- this can easily cause double freeing.
1893 """
1894
1895 error_kind = ERR_NEVER
1896
1897 def __init__(self, src: Value, line: int = -1) -> None:
1898 super().__init__(line)
1899 assert src.is_borrowed
1900 self.src = src
1901 self.type = src.type
1902
1903 def sources(self) -> list[Value]:
1904 return [self.src]
1905
1906 def set_sources(self, new: list[Value]) -> None:
1907 (self.src,) = new
1908
1909 def stolen(self) -> list[Value]:
1910 return []
1911
1912 def accept(self, visitor: OpVisitor[T]) -> T:
1913 return visitor.visit_unborrow(self)
1914
1915
1916@trait

Callers 2

vec_popFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…