Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Follow up on source calls #609

Merged
merged 51 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b11decd
wip: added testfile & started on environment (??)
Ellpeck Jan 22, 2024
006aa10
wip: some todos
Ellpeck Jan 22, 2024
e5268f5
wip: start of source argument resolve
Ellpeck Jan 22, 2024
969815e
wip: added testfile & started on environment (??)
Ellpeck Jan 22, 2024
50a461b
wip: some todos
Ellpeck Jan 22, 2024
552bf5d
wip: start of source argument resolve
Ellpeck Jan 22, 2024
74d71da
Merge remote-tracking branch 'origin/605-feat-follow-up-on-source-cal…
Ellpeck Jan 25, 2024
df033ab
refactor: start using sync r shell implementation
Ellpeck Jan 25, 2024
97761a7
wip: rebase
Ellpeck Jan 22, 2024
e6ec40f
refactor: start using sync r shell implementation
Ellpeck Jan 25, 2024
7f5a006
Merge remote-tracking branch 'origin/605-feat-follow-up-on-source-cal…
Ellpeck Jan 25, 2024
c1d1346
wip: use executeSingleSubStep for parsing sourced code
Ellpeck Jan 25, 2024
1eae7f6
wip: added testfile & started on environment (??)
Ellpeck Jan 22, 2024
a88f8bb
wip: some todos
Ellpeck Jan 22, 2024
83cb725
wip: start of source argument resolve
Ellpeck Jan 22, 2024
10699e8
wip: rebase
Ellpeck Jan 22, 2024
5f4f31e
refactor: start using sync r shell implementation
Ellpeck Jan 25, 2024
559d80c
wip: some todos
Ellpeck Jan 22, 2024
061aaea
wip: use executeSingleSubStep for parsing sourced code
Ellpeck Jan 25, 2024
3d74428
Merge remote-tracking branch 'origin/605-feat-follow-up-on-source-cal…
Ellpeck Jan 30, 2024
4f9e9ea
wip: fix merge issues
Ellpeck Jan 30, 2024
a0f8f00
feat-fix: avoid cyclic dependency when using step executor
Ellpeck Jan 30, 2024
9fc51f0
wip: run normalize and dataflow on sourced file
Ellpeck Jan 30, 2024
32b049e
wip: some work on source dataflowing
Ellpeck Jan 31, 2024
0392ad6
refactor: remove print
Ellpeck Jan 31, 2024
ac7eb1d
Merge branch 'main' into 605-feat-follow-up-on-source-calls
EagleoutIce Feb 1, 2024
b7add0c
refactor: clean up todos and move source to its own function
Ellpeck Feb 1, 2024
92c96ac
Merge remote-tracking branch 'origin/605-feat-follow-up-on-source-cal…
Ellpeck Feb 1, 2024
787fe00
refactor: explicitly as in processSourceCall
Ellpeck Feb 1, 2024
197c418
refactor: damn u typescript
Ellpeck Feb 1, 2024
136a8eb
feat-fix: ensure we only parse built-in source calls
Ellpeck Feb 1, 2024
f335eee
refactor: remove todo
Ellpeck Feb 1, 2024
1bdbe44
feat: allow overriding the source file provider
Ellpeck Feb 1, 2024
019d49c
test: start on source tests
Ellpeck Feb 1, 2024
345bf4c
refactor: overhaul source providers
Ellpeck Feb 1, 2024
7507a18
refactor: generify source providers to RParseRequestProvider
Ellpeck Feb 1, 2024
911d349
test: added test for conditional source
Ellpeck Feb 5, 2024
ba6dce2
refactor: properly handle missing/invalid sourced files
Ellpeck Feb 5, 2024
48c7928
wip: test for recursive sources
Ellpeck Feb 5, 2024
3f21bcf
feat: skip dataflow analysis for re-sourced references
Ellpeck Feb 5, 2024
53d69de
wip: add another todo
Ellpeck Feb 5, 2024
c0eb3fc
refactor: use parse requests in dataflow processor info
Ellpeck Feb 6, 2024
5bc6d08
refactor: first pass of reference chain impl
Ellpeck Feb 6, 2024
56a4047
feat-fix: also catch normalize and dataflow errors
Ellpeck Feb 6, 2024
11b625b
test: finished recursive source test
Ellpeck Feb 6, 2024
85dd0fd
test: added test for non-constant source argument
Ellpeck Feb 6, 2024
0c239af
test: added multi-source test
Ellpeck Feb 6, 2024
f6323c6
feat-fix: sourcing multiple files works correctly now
Ellpeck Feb 6, 2024
03b4618
refactor: resolve review comments
Ellpeck Feb 7, 2024
d1ea24a
test: reset the source provider to the default value after each describe
Ellpeck Feb 7, 2024
b5ddd9a
test-fix: reset the source provider in the source describe instead
Ellpeck Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/dataflow/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ const processors: DataflowProcessors<any> = {
}

export function produceDataFlowGraph<OtherInfo>(ast: NormalizedAst<OtherInfo & ParentInformation>, initialScope: DataflowScopeName = LocalScope): DataflowInformation {
return processDataflowFor<OtherInfo>(ast.ast, { completeAst: ast, activeScope: initialScope, environments: initializeCleanEnvironments(), processors: processors as DataflowProcessors<OtherInfo & ParentInformation> })
return processDataflowFor<OtherInfo>(ast.ast, {
completeAst: ast,
activeScope: initialScope,
environments: initializeCleanEnvironments(),
processors: processors as DataflowProcessors<OtherInfo & ParentInformation>,
currentPath: 'initial',
sourceReferences: new Map<string, string[]>()
})
}

export function processBinaryOp<OtherInfo>(node: RBinaryOp<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>) {
Expand Down
16 changes: 13 additions & 3 deletions src/dataflow/internal/process/functions/source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {RArgument, RParseRequestProvider} from '../../../../r-bridge'
import { requestProviderFromFile} from '../../../../r-bridge'
import {requestProviderFromFile} from '../../../../r-bridge'
import {fileNameDeterministicCountingIdGenerator, type NormalizedAst, type ParentInformation, removeTokenMapQuotationMarks, type RFunctionCall, RType} from '../../../../r-bridge'
import {RShellExecutor} from '../../../../r-bridge/shell-executor'
import {executeSingleSubStep} from '../../../../core'
Expand Down Expand Up @@ -28,6 +28,12 @@ export function processSourceCall<OtherInfo>(functionCall: RFunctionCall<OtherIn
const path = removeTokenMapQuotationMarks(sourceFile.lexeme)
const request = sourceProvider.createRequest(path)

// check if the sourced file has already been dataflow analyzed, and if so, skip it
if(data.sourceReferences.has(path)) {
dataflowLogger.info(`Sourced file ${path} was already dataflow analyzed, skipping`)
return information
}

// parse, normalize and dataflow the sourced file
let parsed: string
try {
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -36,11 +42,15 @@ export function processSourceCall<OtherInfo>(functionCall: RFunctionCall<OtherIn
dataflowLogger.warn(`Failed to parse sourced file ${path}, ignoring: ${(e as Error).message}`)
return information
}

// make the currently analyzed file remember that it already referenced the path
data.sourceReferences.set(data.currentPath, [...(data.sourceReferences.get(data.currentPath) ?? []), path])

const normalized = executeSingleSubStep('normalize', parsed, executor.getTokenMap(), undefined, fileNameDeterministicCountingIdGenerator(path)) as NormalizedAst<OtherInfo & ParentInformation>
const dataflow = processDataflowFor(normalized.ast, {...data, environments: information.environments})
const dataflow = processDataflowFor(normalized.ast, {...data, currentPath: path, environments: information.environments})

// update our graph with the sourced file's information
const newInformation = {...information}
const newInformation = {...information}
newInformation.environments = overwriteEnvironments(information.environments, dataflow.environments)
newInformation.graph.mergeWith(dataflow.graph)
// this can be improved, see issue #628
Expand Down
14 changes: 7 additions & 7 deletions src/dataflow/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ export interface DataflowProcessorInformation<OtherInfo> {
/**
* Initial and frozen ast-information
*/
readonly completeAst: NormalizedAst<OtherInfo>
readonly completeAst: NormalizedAst<OtherInfo>
/**
* Correctly contains pushed local scopes introduced by `function` scopes.
* Will by default *not* contain any symbol-bindings introduces along the way, they have to be decorated when moving up the tree.
*/
readonly environments: REnvironmentInformation
readonly environments: REnvironmentInformation
/**
* Name of the currently active scope, (hopefully) always {@link LocalScope | Local}
*/
readonly activeScope: DataflowScopeName
readonly activeScope: DataflowScopeName
/**
* Other processors to be called by the given functions
*/
readonly processors: DataflowProcessors<OtherInfo>
readonly processors: DataflowProcessors<OtherInfo>
// TODO using "initial" as the default path doesn't allow us to skip re-sourcing the initial file - how do we find out the initial file's name/path?
readonly currentPath: string | 'initial'
Ellpeck marked this conversation as resolved.
Show resolved Hide resolved
readonly sourceReferences: Map<string, string[]>
}

export type DataflowProcessor<OtherInfo, NodeType extends RNodeWithParent<OtherInfo>> = (node: NodeType, data: DataflowProcessorInformation<OtherInfo>) => DataflowInformation
Expand Down Expand Up @@ -55,6 +58,3 @@ export type DataflowProcessors<OtherInfo> = {
export function processDataflowFor<OtherInfo>(current: RNodeWithParent<OtherInfo>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation {
return data.processors[current.type](current as never, data)
}



Loading