Skip to content

Ship box module functions to the worker and keep NULL function bodies - #31

Open
dawiegriesel wants to merge 1 commit into
mainfrom
fix/box-namespaces-and-null-body
Open

dawiegriesel wants to merge 1 commit into
mainfrom
fix/box-namespaces-and-null-body

Conversation

@dawiegriesel

Copy link
Copy Markdown
Owner

Summary

  • Box modules (Functions defined in a box module are never shipped, and are not reported as missing #29). A box module's own environment (namespace:<mod>) and the one a top-level box::use() attaches (mod:<path>) are not R namespaces, so collect_globals() skipped their functions without shipping them or reporting them missing, and the task failed on the worker with "could not find function". These environments are now recognised (is_box_env(), using box's own .__module__. marker or the box$mod class) and their functions are shipped as the global environment's are, together with the helpers their module defines.
  • S4 generics. A generic such as DBI::dbConnect() imported with box::use() is now shipped as it is instead of being rebound to a clone of its environment, which lost the method tables and broke dispatch.
  • NULL bodies (function(e) NULL is rewritten into a function returning its srcref when source references are kept #30). With srcrefs kept, rewriting function(e) NULL assigned NULL into the call, which deleted the body so the function returned its srcref. Only call bodies are rewritten now.

Tests

New tests in tests/testthat/test-capture.R cover a function defined in a box module, an imported box function and its module helpers, a top-level box::use() attachment, an end-to-end testServer() run on the worker, an imported S4 generic, and a NULL body parsed with keep.source = TRUE.

Fixes #29
Fixes #30

A box module's environment is not an R namespace, so functions defined in
a module, or attached by a top-level box::use(), were neither shipped nor
reported missing and failed with "could not find function" on the worker.
They are now shipped as the global environment's are (#29). S4 generics,
such as DBI::dbConnect() imported through box, are shipped as they are so
they keep the method tables dispatch needs.

With srcrefs, `function(e) NULL` lost its body when capture rewrote it,
since assigning NULL into a call deletes the element; only call bodies
are now rewritten (#30).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant