[be] Split files into directories

Moves _some_ files from HIR into new top-level directories. To not make 
@gsathya's life a pain I left the files he's touching alone, but I moved some 
others. My intent is to have something like this: 

* Babel/ - code for the Babel plugin, though ideally this actually gets split 
into a separate package and the compiler itself is AST in, AST out w no Babel 
dep. 

* HIR/ - the core HIRFunction, HIR and related data types, plus the HIR 
construction and printing, HIR visitors. 

* Inference/ - the core inference passes that operate on the HIR, including type 
inference, reference effects, alias analysis, mutable range analysis, etc. I'll 
let @gsathya  move these files when at a good stopping point. 

* ReactiveScopes/ - inference relating to reactive scopes, 
constructing/printing/codegenning ReactiveFunction 

* SSA/ - enter/leave SSA and eliminate redundant phis 

* Utils/ - every project needs a place to put stuff that doesn't fit into the 
other categories, this is ours. 

This leaves just index.ts at the top level, and overall feels pretty tidy. Not 
too tedious to figure out where anything goes, hopefully.
This commit is contained in:
Joe Savona
2022-12-16 17:25:11 -08:00
parent 6053703dbb
commit 05d1fe94f9
37 changed files with 98 additions and 456 deletions
@@ -10,8 +10,8 @@
import type * as BabelCore from "@babel/core";
import type { PluginObj } from "@babel/core";
import jsx from "@babel/plugin-syntax-jsx";
import { invariant } from "./CompilerError";
import Pipeline from "./HIR/Pipeline";
import Pipeline from "../HIR/Pipeline";
import { invariant } from "../Utils/CompilerError";
/**
* The React Forget Babel Plugin
-113
View File
@@ -1,113 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as t from "@babel/types";
import generate from "@babel/generator";
/**
* Dumper.
*/
const defaultDumpNodeOption = {
// dump with location.
loc: false,
// dump with the node type.
type: false,
// dump as the entire source code instead of a shorten name.
source: false,
// instead of <anno>, fallback to source.
fallbackToSource: true,
};
type DumpNodeOption = typeof defaultDumpNodeOption;
export function dumpNodeLoc(node: t.Node): string {
return `${node.loc?.start.line ?? "?"}:${node.loc?.start.column ?? "?"}`;
}
/**
* Dump a string form of the @param node to help with debugging.
*/
export function dumpNode(
node: t.Node | null | undefined,
options: Partial<DumpNodeOption> = defaultDumpNodeOption
): string {
let str = "";
let opt = { ...defaultDumpNodeOption, ...options };
if (!node) return "";
if (opt.loc) {
str += `${dumpNodeLoc(node)} `;
}
if (opt.source) {
str += generate(node).code;
} else {
switch (node.type) {
case "Identifier":
str += node.name;
break;
case "JSXIdentifier":
str += `${node.name}`;
break;
case "VariableDeclarator":
str += `${dumpNode(node.id, { source: true })}`;
break;
case "JSXMemberExpression":
str += `${dumpNode(node.object)}.${dumpNode(node.property)}`;
break;
case "JSXNamespacedName":
str += `${dumpNode(node.namespace)}:${dumpNode(node.name)}`;
break;
case "JSXOpeningElement":
str += dumpNode(node.name);
break;
case "JSXAttribute":
str += dumpNode(node.name);
break;
case "FunctionDeclaration":
str += `function ${dumpNode(node.id)}`;
break;
case "JSXFragment":
str += `<>`;
break;
case "JSXElement":
if (node.selfClosing) {
str += `<${dumpNode(node.openingElement)} />`;
} else {
str += `<${dumpNode(node.openingElement)}>`;
}
break;
default:
if (opt.fallbackToSource) {
str += "`" + generate(node, { compact: true }).code + "`";
} else {
str += `<anno>`;
}
}
}
if (opt.type) {
str += ` : ${node.type}`;
}
return str;
}
-39
View File
@@ -1,39 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { Node, NodePath } from "@babel/traverse";
/**
* A utility type to generate NodePath as a disjointed union type for better
* type refinement and exhaustiveness check.
*
* @see https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
*/
export type PathUnion<N extends Node | undefined | null> = N extends Node
? NodePath<N>
: N extends undefined
? NodePath<undefined>
: N extends null
? NodePath<null>
: never;
/**
* Cast @param path of type {@link NodePath} to {@link PathUnion}.
*
* This should only be used right before a type refinement (aka. narrowing):
*
* const path = pathUnion(rawPath)
* switch(path.kind) {
* case "A":
* // path is now refined to NodePath<A>
* }
*/
export function pathUnion<N extends Node | null | undefined>(
path: NodePath<N>
): PathUnion<N> {
return path as PathUnion<N>;
}
+3 -3
View File
@@ -7,8 +7,9 @@
import { NodePath } from "@babel/traverse";
import * as t from "@babel/types";
import { assertExhaustive } from "../Common/utils";
import { invariant } from "../CompilerError";
import { invariant } from "../Utils/CompilerError";
import todo, { todoInvariant } from "../Utils/todo";
import { assertExhaustive } from "../Utils/utils";
import {
Effect,
GeneratedSource,
@@ -24,7 +25,6 @@ import {
ThrowTerminal,
} from "./HIR";
import HIRBuilder, { Environment } from "./HIRBuilder";
import todo, { todoInvariant } from "./todo";
// *******************************************************************************************
// *******************************************************************************************
+3 -3
View File
@@ -6,8 +6,9 @@
*/
import * as t from "@babel/types";
import { assertExhaustive } from "../Common/utils";
import { invariant } from "../CompilerError";
import { invariant } from "../Utils/CompilerError";
import { todoInvariant } from "../Utils/todo";
import { assertExhaustive } from "../Utils/utils";
import {
BlockId,
GeneratedSource,
@@ -23,7 +24,6 @@ import {
SourceLocation,
} from "./HIR";
import { BlockTerminal, Visitor, visitTree } from "./HIRTreeVisitor";
import { todoInvariant } from "./todo";
function withLoc<TNode extends t.Node, T extends (...args: any[]) => TNode>(
fn: T
+1 -1
View File
@@ -6,7 +6,7 @@
*/
import * as t from "@babel/types";
import { invariant } from "../CompilerError";
import { invariant } from "../Utils/CompilerError";
// *******************************************************************************************
// *******************************************************************************************
+3 -3
View File
@@ -6,8 +6,9 @@
*/
import * as t from "@babel/types";
import { assertExhaustive } from "../Common/utils";
import { invariant } from "../CompilerError";
import { invariant } from "../Utils/CompilerError";
import { logHIR } from "../Utils/logger";
import { assertExhaustive } from "../Utils/utils";
import {
BasicBlock,
BlockId,
@@ -23,7 +24,6 @@ import {
makeType,
Terminal,
} from "./HIR";
import { logHIR } from "./logger";
import { printInstruction } from "./PrintHIR";
import { eachTerminalSuccessor, mapTerminalSuccessors } from "./visitors";
+1 -1
View File
@@ -6,7 +6,7 @@
*/
import invariant from "invariant";
import { assertExhaustive } from "../Common/utils";
import { assertExhaustive } from "../Utils/utils";
import {
BasicBlock,
BlockId,
+1 -3
View File
@@ -1,7 +1,5 @@
import invariant from "invariant";
import DisjointSet from "./DisjointSet";
import DisjointSet from "../Utils/DisjointSet";
import { HIRFunction, Identifier, Instruction, LValue, Place } from "./HIR";
import { printInstructionValue } from "./PrintHIR";
export type AliasSet = Set<Identifier>;
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import DisjointSet from "./DisjointSet";
import DisjointSet from "../Utils/DisjointSet";
import { HIRFunction, Identifier } from "./HIR";
export function inferAliasForFields(
@@ -6,7 +6,7 @@
*/
import invariant from "invariant";
import { assertExhaustive } from "../Common/utils";
import { assertExhaustive } from "../Utils/utils";
import {
Effect,
HIRFunction,
@@ -1,4 +1,4 @@
import DisjointSet from "./DisjointSet";
import DisjointSet from "../Utils/DisjointSet";
import { Identifier, InstructionId } from "./HIR";
export function inferMutableRangesForAlias(aliases: DisjointSet<Identifier>) {
@@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
import { assertExhaustive } from "../Common/utils";
import { invariant } from "../CompilerError";
import { invariant } from "../Utils/CompilerError";
import { assertExhaustive } from "../Utils/utils";
import {
BasicBlock,
BlockId,
@@ -14,7 +14,6 @@ import {
HIRFunction,
IdentifierId,
InstructionValue,
makeType,
Phi,
Place,
ValueKind,
+12 -12
View File
@@ -7,23 +7,23 @@
import { NodePath } from "@babel/traverse";
import * as t from "@babel/types";
import { lower } from "../HIR/BuildHIR";
import { eliminateRedundantPhi } from "../HIR/EliminateRedundantPhi";
import enterSSA from "../HIR/EnterSSA";
import { Environment } from "../HIR/HIRBuilder";
import inferReferenceEffects from "../HIR/InferReferenceEffects";
import { leaveSSA } from "../HIR/LeaveSSA";
import { buildReactiveFunction } from "./BuildReactiveFunction";
import { codegenReactiveFunction } from "./CodegenReactiveFunction";
import { flattenReactiveLoops } from "./FlattenReactiveLoops";
import { buildReactiveFunction } from "../ReactiveScopes/BuildReactiveFunction";
import { codegenReactiveFunction } from "../ReactiveScopes/CodegenReactiveFunction";
import { flattenReactiveLoops } from "../ReactiveScopes/FlattenReactiveLoops";
import { inferReactiveScopes } from "../ReactiveScopes/InferReactiveScopes";
import { inferReactiveScopeVariables } from "../ReactiveScopes/InferReactiveScopeVariables";
import { printReactiveFunction } from "../ReactiveScopes/PrintReactiveFunction";
import { propagateScopeDependencies } from "../ReactiveScopes/PropagateScopeDependencies";
import { pruneUnusedLabels } from "../ReactiveScopes/PruneUnusedLabels";
import { eliminateRedundantPhi } from "../SSA/EliminateRedundantPhi";
import enterSSA from "../SSA/EnterSSA";
import { leaveSSA } from "../SSA/LeaveSSA";
import { logHIRFunction } from "../Utils/logger";
import { HIRFunction } from "./HIR";
import { inferMutableRanges } from "./InferMutableRanges";
import { inferReactiveScopes } from "./InferReactiveScopes";
import { inferReactiveScopeVariables } from "./InferReactiveScopeVariables";
import { inferTypes } from "./InferTypes";
import { logHIRFunction } from "./logger";
import { printReactiveFunction } from "./PrintReactiveFunction";
import { propagateScopeDependencies } from "./PropagateScopeDependencies";
import { pruneUnusedLabels } from "./PruneUnusedLabels";
export type CompilerFlags = {
eliminateRedundantPhi: boolean;
+2 -2
View File
@@ -6,8 +6,8 @@
*/
import generate from "@babel/generator";
import { assertExhaustive } from "../Common/utils";
import DisjointSet from "./DisjointSet";
import DisjointSet from "../Utils/DisjointSet";
import { assertExhaustive } from "../Utils/utils";
import {
GotoVariant,
HIR,
-173
View File
@@ -1,173 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { assertExhaustive } from "../Common/utils";
import {
BlockId,
HIRFunction,
Instruction,
InstructionId,
InstructionValue,
} from "./HIR";
import { BlockTerminal, Visitor, visitTree } from "./HIRTreeVisitor";
import { printLValue, printMixedHIR } from "./PrintHIR";
/**
* Returns a text description of the HIR that has the overall tree shape
* of the original AST, but with the contents of each block printed
* similarly to printHIR's instruction formatting.
*/
export function printHIRTree(fn: HIRFunction): string {
return visitTree(fn, new PrintVisitor());
}
class PrintVisitor
implements
Visitor<
Array<string>,
string,
Array<string>,
Array<string>,
string,
string,
string
>
{
depth: number = 0; // for indentation
enterBlock(): string[] {
this.depth++;
return [];
}
enterValueBlock(): string[] {
return this.enterBlock();
}
leaveValueBlock(block: string[], value: string): string {
return this.leaveBlock(block);
}
enterInitBlock(block: string[]): string[] {
return this.enterBlock();
}
leaveInitBlock(block: string[]): string[] {
return block;
}
visitValue(value: InstructionValue): string {
return printMixedHIR(value);
}
visitInstruction(instr: Instruction, value: string): string {
if (instr.lvalue !== null) {
return `[${instr.id}] ${printLValue(instr.lvalue)} = ${value}`;
} else {
return `[${instr.id}] ${value}`;
}
}
visitTerminalId(id: InstructionId): void {}
visitImplicitTerminal(): string | null {
return null;
}
visitTerminal(
terminal: BlockTerminal<string[], string, string, string>
): string {
let value: string;
switch (terminal.kind) {
case "break": {
if (terminal.label !== null) {
value = `Break ${terminal.label}`;
} else {
value = "Break";
}
break;
}
case "continue": {
if (terminal.label !== null) {
value = `Continue ${terminal.label}`;
} else {
value = "Continue";
}
break;
}
case "if": {
if (terminal.alternate !== null) {
value = `If (${
terminal.test
}) ${terminal.consequent.trimStart()} else ${terminal.alternate}`;
} else {
value = `If (${terminal.test}) ${terminal.consequent.trimStart()}`;
}
break;
}
case "switch": {
const prefix = " ".repeat(this.depth);
value = `Switch (${terminal.test}) {\n${terminal.cases
.flatMap((case_) => case_.split("\n").map((line) => ` ${line}`))
.join("\n")}\n${prefix}}`;
break;
}
case "while": {
value = `While (${terminal.test}) ${terminal.loop.trimStart()}`;
break;
}
case "for": {
value = `For (TODO) (${
terminal.test
}) (TODO) ${terminal.loop.trimStart()}`;
break;
}
case "return": {
if (terminal.value !== null) {
value = `Return ${terminal.value}`;
} else {
value = "Return";
}
break;
}
case "throw": {
value = `Throw ${terminal.value}`;
break;
}
default: {
assertExhaustive(
terminal,
`Unexpected terminal kind '${(terminal as any).kind}'`
);
}
}
return value;
}
visitCase(test: string | null, block: string): string {
const prefix = " ".repeat(this.depth);
if (test === null) {
return `${prefix}default: ${block.trimStart()}`;
} else {
return `${prefix}case ${test}: ${block.trimStart()}`;
}
}
appendBlock(
block: string[],
item: string,
label?: BlockId | undefined
): void {
const prefix = " ".repeat(this.depth);
if (item !== "") {
block.push(`${prefix}${item.trimStart()}`);
}
if (label !== undefined) {
block.push(`${prefix}bb${label}:`);
}
}
appendValueBlock(block: string[], item: string): void {
this.appendBlock(block, item);
}
appendInitBlock(block: string[], item: string): void {
this.appendBlock(block, item);
}
leaveBlock(block: string[]): string {
this.depth--;
const prefix = " ".repeat(this.depth);
return `${prefix}{\n${block.join("\n")}\n${prefix}}`;
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import { assertExhaustive } from "../Common/utils";
import { assertExhaustive } from "../Utils/utils";
import {
BasicBlock,
BlockId,
@@ -6,7 +6,6 @@
*/
import invariant from "invariant";
import { assertExhaustive } from "../Common/utils";
import {
BlockId,
HIRFunction,
@@ -22,9 +21,10 @@ import {
ReactiveTerminal,
ReactiveValueBlock,
ScopeId,
} from "./HIR";
import { BlockTerminal, Visitor, visitTree } from "./HIRTreeVisitor";
import { eachInstructionOperand } from "./visitors";
} from "../HIR/HIR";
import { BlockTerminal, Visitor, visitTree } from "../HIR/HIRTreeVisitor";
import { eachInstructionOperand } from "../HIR/visitors";
import { assertExhaustive } from "../Utils/utils";
export function buildReactiveFunction(fn: HIRFunction): ReactiveFunction {
const builder = new ReactiveFunctionBuilder();
@@ -7,7 +7,6 @@
import * as t from "@babel/types";
import invariant from "invariant";
import { assertExhaustive } from "../Common/utils";
import {
codegenInstruction,
codegenInstructionValue,
@@ -16,7 +15,7 @@ import {
convertIdentifier,
createFunctionDeclaration,
Temporaries,
} from "./Codegen";
} from "../HIR/Codegen";
import {
Identifier,
Instruction,
@@ -26,8 +25,9 @@ import {
ReactiveScope,
ReactiveTerminal,
ReactiveValueBlock,
} from "./HIR";
import { todoInvariant } from "./todo";
} from "../HIR/HIR";
import { todoInvariant } from "../Utils/todo";
import { assertExhaustive } from "../Utils/utils";
export function codegenReactiveFunction(fn: ReactiveFunction): t.Function {
const cx = new Context();
@@ -5,8 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
import { assertExhaustive } from "../Common/utils";
import { ReactiveBlock, ReactiveFunction, ReactiveScopeBlock } from "./HIR";
import {
ReactiveBlock,
ReactiveFunction,
ReactiveScopeBlock,
} from "../HIR/HIR";
import { assertExhaustive } from "../Utils/utils";
/**
* Given a reactive function, flattens any scopes contained within a loop construct.
@@ -6,8 +6,6 @@
*/
import invariant from "invariant";
import { assertExhaustive } from "../Common/utils";
import DisjointSet from "./DisjointSet";
import {
HIRFunction,
Identifier,
@@ -18,8 +16,10 @@ import {
Place,
ReactiveScope,
ScopeId,
} from "./HIR";
import { eachInstructionOperand } from "./visitors";
} from "../HIR/HIR";
import { eachInstructionOperand } from "../HIR/visitors";
import DisjointSet from "../Utils/DisjointSet";
import { assertExhaustive } from "../Utils/utils";
/**
* For each mutable variable, infers a reactive scope which will construct that
@@ -6,8 +6,6 @@
*/
import invariant from "invariant";
import { retainWhere } from "../Common/utils";
import DisjointSet from "./DisjointSet";
import {
BlockId,
HIRFunction,
@@ -18,14 +16,16 @@ import {
MutableRange,
ReactiveScope,
ScopeId,
} from "./HIR";
import { BlockTerminal, Visitor, visitTree } from "./HIRTreeVisitor";
import { log } from "./logger";
import { printFunction } from "./PrintHIR";
} from "../HIR/HIR";
import { BlockTerminal, Visitor, visitTree } from "../HIR/HIRTreeVisitor";
import { printFunction } from "../HIR/PrintHIR";
import {
eachInstructionOperand,
eachInstructionValueOperand,
} from "./visitors";
} from "../HIR/visitors";
import DisjointSet from "../Utils/DisjointSet";
import { log } from "../Utils/logger";
import { retainWhere } from "../Utils/utils";
/**
* This is a second (final) stage of constructing reactive scopes. Prior to this pass,
@@ -6,20 +6,20 @@
*/
import invariant from "invariant";
import { assertExhaustive } from "../Common/utils";
import {
ReactiveFunction,
ReactiveScopeBlock,
ReactiveStatement,
ReactiveTerminal,
ReactiveValueBlock,
} from "./HIR";
} from "../HIR/HIR";
import {
printIdentifier,
printInstruction,
printInstructionValue,
printPlace,
} from "./PrintHIR";
} from "../HIR/PrintHIR";
import { assertExhaustive } from "../Utils/utils";
export function printReactiveFunction(fn: ReactiveFunction): string {
const writer = new Writer();
@@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
import { assertExhaustive } from "../Common/utils";
import {
Identifier,
Instruction,
@@ -18,8 +17,9 @@ import {
ReactiveBlock,
ReactiveFunction,
ReactiveValueBlock,
} from "./HIR";
import { eachInstructionValueOperand } from "./visitors";
} from "../HIR/HIR";
import { eachInstructionValueOperand } from "../HIR/visitors";
import { assertExhaustive } from "../Utils/utils";
/**
* Infers the dependencies of each scope to include variables whose values
@@ -5,13 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/
import { assertExhaustive } from "../Common/utils";
import {
BlockId,
ReactiveBlock,
ReactiveFunction,
ReactiveTerminal,
} from "./HIR";
} from "../HIR/HIR";
import { assertExhaustive } from "../Utils/utils";
/**
* Prunes terminal labels that are never explicitly jumped to.
@@ -6,8 +6,8 @@
*/
import invariant from "invariant";
import { BlockId, HIRFunction, Identifier, Place } from "./HIR";
import { eachInstructionOperand, eachTerminalOperand } from "./visitors";
import { BlockId, HIRFunction, Identifier, Place } from "../HIR/HIR";
import { eachInstructionOperand, eachTerminalOperand } from "../HIR/visitors";
/**
* Pass to eliminate redundant phi nodes:
@@ -1,4 +1,3 @@
import { invariant } from "../CompilerError";
import {
BasicBlock,
HIRFunction,
@@ -8,14 +7,15 @@ import {
makeType,
Phi,
Place,
} from "./HIR";
import { Environment } from "./HIRBuilder";
import { printIdentifier } from "./PrintHIR";
} from "../HIR/HIR";
import { Environment } from "../HIR/HIRBuilder";
import { printIdentifier } from "../HIR/PrintHIR";
import {
eachTerminalSuccessor,
mapInstructionOperands,
mapTerminalOperands,
} from "./visitors";
} from "../HIR/visitors";
import { invariant } from "../Utils/CompilerError";
type IncompletePhi = {
oldId: Identifier;
@@ -17,8 +17,11 @@ import {
makeInstructionId,
Phi,
Place,
} from "./HIR";
import { eachInstructionValueOperand, eachTerminalOperand } from "./visitors";
} from "../HIR/HIR";
import {
eachInstructionValueOperand,
eachTerminalOperand,
} from "../HIR/visitors";
/**
* Removes SSA form by creating unique variable declarations for the versions of each variables.
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import { invariant } from "../CompilerError";
import { invariant } from "./CompilerError";
/**
* Represents items which form disjoint sets.
@@ -1,6 +1,6 @@
import { assertExhaustive } from "../Common/utils";
import { BasicBlock, BlockId, HIRFunction, Terminal } from "./HIR";
import { printInstruction, printPlace } from "./PrintHIR";
import { BasicBlock, BlockId, HIRFunction, Terminal } from "../HIR/HIR";
import { printInstruction, printPlace } from "../HIR/PrintHIR";
import { assertExhaustive } from "./utils";
const INSTRUCTIONS_NODE_NAME = "instrs";
const TERMINAL_NODE_NAME = "terminal";
@@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
import { HIR, HIRFunction } from "./HIR";
import printHIR, { printFunction } from "./PrintHIR";
import { HIR, HIRFunction } from "../HIR/HIR";
import printHIR, { printFunction } from "../HIR/PrintHIR";
let ENABLED: boolean = false;
@@ -5,43 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
/**
* Individual util functions.
*/
export function setEq<T>(a: Set<T>, b: Set<T>): boolean {
return a.size === b.size && [...a].every((v) => b.has(v));
}
export function nullableSetEq<T>(
a: Set<T> | undefined,
b: Set<T> | undefined
): boolean {
if (a === undefined && b === undefined) return true;
if (a === undefined || b === undefined) return false;
return a.size === b.size && [...a].every((v) => b.has(v));
}
export function setSubset<T>(a: Set<T>, b: Set<T>): boolean {
return a.size <= b.size && [...a].every((v) => b.has(v));
}
export function setIntersect<T>(a: Set<T>, b: Set<T>): boolean {
return [...a].some((v) => b.has(v));
}
export function setFirst<T>(s: Set<T>): T {
return [...s][0];
}
export function setEmpty<T>(s: Set<T>): boolean {
return s.size === 0;
}
export function hasOwnProperty<T>(obj: T, key: PropertyKey): key is keyof T {
return Object.prototype.hasOwnProperty.call(obj, key);
}
/**
* Trigger an exhaustivess check in TypeScript and throw at runtime.
*
+1 -1
View File
@@ -14,9 +14,9 @@ import { wasmFolder } from "@hpcc-js/wasm";
import invariant from "invariant";
import path from "path";
import prettier from "prettier";
import { toggleLogging } from "../HIR/logger";
import run from "../HIR/Pipeline";
import { printFunction } from "../HIR/PrintHIR";
import { toggleLogging } from "../Utils/logger";
import generateTestsFromFixtures from "./test-utils/generateTestsFromFixtures";
function wrapWithTripleBackticks(s: string, ext?: string) {
+12 -12
View File
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import BabelPlugin from "./BabelPlugin";
import BabelPlugin from "./Babel/BabelPlugin";
declare global {
var __DEV__: boolean | null | undefined;
@@ -15,22 +15,22 @@ import { parse } from "@babel/parser";
import traverse, { NodePath } from "@babel/traverse";
import * as t from "@babel/types";
import { lower } from "./HIR/BuildHIR";
import { buildReactiveFunction } from "./HIR/BuildReactiveFunction";
import codegen from "./HIR/Codegen";
import { codegenReactiveFunction } from "./HIR/CodegenReactiveFunction";
import { eliminateRedundantPhi } from "./HIR/EliminateRedundantPhi";
import enterSSA from "./HIR/EnterSSA";
import { flattenReactiveLoops } from "./HIR/FlattenReactiveLoops";
import { Environment } from "./HIR/HIRBuilder";
import { inferMutableRanges } from "./HIR/InferMutableRanges";
import { inferReactiveScopes } from "./HIR/InferReactiveScopes";
import { inferReactiveScopeVariables } from "./HIR/InferReactiveScopeVariables";
import inferReferenceEffects from "./HIR/InferReferenceEffects";
import { leaveSSA } from "./HIR/LeaveSSA";
import printHIR, { printFunction } from "./HIR/PrintHIR";
import { printReactiveFunction } from "./HIR/PrintReactiveFunction";
import { propagateScopeDependencies } from "./HIR/PropagateScopeDependencies";
import { pruneUnusedLabels } from "./HIR/PruneUnusedLabels";
import { buildReactiveFunction } from "./ReactiveScopes/BuildReactiveFunction";
import { codegenReactiveFunction } from "./ReactiveScopes/CodegenReactiveFunction";
import { flattenReactiveLoops } from "./ReactiveScopes/FlattenReactiveLoops";
import { inferReactiveScopes } from "./ReactiveScopes/InferReactiveScopes";
import { inferReactiveScopeVariables } from "./ReactiveScopes/InferReactiveScopeVariables";
import { printReactiveFunction } from "./ReactiveScopes/PrintReactiveFunction";
import { propagateScopeDependencies } from "./ReactiveScopes/PropagateScopeDependencies";
import { pruneUnusedLabels } from "./ReactiveScopes/PruneUnusedLabels";
import { eliminateRedundantPhi } from "./SSA/EliminateRedundantPhi";
import enterSSA from "./SSA/EnterSSA";
import { leaveSSA } from "./SSA/LeaveSSA";
function parseFunctions(
source: string