Make it easier to debug lambdas
Joe Savona committed
Feb 22, 2023 at 14:07 UTC
1d0aa64b242e29020a8a5086fbedd6361f986532
3 files changed
+8
-7
compiler/forget/src/HIR/BuildHIR.ts
+5
-3
@@ -55,9 +55,10 @@ export function lower(
55
options: EnvironmentOptions | null,
56
capturedRefs: t.Identifier[] = [],
57
// the outermost function being compiled, in case lower() is called recursively (for lambdas)
58
- parent: NodePath<t.Function> | null = null
58
+ parent: NodePath<t.Function> | null = null,
59
+ environment: Environment | null = null
60
): Result<HIRFunction, CompilerError> {
60
- const env = new Environment(options);
61
+ const env = environment ?? new Environment(options);
62
const builder = new HIRBuilder(env, parent ?? func, capturedRefs);
63
const context: Place[] = [];
64
@@ -1349,7 +1350,8 @@ function lowerExpression(
1350
expr,
1351
builder.environment.options,
1352
[...builder.context, ...captured.identifiers],
1352
- builder.parentFunction
1353
+ builder.parentFunction,
1354
+ builder.environment
1355
);
1356
let loweredFunc: HIRFunction;
1357
if (lowering.isErr()) {
compiler/forget/src/HIR/PrintHIR.ts
+1
-2
@@ -333,13 +333,12 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
333
break;
334
}
335
case "FunctionExpression": {
336
- // const fn = generate(instrValue.expr).code;
336
const fn = printFunction(instrValue.loweredFunc)
337
.split("\n")
338
.map((line) => ` ${line}`)
339
.join("\n");
340
const deps = instrValue.dependencies
342
- .map((i) => printIdentifier(i.identifier))
341
+ .map((dep) => printPlace(dep))
342
.join(",");
343
value = `Function @deps[${deps}]:\n${fn}`;
344
break;
compiler/forget/src/__tests__/fixtures/hir/capturing-function-member-expr-call.expect.md
+2
-2
@@ -19,9 +19,9 @@ function component({ mutator }) {
19
## Code
20
21
```javascript
22
-function component(t10) {
22
+function component(t15) {
23
const $ = React.unstable_useMemoCache(7);
24
- const t0 = t10;
24
+ const t0 = t15;
25
const mutator = t0.mutator;
26
const c_0 = $[0] !== mutator;
27
let poke;