-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(slice-query): base slice query implementation * doc(slice-query): document the slice query
- Loading branch information
1 parent
9f778ba
commit fb720ff
Showing
13 changed files
with
464 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/queries/catalog/static-slice-query/static-slice-query-executor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { BasicQueryData } from '../../query'; | ||
import type { StaticSliceQuery, StaticSliceQueryResult } from './static-slice-query-format'; | ||
import { staticSlicing } from '../../../slicing/static/static-slicer'; | ||
import { reconstructToCode } from '../../../reconstruct/reconstruct'; | ||
import { doNotAutoSelect } from '../../../reconstruct/auto-select/auto-select-defaults'; | ||
import { makeMagicCommentHandler } from '../../../reconstruct/auto-select/magic-comments'; | ||
import { log } from '../../../util/log'; | ||
|
||
export function fingerPrintOfQuery(query: StaticSliceQuery): string { | ||
return JSON.stringify(query); | ||
} | ||
|
||
export function executeStaticSliceClusterQuery({ graph, ast }: BasicQueryData, queries: readonly StaticSliceQuery[]): StaticSliceQueryResult { | ||
const start = Date.now(); | ||
const results: StaticSliceQueryResult['results'] = {}; | ||
for(const query of queries) { | ||
const key = fingerPrintOfQuery(query); | ||
if(results[key]) { | ||
log.warn(`Duplicate Key for slicing-query: ${key}, skipping...`); | ||
} | ||
const { criteria, noReconstruction, noMagicComments } = query; | ||
const slice = staticSlicing(graph, ast, criteria); | ||
if(noReconstruction) { | ||
results[key] = { slice }; | ||
} else { | ||
results[key] = { | ||
slice, | ||
reconstruct: reconstructToCode(ast, slice.result, noMagicComments ? doNotAutoSelect : makeMagicCommentHandler(doNotAutoSelect)) | ||
}; | ||
} | ||
} | ||
return { | ||
'.meta': { | ||
timing: Date.now() - start | ||
}, | ||
results | ||
}; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/queries/catalog/static-slice-query/static-slice-query-format.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { BaseQueryFormat, BaseQueryResult } from '../../base-query-format'; | ||
import type { PipelineOutput } from '../../../core/steps/pipeline/pipeline'; | ||
import type { | ||
DEFAULT_DATAFLOW_PIPELINE, DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE, | ||
DEFAULT_SLICING_PIPELINE | ||
} from '../../../core/steps/pipeline/default-pipelines'; | ||
import type { SlicingCriteria } from '../../../slicing/criterion/parse'; | ||
|
||
/** Calculates and returns all clusters encountered in the dataflow graph. */ | ||
export interface StaticSliceQuery extends BaseQueryFormat { | ||
readonly type: 'static-slice'; | ||
/** The slicing criteria to use */ | ||
readonly criteria: SlicingCriteria, | ||
/** do not reconstruct the slice into readable code */ | ||
readonly noReconstruction?: boolean; | ||
/** Should the magic comments (force-including lines within the slice) be ignored? */ | ||
readonly noMagicComments?: boolean | ||
} | ||
|
||
export interface StaticSliceQueryResult extends BaseQueryResult { | ||
/** | ||
* only contains the results of the slice steps to not repeat ourselves, this does not contain the reconstruction | ||
* if you set the {@link SliceQuery#noReconstruction|noReconstruction} flag. | ||
* | ||
* The keys are serialized versions of the used queries (i.e., the result of `JSON.stringify`). | ||
* This implies that multiple slice queries with the same query configuration will _not_ be re-executed. | ||
*/ | ||
results: Record<string, | ||
Omit<PipelineOutput<typeof DEFAULT_SLICING_PIPELINE>, keyof PipelineOutput<typeof DEFAULT_DATAFLOW_PIPELINE>> | | ||
Omit<PipelineOutput<typeof DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE>, keyof PipelineOutput<typeof DEFAULT_DATAFLOW_PIPELINE>> | ||
> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { assertQuery } from '../../_helper/query'; | ||
import { label } from '../../_helper/label'; | ||
import { withShell } from '../../_helper/shell'; | ||
import type { | ||
StaticSliceQuery, | ||
StaticSliceQueryResult | ||
} from '../../../../src/queries/catalog/static-slice-query/static-slice-query-format'; | ||
import { fingerPrintOfQuery } from '../../../../src/queries/catalog/static-slice-query/static-slice-query-executor'; | ||
import { PipelineExecutor } from '../../../../src/core/pipeline-executor'; | ||
import { | ||
DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE, | ||
DEFAULT_SLICING_PIPELINE | ||
} from '../../../../src/core/steps/pipeline/default-pipelines'; | ||
import { requestFromInput } from '../../../../src/r-bridge/retriever'; | ||
import { doNotAutoSelect } from '../../../../src/reconstruct/auto-select/auto-select-defaults'; | ||
import { makeMagicCommentHandler } from '../../../../src/reconstruct/auto-select/magic-comments'; | ||
|
||
describe('Static Slice Query', withShell(shell => { | ||
function testQuery(name: string, code: string, queries: readonly StaticSliceQuery[]) { | ||
assertQuery(label(name), shell, code, queries, async() => { | ||
const results: StaticSliceQueryResult['results'] = {}; | ||
for(const query of queries) { | ||
const out = await new PipelineExecutor(query.noReconstruction ? DEFAULT_SLICE_WITHOUT_RECONSTRUCT_PIPELINE : DEFAULT_SLICING_PIPELINE, { | ||
shell: shell, | ||
request: requestFromInput(code), | ||
criterion: query.criteria, | ||
autoSelectIf: query.noMagicComments ? doNotAutoSelect : makeMagicCommentHandler(doNotAutoSelect) | ||
}).allRemainingSteps(); | ||
const key = fingerPrintOfQuery(query); | ||
results[key] = query.noReconstruction ? { slice: out.slice } : { slice: out.slice, reconstruct: out.reconstruct }; | ||
} | ||
|
||
return { | ||
'static-slice': { | ||
results | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
const baseQuery: StaticSliceQuery = { type: 'static-slice', criteria: ['1@x'] }; | ||
describe('With Reconstruction', () => { | ||
testQuery('Single Expression', 'x + 1', [baseQuery]); | ||
testQuery('Multiple Queries', 'x + 1', [baseQuery, baseQuery, baseQuery]); | ||
}); | ||
const noReconstructQuery: StaticSliceQuery = { type: 'static-slice', criteria: ['1@x'], noReconstruction: true }; | ||
describe('Without Reconstruction', () => { | ||
testQuery('Single Expression (No Reconstruct)', 'x + 1', [noReconstructQuery]); | ||
testQuery('Multiple Queries (No Reconstruct)', 'x + 1', [noReconstructQuery, noReconstructQuery, noReconstructQuery]); | ||
}); | ||
})); |
Oops, something went wrong.
fb720ff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"artificial" Benchmark Suite
Retrieve AST from R code
239.1878134090909
ms (100.07016011716344
)238.12351204545453
ms (103.59720843756357
)1.00
Normalize R AST
18.289318045454547
ms (31.42206962413676
)19.968034227272728
ms (34.84298543847825
)0.92
Produce dataflow information
39.44545631818182
ms (83.21461285961888
)38.310942090909094
ms (82.04448044777155
)1.03
Total per-file
818.9351105
ms (1463.0636513006111
)811.1703915909092
ms (1431.4404310276739
)1.01
Static slicing
2.136388743223465
ms (1.3517004805025001
)2.258090287874194
ms (1.2792808105316449
)0.95
Reconstruct code
0.23223599750638615
ms (0.17812559248692914
)0.22489327849282828
ms (0.17585774592637268
)1.03
Total per-slice
2.383691379856576
ms (1.423209995731651
)2.4996261233332735
ms (1.3278746913052974
)0.95
failed to reconstruct/re-parse
0
#0
#1
times hit threshold
0
#0
#1
reduction (characters)
0.7869360165281424
#0.7869360165281424
#1
reduction (normalized tokens)
0.7639690077689504
#0.7639690077689504
#1
memory (df-graph)
95.46617542613636
KiB (244.77619956879823
)147.42458274147728
KiB (358.6827375397903
)0.65
This comment was automatically generated by workflow using github-action-benchmark.
fb720ff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"social-science" Benchmark Suite
Retrieve AST from R code
237.497045
ms (43.583564030948246
)238.40722376
ms (42.95412443307438
)1.00
Normalize R AST
20.6991038
ms (15.360338777622799
)22.0872248
ms (17.016890594916376
)0.94
Produce dataflow information
75.26545594
ms (87.93598631340696
)74.60461736
ms (88.95210983454488
)1.01
Total per-file
7671.73540802
ms (28654.839983725476
)11091.201449639999
ms (52310.41942604725
)0.69
Static slicing
15.936251020016991
ms (43.79666198137641
)22.047137876062838
ms (78.30877993604865
)0.72
Reconstruct code
0.24095534033824254
ms (0.14875106021074844
)0.2327517832436913
ms (0.14954480815603388
)1.04
Total per-slice
16.184893299955597
ms (43.822625551525974
)22.287796325154986
ms (78.33211951742135
)0.73
failed to reconstruct/re-parse
0
#0
#1
times hit threshold
0
#0
#1
reduction (characters)
0.8712997340230448
#0.8719618340615195
#1.00
reduction (normalized tokens)
0.8102441553774778
#0.810633662275233
#1.00
memory (df-graph)
99.8990234375
KiB (113.72812769327498
)145.6434765625
KiB (153.49028997815503
)0.69
This comment was automatically generated by workflow using github-action-benchmark.