Skip to content
Snippets Groups Projects
Commit e85c1ac4 authored by David Bühler's avatar David Bühler
Browse files

[Ivette] Values table: removes cache to Eva requests.

These caches are incorrect when the analysis is re-run, as they are not cleared
when the analysis results change.
parent 4bd1dd6e
No related branches found
No related tags found
No related merge requests found
...@@ -105,30 +105,18 @@ function TableCell(props: TableCellProps): JSX.Element { ...@@ -105,30 +105,18 @@ function TableCell(props: TableCellProps): JSX.Element {
* cleanly represent the summary of all the callstacks. */ * cleanly represent the summary of all the callstacks. */
type callstack = 'Summary' | Values.callstack type callstack = 'Summary' | Values.callstack
/* Builds a cached version of the `getCallstacks` request */ /* `getCallstacks` request */
function useCallstacksCache(): Request<Ast.marker[], callstack[]> { function useCallstacks(): Request<Ast.marker[], callstack[]> {
const g: Request<Ast.marker[], callstack[]> = return React.useCallback((m) => Server.send(Values.getCallstacks, m), []);
React.useCallback((m) => Server.send(Values.getCallstacks, m), []);
const toString = React.useCallback((ms: string[]) => ms.join('|'), []);
return Dome.useCache(g, toString);
} }
/* -------------------------------------------------------------------------- */ /* `getCallstackInfo` request */
function useCallsites(): Request<callstack, Values.callsite[]> {
return React.useCallback(
/* -------------------------------------------------------------------------- */
/* --- Callsite related definitions --- */
/* -------------------------------------------------------------------------- */
/* Builds a cached version of the `getCallstackInfo` request */
function useCallsitesCache(): Request<callstack, Values.callsite[]> {
const getter = React.useCallback(
(c: callstack): Promise<Values.callsite[]> => { (c: callstack): Promise<Values.callsite[]> => {
if (c !== 'Summary') return Server.send(Values.getCallstackInfo, c); if (c !== 'Summary') return Server.send(Values.getCallstackInfo, c);
else return Promise.resolve([]); else return Promise.resolve([]);
}, []); }, []);
return Dome.useCache(getter);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
...@@ -164,37 +152,22 @@ interface Probe { ...@@ -164,37 +152,22 @@ interface Probe {
evaluate: Request<callstack, Evaluation> evaluate: Request<callstack, Evaluation>
} }
/* Builds a cached version of the `getValues` request */ /* Builds a Probe given a Location */
function useEvaluationCache(): Request<[Ast.marker, callstack], Evaluation> { function useProbe(): Request<[Ast.decl, Ast.marker], Probe> {
type LocStack = [Ast.marker, callstack]; const getValues = React.useCallback(
const getKey = React.useCallback(([m, c]: LocStack): string => { ([target, cs]: [Ast.marker, callstack]): Promise<Evaluation> => {
return `${m}:${c}`; const callstack = cs === 'Summary' ? undefined : cs;
}, []); return Server.send(Values.getValues, { target, callstack });
const getData: Request<LocStack, Evaluation> =
React.useCallback(([t, c]) => {
const callstack = c === 'Summary' ? undefined : c;
return Server.send(Values.getValues, { target: t, callstack });
}, []);
return Dome.useCache(getData, getKey);
}
/* Builds a cached function that builds a Probe given a Location */
function useProbeCache(): Request<[Ast.decl, Ast.marker], Probe> {
const cache = useEvaluationCache();
const getKey = React.useCallback(
([scope, marker]: [Ast.decl, Ast.marker]): string => {
return `${scope}:${marker}`;
}, [] }, []
); );
const getData = React.useCallback( return React.useCallback(
async ([scope, marker]: [Ast.decl, Ast.marker]): Promise<Probe> => { async ([scope, marker]: [Ast.decl, Ast.marker]): Promise<Probe> => {
const infos = await Server.send(Values.getProbeInfo, marker); const infos = await Server.send(Values.getProbeInfo, marker);
const evaluate: Request<callstack, Evaluation> = (c) => const evaluate: Request<callstack, Evaluation> = (c) =>
cache([marker, c]); getValues([marker, c]);
return { marker, scope, ...infos, evaluate }; return { marker, scope, ...infos, evaluate };
}, [cache] }, [getValues]
); );
return Dome.useCache(getData, getKey);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
...@@ -1009,10 +982,10 @@ function EvaTable(): JSX.Element { ...@@ -1009,10 +982,10 @@ function EvaTable(): JSX.Element {
* related column into view if needed */ * related column into view if needed */
const [locEvt] = React.useState(new Dome.Event<Ast.marker>('eva-location')); const [locEvt] = React.useState(new Dome.Event<Ast.marker>('eva-location'));
/* Build cached version of needed server's requests */ /* Needed server's requests */
const getProbe = useProbeCache(); const getProbe = useProbe();
const getCallsites = useCallsitesCache(); const getCallsites = useCallsites();
const getCallstacks = useCallstacksCache(); const getCallstacks = useCallstacks();
/* Updates the scope manager when the showCallstacks state changes. */ /* Updates the scope manager when the showCallstacks state changes. */
React.useEffect(() => { React.useEffect(() => {
...@@ -1154,6 +1127,13 @@ function EvaTable(): JSX.Element { ...@@ -1154,6 +1127,13 @@ function EvaTable(): JSX.Element {
const computationState = States.useSyncValue(Eva.computationState); const computationState = States.useSyncValue(Eva.computationState);
useEvaluationMode({ computationState, marker, scope, setLocPin }); useEvaluationMode({ computationState, marker, scope, setLocPin });
/* Clear the table when Eva values change. */
const clear = (): void => {
fcts.clear();
setTic(tac + 1);
};
Server.useSignal(Values.changed, clear);
/* Builds the component */ /* Builds the component */
return ( return (
<> <>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment