@onda-lang/binaryen-web 0.8.39 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { PayloadPlan } from "@onda-lang/processor-abi";
2
2
  import { prepareEventInput } from "./event-input.js";
3
+ import { CollectionOrigins, selectedResourceRange } from "./resource-origins.js";
3
4
  import binaryen from "binaryen";
4
5
  import {
5
6
  SUPPORTED_MIR_SCHEMA_VERSION,
@@ -58,8 +59,10 @@ export class MirCompilerCore {
58
59
  this.controlOutputLayout = [];
59
60
  this.eventLayout = [];
60
61
  this.constLayout = [];
62
+ this.bufferMapLayout = [];
61
63
  this.localArrayLayout = [];
62
64
  this.localScalarRefLayout = [];
65
+ this.functionAbiLayout = [];
63
66
  this.memorySegments = [];
64
67
  this.requiredMathHelpers = collectMathKernelHelpers(mir);
65
68
  this.nextStaticAddress = this.requiredMathHelpers.size > 0
@@ -706,6 +709,15 @@ export class MirCompilerCore {
706
709
  ) {
707
710
  this.fail("Binaryen shrinkLevel must be an integer from 0 through 2");
708
711
  }
712
+ if (mir.buffer_maps !== undefined && !Array.isArray(mir.buffer_maps)) {
713
+ this.fail("MIR field 'buffer_maps' must be an array");
714
+ }
715
+ for (const [id, map] of (mir.buffer_maps ?? []).entries()) {
716
+ if (!Array.isArray(map?.buffers) || map.buffers.length === 0 || map.buffers.length > 0x7fff_ffff
717
+ || map.buffers.some((entry) => !Number.isInteger(entry) || entry < 0 || entry >= mir.interface.buffers.length)) {
718
+ this.fail(`buffer map ${id} contains invalid symbolic resources`);
719
+ }
720
+ }
709
721
  this.validateCurrentSchemaEnvelope();
710
722
  this.validateProcessEntrySignature();
711
723
  this.validateAcyclicCallGraph();
@@ -996,20 +1008,8 @@ export class MirCompilerCore {
996
1008
  const bufferOrigin = (id) => `buffer:${id}`;
997
1009
  const parameterOrigin = (id, slot = 0) => `parameter:${id}:${slot}`;
998
1010
  const selectedSlots = (selector, len, bounds) => {
999
- if (!Number.isInteger(len) || len <= 0) return [];
1000
- if (
1001
- selector?.kind === "constant"
1002
- && selector.data?.type === "i32"
1003
- && Number.isInteger(selector.data.value)
1004
- ) {
1005
- let slot = selector.data.value;
1006
- if (bounds === "clamp") {
1007
- slot = Math.min(len - 1, Math.max(0, slot));
1008
- return [slot];
1009
- }
1010
- if (slot >= 0 && slot < len) return [slot];
1011
- }
1012
- return Array.from({ length: len }, (_, slot) => slot);
1011
+ const [start, end] = selectedResourceRange(selector, len, bounds);
1012
+ return Array.from({ length: end - start }, (_, index) => start + index);
1013
1013
  };
1014
1014
  const bufferIds = (bufferRef) => {
1015
1015
  if (Number.isInteger(bufferRef)) return [bufferRef];
@@ -1050,7 +1050,7 @@ export class MirCompilerCore {
1050
1050
  ) {
1051
1051
  const parameter = func.params?.[parameterRef.data.span];
1052
1052
  const type = parameter && this.type(parameter.ty);
1053
- const len = type?.kind === "buffer_span" ? type.data.len : 1;
1053
+ const len = ["buffer_span", "buffer_map"].includes(type?.kind) ? type.data.len : 1;
1054
1054
  return selectedSlots(
1055
1055
  parameterRef.data.selector,
1056
1056
  len,
@@ -1059,11 +1059,16 @@ export class MirCompilerCore {
1059
1059
  }
1060
1060
  return [];
1061
1061
  };
1062
- const bufferParamOrigins = (parameterRef, func) => new Set(
1063
- bufferParamSlots(parameterRef, func).map(({ parameter, slot }) =>
1064
- parameterOrigin(parameter, slot)
1065
- ),
1066
- );
1062
+ const bufferParamOrigins = (parameterRef, func, aliases) => {
1063
+ if (parameterRef?.kind === "local") return new Set(aliases?.[parameterRef.data] ?? []);
1064
+ if (parameterRef?.kind === "local_element") {
1065
+ const { collection, selector, bounds } = parameterRef.data;
1066
+ const len = this.type(func.locals[collection].ty).data.len;
1067
+ const [start, end] = selectedResourceRange(selector, len, bounds);
1068
+ return aliases.collections.range(collection, start, end, (id) => aliases[id] ?? []);
1069
+ }
1070
+ return new Set(bufferParamSlots(parameterRef, func).map(({ parameter, slot }) => parameterOrigin(parameter, slot)));
1071
+ };
1067
1072
  const localId = (value) =>
1068
1073
  value?.kind === "local" && Number.isInteger(value.data)
1069
1074
  ? value.data
@@ -1074,9 +1079,12 @@ export class MirCompilerCore {
1074
1079
  setEquals(lhs.buffers, rhs.buffers)
1075
1080
  && setEquals(lhs.parameters, rhs.parameters);
1076
1081
 
1082
+ const localOrigins = (id, aliases) => aliases.collections.has(id)
1083
+ ? aliases.collections.slot(id, null, (id) => aliases[id] ?? [])
1084
+ : new Set(aliases[id] ?? []);
1077
1085
  const valueOrigins = (value, aliases) => {
1078
1086
  const id = localId(value);
1079
- return id === null ? new Set() : new Set(aliases[id] ?? []);
1087
+ return id === null ? new Set() : localOrigins(id, aliases);
1080
1088
  };
1081
1089
  const placeOrigins = (place, aliases) => {
1082
1090
  const base = place?.base;
@@ -1084,11 +1092,12 @@ export class MirCompilerCore {
1084
1092
  return new Set([parameterOrigin(base.data, 0)]);
1085
1093
  }
1086
1094
  if (base?.kind === "local" && Number.isInteger(base.data)) {
1087
- return new Set(aliases[base.data] ?? []);
1095
+ return localOrigins(base.data, aliases);
1088
1096
  }
1089
1097
  return new Set();
1090
1098
  };
1091
1099
  const rvalueOrigins = (value, aliases, func) => {
1100
+ if (value?.kind === "make_buffer") return argumentOrigins(value.data.source, aliases, func, null);
1092
1101
  if (value?.kind === "use") {
1093
1102
  return valueOrigins(value.data, aliases);
1094
1103
  }
@@ -1103,7 +1112,7 @@ export class MirCompilerCore {
1103
1112
  return bufferOrigins(source.data?.buffer);
1104
1113
  }
1105
1114
  if (source?.kind === "buffer_param") {
1106
- return bufferParamOrigins(source.data?.parameter, func);
1115
+ return bufferParamOrigins(source.data?.parameter, func, aliases);
1107
1116
  }
1108
1117
  if (source?.kind === "place") {
1109
1118
  return placeOrigins(source.data, aliases);
@@ -1111,36 +1120,69 @@ export class MirCompilerCore {
1111
1120
  return new Set();
1112
1121
  };
1113
1122
  const collectAliases = (func) => {
1114
- const aliases = (func.locals ?? []).map(() => new Set());
1115
- let changed = true;
1116
- const visitBlock = (block) => {
1117
- for (const statement of block?.statements ?? []) {
1118
- const kind = statement.kind?.kind;
1119
- const data = statement.kind?.data;
1120
- if (
1121
- kind === "assign"
1122
- && data?.destination?.projections?.length === 0
1123
- && data.destination.base?.kind === "local"
1124
- ) {
1125
- const destination = data.destination.base.data;
1126
- const origins = rvalueOrigins(data.value, aliases, func);
1127
- for (const origin of origins) {
1128
- if (!aliases[destination].has(origin)) {
1129
- aliases[destination].add(origin);
1130
- changed = true;
1131
- }
1132
- }
1133
- } else if (kind === "if") {
1134
- visitBlock(data?.then_block);
1135
- visitBlock(data?.else_block);
1136
- } else if (kind === "loop") {
1137
- visitBlock(data?.body);
1138
- }
1139
- }
1123
+ const aliases = [];
1124
+ aliases.collections = new CollectionOrigins(this.mir.buffer_maps, {
1125
+ buffer: bufferOrigin, parameter: parameterOrigin,
1126
+ });
1127
+ const resourceType = (id) => {
1128
+ const type = this.type(func.locals[id].ty);
1129
+ return ["slice", "buffer", "buffer_span", "buffer_map"].includes(type.kind) ? type : null;
1140
1130
  };
1141
- while (changed) {
1142
- changed = false;
1143
- visitBlock(func.body);
1131
+ if (!(func.locals ?? []).some((_, id) => resourceType(id))) return aliases;
1132
+ const sourceLocal = (value) => {
1133
+ if (value.kind === "use") return localId(value.data);
1134
+ if (value.kind === "load") return value.data.base?.kind === "local" ? value.data.base.data : null;
1135
+ const source = value.kind === "make_buffer" || value.kind === "make_slice" ? value.data.source : null;
1136
+ if (source?.kind === "value") return localId(source.data);
1137
+ if (source?.kind === "place") return source.data.base?.kind === "local" ? source.data.base.data : null;
1138
+ if (source?.kind === "buffer_span" && source.data.kind === "local") return source.data.data.collection;
1139
+ const reference = source?.kind === "buffer_param" ? source.data?.parameter ?? source.data : null;
1140
+ if (reference?.kind === "local") return reference.data;
1141
+ if (reference?.kind === "local_element") return reference.data.collection;
1142
+ return null;
1143
+ };
1144
+ const assignments = [];
1145
+ const blocks = [func.body];
1146
+ while (blocks.length) {
1147
+ for (const statement of blocks.pop()?.statements ?? []) {
1148
+ const { kind, data } = statement.kind;
1149
+ if (kind === "assign" && data.destination.projections.length === 0
1150
+ && data.destination.base.kind === "local" && resourceType(data.destination.base.data)) {
1151
+ const id = data.destination.base.data;
1152
+ const type = resourceType(id);
1153
+ if (["buffer_span", "buffer_map"].includes(type.kind)) {
1154
+ const { value } = data;
1155
+ const source = value.kind === "make_buffer" ? value.data.source
1156
+ : value.kind === "use" ? { kind: "value", data: value.data }
1157
+ : value.kind === "load" ? { kind: "place", data: value.data } : null;
1158
+ aliases.collections.add(id, type.data.len, source);
1159
+ } else assignments.push(data);
1160
+ } else if (kind === "if") blocks.push(data.else_block, data.then_block);
1161
+ else if (kind === "loop") blocks.push(data.body);
1162
+ }
1163
+ }
1164
+ const dependents = new Map();
1165
+ assignments.forEach((assignment, index) => {
1166
+ const source = sourceLocal(assignment.value);
1167
+ if (source !== null) {
1168
+ if (!dependents.has(source)) dependents.set(source, []);
1169
+ dependents.get(source).push(index);
1170
+ }
1171
+ });
1172
+ const pending = assignments.map((_, index) => index);
1173
+ const queued = new Uint8Array(assignments.length).fill(1);
1174
+ for (let cursor = 0; cursor < pending.length; cursor += 1) {
1175
+ const index = pending[cursor];
1176
+ queued[index] = 0;
1177
+ const { destination, value } = assignments[index];
1178
+ const id = destination.base.data;
1179
+ const origins = rvalueOrigins(value, aliases, func);
1180
+ const target = aliases[id] ??= new Set();
1181
+ let changed = false;
1182
+ for (const origin of origins) if (!target.has(origin)) { target.add(origin); changed = true; }
1183
+ if (changed) for (const dependent of dependents.get(id) ?? []) {
1184
+ if (!queued[dependent]) { queued[dependent] = 1; pending.push(dependent); }
1185
+ }
1144
1186
  }
1145
1187
  return aliases;
1146
1188
  };
@@ -1197,9 +1239,16 @@ export class MirCompilerCore {
1197
1239
  case "buffer":
1198
1240
  return bufferOrigins(argument.data);
1199
1241
  case "buffer_param":
1200
- return bufferParamOrigins(argument.data, func);
1242
+ return bufferParamOrigins(argument.data, func, aliases);
1201
1243
  case "buffer_span": {
1202
1244
  const span = argument.data;
1245
+ if (span?.kind === "local") {
1246
+ const { collection, start, len, bounds } = span.data;
1247
+ const sourceLen = this.type(func.locals[collection].ty).data.len;
1248
+ const [first, last] = selectedResourceRange(start, sourceLen - len + 1, bounds);
1249
+ const selected = Number.isInteger(slot) && slot >= 0 && slot < len ? [slot, slot + 1] : [0, len];
1250
+ return aliases.collections.range(collection, first + selected[0], last - 1 + selected[1], (id) => aliases[id] ?? []);
1251
+ }
1203
1252
  if (span?.kind === "interface") {
1204
1253
  const len = span.data?.len ?? 0;
1205
1254
  if (Number.isInteger(slot) && slot >= 0 && slot < len) {
@@ -1209,6 +1258,12 @@ export class MirCompilerCore {
1209
1258
  bufferOrigin(span.data.first + index)
1210
1259
  ));
1211
1260
  }
1261
+ if (span?.kind === "mapped_interface") {
1262
+ const entries = this.mir.buffer_maps[span.data.map].buffers;
1263
+ return new Set(Number.isInteger(slot) && slot >= 0 && slot < span.data.len
1264
+ ? [bufferOrigin(entries[span.data.start + slot])]
1265
+ : entries.slice(span.data.start, span.data.start + span.data.len).map(bufferOrigin));
1266
+ }
1212
1267
  if (span?.kind === "parameter") {
1213
1268
  const start = span.data?.start ?? 0;
1214
1269
  const len = span.data?.len ?? 0;
@@ -1221,11 +1276,16 @@ export class MirCompilerCore {
1221
1276
  }
1222
1277
  return new Set();
1223
1278
  }
1224
- case "place":
1279
+ case "place": {
1280
+ const base = argument.data?.base;
1281
+ if (base?.kind === "local" && aliases.collections.has(base.data)) return aliases.collections.slot(base.data, slot, (id) => aliases[id] ?? []);
1282
+ if (base?.kind === "parameter" && ["buffer_span", "buffer_map"].includes(this.type(func.params[base.data].ty).kind) && Number.isInteger(slot)) return new Set([parameterOrigin(base.data, slot)]);
1225
1283
  return placeOrigins(argument.data, aliases);
1284
+ }
1226
1285
  case "array_window":
1227
1286
  return placeOrigins(argument.data?.array, aliases);
1228
1287
  case "value":
1288
+ if (argument.data?.kind === "local" && aliases.collections.has(argument.data.data)) return aliases.collections.slot(argument.data.data, slot, (id) => aliases[id] ?? []);
1229
1289
  return valueOrigins(argument.data, aliases);
1230
1290
  case "slice_element":
1231
1291
  case "slice_window":
@@ -1279,7 +1339,7 @@ export class MirCompilerCore {
1279
1339
  }
1280
1340
  } else if (kind === "buffer_param_store") {
1281
1341
  markOrigins(
1282
- bufferParamOrigins(data?.parameter, func),
1342
+ bufferParamOrigins(data?.parameter, func, aliases[functionId]),
1283
1343
  summary,
1284
1344
  );
1285
1345
  } else if (kind === "slice_store") {
@@ -1394,6 +1454,7 @@ export class MirCompilerCore {
1394
1454
  return scalar === "i32" || scalar === "i64";
1395
1455
  };
1396
1456
  const checkedBoundsKinds = new Set([
1457
+ "array_element",
1397
1458
  "array_window",
1398
1459
  "buffer_load",
1399
1460
  "buffer_param_load",
@@ -1402,6 +1463,7 @@ export class MirCompilerCore {
1402
1463
  "const_data_load",
1403
1464
  "index",
1404
1465
  "input_load",
1466
+ "local_element",
1405
1467
  "make_slice",
1406
1468
  "output_load",
1407
1469
  "output_store",
@@ -1435,7 +1497,7 @@ export class MirCompilerCore {
1435
1497
  || value.kind === "slice_copy"
1436
1498
  || delegatePayloadMayFail
1437
1499
  || binaryMayFail(functionId, value)
1438
- || (checkedBoundsKinds.has(value.kind) && bounds === "checked")
1500
+ || ((checkedBoundsKinds.has(value.kind) || (value.kind === "local" && value.data?.collection !== undefined)) && bounds === "checked")
1439
1501
  || (dynamicBoundsKinds.has(value.kind) && bounds !== "unchecked")
1440
1502
  ) {
1441
1503
  direct[functionId] = true;
@@ -1511,6 +1573,17 @@ export class MirCompilerCore {
1511
1573
  this.nextStaticAddress += bytes.byteLength;
1512
1574
  }
1513
1575
 
1576
+ for (const map of this.mir.buffer_maps ?? []) {
1577
+ this.nextStaticAddress = alignUp(this.nextStaticAddress, 4);
1578
+ const address = this.nextStaticAddress;
1579
+ const bytes = new Uint8Array(map.buffers.length * 4);
1580
+ const view = new DataView(bytes.buffer);
1581
+ map.buffers.forEach((id, index) => view.setUint32(index * 4, id, true));
1582
+ this.memorySegments.push({ offset: this.module.i32.const(address), data: bytes });
1583
+ this.bufferMapLayout.push({ address });
1584
+ this.nextStaticAddress += bytes.byteLength;
1585
+ }
1586
+
1514
1587
  this.localArrayLayout = this.mir.functions.map((func) =>
1515
1588
  func.locals.map((local) => {
1516
1589
  const type = this.type(local.ty);
@@ -1547,6 +1620,25 @@ export class MirCompilerCore {
1547
1620
  this.fallbackBufferWriteAddress = this.nextStaticAddress;
1548
1621
  this.nextStaticAddress += fallbackBytes;
1549
1622
  }
1623
+ // Wasm engines cap positional signatures at 1,000 parameters. Wide MIR
1624
+ // signatures use one pointer to a private argument frame instead. MIR call
1625
+ // graphs are acyclic, so each callee can reuse its frame; it snapshots all
1626
+ // components into locals before entering its body or making another call.
1627
+ this.functionAbiLayout = this.mir.functions.map((func, functionId) => {
1628
+ const scalars = func.params.flatMap((param, index) => this.functionValueLayout(
1629
+ param.ty, 0, `parameter '${param.name}'`, false,
1630
+ this.parameterPassingMode(functionId, index),
1631
+ ).components);
1632
+ if (scalars.length <= 1000) return null;
1633
+ const entries = scalars.map((scalar) => {
1634
+ const size = this.scalarSize(scalar);
1635
+ this.nextStaticAddress = alignUp(this.nextStaticAddress, size);
1636
+ const address = this.nextStaticAddress;
1637
+ this.nextStaticAddress += size;
1638
+ return { scalar, address };
1639
+ });
1640
+ return { address: entries[0].address, entries };
1641
+ });
1550
1642
  this.nextStaticAddress = alignUp(this.nextStaticAddress, 16);
1551
1643
  this.requireWasm32Extent(this.nextStaticAddress, "MIR static storage");
1552
1644
  this.requireWasm32Extent(
@@ -1820,7 +1912,9 @@ export class MirCompilerCore {
1820
1912
  }
1821
1913
 
1822
1914
  addMirFunction(id, func) {
1823
- let nextIndex = 0;
1915
+ const packed = this.functionAbiLayout[id];
1916
+ const paramValueBase = packed ? 1 : 0;
1917
+ let nextIndex = paramValueBase;
1824
1918
  const paramLayouts = func.params.map((param, parameterId) => {
1825
1919
  const layout = this.functionValueLayout(
1826
1920
  param.ty,
@@ -1833,6 +1927,7 @@ export class MirCompilerCore {
1833
1927
  return layout;
1834
1928
  });
1835
1929
  const paramScalars = paramLayouts.flatMap((layout) => layout.components);
1930
+ const paramValueEnd = nextIndex;
1836
1931
  const localLayouts = func.locals.map((local, localId) => {
1837
1932
  const layout = this.functionValueLayout(
1838
1933
  local.ty,
@@ -1855,7 +1950,7 @@ export class MirCompilerCore {
1855
1950
  const sliceScratch = this.collectSliceScratchLocals(func);
1856
1951
  const processFrameLocals = this.collectProcessFrameLocals(func);
1857
1952
  const generatedLocalBase =
1858
- paramScalars.length +
1953
+ paramValueEnd +
1859
1954
  flatLocalScalars.length +
1860
1955
  callResultLocals.length +
1861
1956
  sliceScratch.count;
@@ -1879,7 +1974,7 @@ export class MirCompilerCore {
1879
1974
  callResultLocals.map((entry, index) => [
1880
1975
  entry.call,
1881
1976
  {
1882
- index: paramScalars.length + flatLocalScalars.length + index,
1977
+ index: paramValueEnd + flatLocalScalars.length + index,
1883
1978
  type: entry.type,
1884
1979
  },
1885
1980
  ]),
@@ -1889,7 +1984,7 @@ export class MirCompilerCore {
1889
1984
  entry.statement,
1890
1985
  {
1891
1986
  index:
1892
- paramScalars.length +
1987
+ paramValueEnd +
1893
1988
  flatLocalScalars.length +
1894
1989
  callResultLocals.length +
1895
1990
  sliceScratch.offsets[index],
@@ -1907,6 +2002,13 @@ export class MirCompilerCore {
1907
2002
  breakLabels: [],
1908
2003
  continueLabels: [],
1909
2004
  };
2005
+ if (packed) {
2006
+ packed.entries.forEach(({ scalar, address }, index) => {
2007
+ context.entryInitializers.push(this.module.local.set(paramValueBase + index,
2008
+ this.loadScalar(scalar, this.module.i32.add(this.module.local.get(0, binaryen.i32),
2009
+ this.module.i32.const(address - packed.address)))));
2010
+ });
2011
+ }
1910
2012
  const compiledBody = this.compileBlock(func.body, context);
1911
2013
  const body = context.entryInitializers.length === 0
1912
2014
  ? compiledBody
@@ -1916,9 +2018,10 @@ export class MirCompilerCore {
1916
2018
  ]);
1917
2019
  const functionRef = this.module.addFunction(
1918
2020
  this.functionNames[id],
1919
- binaryen.createType(paramScalars.map((type) => this.wasmType(type))),
2021
+ packed ? binaryen.i32 : binaryen.createType(paramScalars.map((type) => this.wasmType(type))),
1920
2022
  this.wasmResultType(resultScalars),
1921
2023
  [
2024
+ ...(packed ? paramScalars.map((type) => this.wasmType(type)) : []),
1922
2025
  ...flatLocalScalars.map((type) => this.wasmType(type)),
1923
2026
  ...callResultLocals.map((entry) => entry.type),
1924
2027
  ...Array.from({ length: sliceScratch.count }, () => binaryen.i32),
@@ -1989,16 +2092,20 @@ export class MirCompilerCore {
1989
2092
  components: ["i32", "i32", "i32", "i32", "f32", "i32"],
1990
2093
  };
1991
2094
  }
1992
- if (type.kind === "buffer_span") {
2095
+ if (["buffer_span", "buffer_map"].includes(type.kind)) {
1993
2096
  this.bufferChannelMetadata(type.data.channels, type.data.element);
2097
+ if (!Number.isInteger(type.data.len) || type.data.len <= 0 || type.data.len > 0x7fff_ffff
2098
+ || !["read_only", "read_write"].includes(type.data.access)) {
2099
+ this.fail(`${description} has an invalid buffer collection contract`);
2100
+ }
1994
2101
  if (passingMode !== "value") {
1995
2102
  this.fail(`${description} buffer span must use value passing mode`);
1996
2103
  }
1997
2104
  return {
1998
2105
  index,
1999
2106
  typeId,
2000
- kind: "buffer_span",
2001
- components: ["i32", "i32", "i32", "i32", "i32", "i32"],
2107
+ kind: type.kind,
2108
+ components: Array(type.kind === "buffer_map" ? 7 : 6).fill("i32"),
2002
2109
  };
2003
2110
  }
2004
2111
  if (type.kind === "array") {
@@ -2028,8 +2135,8 @@ export class MirCompilerCore {
2028
2135
  if (layout.kind === "array") return;
2029
2136
  const suffixes = layout.kind === "buffer"
2030
2137
  ? ["read_address", "write_address", "frames", "channels", "sample_rate", "bound"]
2031
- : layout.kind === "buffer_span"
2032
- ? ["read_table", "write_table", "frames_table", "channels_table", "sample_rates_table", "bound_table"]
2138
+ : ["buffer_span", "buffer_map"].includes(layout.kind)
2139
+ ? ["read_table", "write_table", "frames_table", "channels_table", "sample_rates_table", "bound_table", ...(layout.kind === "buffer_map" ? ["resource_map"] : [])]
2033
2140
  : ["read_address", "write_address", "length", "stride"];
2034
2141
  for (const [offset, suffix] of suffixes.entries()) {
2035
2142
  binaryen.Function.setLocalName(
@@ -170,7 +170,7 @@ export class MirCompiler extends MirCompilerLowering {
170
170
  const prelude = [];
171
171
  let selector = null;
172
172
  if (
173
- source.data.parameter?.kind === "array_element"
173
+ ["array_element", "local_element"].includes(source.data.parameter?.kind)
174
174
  && staticSelector === null
175
175
  ) {
176
176
  const selectorLocal = this.allocateGeneratedLocal(
@@ -203,7 +203,7 @@ export class MirCompiler extends MirCompilerLowering {
203
203
  context,
204
204
  );
205
205
  if (
206
- source.data.parameter?.kind === "array_element"
206
+ ["array_element", "local_element"].includes(source.data.parameter?.kind)
207
207
  && staticSelector === null
208
208
  && this.bufferChannelMetadata(
209
209
  type.data.channels,
@@ -1405,7 +1405,7 @@ export class MirCompiler extends MirCompilerLowering {
1405
1405
  lhs.data.element === rhs.data.element &&
1406
1406
  JSON.stringify(lhs.data.channels) === JSON.stringify(rhs.data.channels) &&
1407
1407
  lhs.data.access === rhs.data.access;
1408
- } else if (lhs.kind === "buffer_span") {
1408
+ } else if (["buffer_span", "buffer_map"].includes(lhs.kind)) {
1409
1409
  equivalent =
1410
1410
  lhs.data.element === rhs.data.element &&
1411
1411
  JSON.stringify(lhs.data.channels) === JSON.stringify(rhs.data.channels) &&
@@ -1709,6 +1709,7 @@ export class MirCompiler extends MirCompilerLowering {
1709
1709
  outputs: this.portMetadata(this.mir.interface.outputs, this.outputLayout),
1710
1710
  control_outputs: this.mir.interface.control_outputs.map((output, id) => ({
1711
1711
  name: output.name,
1712
+ ...(output.enumeration ? { enumeration: output.enumeration } : {}),
1712
1713
  type_repr: typeName(this.type(output.ty), this),
1713
1714
  scalar: this.storageShape(output.ty).scalar,
1714
1715
  array_len: this.storageShape(output.ty).length,
@@ -1727,6 +1728,7 @@ export class MirCompiler extends MirCompilerLowering {
1727
1728
  })),
1728
1729
  params: this.mir.interface.params.map((param, id) => ({
1729
1730
  name: param.name,
1731
+ ...(param.enumeration ? { enumeration: param.enumeration } : {}),
1730
1732
  type_repr: typeName(this.type(param.ty), this),
1731
1733
  scalar: this.storageShape(param.ty).scalar,
1732
1734
  array_len: this.storageShape(param.ty).length,