Skip to content

Commit 566a471

Browse files
committed
perf: heavy bump to unseeded randomness
1 parent f983c40 commit 566a471

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/linter/rules/seeded-randomness.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { resolveIdToValue } from '../../dataflow/eval/resolve/alias-tracking';
2222
import { valueSetGuard } from '../../dataflow/eval/values/general';
2323
import { VariableResolve } from '../../config';
2424
import type { DataflowGraphVertexFunctionCall } from '../../dataflow/graph/vertex';
25+
import { VertexType } from '../../dataflow/graph/vertex';
2526
import { EmptyArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
2627
import { asValue } from '../../dataflow/eval/values/r-value';
2728
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
@@ -56,7 +57,7 @@ export interface SeededRandomnessMeta extends MergeableRecord {
5657
}
5758

5859
export const SEEDED_RANDOMNESS = {
59-
createSearch: (config) => Q.all()
60+
createSearch: (config) => Q.all().filter(VertexType.FunctionCall)
6061
.with(Enrichment.CallTargets, { onlyBuiltin: true })
6162
.filter({
6263
name: FlowrFilter.MatchesEnrichment,

src/search/flowr-search-filters.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,17 @@ function evalTree(tree: BooleanNode, data: FilterData): boolean {
273273
* Evaluates the given filter expression against the provided data.
274274
*/
275275
export function evalFilter<Filter extends FlowrFilter>(filter: FlowrFilterExpression<Filter>, data: FilterData): boolean {
276-
/* common lift, this can be improved easily :D */
277-
const tree = FlowrFilterCombinator.is(filter as FlowrFilterExpression);
278-
return evalTree(tree.get(), data);
276+
if(filter instanceof FlowrFilterCombinator) {
277+
return evalTree(filter.get(), data);
278+
} else if(typeof filter === 'string' && ValidFlowrFilters.has(filter)) {
279+
const handler = FlowrFilters[filter as FlowrFilter];
280+
return handler(data.element, undefined as unknown as FlowrFilterArgs<FlowrFilter>, data.data);
281+
} else if(typeof filter === 'object' && 'name' in filter) {
282+
const handler = FlowrFilters[filter.name];
283+
const args = ('args' in filter ? filter.args : undefined) as unknown as never;
284+
return handler(data.element, args, data.data);
285+
} else {
286+
const tree = FlowrFilterCombinator.is(filter as FlowrFilterExpression);
287+
return evalTree(tree.get(), data);
288+
}
279289
}

src/search/search-executor/search-enrichers.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import type { AsyncOrSync, AsyncOrSyncType } from 'ts-essentials';
1717
import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
1818
import { promoteCallName } from '../../queries/catalog/call-context-query/call-context-query-executor';
1919
import { CfgKind } from '../../project/cfg-kind';
20-
import { identifyLinkToRelation } from '../../queries/catalog/call-context-query/identify-link-to-relation';
20+
import {
21+
identifyLinkToLastCallRelationSync
22+
} from '../../queries/catalog/call-context-query/identify-link-to-last-call-relation';
2123

2224

2325
export interface EnrichmentData<ElementContent extends MergeableRecord, ElementArguments = undefined, SearchContent extends MergeableRecord = never, SearchArguments = ElementArguments> {
@@ -154,12 +156,13 @@ export const Enrichments = {
154156
enrichElement: async(e, _s, analyzer, args, prev) => {
155157
guard(args && args.length, `${Enrichment.LastCall} enrichment requires at least one argument`);
156158
const content = prev ?? { linkedIds: [] };
157-
const df = await analyzer.dataflow();
158-
const n = await analyzer.normalize();
159-
const vertex = df.graph.get(e.node.info.id);
160-
if(vertex !== undefined && vertex[0].tag === VertexType.FunctionCall) {
159+
const df = (await analyzer.dataflow()).graph;
160+
const vertex = df.getVertex(e.node.info.id);
161+
if(vertex?.tag === VertexType.FunctionCall) {
162+
const n = await analyzer.normalize();
163+
const cfg = (await analyzer.controlflow(undefined, CfgKind.Quick)).graph;
161164
for(const arg of args) {
162-
const lastCalls = await identifyLinkToRelation(vertex[0].id, analyzer, {
165+
const lastCalls = identifyLinkToLastCallRelationSync(vertex.id, cfg, df, {
163166
...arg,
164167
callName: promoteCallName(arg.callName),
165168
type: 'link-to-last-call',

0 commit comments

Comments
 (0)