Skip to content

Commit

Permalink
Additional tests (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleoutIce authored May 28, 2024
2 parents 532b19d + 0390258 commit f0ac322
Show file tree
Hide file tree
Showing 24 changed files with 1,476 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/dataflow/graph/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function diffVertices(ctx: DataflowDiffContext): void {
})
}
}
diffControlDependencies(lInfo.controlDependencies, rInfo.controlDependencies, { ...ctx, position: `Vertex ${id} differs in controlDependency. ` })
diffControlDependencies(lInfo.controlDependencies, rInfo.controlDependencies, { ...ctx, position: `Vertex ${id} differs in controlDependencies. ` })

diffEnvironmentInformation(lInfo.environment, rInfo.environment, { ...ctx, position: `${ctx.position}Vertex ${id} differs in environment. ` })

Expand Down
2 changes: 1 addition & 1 deletion src/r-bridge/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export const flowrCapabilities = {
name: 'Sequencing',
id: 'built-in-sequencing',
supported: 'not',
description: '_Handle `:`, `seq`, ... as they are used often._'
description: '_Handle `:`, `seq`, ... by gathering value information using abstract interpretation._'
},
{
name: 'Internal and Primitive Functions',
Expand Down
2 changes: 1 addition & 1 deletion src/r-bridge/lang-4.x/ast/model/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const OperatorDatabase: Record<StringUsedInRCode, OperatorInformationValu
'=': { name: 'equal assignment', stringUsedInRAst: RawRType.EqualAssign, stringUsedInternally: '=', writtenAs: 'infix', arity: OperatorArity.Binary, usedAs: 'assignment', capabilities: ['binary-operator', 'infix-calls', 'assignment-functions', 'local-equal-assignment', 'function-calls'] },
/* others */
/* maybe introduce custom in-r-ast flavor for these? we consider it arithmetic, as it works on numbers => if we change this we have to create custom tests! (with arithmetic, there is the automatic test set) */
':': { name: 'sequence operator', stringUsedInRAst: RawRType.Colon, stringUsedInternally: ':', writtenAs: 'infix', arity: OperatorArity.Binary, usedAs: 'operation', capabilities: ['binary-operator', 'infix-calls', 'function-calls', 'built-in-sequencing'] },
':': { name: 'sequence operator', stringUsedInRAst: RawRType.Colon, stringUsedInternally: ':', writtenAs: 'infix', arity: OperatorArity.Binary, usedAs: 'operation', capabilities: ['binary-operator', 'infix-calls', 'function-calls'] },
'?': { name: 'question', stringUsedInRAst: RawRType.Question, stringUsedInternally: '?', writtenAs: 'prefix', arity: OperatorArity.Unary, usedAs: 'operation', capabilities: ['unary-operator', 'built-in-help'] }
}
/* eslint-enable */
Expand Down
10 changes: 5 additions & 5 deletions test/functionality/_helper/dataflow/dataflow-builder-printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { assertUnreachable, isNotUndefined } from '../../../../src/util/assert'
import { DefaultMap } from '../../../../src/util/defaultmap'
import { EnvironmentBuilderPrinter } from './environment-builder-printer'
import { wrap, wrapControlDependency, wrapReference } from './printer'
import { wrap, wrapControlDependencies, wrapReference } from './printer'
import { EdgeType, splitEdgeTypes } from '../../../../src/dataflow/graph/edge'
import type { DataflowGraph, FunctionArgument } from '../../../../src/dataflow/graph/graph'
import { isPositionalArgument } from '../../../../src/dataflow/graph/graph'
Expand Down Expand Up @@ -128,13 +128,13 @@ class DataflowBuilderPrinter {
if(arg === undefined || arg === EmptyArgument) {
return 'EmptyArgument'
} else if(isPositionalArgument(arg)) {
const suffix = this.getControlDependencySuffix(this.controlDependencyForArgument(arg.nodeId), ', { ') ?? ''
const suffix = this.getControlDependencySuffix(this.controlDependenciesForArgument(arg.nodeId), ', { ') ?? ''
this.handleArgumentArgLinkage(fn, arg.nodeId)
return `argumentInCall('${arg.nodeId}'${suffix})`
} else {
this.coveredVertices.add(arg.nodeId)
this.handleArgumentArgLinkage(fn, arg.nodeId)
const suffix = this.getControlDependencySuffix(this.controlDependencyForArgument(arg.nodeId), ', ', '') ?? ''
const suffix = this.getControlDependencySuffix(this.controlDependenciesForArgument(arg.nodeId), ', ', '') ?? ''
return `argumentInCall('${arg.nodeId}', { name: '${arg.name}'${suffix} } )`
}
}
Expand All @@ -154,7 +154,7 @@ class DataflowBuilderPrinter {
}
}

private controlDependencyForArgument(id: NodeId): ControlDependency[] | undefined {
private controlDependenciesForArgument(id: NodeId): ControlDependency[] | undefined {
// we ignore the control dependency of the argument in the call as it is usually separate, and the auto creation
// will respect the corresponding node!
return this.graph.getVertex(id, true)?.controlDependencies
Expand Down Expand Up @@ -248,7 +248,7 @@ class DataflowBuilderPrinter {

private getControlDependencySuffix(arg: ControlDependency[] | undefined, prefix: string = '{ ', suffix: string = ' }'): string | undefined {
if(arg !== undefined) {
return `${prefix}controlDependency: ${wrapControlDependency(arg)}${suffix}`
return `${prefix}controlDependencies: ${wrapControlDependencies(arg)}${suffix}`
}
return undefined
}
Expand Down
26 changes: 13 additions & 13 deletions test/functionality/_helper/dataflow/dataflowgraph-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class DataflowGraphBuilder extends DataflowGraph {
*/
public defineFunction(id: NodeId,
exitPoints: readonly NodeId[], subflow: DataflowFunctionFlowInformation,
info?: { environment?: REnvironmentInformation, controlDependency?: ControlDependency[] },
info?: { environment?: REnvironmentInformation, controlDependencies?: ControlDependency[] },
asRoot: boolean = true) {
return this.addVertex({
tag: VertexType.FunctionDefinition,
Expand All @@ -55,7 +55,7 @@ export class DataflowGraphBuilder extends DataflowGraph {
unknownReferences: subflow.unknownReferences.map(o => ({ ...o, nodeId: normalizeIdToNumberIfPossible(o.nodeId), controlDependencies: o.controlDependencies?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })) }))
} as DataflowFunctionFlowInformation,
exitPoints: exitPoints.map(normalizeIdToNumberIfPossible),
controlDependencies: info?.controlDependency?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
controlDependencies: info?.controlDependencies?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
environment: info?.environment
}, asRoot)
}
Expand All @@ -72,21 +72,21 @@ export class DataflowGraphBuilder extends DataflowGraph {
*/
public call(id: NodeId, name: string, args: FunctionArgument[],
info?: {
returns?: readonly NodeId[],
reads?: readonly NodeId[],
onlyBuiltIn?: boolean,
environment?: REnvironmentInformation,
controlDependency?: ControlDependency[]
returns?: readonly NodeId[],
reads?: readonly NodeId[],
onlyBuiltIn?: boolean,
environment?: REnvironmentInformation,
controlDependencies?: ControlDependency[]
},
asRoot: boolean = true) {
const onlyBuiltInAuto = info?.reads?.length === 1 && info?.reads[0] === BuiltIn
this.addVertex({
tag: VertexType.FunctionCall,
id: normalizeIdToNumberIfPossible(id),
name,
args: args.map(a => a === EmptyArgument ? EmptyArgument : { ...a, nodeId: normalizeIdToNumberIfPossible(a.nodeId), controlDependency: undefined }),
args: args.map(a => a === EmptyArgument ? EmptyArgument : { ...a, nodeId: normalizeIdToNumberIfPossible(a.nodeId), controlDependencies: undefined }),
environment: info?.environment ?? initializeCleanEnvironments(),
controlDependencies: info?.controlDependency?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
controlDependencies: info?.controlDependencies?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
onlyBuiltin: info?.onlyBuiltIn ?? onlyBuiltInAuto ?? false
}, asRoot)
this.addArgumentLinks(id, args)
Expand Down Expand Up @@ -132,12 +132,12 @@ export class DataflowGraphBuilder extends DataflowGraph {
* (i.e., be a valid entry point), or is it nested (e.g., as part of a function definition)
*/
public defineVariable(id: NodeId, name: string,
info?: { controlDependency?: ControlDependency[], definedBy?: NodeId[]}, asRoot: boolean = true) {
info?: { controlDependencies?: ControlDependency[], definedBy?: NodeId[]}, asRoot: boolean = true) {
this.addVertex({
tag: VertexType.VariableDefinition,
id: normalizeIdToNumberIfPossible(id),
name,
controlDependencies: info?.controlDependency?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
controlDependencies: info?.controlDependencies?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
}, asRoot)
if(info?.definedBy) {
for(const def of info.definedBy) {
Expand Down Expand Up @@ -178,11 +178,11 @@ export class DataflowGraphBuilder extends DataflowGraph {
* @param asRoot - should the vertex be part of the root vertex set of the graph
* (i.e., be a valid entry point), or is it nested (e.g., as part of a function definition)
*/
public constant(id: NodeId, options?: { controlDependency?: ControlDependency[] }, asRoot: boolean = true) {
public constant(id: NodeId, options?: { controlDependencies?: ControlDependency[] }, asRoot: boolean = true) {
return this.addVertex({
tag: VertexType.Value,
id: normalizeIdToNumberIfPossible(id),
controlDependencies: options?.controlDependency?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
controlDependencies: options?.controlDependencies?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })),
environment: undefined
}, asRoot)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertUnreachable, isNotUndefined } from '../../../../src/util/assert'
import { wrap, wrapControlDependency } from './printer'
import { wrap, wrapControlDependencies } from './printer'
import type { IEnvironment, REnvironmentInformation } from '../../../../src/dataflow/environments/environment'
import { BuiltInEnvironment } from '../../../../src/dataflow/environments/environment'
import type { IdentifierDefinition } from '../../../../src/dataflow/environments/identifier'
Expand Down Expand Up @@ -77,7 +77,7 @@ export class EnvironmentBuilderPrinter {
}

private getControlDependencyArgument(def: IdentifierDefinition) {
return def.controlDependencies ? wrapControlDependency(def.controlDependencies) : undefined
return def.controlDependencies ? wrapControlDependencies(def.controlDependencies) : undefined
}

private push() {
Expand Down
4 changes: 2 additions & 2 deletions test/functionality/_helper/dataflow/environment-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export function variable(name: string, definedAt: NodeId): IdentifierDefinition
* @param nodeId - AST Node ID
* @param options - optional allows to give further options
*/
export function argumentInCall(nodeId: NodeId, options?: { name?: string, controlDependency?: ControlDependency[] }): FunctionArgument {
return { nodeId: normalizeIdToNumberIfPossible(nodeId), name: options?.name, controlDependencies: options?.controlDependency?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })) }
export function argumentInCall(nodeId: NodeId, options?: { name?: string, controlDependencies?: ControlDependency[] }): FunctionArgument {
return { nodeId: normalizeIdToNumberIfPossible(nodeId), name: options?.name, controlDependencies: options?.controlDependencies?.map(c => ({ ...c, id: normalizeIdToNumberIfPossible(c.id) })) }
}
/**
* The constant global environment with all pre-defined functions.
Expand Down
8 changes: 4 additions & 4 deletions test/functionality/_helper/dataflow/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export function wrap(id: string | NodeId | undefined): string {
}
}

export function wrapControlDependency(controlDependency: ControlDependency[] | undefined): string {
if(controlDependency === undefined) {
export function wrapControlDependencies(controlDependencies: ControlDependency[] | undefined): string {
if(controlDependencies === undefined) {
return 'undefined'
} else {
return `[${controlDependency.map(c =>
return `[${controlDependencies.map(c =>
`{ id: ${wrap(c.id)}, when: ${c.when} }`
).join(', ')}]`
}
}
export function wrapReference(ref: IdentifierReference): string {
return `{ nodeId: ${wrap(ref.nodeId)}, name: ${wrap(ref.name)}, controlDependencies: ${wrapControlDependency(ref.controlDependencies)} }`
return `{ nodeId: ${wrap(ref.nodeId)}, name: ${wrap(ref.name)}, controlDependencies: ${wrapControlDependencies(ref.controlDependencies)} }`
}
2 changes: 2 additions & 0 deletions test/functionality/_helper/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ export function assertSliced(name: string | TestLabel, shell: RShell, input: str
const fullname = decorateLabelContext(name, ['slice'])

const t = it(`${JSON.stringify(criteria)} ${fullname}`, async function() {
await ensureConfig(shell, this, userConfig)

const result = await new PipelineExecutor(DEFAULT_RECONSTRUCT_PIPELINE,{
getId,
request: requestFromInput(input),
Expand Down
Loading

2 comments on commit f0ac322

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"artificial" Benchmark Suite

Benchmark suite Current: f0ac322 Previous: eddce74 Ratio
Retrieve AST from R code 235.13640504545452 ms 282.3815673181818 ms 0.83
Normalize R AST 31.622919363636363 ms 36.45953090909091 ms 0.87
Produce dataflow information 57.411243590909095 ms 66.17186054545455 ms 0.87
Total per-file 1252.297090909091 ms 1557.712024590909 ms 0.80
Static slicing 1.2133106701566374 ms (1.0351196959774094) 1.4160048835200516 ms (1.1715105189277293) 0.86
Reconstruct code 0.3997989978696819 ms (0.22130739804222646) 0.48975330853571625 ms (0.2799126163528146) 0.82
Total per-slice 1.632186593057531 ms (1.0922357243615846) 1.9280102618968917 ms (1.2491682419110006) 0.85
failed to reconstruct/re-parse 0 # 0 # 1
times hit threshold 0 # 0 # 1
reduction (characters) 0.797431685913541 # 0.797431685913541 # 1
reduction (normalized tokens) 0.7740577588998524 # 0.7740577588998524 # 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"social-science" Benchmark Suite

Benchmark suite Current: f0ac322 Previous: eddce74 Ratio
Retrieve AST from R code 240.32837296 ms 236.60308994 ms 1.02
Normalize R AST 32.1317648 ms 31.77161632 ms 1.01
Produce dataflow information 83.08882486 ms 81.86384715999999 ms 1.01
Total per-file 2704.2843193000003 ms 2674.55292236 ms 1.01
Static slicing 5.466985639938921 ms (10.324201099160314) 5.448939336693711 ms (10.154387662460568) 1.00
Reconstruct code 0.37569927137410214 ms (0.19967730798195385) 0.35616079097800935 ms (0.1827576285958724) 1.05
Total per-slice 5.851926701371236 ms (10.393564270706712) 5.814113487370482 ms (10.211794878365124) 1.01
failed to reconstruct/re-parse 2 # 2 # 1
times hit threshold 0 # 0 # 1
reduction (characters) 0.9244759792036856 # 0.9241844105867956 # 1.00
reduction (normalized tokens) 0.8924953600737399 # 0.8924953600737399 # 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.