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

Move data mask cleaning from rlang to dplyr #3318

Closed
lionel- opened this issue Jan 23, 2018 · 14 comments
Closed

Move data mask cleaning from rlang to dplyr #3318

lionel- opened this issue Jan 23, 2018 · 14 comments

Comments

@lionel-
Copy link
Member

lionel- commented Jan 23, 2018

As we're no longer cleaning the mask by default.

Also investigate whether we can avoid active binding crashes without cleaning the data mask.

@krlmlr
Copy link
Member

krlmlr commented Mar 17, 2018

We might be able to avoid cleaning the data mask with weak references (WEAKREFSXP), need to look into it. But:

At the time of writing no CRAN or Bioconductor package uses weak references.

That's not very promising...

@krlmlr
Copy link
Member

krlmlr commented Mar 17, 2018

On the other hand, we might also use a C++ implementation of weak references.

To recap: We need to clean the data mask because otherwise a pointer to an object with limited lifetime might leak. We are not in control of the lifetime of the objects for which we share an XPtr. We can overcome this by sharing only proxy objects that contain an internal weak reference to the real C++ object; when the real C++ object goes out of scope, the proxy returns some default value when accessed.

@lionel-
Copy link
Member Author

lionel- commented Mar 17, 2018

Maybe an alternative is to add a stale flag in the data mask. When that flag is set a default value would be returned?

Or: adding a finalizer to the environment containing the active bindings and clean up the relevant dplyr objects from that finalizer?

@krlmlr
Copy link
Member

krlmlr commented Mar 17, 2018

One way or another, the proxy object needs to know that the data source isn't available anymore. I prefer controlling lifetime of internal dplyr classes from dplyr code.

@krlmlr
Copy link
Member

krlmlr commented Mar 17, 2018

This needs an enhancement to bindrcpp, which I meant to release anyway before updating dplyr: krlmlr/bindrcpp#7. The current interface only supports naked pointers, I need to give up ownership at least for a proxy object.

@lionel-
Copy link
Member Author

lionel- commented Mar 17, 2018

Is it useful to keep bindrcpp as a separate package?

@krlmlr
Copy link
Member

krlmlr commented Mar 17, 2018

It has two downstream dependencies ;-)

@krlmlr
Copy link
Member

krlmlr commented Mar 17, 2018

And, yes, the ping-pong between R and C++ is pretty convoluted, it helps to isolate it from the rest of the codebase.

@krlmlr
Copy link
Member

krlmlr commented Mar 18, 2018

I have an implementation that uses boost::weak_ptr, will share soon.

@krlmlr
Copy link
Member

krlmlr commented Mar 19, 2018

@lionel-: Is there functionality in rlang that can replace bindr and bindrcpp? I kept these packages separate to avoid the Rcpp dependency in bindr.

@lionel-
Copy link
Member Author

lionel- commented Mar 19, 2018

I don't understand completely what those packages do but I don't think so.

krlmlr added a commit that referenced this issue Mar 19, 2018
- Avoid cleaning the data mask, a temporary environment used to evaluate expressions. If the environment, in which e.g. a `mutate()` expression is evaluated, is preserved until after the operation, accessing variables from that environment now gives a warning but still returns `NULL` (#3318).
@krlmlr
Copy link
Member

krlmlr commented Mar 19, 2018

bindr creates an environment full of almost identical active bindings. bindrcpp is the Rcpp interface to bindr.

@lionel-
Copy link
Member Author

lionel- commented Mar 19, 2018

I think this functionality is too specific for rlang.

@lock
Copy link

lock bot commented Sep 15, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Sep 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants