Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Retype ASTs #739

Merged
merged 7 commits into from
Jan 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/browser-ui/src/inspector/views/GraphUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
prettyPrintFn,
prettyPrintPath,
} from "@penrose/core";
import { A } from "@penrose/core/build/dist/types/ast";
import { Fn } from "@penrose/core/build/dist/types/state";
import { Path } from "@penrose/core/build/dist/types/style";
import { flatMap, uniqBy } from "lodash";
Expand Down Expand Up @@ -101,7 +102,7 @@ export const convertSchema = (graph: PGraph): PGraph => {
// -----

// Make nodes and edges related to showing one DOF node (p is a varying path)
export const toGraphDOF = (p: Path, allArgs: string[]): PGraph => {
export const toGraphDOF = (p: Path<A>, allArgs: string[]): PGraph => {
const empty = { nodes: [], edges: [] };

if (p.tag === "FieldPath") {
Expand Down Expand Up @@ -165,7 +166,7 @@ export const toGraphDOF = (p: Path, allArgs: string[]): PGraph => {
// Make nodes and edges related to showing DOF nodes

export const toGraphDOFs = (
varyingPaths: Path[],
varyingPaths: Path<A>[],
allFns: Fn[],
allArgs: string[]
): PGraph => {
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/analysis/SubstanceAnalysis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { dummyIdentifier } from "engine/EngineUtils";
import { intersectionWith } from "lodash";
import { similarMappings, similarNodes } from "synthesis/Search";
import { ASTNode } from "types/ast";
import { A, ASTNode } from "types/ast";
import { Env } from "types/domain";
import { SubProg, SubStmt } from "types/substance";
import {
Expand All @@ -28,13 +28,13 @@ function Subset(Set a, Set b) -> Set
`;
const env: Env = compileDomain(domain).unsafelyUnwrap();

const compile = (src: string): SubProg =>
const compile = (src: string): SubProg<A> =>
compileSubstance(src, env).unsafelyUnwrap()[0].ast;

describe("Substance AST queries", () => {
test("Similar AST nodes", () => {
let node1: ASTNode;
let node2: ASTNode;
let node1: ASTNode<A>;
let node2: ASTNode<A>;
node1 = compile("Set A");
node2 = compile("Set B");
expect(similarNodes(node1, node2)).toBe(true);
Expand Down Expand Up @@ -154,13 +154,15 @@ Set B`;
Set B
Set C`;
const originalAST = compileSubstance(original, env).unsafelyUnwrap()[0].ast;
const newStmt: SubStmt = {
const newStmt: SubStmt<A> = {
nodeType: "SyntheticSubstance",
children: [],
tag: "Decl",
name: dummyIdentifier("C", "SyntheticSubstance"),
type: {
tag: "TypeConstructor",
nodeType: "SyntheticSubstance",
children: [],
args: [],
name: dummyIdentifier("Set", "SyntheticSubstance"),
},
Expand All @@ -186,13 +188,15 @@ Set B`;
Set ZZZ`;
const originalAST = compileSubstance(original, env).unsafelyUnwrap()[0].ast;
const toReplace = originalAST.statements[1];
const newStmt: SubStmt = {
const newStmt: SubStmt<A> = {
nodeType: "SyntheticSubstance",
children: [],
tag: "Decl",
name: dummyIdentifier("ZZZ", "SyntheticSubstance"),
type: {
tag: "TypeConstructor",
nodeType: "SyntheticSubstance",
children: [],
args: [],
name: dummyIdentifier("Set", "SyntheticSubstance"),
},
Expand Down