Refactor: remove language-specific type coercion from CseSnapshotAdapter — move to runner side
CseSnapshotAdapter.ts contains a toJsValue function that maps serialized snapshot value labels to JS runtime values:
if (label === 'int' || label === 'number') { ... }
if (label === 'float' || label === 'complex') { return { toReplString: () => v.displayValue }; }
if (label === 'bool' || label === 'boolean') { return v.displayValue === 'True' || ...; }
if (label === 'str' || label === 'string') { ... }
if (label === 'nonetype' || label === 'none' || label === 'null') { ... }
This is entirely Python-specific knowledge baked into the frontend. It happens to work for Python and JavaScript but breaks for any other language:
- Go uses nil not null/none
- Racket uses #t/#f not true/false
- Any language with non-standard numeric tower (e.g. rationals, bignums) has no representation here
@AaravMalani has pointed this out yet again in the review of #4000.
Proposed direction:
The snapshot protocol should carry values in a frontend-agnostic form. Two options to discuss:
- Standardised kind enum: runner serializes each value with a kind field from a fixed set (number, boolean, string, null, closure, list, raw) plus a displayValue string. Frontend renders purely from kind + displayValue with no language knowledge.
- Pre-rendered display string only: runner is solely responsible for producing the display string; frontend treats all primitives as opaque strings and only structures (closures, lists, pairs) need structural metadata.
Steps:
- Agree on snapshot protocol value format (needs discussion — see above)
- Update py-slang's CSE runner to serialize values in the agreed format
- Simplify CseSnapshotAdapter.toJsValue to consume the standardised format with no language-specific branching
- Document the value format as part of the conductor snapshot protocol spec so future language runners know what to emit
Needs design agreement between frontend and runner maintainers before implementation.
Refactor: remove language-specific type coercion from CseSnapshotAdapter — move to runner side
CseSnapshotAdapter.ts contains a toJsValue function that maps serialized snapshot value labels to JS runtime values:
This is entirely Python-specific knowledge baked into the frontend. It happens to work for Python and JavaScript but breaks for any other language:
@AaravMalani has pointed this out yet again in the review of #4000.
Proposed direction:
The snapshot protocol should carry values in a frontend-agnostic form. Two options to discuss:
Steps:
Needs design agreement between frontend and runner maintainers before implementation.