Skip to content

Commit

Permalink
Fix MobX overflow and expose safe TyValue printing
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Jul 8, 2024
1 parent cc3123e commit e0f7c04
Show file tree
Hide file tree
Showing 10 changed files with 1,568 additions and 987 deletions.
2,320 changes: 1,447 additions & 873 deletions examples/bevy/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.10.1"
bevy = "0.14.0"
4 changes: 2 additions & 2 deletions examples/bevy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use bevy::prelude::*;
#[derive(Resource)]
struct Timer(usize);

fn startup_system(_: Timer) {}
fn run_timer(_: Timer) {}

fn main() {
App::new().add_startup_system(startup_system).run();
App::new().add_systems(Update, run_timer).run();
}
84 changes: 42 additions & 42 deletions ide/packages/panoptes/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DefinedPath } from "@argus/common/bindings";
import type { DefinedPath, TyVal } from "@argus/common/bindings";
import {
createClosedMessageSystem,
vscodeMessageSystem
Expand All @@ -17,11 +17,10 @@ import {
isSysMsgUnpin
} from "@argus/common/lib";
import { IcoComment } from "@argus/print/Icons";
import Indented from "@argus/print/Indented";
import {
AllowPathTrim,
AllowProjectionSubst,
DefPathRender
DefPathRender,
ProjectionPathRender,
TyCtxt
} from "@argus/print/context";
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react";
import _ from "lodash";
Expand All @@ -30,6 +29,7 @@ import React, { useEffect, useState } from "react";

import "./App.css";
import type { TypeContext } from "@argus/print/context";
import { PrintTyValue } from "@argus/print/lib";
import MiniBuffer from "./MiniBuffer";
import Workspace from "./Workspace";
import { MiniBufferDataStore, highlightedObligation } from "./signals";
Expand Down Expand Up @@ -126,42 +126,40 @@ const CustomPathRenderer = observer(
}
);

const CustomProjectionRender = ({
original,
projection,
ctx
}: {
original: React.ReactElement;
projection: React.ReactElement;
ctx: TypeContext;
}) => {
const content = (
<AllowPathTrim.Provider value={false}>
<AllowProjectionSubst.Provider value={false}>
<p> This type is from a projection:</p>
<p>Projected type:</p>
<Indented>{projection}</Indented>
<p>Full path:</p>
<Indented>{original}</Indented>
</AllowProjectionSubst.Provider>
</AllowPathTrim.Provider>
);
const setStore = () =>
MiniBufferDataStore.set({ kind: "projection", content, ctx });
const resetStore = () => MiniBufferDataStore.reset();
return (
<>
{projection}
<span
onMouseEnter={setStore}
onMouseLeave={resetStore}
style={{ verticalAlign: "super", fontSize: "0.25rem" }}
>
<IcoComment />
</span>
</>
);
};
const CustomProjectionRender = observer(
({
ctx,
original,
projection
}: {
ctx: TypeContext;
original: TyVal;
projection: TyVal;
}) => {
const setStore = () =>
MiniBufferDataStore.set({
kind: "projection",
original,
projection,
ctx
});
const resetStore = () => MiniBufferDataStore.reset();
return (
<>
<TyCtxt.Provider value={ctx}>
<PrintTyValue ty={projection} />
</TyCtxt.Provider>
<span
onMouseEnter={setStore}
onMouseLeave={resetStore}
style={{ verticalAlign: "super", fontSize: "0.25rem" }}
>
<IcoComment />
</span>
</>
);
}
);

const App = observer(({ config }: { config: PanoptesConfig }) => {
const [openFiles, setOpenFiles] = useState(buildInitialData(config));
Expand Down Expand Up @@ -215,7 +213,9 @@ const App = observer(({ config }: { config: PanoptesConfig }) => {
<AppContext.MessageSystemContext.Provider value={messageSystem}>
<AppContext.ShowHiddenObligationsContext.Provider value={showHidden}>
<DefPathRender.Provider value={CustomPathRenderer}>
<Workspace files={openFiles} reset={resetState} />
<ProjectionPathRender.Provider value={CustomProjectionRender}>
<Workspace files={openFiles} reset={resetState} />
</ProjectionPathRender.Provider>
</DefPathRender.Provider>
</AppContext.ShowHiddenObligationsContext.Provider>
</AppContext.MessageSystemContext.Provider>
Expand Down
34 changes: 27 additions & 7 deletions ide/packages/panoptes/src/MiniBuffer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { TyCtxt } from "@argus/print/context";
import { PrintDefPathFull } from "@argus/print/lib";
import {
AllowPathTrim,
AllowProjectionSubst,
TyCtxt
} from "@argus/print/context";
import { PrintDefPathFull, PrintTyValue } from "@argus/print/lib";
import { observer } from "mobx-react";
import React from "react";

import { IcoPinned } from "@argus/print/Icons";
import Indented from "@argus/print/Indented";
import { MiniBufferDataStore } from "./signals";
import "./MiniBuffer.css";

Expand All @@ -21,21 +26,36 @@ const MiniBuffer = observer(() => {
<h2>Type Projection</h2>
) : null;
const pinned = data.pinned ? <IcoPinned onClick={unpinClick} /> : null;
const Content =
const Content = () =>
data.kind === "path" ? (
<PrintDefPathFull defPath={data.path} />
) : data.kind === "projection" ? (
data.content
<>
<p>The projected type:</p>
<Indented>
<PrintTyValue ty={data.projection} />
</Indented>
<p>comes from the definition path:</p>
<Indented>
<PrintTyValue ty={data.original} />
</Indented>
</>
) : null;

return (
<>
<div id="MiniBuffer">
{pinned}
{heading}
<div className="Data">
<TyCtxt.Provider value={data.ctx}>{Content}</TyCtxt.Provider>
</div>
<AllowPathTrim.Provider value={false}>
<AllowProjectionSubst.Provider value={false}>
<TyCtxt.Provider value={data.ctx}>
<div className="Data">
<Content />
</div>
</TyCtxt.Provider>
</AllowProjectionSubst.Provider>
</AllowPathTrim.Provider>
</div>
<div className="spacer">{"\u00A0"}</div>
</>
Expand Down
5 changes: 3 additions & 2 deletions ide/packages/panoptes/src/signals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DefinedPath } from "@argus/common/bindings";
import type { DefinedPath, TyVal } from "@argus/common/bindings";
import type { ErrorJumpTargetInfo } from "@argus/common/lib";
import type { TypeContext } from "@argus/print/context";
import { action, makeObservable, observable } from "mobx";
Expand Down Expand Up @@ -36,7 +36,8 @@ export type BufferDataKind = {
}
| {
kind: "projection";
content: React.ReactElement;
original: TyVal;
projection: TyVal;
}
);

Expand Down
9 changes: 5 additions & 4 deletions ide/packages/print/src/context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DefinedPath, Ty, TyVal } from "@argus/common/bindings";
import { createContext } from "react";
import React, { type ReactElement } from "react";
import { PrintTyValue } from "./private/ty";

// Change this to true if we want to by default toggle type parameter lists
export const AllowToggle = createContext(false);
Expand All @@ -21,8 +22,8 @@ export const DefPathRender = createContext(
Head,
Rest
}: {
fullPath: DefinedPath;
ctx: TypeContext;
fullPath: DefinedPath;
Head: ReactElement;
Rest: ReactElement;
}) => (
Expand All @@ -39,8 +40,8 @@ export const ProjectionPathRender = createContext(
projection: _prj,
ctx: _ctx
}: {
original: ReactElement;
projection: ReactElement;
ctx: TypeContext;
}) => original
original: TyVal;
projection: TyVal;
}) => <PrintTyValue o={original} />
);
70 changes: 36 additions & 34 deletions ide/packages/print/src/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type {
GoalData,
ImplHeader,
Obligation,
Ty
Ty,
TyVal
} from "@argus/common/bindings";
import React from "react";
import { ErrorBoundary } from "react-error-boundary";
Expand All @@ -23,7 +24,10 @@ import {
PrintGoalPredicate as UnsafePrintGoalPredicate,
PrintPredicateObligation as UnsafePrintPredicateObligation
} from "./private/predicate";
import { PrintTy as UnsafePrintTy } from "./private/ty";
import {
PrintTy as UnsafePrintTy,
PrintTyValue as UnsafePrintTyValue
} from "./private/ty";

// NOTE: please Please PLEASE wrap all printing components in this
// `PrintWithFallback`. Pretty printing is still a fragile process and
Expand Down Expand Up @@ -76,11 +80,9 @@ export const PrintWithFallback = ({
);
};

export const PrintTy = ({ ty }: { ty: Ty }) => {
return (
<PrintWithFallback object={ty} Content={() => <UnsafePrintTy o={ty} />} />
);
};
export const PrintTy = ({ ty }: { ty: Ty }) => (
<PrintWithFallback object={ty} Content={() => <UnsafePrintTy o={ty} />} />
);

export const PrintObligation = ({ obligation }: { obligation: Obligation }) => {
const InnerContent = () => (
Expand All @@ -91,16 +93,14 @@ export const PrintObligation = ({ obligation }: { obligation: Obligation }) => {
return <PrintWithFallback object={obligation} Content={InnerContent} />;
};

export const PrintImplHeader = ({ impl }: { impl: ImplHeader }) => {
return (
<AllowToggle.Provider value={true}>
<PrintWithFallback
object={impl}
Content={() => <UnsafePrintImplHeader o={impl} />}
/>
</AllowToggle.Provider>
);
};
export const PrintImplHeader = ({ impl }: { impl: ImplHeader }) => (
<AllowToggle.Provider value={true}>
<PrintWithFallback
object={impl}
Content={() => <UnsafePrintImplHeader o={impl} />}
/>
</AllowToggle.Provider>
);

export const PrintGoal = ({ o }: { o: GoalData }) => {
const debugString =
Expand Down Expand Up @@ -135,21 +135,23 @@ export const PrintExtensionCandidate = ({
);
};

export const PrintBodyName = ({ defPath }: { defPath: DefinedPath }) => {
return (
<PrintWithFallback
object={defPath}
// Content={() => <UnsafePrintDefPathFull o={defPath} />}
Content={() => <UnsafePrintDefPath o={defPath} />}
/>
);
};
export const PrintBodyName = ({ defPath }: { defPath: DefinedPath }) => (
<PrintWithFallback
object={defPath}
Content={() => <UnsafePrintDefPath o={defPath} />}
/>
);

export const PrintDefPathFull = ({ defPath }: { defPath: DefinedPath }) => {
return (
<PrintWithFallback
object={defPath}
Content={() => <UnsafePrintDefPathFull o={defPath} />}
/>
);
};
export const PrintDefPathFull = ({ defPath }: { defPath: DefinedPath }) => (
<PrintWithFallback
object={defPath}
Content={() => <UnsafePrintDefPathFull o={defPath} />}
/>
);

export const PrintTyValue = ({ ty }: { ty: TyVal }) => (
<PrintWithFallback
object={ty}
Content={() => <UnsafePrintTyValue o={ty} />}
/>
);
2 changes: 1 addition & 1 deletion ide/packages/print/src/private/path.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export const PrintDefPath = ({ o }: { o: DefinedPath }) => {
}) => {
return (
<PrintCustomDefPath
fullPath={o}
ctx={tyCtxt}
fullPath={o}
Head={<Prefix />}
Rest={<Rest />}
/>
Expand Down
25 changes: 4 additions & 21 deletions ide/packages/print/src/private/ty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,15 @@ export const PrintTyProjected = ({
original,
projection
}: { original: TyVal; projection: TyVal }) => {
const RenderProjection = useContext(ProjectionPathRender);
const PrintCustomProjection = useContext(ProjectionPathRender);
const tyCtx = useContext(TyCtxt)!;
return (
<RenderProjection
original={<PrintTyValue o={original} />}
projection={<PrintTyValue o={projection} />}
<PrintCustomProjection
ctx={tyCtx}
original={original}
projection={projection}
/>
);
// const Content = (
// <AllowPathTrim.Provider value={false}>
// <AllowProjectionSubst.Provider value={false}>
// <p> This type is from a projection:</p>
// <p>Projected type:</p>
// <Indented>
// <PrintTyValue o={projection} />
// </Indented>
// <p>Full path:</p>
// <Indented>
// <PrintTyValue o={original} />
// </Indented>
// </AllowProjectionSubst.Provider>
// </AllowPathTrim.Provider>
// );

// return <Comment Child={<PrintTyValue o={projection} />} Content={Content} />;
};

export const PrintTyValue = ({ o }: { o: TyVal }) => {
Expand Down

0 comments on commit e0f7c04

Please sign in to comment.