Skip to content

Commit

Permalink
[compiler] Flatten returnIdentifier to just returnType
Browse files Browse the repository at this point in the history
We don't a full Identifier object for the return type, we can just store the type.

ghstack-source-id: 4594d64ce3900ced3e461945697926489898318e
Pull Request resolved: #30790
  • Loading branch information
josephsavona committed Aug 22, 2024
1 parent 98b5740 commit 7a3fcc9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
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

0 comments on commit 7a3fcc9

Please sign in to comment.