Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,12 @@ export function lower(
null,
);

const returnIdentifier = builder.makeTemporary(
func.node.loc ?? GeneratedSource,
);

return Ok({
id,
params,
fnType: parent == null ? env.fnType : 'Other',
returnTypeAnnotation: null, // TODO: extract the actual return type node if present
returnIdentifier,
returnType: makeType(),
body: builder.build(),
context,
generator: func.node.generator === true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export type HIRFunction = {
env: Environment;
params: Array<Place | SpreadPattern>;
returnTypeAnnotation: t.FlowType | t.TSType | null;
returnIdentifier: Identifier;
returnType: Type;
context: Array<Place>;
effects: Array<FunctionEffect> | null;
body: HIR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function printFunction(fn: HIRFunction): string {
if (definition.length !== 0) {
output.push(definition);
}
output.push(printType(fn.returnIdentifier.type));
output.push(printType(fn.returnType));
output.push(printHIR(fn.body));
output.push(...fn.directives);
return output.join('\n');
Expand Down Expand Up @@ -556,9 +556,7 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
}
})
.join(', ') ?? '';
const type = printType(
instrValue.loweredFunc.func.returnIdentifier.type,
).trim();
const type = printType(instrValue.loweredFunc.func.returnType).trim();
value = `${kind} ${name} @deps[${deps}] @context[${context}] @effects[${effects}]${type !== '' ? ` return${type}` : ''}:\n${fn}`;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
isUseContextHookType,
makeBlockId,
makeInstructionId,
makeType,
markInstructionIds,
promoteTemporary,
reversePostorderBlocks,
Expand Down Expand Up @@ -238,18 +239,14 @@ function emitSelectorFn(env: Environment, keys: Array<string>): Instruction {
phis: new Set(),
};

const returnIdentifier = createTemporaryPlace(
env,
GeneratedSource,
).identifier;
const fn: HIRFunction = {
loc: GeneratedSource,
id: null,
fnType: 'Other',
env,
params: [obj],
returnTypeAnnotation: null,
returnIdentifier,
returnType: makeType(),
context: [],
effects: null,
body: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function apply(func: HIRFunction, unifier: Unifier): void {
}
}
}
func.returnIdentifier.type = unifier.get(func.returnIdentifier.type);
func.returnType = unifier.get(func.returnType);
}

type TypeEquation = {
Expand Down Expand Up @@ -141,12 +141,12 @@ function* generate(
}
}
if (returnTypes.length > 1) {
yield equation(func.returnIdentifier.type, {
yield equation(func.returnType, {
kind: 'Phi',
operands: returnTypes,
});
} else if (returnTypes.length === 1) {
yield equation(func.returnIdentifier.type, returnTypes[0]!);
yield equation(func.returnType, returnTypes[0]!);
}
}

Expand Down Expand Up @@ -363,7 +363,7 @@ function* generateInstructionTypes(
yield equation(left, {
kind: 'Function',
shapeId: BuiltInFunctionId,
return: value.loweredFunc.func.returnIdentifier.type,
return: value.loweredFunc.func.returnType,
});
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Component(props) {
7 | return hasErrors;
8 | }
> 9 | return hasErrors();
| ^^^^^^^^^ Invariant: [hoisting] Expected value for identifier to be initialized. hasErrors_0$17 (9:9)
| ^^^^^^^^^ Invariant: [hoisting] Expected value for identifier to be initialized. hasErrors_0$16 (9:9)
10 | }
11 |
```
Expand Down