Skip to content

[BUG] stanc.js persisting model name & namespace between calls #1491

@andrjohns

Description

@andrjohns

Current Behavior:

After calling stanc.js once with a model name, all future calls will reuse the same initial model name:

stanc_js <- tempfile(fileext = ".js")
download.file("https://github.com/stan-dev/stanc3/releases/download/nightly/stanc.js",
              destfile = stanc_js)

qjs_ctx <- QuickJSR::JSContext$new()
qjs_ctx$source(stanc_js)

mod1 <- "data { real y_mean; } parameters { real y; } model { y ~ normal(y_mean, 1); }"
> qjs_res_1 <- qjs_ctx$call("stanc", "model_one", mod1)
> cat(qjs_res_1$result, sep = "\n")
# // Code generated by stanc v2.36.0-28-gd13e71e
# #include <stan/model/model_header.hpp>
# namespace model_one_model_namespace {
# ...
> qjs_res_2 <- qjs_ctx$call("stanc", "model_two", mod1)
> cat(qjs_res_2$result, sep = "\n")
# // Code generated by stanc v2.36.0-28-gd13e71e
# #include <stan/model/model_header.hpp>
# namespace model_one_model_namespace {
# ...

(happens with both V8 & QuickJS)

This is an issue for R packages since it leads to duplicate symbols, so I'm seeing failures like this for rstanarm:

C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: stanExports_binomial.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_binomial.h:29: multiple definition of `model_bernoulli_model_namespace::profiles__[abi:cxx11]'; stanExports_bernoulli.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_bernoulli.h:29: first defined here
C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: stanExports_continuous.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_continuous.h:29: multiple definition of `model_bernoulli_model_namespace::profiles__[abi:cxx11]'; stanExports_bernoulli.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_bernoulli.h:29: first defined here
C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: stanExports_count.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_count.h:29: multiple definition of `model_bernoulli_model_namespace::profiles__[abi:cxx11]'; stanExports_bernoulli.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_bernoulli.h:29: first defined here
C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: stanExports_jm.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_jm.h:29: multiple definition of `model_bernoulli_model_namespace::profiles__[abi:cxx11]'; stanExports_bernoulli.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_bernoulli.h:29: first defined here
C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: stanExports_lm.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_lm.h:29: multiple definition of `model_bernoulli_model_namespace::profiles__[abi:cxx11]'; stanExports_bernoulli.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_bernoulli.h:29: first defined here
C:\rtools44\x86_64-w64-mingw32.static.posix\bin/ld.exe: stanExports_mvmer.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_mvmer.h:29: multiple definition of `model_bernoulli_model_namespace::profiles__[abi:cxx11]'; stanExports_bernoulli.o:C:\Users\Andrew\Git\rstanarm\src/stanExports_bernoulli.h:29: first defined here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions