-
-
Notifications
You must be signed in to change notification settings - Fork 8
assign side_effects and occurrence as attributes of @code
#223
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
Conversation
…qenv with 2 new attributes: side_effects, occurrence
…object instead of a list
|
Hey @gogonzo - if you have some spare time, this PR is ready for the first review. |
R/qenv-eval_code.R
Outdated
|
|
||
| pd <- utils::getParseData(current_call) | ||
| pd <- normalize_pd(pd) | ||
| call_pd <- extract_calls(pd)[[1]] |
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.
extract_calls while calls are already split?
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.
extract_occurrence assume that pd has a specific order of rows, that gets changed when you apply extract_calls(pd) on pd.
I can move call_pd <- extract_calls(pd)[[1]] inside extract_occurrence. Or is it ok to keep in eval_code?
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.
Let me ask another question - why to reorder pd?
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.
extract_occurrence assumes object names (SYMBOL) appear after <- (LEFT_ASSIGN/ASSIGN).
extract_calls reorders pd in this way.
code <- "a<-1"
parsed_code <- parse(text = code, keep.source = TRUE)
pd <- utils::getParseData(parsed_code)
> pd
line1 col1 line2 col2 id parent token terminal text
7 1 1 1 4 7 0 expr FALSE
1 1 1 1 1 1 3 SYMBOL TRUE a
3 1 1 1 1 3 7 expr FALSE
2 1 2 1 3 2 7 LEFT_ASSIGN TRUE <-
4 1 4 1 4 4 5 NUM_CONST TRUE 1
5 1 4 1 4 5 7 expr FALSE
> extract_calls(pd)
line1 col1 line2 col2 id parent token terminal text
7 1 1 1 4 7 0 expr FALSE
3 1 1 1 1 3 7 expr FALSE
2 1 2 1 3 2 7 LEFT_ASSIGN TRUE <-
5 1 4 1 4 5 7 expr FALSE
1 1 1 1 1 1 3 SYMBOL TRUE a
4 1 4 1 4 4 5 NUM_CONST TRUE 1If we don't want to use extract_calls we need to revisit and rewrite extract_occurrence. I am not sure we will invent rules to figure out dependencies for a non-sorted pd.
So right now this is a matter of whether we
- use
extract_callsonpdand before we applypdinsideextract_occurrence - or whether we put
extract_callsinsideextract_occurrence - or whether we rewrite
extract_occurrence.
extract_occurrence is a pretty big beast : P
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.
Maybe we can simplify extract_calls part so that it only reorders
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.
I just played with what parts of extract_calls are needed so that extract_occurrence works and below are the needed parts:
# reordering basen on parent-children relation
parent_ids <- pd[pd$parent == 0 & (pd$token !e= "COMMENT" | grepl("@linksto", pd$text, fixed = TRUE)), "id"]
pd_order <- do.call(rbind, lapply(parent_ids, function(parent) rbind(pd[pd$id == parent, ], get_children(pd, parent))))
# filtering or edge cases
if (!is.null(pd_order) && !(nrow(pd_order) == 1 && call$token == "';'")) {
# fixing assignment arrows
pd_order <- fix_arrows(list(pd_order))[[1]]
attr(current_code, "dependency") <- c(extract_side_effects(pd_order), extract_occurrence(pd_order))
}So this is basically all of extract_calls without fix_shifted_comments that is skipped if there is only 1 call.
If extract_calls would be renamed to reorder_and_clean_calls then I suppose usage of this function is totally justified in here. We can always put this part in extract_occurrence but it's gonna be repeated in extract_calls and extract_occurrence
|
Hey @gogonzo I also needed to change the way we create There is a bit code from teal.code for unexported functions. Should we export something in teal.code, so that it could be reused in teal.data? |
| } | ||
|
|
||
| attr(current_code, "id") <- sample.int(.Machine$integer.max, size = 1) | ||
| attr(current_code, "dependency") <- extract_dependency(current_call) |
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.
This loop looks nice now. extract_dependency is a good move 👍
gogonzo
left a comment
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.
All good here 👍 Please see the comment below
Co-authored-by: Dawid Kałędkowski <[email protected]> Signed-off-by: Marcin <[email protected]>
Part of #216
Changes:
dependencyextraction fromget_code_dependencytoeval_codeextract_code_graphqenvwith 1 new attributes:dependency,occurrenceside_effectsandoccurrenceinsideeval_codeas they were previously joined inextract_code_graphanywayqenv() |> eval_code |> get_code_attr("dependency")extract_side_effectsandextract_occurrenceso they work on an element, and they don't uselapply