Skip to content

Commit 6caa90f

Browse files
committed
Prefer human-friendly property names in serializations
1 parent ac2e2f8 commit 6caa90f

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

src/language/compiling/compiler.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
6666
],
6767
[
6868
['@runtime', ['@lookup', ['identity']]],
69-
success({ 0: '@runtime', 1: { 0: '@lookup', 1: { 0: 'identity' } } }),
69+
success({
70+
0: '@runtime',
71+
function: { 0: '@lookup', query: { 0: 'identity' } },
72+
}),
7073
],
7174
[
7275
[
@@ -75,7 +78,7 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
7578
],
7679
success({
7780
0: '@runtime',
78-
1: { 0: '@lookup', 1: { 0: 'identity' } },
81+
function: { 0: '@lookup', query: { 0: 'identity' } },
7982
}),
8083
],
8184
[
@@ -114,12 +117,12 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
114117
],
115118
success({
116119
0: '@runtime',
117-
1: {
120+
function: {
118121
0: '@apply',
119-
1: { 0: '@lookup', 1: { 0: 'flow' } },
120-
2: {
121-
0: { 0: '@lookup', 1: { 0: 'identity' } },
122-
1: { 0: '@lookup', 1: { 0: 'identity' } },
122+
function: { 0: '@lookup', query: { 0: 'flow' } },
123+
argument: {
124+
0: { 0: '@lookup', query: { 0: 'identity' } },
125+
1: { 0: '@lookup', query: { 0: 'identity' } },
123126
},
124127
},
125128
}),
@@ -154,8 +157,8 @@ testCases(compile, input => `compiling \`${JSON.stringify(input)}\``)(
154157
0: '@runtime',
155158
function: {
156159
0: '@apply',
157-
1: { 0: '@lookup', 1: { 0: 'object', 1: 'lookup' } },
158-
2: 'key which does not exist in runtime context',
160+
function: { 0: '@lookup', query: { 0: 'object', 1: 'lookup' } },
161+
argument: 'key which does not exist in runtime context',
159162
},
160163
}),
161164
],

src/language/compiling/semantics.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ elaborationSuite('@runtime', [
586586
{ 0: '@runtime', 1: { 0: '@lookup', query: { 0: 'identity' } } },
587587
either.makeRight(
588588
withPhantomData<never>()(
589-
makeObjectNode({ 0: '@runtime', 1: prelude.identity! }),
589+
makeObjectNode({ 0: '@runtime', function: prelude.identity! }),
590590
),
591591
),
592592
],

src/language/compiling/semantics/expressions/runtime-expression.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
} from '../../../semantics/semantic-graph.js'
2121
import {
2222
asSemanticGraph,
23-
locateSelf,
2423
readArgumentsFromExpression,
2524
} from './expression-utilities.js'
2625

@@ -68,28 +67,25 @@ export const makeRuntimeExpression = (
6867

6968
export const runtimeKeywordHandler: KeywordHandler = (
7069
expression: Expression,
71-
context: ExpressionContext,
70+
_context: ExpressionContext,
7271
): Either<ElaborationError, SemanticGraph> =>
7372
either.flatMap(readRuntimeExpression(expression), ({ function: f }) => {
7473
const runtimeFunction = asSemanticGraph(f)
7574
if (isFunctionNode(runtimeFunction)) {
7675
const runtimeFunctionSignature = runtimeFunction.signature
77-
return either.flatMap(locateSelf(context), valueFromProgram =>
78-
!isAssignable({
79-
source: types.runtimeContext,
80-
target: replaceAllTypeParametersWithTheirConstraints(
81-
runtimeFunctionSignature.parameter,
82-
),
83-
})
84-
? either.makeLeft({
85-
kind: 'typeMismatch',
86-
message:
87-
'@runtime function must accept a runtime context argument',
88-
})
89-
: either.makeRight(valueFromProgram),
90-
)
76+
return !isAssignable({
77+
source: types.runtimeContext,
78+
target: replaceAllTypeParametersWithTheirConstraints(
79+
runtimeFunctionSignature.parameter,
80+
),
81+
})
82+
? either.makeLeft({
83+
kind: 'typeMismatch',
84+
message: '@runtime function must accept a runtime context argument',
85+
})
86+
: either.makeRight(makeRuntimeExpression(f))
9187
} else {
9288
// TODO: Type-check unelaborated nodes.
93-
return locateSelf(context)
89+
return either.makeRight(makeRuntimeExpression(f))
9490
}
9591
})

src/language/compiling/semantics/prelude.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const preludeFunction = (
5959
either.makeRight(
6060
makeUnelaboratedObjectNode({
6161
0: '@lookup',
62-
1: Object.fromEntries(keyPath.map((key, index) => [index, key])),
62+
query: Object.fromEntries(keyPath.map((key, index) => [index, key])),
6363
}),
6464
),
6565
option.none,
@@ -92,8 +92,8 @@ export const prelude: ObjectNode = makeObjectNode({
9292
either.map(serialize(argument), serializedArgument =>
9393
makeUnelaboratedObjectNode({
9494
0: '@apply',
95-
1: { 0: '@lookup', 1: { 0: 'apply' } },
96-
2: serializedArgument,
95+
function: { 0: '@lookup', query: { 0: 'apply' } },
96+
argument: serializedArgument,
9797
}),
9898
),
9999
option.none,
@@ -167,8 +167,8 @@ export const prelude: ObjectNode = makeObjectNode({
167167
either.map(function1.serialize(), serializedFunction1 =>
168168
makeUnelaboratedObjectNode({
169169
0: '@apply',
170-
1: { 0: '@lookup', 1: { 0: 'flow' } },
171-
2: makeUnelaboratedObjectNode({
170+
function: { 0: '@lookup', query: { 0: 'flow' } },
171+
argument: makeUnelaboratedObjectNode({
172172
0: serializedFunction0,
173173
1: serializedFunction1,
174174
}),
@@ -245,8 +245,8 @@ export const prelude: ObjectNode = makeObjectNode({
245245
either.map(serializeObjectNode(cases), serializedCases =>
246246
makeUnelaboratedObjectNode({
247247
0: '@apply',
248-
1: { 0: '@lookup', 1: { 0: 'match' } },
249-
2: serializedCases,
248+
function: { 0: '@lookup', query: { 0: 'match' } },
249+
argument: serializedCases,
250250
}),
251251
),
252252
option.none,
@@ -305,8 +305,11 @@ export const prelude: ObjectNode = makeObjectNode({
305305
either.makeRight(
306306
makeUnelaboratedObjectNode({
307307
0: '@apply',
308-
1: { 0: '@lookup', 1: { 0: 'object', 1: 'lookup' } },
309-
2: key,
308+
function: {
309+
0: '@lookup',
310+
query: { 0: 'object', 1: 'lookup' },
311+
},
312+
argument: key,
310313
}),
311314
),
312315
option.none,

0 commit comments

Comments
 (0)