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

Zap inline objects from backtraces #1278

Merged
merged 4 commits into from
Sep 15, 2021
Merged

Zap inline objects from backtraces #1278

merged 4 commits into from
Sep 15, 2021

Conversation

lionel-
Copy link
Member

@lionel- lionel- commented Sep 14, 2021

Closes #1069.
Closes r-lib/testthat#1223.

Inline objects are replaced by their pillar type sum:

call <- expr(foo(!!(1:2)))
call_zap_inline(call)
#> foo(`<int>`)

Comment on lines +1064 to +1068
return(x)
}

if (is_symbol(x) || is_syntactic_literal(x)) {
x
Copy link
Member

Choose a reason for hiding this comment

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

I find this slightly easier to understand, but it's not that important

Suggested change
return(x)
}
if (is_symbol(x) || is_syntactic_literal(x)) {
x
x
} else if (is_symbol(x) || is_syntactic_literal(x)) {
x

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea here is to keep the terminating and recursive branches separate.

f <- function(...) g()
g <- function() h()
h <- function() trace_back(e)
trace <- inject(f(!!list()))
Copy link
Member

Choose a reason for hiding this comment

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

Could also use do.call() here, since that's the most common way that users will create inlined objects.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like along these lines:

e <- environment()
f <- function() do.call("g", list(1:1e6 + 1))
g <- function(...) h()
h <- function() rlang::trace_back(e)
lobstr::obj_size(f())
#> 8,014,888 B

Created on 2021-09-14 by the reprex package (v2.0.0)

(But using something other than obj_size())

Copy link
Member

Choose a reason for hiding this comment

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

Maybe

trace <- f()
trace$calls[[3]]

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I've added a do.call() and size check in the test.

@@ -40,7 +40,7 @@
12. \-rlang:::c()
13. +-base::withCallingHandlers(...)
14. +-rlang::with_abort(f())
15. | \-base::withCallingHandlers(...)
15. | \-base::withCallingHandlers(expr, error = `<fn>`)
Copy link
Member

Choose a reason for hiding this comment

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

Again, not very important, but why does this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

The injected handler is now a symbol. This allows as_label() to keep the whole call instead of eliding.

@lionel- lionel- merged commit bd1b0be into r-lib:master Sep 15, 2021
@lionel- lionel- deleted the zap-inline branch September 15, 2021 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trim literal objects from backtraces Writing testthat-problems.rds is slow
3 participants