Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ without running its cleanup, for example a future worker interrupted from the
parent session. Previously they kept running as orphans. (#1086)
* `$init_model_methods()` and `$expose_functions()` now work in the same R
session as rstan or brms, whichever loads first, when RcppParallel 6.2.0 or
later is installed. (#1270)
later is installed. (#1177, #1270)
* A function exposed with `$expose_functions()` that returns a tuple no longer
occasionally crashes R or returns a list with wrong elements. (#1001)
* `$expose_functions(global = TRUE)` now also keeps the functions in the
Expand Down
5 changes: 4 additions & 1 deletion R/expose.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ rcpp_source_stan <- function(code, env, verbose = FALSE, ...) {
make_args
)
check_sundials_fpic(flags[8], verbose)
cxxflags <- flags[1]
# With GCC, Stan Math's autodiff stack is a unique symbol that the loader
# binds to rstan's, or any other Stan Math build in the session, and R
# crashes (#1177). Hidden visibility keeps it out of the exported symbols.
cxxflags <- paste(flags[1], "$(CXX_VISIBILITY)")
cppflags <- flags[2]
libs <- paste(flags[3:7], collapse = " ")
cmdstanr_includes <- system.file(
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-model-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ test_that("Methods return correct values", {
expect_equal(unconstrained_variables, c(0.1))
})

test_that("model methods don't export Stan Math's autodiff stack", {
skip_on_os("windows")
# On Linux the loader would bind rstan's copy to it (#1177)
instance <- paste0(
"_ZN4stan4math22AutodiffStackSingletonINS0_9vari_baseE",
"NS0_15chainable_allocEE9instance_E"
)
fit$init_model_methods()
dlls <- Filter(
function(dll) startsWith(dll[["name"]], "sourceCpp"),
getLoadedDLLs()
)
expect_gt(length(dlls), 0)
for (dll in dlls) {
expect_false(is.loaded(instance, PACKAGE = dll[["name"]]))
}
})

test_that("Model methods environments are independent", {
data_list_2 <- data_list
data_list_2$N <- 20
Expand Down
Loading