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

force 'finalize' method to be materialized on Modules #1231

Merged
merged 3 commits into from
Sep 25, 2022

Conversation

kevinushey
Copy link
Contributor

Closes #1230.

Checklist

  • Code compiles correctly
  • R CMD check still passes all tests
  • Preferebly, new tests were added which fail without the change
  • Document the changes by file in ChangeLog

ChangeLog Outdated
@@ -1,3 +1,7 @@
2022-09-23 Kevin Ushey <kevinushey@gmail.com>

* R/Module.R: Force 'finalize' method to be materialized
Copy link
Member

Choose a reason for hiding this comment

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

Old Emacs roots here: 1 tab or eight spaces, please.

(Not sure editorconfig has a mode for ChangeLog...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, will fix that up! RStudio wasn't smart enough to infer the indentation here...

Copy link
Member

Choose a reason for hiding this comment

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

If only we knew someone working on the IDE 😹

@@ -131,6 +131,8 @@ new_dummyObject <- function(...) # #nocov

# class method for $initialize
cpp_object_initializer <- function(.self, .refClassDef, ..., .object_pointer){
# force finalize method to be materialized
invisible(.self$finalize)
Copy link
Member

Choose a reason for hiding this comment

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

Wow. A one-liner to fix a woe. I presume you played with some Rprintf or REprintf here to see it hits?

@eddelbuettel
Copy link
Member

I'll turn the rev.dep machine on. It'll take a few moments as usual.

@kevinushey
Copy link
Contributor Author

kevinushey commented Sep 23, 2022

Wow. A one-liner to fix a woe. I presume you played with some Rprintf or REprintf here to see it hits?

Right -- just to confirm, this is the script I was running to exercise the issue.


trace(Rcpp:::cpp_object_initializer, quote({
    writeLines("Hello from C++Object initializer!")
}))

library("terra")
library("raster")
#terra version 1.2.13
fnz <- "nz_elev.rda"
if (!file.exists(fnz)) {
 download.file("https://github.com/Nowosad/spDataLarge/raw/master/data/nz_elev.rda", fnz, mode = "wb")
}
load("nz_elev.rda")
nz <- rast(nz_elev)
plot(nz)

The tracer indeed fires, and the above code reliably prints some errors with the CRAN release of Rcpp, but not with the bandaid from this PR.

Also emphasizing; it's not clear whether this is an issue in Rcpp Modules or something else but this is still the simplest way for us to paper over the issue -- evidently it's been reported in a number of places...

sneumann/xcms#288
https://stackoverflow.com/questions/65556253/r-raster-selffinalize-error-causing-failure
https://discourse.mc-stan.org/t/very-mysterious-debug-error-when-running-rstanarm-rstan-chains-error-in-x-self-finalize-attempt-to-apply-non-function/4746

@eddelbuettel
Copy link
Member

Yes. I encountered similar mysterious issues with XPtr once and in one use case ensure I always explicitly set one. It's weird because it generally works. But corner cases exist, so I think this goes the right way.

The rev.dep tests being CI we may not see real side effects. But it being September maybe we can get some user segments (geospatial, rstan, ...) to pretty-please try a rc release from the drat before 1.0.10 gets cases in January (under normal timelines).

@eddelbuettel
Copy link
Member

So big thank you to you for digging in here!

@eddelbuettel
Copy link
Member

Ran the (slow, long) battery of reverse depends checks (resuls as usual in the rcpp-logs sibbling repo) and "no change to worse" so merging this now.

@eddelbuettel eddelbuettel merged commit 9e18f44 into master Sep 25, 2022
@eddelbuettel
Copy link
Member

I also marked it as 1.0.9.3 and pushed a build into the rcpp-drat so we could reach out to the affected packages and suggest they try this version.

@kevinushey
Copy link
Contributor Author

Thanks! I'll send a ping on Twitter and see if there's anyone interested in testing.

@rhijmans
Copy link

Halleluja. I can confirm that this fixes the issue in "terra" --- at least for the cases that I could reproduce this with

@eddelbuettel eddelbuettel deleted the bugfix/rcpp-modules-finalize-materialize branch October 7, 2022 12:58
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.

Modules: ensure 'finalize' method is materialized on object instances
3 participants