Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(aot): a resource a compiled system writes, on every road

yhh75fa707a9886
diff --git a/compiler/src/frontend.ts b/compiler/src/frontend.ts
index 876850eda..34746bc7e 100644
--- a/compiler/src/frontend.ts
+++ b/compiler/src/frontend.ts
@@ -207,6 +207,8 @@ class SystemLowerer {
private next = 0;
/** A stack, not one map: a `const` in a row loop must not outlive the loop. */
private readonly scopes: Map<string, Local>[] = [new Map()];
+ /** Depth inside a `res.modify` body, where writing the resource is the point. */
+ private inModify = 0;
constructor(
private readonly comps: Map<string, CompShape>,
@@ -399,7 +401,7 @@ class SystemLowerer {
private stmt(node: ts.Statement): Stmt[] {
if (ts.isForOfStatement(node)) return [this.rowLoop(node)];
if (ts.isExpressionStatement(node)) {
- if (ts.isCallExpression(node.expression)) return [this.emit(node.expression)];
+ if (ts.isCallExpression(node.expression)) return this.callStmt(node.expression);
return [this.assignment(node.expression)];
}
if (ts.isBlock(node)) return this.scoped(() => node.statements.flatMap((s) => this.stmt(s)));
@@ -503,6 +505,58 @@ class SystemLowerer {
return { s: 'rowLoop', query: { p: 'local', id: q.id }, entity, binds, body };
}
+ /**
+ * A call statement: `res.modify(fn)`, which is inlined, or a channel emit.
+ *
+ * `ResMut` is the one parameter whose SOURCE FORM differs by road: the
+ * interpreter hands a WRAPPER, so `r.n = 1` sets a field of it and the world
+ * never sees the write. `.modify` is the spelling both roads take.
+ */
+ private callStmt(node: ts.CallExpression): Stmt[] {
+ const callee = node.expression;
+ if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)
+ && callee.name.text === 'modify') {
+ const target = this.tryLookup(callee.expression.text);
+ if (target !== null && target.type.k === 'res') return this.modify(node, target);
+ }
+ return [this.emit(node)];
+ }
+
+ /**
+ * `res.modify((v) => { ... })`, inlined with `v` bound to the resource.
+ *
+ * An ALIAS, not a copy: the body addresses exactly what `res.field` would,
+ * so one authored line becomes one write on either road.
+ */
+ private modify(node: ts.CallExpression, target: Local): Stmt[] {
+ if (target.type.k !== 'res' || !target.type.mut) {
+ throw new NotInSubset(node, `'${target.name}' is a Res; only a ResMut can be modified`);
+ }
+ const fn = node.arguments[0];
+ if (fn === undefined || node.arguments.length !== 1 || !ts.isArrowFunction(fn)) {
+ throw new NotInSubset(node, 'modify takes exactly one arrow function');
+ }
+ if (fn.parameters.length !== 1) {
+ throw new NotInSubset(node,
+ `modify's callback takes 1 parameter, not ${fn.parameters.length}`);
+ }
+ const name = fn.parameters[0]!.name;
+ if (!ts.isIdentifier(name)) {
+ throw new NotInSubset(node, "modify's parameter must be a plain name");
+ }
+ this.inModify++;
+ try {
+ return this.scoped(() => {
+ this.scopes[this.scopes.length - 1]!.set(name.text, target);
+ return ts.isBlock(fn.body)
+ ? fn.body.statements.flatMap((st) => this.stmt(st))
+ : [this.assignment(fn.body)];
+ });
+ } finally {
+ this.inModify--;
+ }
+ }
+
/**
* `cmds.despawn(entity)` — a record appended to a channel, not a call. The
* SDK already defers these to a flush at system end, so this models what it
@@ -604,6 +658,7 @@ class SystemLowerer {
}
const compound = COMPOUND.get(node.operatorToken.kind);
const target = this.place(node.left);
+ this.refuseBareResourceWrite(node.left, target);
if (compound) {
const type = this.placeType(node.left);
const read: Expr = { e: 'read', place: target, type };
@@ -613,9 +668,30 @@ class SystemLowerer {
if (node.operatorToken.kind !== ts.SyntaxKind.EqualsToken) {
throw new NotInSubset(node, `'${tokenText(node.operatorToken.kind)}' is not an assignment this subset lowers`);
}
+ // Resolved for its REFUSALS: a plain `=` needs no read, so a field no
+ // declared shape has reached the IR verifier rather than being refused
+ // here, which coverage.test.ts calls a frontend bug.
+ this.placeType(node.left);
return { s: 'assign', target, value: this.expr(node.right) };
}
+ /**
+ * A write straight into a resource, outside `modify`, is refused.
+ *
+ * One line, two meanings: this side lowers a write, and the interpreter sets
+ * a field on the ResMut WRAPPER that no reader of the world sees.
+ */
+ private refuseBareResourceWrite(node: ts.Expression, target: Place): void {
+ if (this.inModify > 0) return;
+ let base = target;
+ while (base.p === 'field') base = base.base;
+ const local = this.locals.find((l) => l.id === base.id);
+ if (local?.type.k !== 'res') return;
+ throw new NotInSubset(node, `'${local.name}' is a resource, and a bare write to one is a `
+ + 'no-op in the interpreter — write it as '
+ + `${local.name}.modify((v) => { ... }), which both roads lower the same`);
+ }
+
/** A place is a local, or a dotted path from one. Nothing else is addressable. */
private place(node: ts.Expression): Place {
if (ts.isIdentifier(node)) {
diff --git a/fixtures/aot-conformance/src/main.ts b/fixtures/aot-conformance/src/main.ts
index b7b0be396..ff66d4bc6 100644
--- a/fixtures/aot-conformance/src/main.ts
+++ b/fixtures/aot-conformance/src/main.ts
@@ -6,7 +6,7 @@ import {
Query, Res, Schedule, Time,
} from 'esengine';
-import { Mover, driftSystem, clampSystem } from './systems.generated';
+import { Mover, Tally, driftSystem, clampSystem, tallySystem } from './systems.generated';
import { SEED } from './seed.generated';
/** Spawned in the order the trace records rows in, which is pool order. */
@@ -24,11 +24,12 @@ let frame = 0;
* The delta goes out with the rows because a road that stepped by another one
* is a different question from a road that computed the step wrong. */
const reportSystem = defineSystem(
- [Query(Mover), Res(Time)],
- (query, time) => {
+ [Query(Mover), Res(Time), Res(Tally)],
+ (query, time, tally) => {
const rows: number[][] = [];
for (const [, m] of query) rows.push([m.x, m.speed, m.bounces]);
- console.log(`CONF ${frame} ${time.delta} ${JSON.stringify(rows)}`);
+ console.log(`CONF ${frame} ${time.delta} ${JSON.stringify(rows)} `
+ + `${JSON.stringify([tally.bounces, tally.frames])}`);
frame++;
},
{ name: 'ConfReport' },
@@ -37,4 +38,5 @@ const reportSystem = defineSystem(
addStartupSystem(spawnSystem);
addSystemToSchedule(Schedule.Update, driftSystem);
addSystemToSchedule(Schedule.Update, clampSystem);
+addSystemToSchedule(Schedule.Update, tallySystem);
addSystemToSchedule(Schedule.Update, reportSystem);
diff --git a/fixtures/aot-conformance/src/systems.generated.ts b/fixtures/aot-conformance/src/systems.generated.ts
index da2004746..6f9542f47 100644
--- a/fixtures/aot-conformance/src/systems.generated.ts
+++ b/fixtures/aot-conformance/src/systems.generated.ts
@@ -13,10 +13,14 @@
* compiler — which matches `defineSystem` by name, not by where it
* came from.
*/
-import { defineComponent, defineSystem, Query, Mut, Res, Time } from 'esengine';
+import { defineComponent, defineSystem, Query, Mut, Res, ResMut, Time, defineResource } from 'esengine';
export const Mover = defineComponent('ConfMover', { x: 0, speed: 0, bounces: 0 });
+/** A resource the compiled code WRITES. A ResMut lands in the mirror and
+ * nowhere else, so it is in the world only if the road copied it back. */
+export const Tally = defineResource({ bounces: 0, frames: 0 }, 'ConfTally');
+
/**
* @compiled
*/
@@ -50,3 +54,21 @@ export const clampSystem = defineSystem(
},
{ name: 'ConfClamp' },
);
+
+/**
+ * @compiled
+ */
+export const tallySystem = defineSystem(
+ [Query(Mover), ResMut(Tally)],
+ (query, tally) => {
+ tally.modify((t) => {
+ t.frames = t.frames + 1;
+ });
+ for (const [, m] of query) {
+ tally.modify((t) => {
+ t.bounces = t.bounces + m.bounces;
+ });
+ }
+ },
+ { name: 'ConfTally' },
+);
diff --git a/sdk/src/app/app.ts b/sdk/src/app/app.ts
index 9cf5a0105..f13b26659 100644
--- a/sdk/src/app/app.ts
+++ b/sdk/src/app/app.ts
@@ -7,7 +7,7 @@
import { World } from '../ecs/world';
import { Schedule, SystemDef, SystemRunner, SystemSet, mergeOrderingEdges, rescopeSystem, type RunCondition } from '../ecs/system';
-import { builtinResource, ResourceStorage, Time, TimeData, type ResourceDef } from '../ecs/resource';
+import { builtinResource, declaredResource, ResourceStorage, Time, TimeData, type ResourceDef } from '../ecs/resource';
import { installAot, prepareAot, type AotHost } from '../ecs/aot/installAot';
import { installNativeAot, nativeAotBindings } from '../ecs/aot/installNativeAot';
import { createNativeHeap } from '../ecs/bridge/nativeHeap';
@@ -632,7 +632,7 @@ export class App {
manifest: opts.manifest,
wasm: opts.wasm,
resourceFields: (name) => {
- const def = builtinResource(name) ?? this.resources_.getByName(name);
+ const def = builtinResource(name) ?? this.resources_.getByName(name) ?? declaredResource(name);
if (def === undefined) return undefined;
const value = this.resources_.get(def);
return typeof value === 'object' && value !== null ? Object.keys(value) : [];
@@ -651,7 +651,7 @@ export class App {
resources: (name) => {
// The engine's own by name, and the PROJECT's through the
// storage's own name registry — a compiled system reads either.
- const def = builtinResource(name) ?? this.resources_.getByName(name);
+ const def = builtinResource(name) ?? this.resources_.getByName(name) ?? declaredResource(name);
// `get`, not `has` then `get`: a slot holding a materialised
// default is what an INTERPRETED system reads, and a twin has to
// see the same world or the two stop being the same program.
@@ -869,7 +869,10 @@ export class App {
}
getResourceByName(name: string): unknown | undefined {
- const def = this.resources_.getByName(name);
+ // The storage learns a name on INSERT; a declared one `get` materialises
+ // at its default, which is what an interpreted system reads on its first
+ // frame. Without this the AOT handshake refused a resource that was there.
+ const def = builtinResource(name) ?? this.resources_.getByName(name) ?? declaredResource(name);
return def ? this.resources_.get(def) : undefined;
}
diff --git a/sdk/src/ecs/aot/installNativeAot.ts b/sdk/src/ecs/aot/installNativeAot.ts
index ce7b42f50..d81ad297f 100644
--- a/sdk/src/ecs/aot/installNativeAot.ts
+++ b/sdk/src/ecs/aot/installNativeAot.ts
@@ -155,6 +155,13 @@ export function installNativeAot(opts: InstallNativeAotOptions): AotRuntime | nu
addressBytes: NATIVE_ADDRESS_BYTES,
runs: (name) => byName.has(name),
moduleContract: paired === '' ? null : paired,
+ // From the RUNTIME's own copy. The default answers "no fields" for every
+ // resource, so this road's handshake could not see a project resource at
+ // all and the mirror was laid out from the manifest alone.
+ resourceFields: (name) => {
+ const value = opts.resources?.(name);
+ return value === undefined ? undefined : Object.keys(value);
+ },
});
// Every script component any twin names, so one epoch change re-reports all
diff --git a/sdk/src/ecs/resource.ts b/sdk/src/ecs/resource.ts
index d9a2ba624..f98e1f6f7 100644
--- a/sdk/src/ecs/resource.ts
+++ b/sdk/src/ecs/resource.ts
@@ -48,11 +48,19 @@ export function defineResource<T>(defaultValue: T, name?: string): ResourceDef<T
// module's manifest carries names. Only the DECLARED ones: a project's
// resource is identified by reference, and two may share a name.
if (name && RESOURCE_SHAPES[name]) builtinByName.set(name, def as ResourceDef<unknown>);
+ else if (name !== undefined) {
+ // Two declarations of one name cannot both be what a manifest means.
+ if (declaredByName.has(name)) ambiguousNames.add(name);
+ declaredByName.set(name, def as ResourceDef<unknown>);
+ }
return def;
}
/** Registered by `defineResource` for the names `resourceShapes.ts` declares. */
const builtinByName = new Map<string, ResourceDef<unknown>>();
+/** And for the names a PROJECT declares, which a manifest also carries. */
+const declaredByName = new Map<string, ResourceDef<unknown>>();
+const ambiguousNames = new Set<string>();
/**
* The engine resource a manifest's NAME refers to, or undefined when the module
@@ -66,6 +74,19 @@ export function builtinResource(name: string): ResourceDef<unknown> | undefined
return builtinByName.get(name);
}
+/**
+ * A named resource a project DECLARED, whether or not anything has inserted one.
+ *
+ * The storage learns a name on INSERT, so a resource nothing had touched was
+ * invisible to the AOT handshake. Undefined for an AMBIGUOUS name: two
+ * declarations sharing one is a project no manifest can describe.
+ *
+ * @internal
+ */
+export function declaredResource(name: string): ResourceDef<unknown> | undefined {
+ return ambiguousNames.has(name) ? undefined : declaredByName.get(name);
+}
+
// =============================================================================
// Resource Descriptors (for system parameters)
// =============================================================================
diff --git a/sdk/tests/aot-conformance.test.ts b/sdk/tests/aot-conformance.test.ts
index 212b65561..8951b2873 100644
--- a/sdk/tests/aot-conformance.test.ts
+++ b/sdk/tests/aot-conformance.test.ts
@@ -81,9 +81,11 @@ function compileFixture(emcc: string): { wasm: Uint8Array; manifest: AotManifest
/** The world the fixture's systems touch, after each frame. */
type Trace = number[][][];
+/** The resource one of them WRITES, after each frame: [bounces, frames]. */
+type ResTrace = number[][];
async function play(compiled: { wasm: Uint8Array; manifest: AotManifest } | null): Promise<{
- trace: Trace; calls: number; delta: number;
+ trace: Trace; resource: ResTrace; calls: number; delta: number;
}> {
// One context for both roads on purpose: the fixture's `defineComponent`
// runs once, at import, and a road that reset the registry under it would
@@ -95,6 +97,10 @@ async function play(compiled: { wasm: Uint8Array; manifest: AotManifest } | null
const fixture = await import('./fixtures/conformance-systems');
app.addSystemToSchedule(Schedule.Update, fixture.driftSystem);
app.addSystemToSchedule(Schedule.Update, fixture.clampSystem);
+ app.addSystemToSchedule(Schedule.Update, fixture.tallySystem);
+ // NOT inserted: a project resource nothing has touched yet is exactly the
+ // case a shipped game boots in, and the handshake has to find it by the name
+ // the manifest carries or refuse the module over a resource that is there.
// Before the first pooled component: a pool cannot move to other memory
// once it has rows, and the module addresses only the heap it was given.
@@ -113,19 +119,24 @@ async function play(compiled: { wasm: Uint8Array; manifest: AotManifest } | null
});
const trace: Trace = [];
+ const resource: ResTrace = [];
for (let f = 0; f < FRAMES; f++) {
await app.tick(DT);
trace.push(entities.map((e) => {
const m = app.world.get(e, fixture.Mover) as { x: number; speed: number; bounces: number };
return [m.x, m.speed, m.bounces];
}));
+ // A ResMut is written into the MIRROR; this reads the world, which is
+ // where it lands only if the road copied it back.
+ const tally = app.getResource(fixture.Tally) as { bounces: number; frames: number };
+ resource.push([tally.bounces, tally.frames]);
}
// The delta the interpreter was HANDED, which is what the native harness is
// given: `tick` scales what it is asked for, and a harness restating 1/60
// would be a second opinion about the frame rather than a reading of it.
const time = (app as unknown as { resources_: { get: (r: unknown) => { delta: number } } })
.resources_.get(Time);
- return { trace, calls: runtime?.systems.calls ?? 0, delta: time.delta };
+ return { trace, resource, calls: runtime?.systems.calls ?? 0, delta: time.delta };
}
describe.skipIf(!EMCC)('one source, interpreted and compiled', () => {
@@ -139,14 +150,18 @@ describe.skipIf(!EMCC)('one source, interpreted and compiled', () => {
// Installed is not the same question as ran, and a differential cannot
// tell them apart — the closure that would have run produces the same
- // numbers. Two systems, every frame.
- expect(twins.calls).toBe(FRAMES * 2);
+ // numbers. Three systems, every frame.
+ expect(twins.calls).toBe(FRAMES * 3);
expect(interpreted.calls).toBe(0);
// Frame for frame, so a divergence names the frame it began on rather
// than only the state it ended in.
for (let f = 0; f < FRAMES; f++) {
expect([f, twins.trace[f]]).toEqual([f, interpreted.trace[f]]);
+ // The resource a twin WROTE, read back out of the world: the road
+ // that never copied the mirror back would leave it at its default
+ // while every row above still agreed.
+ expect([f, twins.resource[f]]).toEqual([f, interpreted.resource[f]]);
}
// And the run went somewhere: a fixture whose systems do nothing agrees
// on every road.
@@ -327,6 +342,11 @@ describe('the inputs a loading host builds against', () => {
fields: ['x', 'speed', 'bounces'],
seed: SEEDS.map(([x, speed]) => [x, speed, 0]),
frames: run.trace,
+ // The resource a twin WROTE, read back out of the world. A road that
+ // never copied the mirror back leaves it at its default while every
+ // row above still agrees, which is why it is traced separately.
+ resourceFields: ['bounces', 'frames'],
+ resource: run.resource,
}, null, 2)}\n`);
});
diff --git a/sdk/tests/fixtures/conformance-systems.ts b/sdk/tests/fixtures/conformance-systems.ts
index b5b160cc0..d9e516679 100644
--- a/sdk/tests/fixtures/conformance-systems.ts
+++ b/sdk/tests/fixtures/conformance-systems.ts
@@ -13,10 +13,14 @@
import { defineComponent } from '../../src/ecs/component';
import { defineSystem } from '../../src/ecs/system';
import { Query, Mut } from '../../src/ecs/query';
-import { Res, Time } from '../../src/ecs/resource';
+import { Res, ResMut, Time, defineResource } from '../../src/ecs/resource';
export const Mover = defineComponent('ConfMover', { x: 0, speed: 0, bounces: 0 });
+/** A resource the compiled code WRITES. A ResMut lands in the mirror and
+ * nowhere else, so it is in the world only if the road copied it back. */
+export const Tally = defineResource({ bounces: 0, frames: 0 }, 'ConfTally');
+
/**
* @compiled
*/
@@ -50,3 +54,21 @@ export const clampSystem = defineSystem(
},
{ name: 'ConfClamp' },
);
+
+/**
+ * @compiled
+ */
+export const tallySystem = defineSystem(
+ [Query(Mover), ResMut(Tally)],
+ (query, tally) => {
+ tally.modify((t) => {
+ t.frames = t.frames + 1;
+ });
+ for (const [, m] of query) {
+ tally.modify((t) => {
+ t.bounces = t.bounces + m.bounces;
+ });
+ }
+ },
+ { name: 'ConfTally' },
+);
diff --git a/tests/aot/generated/conformance/estella_offsets.h b/tests/aot/generated/conformance/estella_offsets.h
index c1d368a03..4b49e6164 100644
--- a/tests/aot/generated/conformance/estella_offsets.h
+++ b/tests/aot/generated/conformance/estella_offsets.h
@@ -8,6 +8,8 @@
#define ES_OFF_ConfMover_bounces 16u
#define ES_OFF_ConfMover_speed 8u
#define ES_OFF_ConfMover_x 0u
+#define ES_OFF_ConfTally_bounces 0u
+#define ES_OFF_ConfTally_frames 8u
#define ES_OFF_Time_delta 0u
#endif /* ESTELLA_OFFSETS_H */
diff --git a/tests/aot/generated/conformance/handshake.h b/tests/aot/generated/conformance/handshake.h
index b44e597a1..2ad56e404 100644
--- a/tests/aot/generated/conformance/handshake.h
+++ b/tests/aot/generated/conformance/handshake.h
@@ -2,4 +2,4 @@
/* The contract half of the handshake. The width half is the harness. */
#define ES_CONF_EXPECTED_CONTRACT_HASH 0xaa8849ed8d31d9a0ULL
/* And which BUILD the artifact beside this one is. */
-#define ES_CONF_EXPECTED_MODULE_CONTRACT 0x1b0366c7f77a6dadULL
+#define ES_CONF_EXPECTED_MODULE_CONTRACT 0xa45bab2f04e812a6ULL
diff --git a/tests/aot/generated/conformance/systems.c b/tests/aot/generated/conformance/systems.c
index 1fbe63a1f..c49fb43d3 100644
--- a/tests/aot/generated/conformance/systems.c
+++ b/tests/aot/generated/conformance/systems.c
@@ -6,8 +6,8 @@
/* Which BUILD this is, for a loader holding the sidecar written beside
it. The two digests above answer "is this engine right" and "are the
project shapes right"; neither answers "are these two the same pair". */
-ES_EXPORT uint32_t es_module_contract_lo(void) { return 0xf77a6dadu; }
-ES_EXPORT uint32_t es_module_contract_hi(void) { return 0x1b0366c7u; }
+ES_EXPORT uint32_t es_module_contract_lo(void) { return 0x04e812a6u; }
+ES_EXPORT uint32_t es_module_contract_hi(void) { return 0xa45bab2fu; }
ES_EXPORT void es_sys_ConfDrift(es_addr_t es_ctx) {
const EsSysCtx *es_c = (const EsSysCtx *)ES_PTR(es_ctx);
@@ -48,3 +48,20 @@ ES_EXPORT void es_sys_ConfClamp(es_addr_t es_ctx) {
}
}
}
+
+ES_EXPORT void es_sys_ConfTally(es_addr_t es_ctx) {
+ const EsSysCtx *es_c = (const EsSysCtx *)ES_PTR(es_ctx);
+ const EsQueryRows *es_queries = (const EsQueryRows *)ES_PTR(es_c->queries);
+ const es_addr_t *es_resources = (const es_addr_t *)ES_PTR(es_c->resources);
+ unsigned char *tally_1 = ES_PTR(es_resources[0]);
+ es_set_f64(tally_1 + ES_OFF_ConfTally_frames, (es_f64(tally_1 + ES_OFF_ConfTally_frames) + 1.0));
+ {
+ const es_addr_t *es_rows0 = (const es_addr_t *)ES_PTR(es_queries[0].rows);
+ const es_addr_t es_n0 = es_queries[0].count;
+ for (es_addr_t es_i0 = 0; es_i0 < es_n0; ++es_i0) {
+ const es_addr_t *es_row0 = es_rows0 + es_i0 * 2u;
+ unsigned char *m_2 = ES_PTR(es_row0[1]);
+ es_set_f64(tally_1 + ES_OFF_ConfTally_bounces, (es_f64(tally_1 + ES_OFF_ConfTally_bounces) + es_f64(m_2 + ES_OFF_ConfMover_bounces)));
+ }
+ }
+}
diff --git a/tests/aot/generated/conformance/systems_decl.c b/tests/aot/generated/conformance/systems_decl.c
index a88746189..b2384b471 100644
--- a/tests/aot/generated/conformance/systems_decl.c
+++ b/tests/aot/generated/conformance/systems_decl.c
@@ -16,6 +16,7 @@ ES_EXPORT const uint64_t es_abi_hash =
ES_EXPORT void es_sys_ConfDrift(es_addr_t es_ctx);
ES_EXPORT void es_sys_ConfClamp(es_addr_t es_ctx);
+ES_EXPORT void es_sys_ConfTally(es_addr_t es_ctx);
/* The systems in this file, and what each one needs filled in. */
static const char *const es_sys_ConfDrift_q0_comps[] = { "ConfMover" };
@@ -26,9 +27,15 @@ static const unsigned char es_sys_ConfDrift_resources_mut[] = { 0u };
static const char *const es_sys_ConfClamp_q0_comps[] = { "ConfMover" };
static const unsigned char es_sys_ConfClamp_q0_mut[] = { 1u };
static const EsQueryDecl es_sys_ConfClamp_queries[] = { { es_sys_ConfClamp_q0_comps, es_sys_ConfClamp_q0_mut, 1u } };
+static const char *const es_sys_ConfTally_q0_comps[] = { "ConfMover" };
+static const unsigned char es_sys_ConfTally_q0_mut[] = { 0u };
+static const EsQueryDecl es_sys_ConfTally_queries[] = { { es_sys_ConfTally_q0_comps, es_sys_ConfTally_q0_mut, 1u } };
+static const char *const es_sys_ConfTally_resources[] = { "ConfTally" };
+static const unsigned char es_sys_ConfTally_resources_mut[] = { 1u };
ES_EXPORT const EsSystemDecl es_systems[] = {
{ "ConfDrift", es_sys_ConfDrift, es_sys_ConfDrift_queries, es_sys_ConfDrift_resources, es_sys_ConfDrift_resources_mut, 1u, 1u },
{ "ConfClamp", es_sys_ConfClamp, es_sys_ConfClamp_queries, NULL, NULL, 1u, 0u },
+ { "ConfTally", es_sys_ConfTally, es_sys_ConfTally_queries, es_sys_ConfTally_resources, es_sys_ConfTally_resources_mut, 1u, 1u },
};
-ES_EXPORT const uint32_t es_system_count = 2u;
+ES_EXPORT const uint32_t es_system_count = 3u;
diff --git a/tests/aot/generated/conformance/trace.json b/tests/aot/generated/conformance/trace.json
index f20dec108..db8222dee 100644
--- a/tests/aot/generated/conformance/trace.json
+++ b/tests/aot/generated/conformance/trace.json
@@ -292,5 +292,59 @@
2
]
]
+ ],
+ "resourceFields": [
+ "bounces",
+ "frames"
+ ],
+ "resource": [
+ [
+ 2,
+ 1
+ ],
+ [
+ 4,
+ 2
+ ],
+ [
+ 7,
+ 3
+ ],
+ [
+ 10,
+ 4
+ ],
+ [
+ 13,
+ 5
+ ],
+ [
+ 17,
+ 6
+ ],
+ [
+ 21,
+ 7
+ ],
+ [
+ 26,
+ 8
+ ],
+ [
+ 31,
+ 9
+ ],
+ [
+ 36,
+ 10
+ ],
+ [
+ 41,
+ 11
+ ],
+ [
+ 46,
+ 12
+ ]
]
}
diff --git a/tools/verify-native-conformance.mjs b/tools/verify-native-conformance.mjs
index b479ee2b9..cfe527be7 100644
--- a/tools/verify-native-conformance.mjs
+++ b/tools/verify-native-conformance.mjs
@@ -101,12 +101,15 @@ function play(compiled) {
}
}
-/** `CONF <frame> <delta> <rows>` — what the fixture's own reporting system says. */
+/** `CONF <frame> <delta> <rows> <resource>` — what the fixture's reporter says. */
function framesIn(log) {
const out = [];
for (const line of log.split('\n')) {
- const m = /CONF (\d+) (\S+) (\[.*\])\s*$/.exec(line);
- if (m !== null) out.push({ at: Number(m[1]), delta: Number(m[2]), rows: JSON.parse(m[3]) });
+ const m = /CONF (\d+) (\S+) (\[.*\]) (\[[^\]]*\])\s*$/.exec(line);
+ if (m !== null) {
+ out.push({ at: Number(m[1]), delta: Number(m[2]), rows: JSON.parse(m[3]),
+ resource: JSON.parse(m[4]) });
+ }
}
return out;
}
@@ -135,6 +138,15 @@ function compare(road, got) {
if (frame.rows.length !== wantRows.length) {
fail(`${road} has ${frame.rows.length} row(s) at frame ${f}, and the trace has ${wantRows.length}`);
}
+ // The resource a twin WROTE, read back out of the world: a road that never
+ // copied the mirror back leaves it at its default while every row agrees.
+ for (let k = 0; k < want.resource[f].length; k++) {
+ if (frame.resource[k] !== want.resource[f][k]) {
+ fail(`${road} disagrees at frame ${f} about the resource, ${want.resourceFields[k]}`,
+ `interpreter ${want.resource[f][k]}
+host ${frame.resource[k]}`);
+ }
+ }
for (let i = 0; i < wantRows.length; i++) {
for (let k = 0; k < wantRows[i].length; k++) {
if (frame.rows[i][k] !== wantRows[i][k]) {