Skip to content

Commit 989cdd6

Browse files
committed
Merge functions that no longer need to be separate
1 parent a7029a6 commit 989cdd6

File tree

2 files changed

+32
-46
lines changed

2 files changed

+32
-46
lines changed

design/mvp/CanonicalABI.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,16 +2827,13 @@ of component-level values with types `ts`.
28272827
def lift_flat_values(cx, max_flat, vi, ts):
28282828
flat_types = flatten_types(ts)
28292829
if len(flat_types) > max_flat:
2830-
return lift_heap_values(cx, vi, ts)
2830+
ptr = vi.next('i32')
2831+
tuple_type = TupleType(ts)
2832+
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2833+
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
2834+
return list(load(cx, ptr, tuple_type).values())
28312835
else:
28322836
return [ lift_flat(cx, vi, t) for t in ts ]
2833-
2834-
def lift_heap_values(cx, vi, ts):
2835-
ptr = vi.next('i32')
2836-
tuple_type = TupleType(ts)
2837-
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2838-
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
2839-
return list(load(cx, ptr, tuple_type).values())
28402837
```
28412838

28422839
Symmetrically, the `lower_flat_values` function defines how to lower a
@@ -2850,27 +2847,23 @@ def lower_flat_values(cx, max_flat, vs, ts, out_param = None):
28502847
cx.inst.may_leave = False
28512848
flat_types = flatten_types(ts)
28522849
if len(flat_types) > max_flat:
2853-
flat_vals = lower_heap_values(cx, vs, ts, out_param)
2850+
tuple_type = TupleType(ts)
2851+
tuple_value = {str(i): v for i,v in enumerate(vs)}
2852+
if out_param is None:
2853+
ptr = cx.opts.realloc(0, 0, alignment(tuple_type), elem_size(tuple_type))
2854+
flat_vals = [ptr]
2855+
else:
2856+
ptr = out_param.next('i32')
2857+
flat_vals = []
2858+
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2859+
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
2860+
store(cx, tuple_value, tuple_type, ptr)
28542861
else:
28552862
flat_vals = []
28562863
for i in range(len(vs)):
28572864
flat_vals += lower_flat(cx, vs[i], ts[i])
28582865
cx.inst.may_leave = True
28592866
return flat_vals
2860-
2861-
def lower_heap_values(cx, vs, ts, out_param):
2862-
tuple_type = TupleType(ts)
2863-
tuple_value = {str(i): v for i,v in enumerate(vs)}
2864-
if out_param is None:
2865-
ptr = cx.opts.realloc(0, 0, alignment(tuple_type), elem_size(tuple_type))
2866-
flat_vals = [ptr]
2867-
else:
2868-
ptr = out_param.next('i32')
2869-
flat_vals = []
2870-
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
2871-
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
2872-
store(cx, tuple_value, tuple_type, ptr)
2873-
return flat_vals
28742867
```
28752868
The `may_leave` flag is guarded by `canon_lower` below to prevent a component
28762869
from calling out of the component while in the middle of lowering, ensuring

design/mvp/canonical-abi/definitions.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,43 +1802,36 @@ def lower_flat_flags(v, labels):
18021802
def lift_flat_values(cx, max_flat, vi, ts):
18031803
flat_types = flatten_types(ts)
18041804
if len(flat_types) > max_flat:
1805-
return lift_heap_values(cx, vi, ts)
1805+
ptr = vi.next('i32')
1806+
tuple_type = TupleType(ts)
1807+
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
1808+
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
1809+
return list(load(cx, ptr, tuple_type).values())
18061810
else:
18071811
return [ lift_flat(cx, vi, t) for t in ts ]
18081812

1809-
def lift_heap_values(cx, vi, ts):
1810-
ptr = vi.next('i32')
1811-
tuple_type = TupleType(ts)
1812-
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
1813-
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
1814-
return list(load(cx, ptr, tuple_type).values())
1815-
18161813
def lower_flat_values(cx, max_flat, vs, ts, out_param = None):
18171814
cx.inst.may_leave = False
18181815
flat_types = flatten_types(ts)
18191816
if len(flat_types) > max_flat:
1820-
flat_vals = lower_heap_values(cx, vs, ts, out_param)
1817+
tuple_type = TupleType(ts)
1818+
tuple_value = {str(i): v for i,v in enumerate(vs)}
1819+
if out_param is None:
1820+
ptr = cx.opts.realloc(0, 0, alignment(tuple_type), elem_size(tuple_type))
1821+
flat_vals = [ptr]
1822+
else:
1823+
ptr = out_param.next('i32')
1824+
flat_vals = []
1825+
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
1826+
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
1827+
store(cx, tuple_value, tuple_type, ptr)
18211828
else:
18221829
flat_vals = []
18231830
for i in range(len(vs)):
18241831
flat_vals += lower_flat(cx, vs[i], ts[i])
18251832
cx.inst.may_leave = True
18261833
return flat_vals
18271834

1828-
def lower_heap_values(cx, vs, ts, out_param):
1829-
tuple_type = TupleType(ts)
1830-
tuple_value = {str(i): v for i,v in enumerate(vs)}
1831-
if out_param is None:
1832-
ptr = cx.opts.realloc(0, 0, alignment(tuple_type), elem_size(tuple_type))
1833-
flat_vals = [ptr]
1834-
else:
1835-
ptr = out_param.next('i32')
1836-
flat_vals = []
1837-
trap_if(ptr != align_to(ptr, alignment(tuple_type)))
1838-
trap_if(ptr + elem_size(tuple_type) > len(cx.opts.memory))
1839-
store(cx, tuple_value, tuple_type, ptr)
1840-
return flat_vals
1841-
18421835
### `canon lift`
18431836

18441837
async def canon_lift(opts, inst, ft, callee, caller, on_start, on_resolve, on_block):

0 commit comments

Comments
 (0)