[be] Fix various eslints

This commit is contained in:
Lauren Tan
2023-02-28 19:19:38 -05:00
parent f28eef3dca
commit 7a6a0e5f72
5 changed files with 22 additions and 22 deletions
+10 -9
View File
@@ -21,6 +21,7 @@ import {
GotoVariant,
HIR,
Identifier,
IdentifierId,
Instruction,
makeBlockId,
makeInstructionId,
@@ -86,7 +87,7 @@ export default class HIRBuilder {
parentFunction: NodePath<t.Function>;
errors: CompilerError = new CompilerError();
get nextIdentifierId() {
get nextIdentifierId(): IdentifierId {
return this.#env.nextIdentifierId;
}
@@ -127,7 +128,7 @@ export default class HIRBuilder {
/**
* Push a statement or expression onto the current block
*/
push(instruction: Instruction) {
push(instruction: Instruction): void {
this.#current.instructions.push(instruction);
}
@@ -272,7 +273,7 @@ export default class HIRBuilder {
/**
* Terminate the current block w the given terminal, and start a new block
*/
terminate(terminal: Terminal, nextBlockKind: BlockKind) {
terminate(terminal: Terminal, nextBlockKind: BlockKind): void {
const { id: blockId, kind, instructions } = this.#current;
this.#completed.set(blockId, {
kind,
@@ -290,7 +291,7 @@ export default class HIRBuilder {
* Terminate the current block w the given terminal, and set the previously
* reserved block as the new current block
*/
terminateWithContinuation(terminal: Terminal, continuation: WipBlock) {
terminateWithContinuation(terminal: Terminal, continuation: WipBlock): void {
const { id: blockId, kind, instructions } = this.#current;
this.#completed.set(blockId, {
kind: kind,
@@ -315,7 +316,7 @@ export default class HIRBuilder {
/**
* Save a previously reserved block as completed
*/
complete(block: WipBlock, terminal: Terminal) {
complete(block: WipBlock, terminal: Terminal): void {
const { id: blockId, kind, instructions } = block;
this.#completed.set(blockId, {
kind,
@@ -536,7 +537,7 @@ export function removeUnreachableFallthroughs(func: HIR): void {
export function reversePostorderBlocks(func: HIR): void {
const visited: Set<BlockId> = new Set();
const postorder: Array<BlockId> = [];
function visit(blockId: BlockId) {
function visit(blockId: BlockId): void {
if (visited.has(blockId)) {
return;
}
@@ -634,7 +635,7 @@ export function reversePostorderBlocks(func: HIR): void {
func.blocks = blocks;
}
export function markInstructionIds(func: HIR) {
export function markInstructionIds(func: HIR): void {
let id = 0;
const visited = new Set<Instruction>();
for (const [_, block] of func.blocks) {
@@ -650,12 +651,12 @@ export function markInstructionIds(func: HIR) {
}
}
export function markPredecessors(func: HIR) {
export function markPredecessors(func: HIR): void {
for (const [, block] of func.blocks) {
block.preds.clear();
}
const visited: Set<BlockId> = new Set();
function visit(blockId: BlockId, prevBlock: BasicBlock | null) {
function visit(blockId: BlockId, prevBlock: BasicBlock | null): void {
const block = func.blocks.get(blockId)!;
if (prevBlock) {
block.preds.add(prevBlock.id);
+1 -1
View File
@@ -42,7 +42,7 @@ export function printFunction(fn: HIRFunction): string {
export function printHIR(ir: HIR, options: Options | null = null): string {
let output = [];
let indent = " ".repeat(options?.indent ?? 0);
const push = (text: string, indent: string = " ") => {
const push = (text: string, indent: string = " "): void => {
output.push(`${indent}${text}`);
};
for (const [blockId, block] of ir.blocks) {
@@ -416,7 +416,7 @@ function codegenDependency(
return object;
}
function withLoc<TNode extends t.Node, T extends (...args: any[]) => TNode>(
function withLoc<T extends (...args: any[]) => t.Node>(
fn: T
): (
loc: SourceLocation | null | undefined,
@@ -430,8 +430,7 @@ function withLoc<TNode extends t.Node, T extends (...args: any[]) => TNode>(
if (loc != null && loc != GeneratedSource) {
node.loc = loc;
}
// @ts-ignore
return node;
return node as ReturnType<T>;
};
}
@@ -439,9 +438,9 @@ const createBinaryExpression = withLoc(t.binaryExpression);
const createCallExpression = withLoc(t.callExpression);
const createExpressionStatement = withLoc(t.expressionStatement);
const createFunctionDeclaration = withLoc(t.functionDeclaration);
const createLabelledStatement = withLoc(t.labeledStatement);
const _createLabelledStatement = withLoc(t.labeledStatement);
const createVariableDeclaration = withLoc(t.variableDeclaration);
const createWhileStatement = withLoc(t.whileStatement);
const _createWhileStatement = withLoc(t.whileStatement);
const createTaggedTemplateExpression = withLoc(t.taggedTemplateExpression);
const createLogicalExpression = withLoc(t.logicalExpression);
const createSequenceExpression = withLoc(t.sequenceExpression);
@@ -30,9 +30,9 @@ export function visitReactiveFunction<TState>(
}
export class ReactiveFunctionVisitor<TState = void> {
visitID(id: InstructionId, state: TState): void {}
visitLValue(id: InstructionId, lvalue: LValue, state: TState): void {}
visitPlace(id: InstructionId, place: Place, state: TState): void {}
visitID(_id: InstructionId, _state: TState): void {}
visitLValue(_id: InstructionId, _lvalue: LValue, _state: TState): void {}
visitPlace(_id: InstructionId, _place: Place, _state: TState): void {}
visitValue(id: InstructionId, value: ReactiveValue, state: TState): void {
this.traverseValue(id, value, state);
+4 -4
View File
@@ -157,14 +157,14 @@ class SSABuilder {
return newId;
}
fixIncompletePhis(block: BasicBlock) {
fixIncompletePhis(block: BasicBlock): void {
const state = this.#states.get(block)!;
for (const phi of state.incompletePhis) {
this.addPhi(block, phi.oldId, phi.newId);
}
}
startBlock(block: BasicBlock) {
startBlock(block: BasicBlock): void {
this.#current = block;
this.#states.set(block, {
defs: new Map(),
@@ -172,7 +172,7 @@ class SSABuilder {
});
}
print() {
print(): void {
const text: string[] = [];
for (const [block, state] of this.#states) {
text.push(`bb${block.id}:`);
@@ -194,7 +194,7 @@ class SSABuilder {
}
}
export default function enterSSA(func: HIRFunction) {
export default function enterSSA(func: HIRFunction): void {
const visitedBlocks: Set<BasicBlock> = new Set();
const builder = new SSABuilder(func.env, func.body.blocks);
for (const [blockId, block] of func.body.blocks) {