stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
138 stars 44 forks source link

Issue a warning when a variable is assigned to itself #1357

Closed cdriveraus closed 9 months ago

cdriveraus commented 10 months ago

Didn't take long to get a package removal threat from CRAN / Ripley... this is for ctsem, I guess the only approach is to wait for a new Rstan?

using R Under development (unstable) (2023-09-08 r85108) using platform: x86_64-pc-linux-gnu R was compiled by clang version 16.0.6 GNU Fortran (GCC) 13.2.0 running under: Fedora Linux 36 (Workstation Edition) using session charset: UTF-8 using option ‘--no-stop-on-test-error’ checking for file ‘ctsem/DESCRIPTION’ ... OK checking extension type ... Package this is package ‘ctsem’ version ‘3.8.1’ package encoding: UTF-8 checking package namespace information ... OK checking package dependencies ... OK checking if this is a source package ... OK checking if there is a namespace ... OK checking for executable files ... OK checking for hidden files and directories ... OK checking for portable file names ... OK checking for sufficient/correct file permissions ... OK checking whether package ‘ctsem’ can be installed ... [41m/100m] WARNING Found the following significant warnings: ./stanExports_ctsm.h:2052:13: warning: explicitly assigning value of variable of type 'local_scalar_t' (aka 'typename boost::math::tools::promote_args::type') to itself [-Wself-assign-overloaded] ./stanExports_ctsmgen.h:2071:13: warning: explicitly assigning value of variable of type 'local_scalar_t' (aka 'typename boost::math::tools::promote_args::type') to itself [-Wself-assign-overloaded] See the install log for details. used C++ compiler: ‘clang version 16.0.6’ checking C++ specification ... OK Not all R platforms support C++17 checking installed package size ... NOTE installed size is 15.8Mb sub-directories of 1Mb or more: R 1.2Mb data 1.6Mb libs 11.8Mb checking package directory ... OK checking ‘build’ directory ... OK checking DESCRIPTION meta-information ... OK checking top-level files ... OK checking for left-over files ... OK checking index information ... OK checking package subdirectories ... OK checking R files for non-ASCII characters ... OK checking R files for syntax errors ... OK checking whether the package can be loaded ... [15s/21s] OK checking whether the package can be loaded with stated dependencies ... [14s/18s] OK checking whether the package can be unloaded cleanly ... [15s/18s] OK checking whether the namespace can be loaded with stated dependencies ... [13s/15s] OK checking whether the namespace can be unloaded cleanly ... [14s/16s] OK checking loading without being on the library search path ... [14s/17s] OK checking whether startup messages can be suppressed ... [14s/16s] OK checking use of S3 registration ... OK checking dependencies in R code ... NOTE Namespace in Imports field not imported from: ‘rstantools’ All declared Imports should be used. checking S3 generic/method consistency ... OK checking replacement functions ... OK checking foreign function calls ... OK checking R code for possible problems ... [124s/134s] OK checking Rd files ... OK checking Rd metadata ... OK checking Rd line widths ... OK checking Rd cross-references ... OK checking for missing documentation entries ... OK checking for code/documentation mismatches ... OK checking Rd \usage sections ... OK checking Rd contents ... OK checking for unstated dependencies in examples ... OK checking contents of ‘data’ directory ... OK checking data for non-ASCII characters ... [14s/14s] OK checking LazyData ... OK checking data for ASCII and uncompressed saves ... OK checking line endings in shell scripts ... OK checking line endings in C/C++/Fortran sources/headers ... OK checking line endings in Makefiles ... OK checking for GNU extensions in Makefiles ... NOTE GNU make is a SystemRequirements. checking for portable use of $(BLAS_LIBS) and $(LAPACKLIBS) ... OK checking use of PKGFLAGS in Makefiles ... OK checking use of SHLIBOPENMPFLAGS in Makefiles ... OK checking pragmas in C/C++ headers and code ... OK checking compilation flags used ... OK checking compiled code ... OK checking sizes of PDF files under ‘inst/doc’ ... OK checking installed files from ‘inst/doc’ ... OK checking files in ‘vignettes’ ... OK checking examples ... [42s/43s] OK checking for unstated dependencies in ‘tests’ ... OK checking tests ... [154s/147s] OK Running ‘testthat.R’ [154s/147s] checking for unstated dependencies in vignettes ... OK checking package vignettes in ‘inst/doc’ ... OK checking re-building of vignette outputs ... [67s/70s] OK checking PDF version of manual ... [10s/11s] OK checking HTML version of manual ... OK checking for non-standard things in the check directory ... OK checking for detritus in the temp directory ... NOTE Found the following files/directories: ‘par-7269706c6579’ DONE

Status: 1 WARNING, 4 NOTEs

andrjohns commented 10 months ago

The warning is about assigning a value to itself, and is caused by the following lines in your package:

cdriveraus commented 10 months ago

Oh. Perils of functions generating functions :) thanks a lot, guess I should have been able to figure that out myself... I'll leave it up to someone in charge to close as if this is a problem, 'maybe' stan should also warn about it?

andrjohns commented 10 months ago

Transferring this to the stanc3 repo so they're aware

WardBrian commented 10 months ago

The proposal is to warn whenever a variable is assigned to itself?

We can do that. We could also probably go one step further and just remove such a statement, since it is semantically meaningless in Stan. Maybe only when optimizations are enabled.

andrjohns commented 10 months ago

Sounds good. It looks like this is a warning introduced with Clang 16, so it's likely to crop up more as people upgrade