Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Exposing a function that returns an array of tuples fails to compile

Aperta
#1,329 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@jgabry ci sta già lavorando.

Dal 15/10/2026.

  • #1330 di @jgabry — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp, r

Direzione di ricerca

Start by reproducing the failure with the snippet in the issue, which calls $expose_functions() on a function that returns an array of tuples. The header inst/include/rcpp_tuple_interop.hpp defines the tuple wrap overload, and compile_functions() in R/expose.R sets the include order for the generated code. Done means the tuple-array return compiles and exposes, and the existing tuple-argument behaviour still works.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

A Stan function that returns an array of tuples can't be exposed with $expose_functions(), and because every function in the block is compiled together, that means no functions from the model can be exposed.

library(cmdstanr)
mod <- cmdstan_model(write_stan_file("
functions {
  array[] tuple(real, real) f(array[] tuple(real, real) x) { return x; }
}
"))
mod$expose_functions()

The only message R shows is "Error 1 occurred building shared library". The compiler output is actually

Rcpp/internal/wrap.h:528:23: error: static assertion failed due to
requirement '!sizeof(std::tuple<double, double>)': cannot convert type
to SEXP

I did some investigating with Claude. Here's its diagnosis, although I haven't verified myself yet that this is correct:

The cause is in inst/include/rcpp_tuple_interop.hpp. It defines Rcpp::wrap for std::tuple, which works when the tuple is the return type itself (and for nested tuples, where the overload calls itself).
For std::vector<std::tuple<...>> Rcpp's own container wrap takes over and calls ::Rcpp::wrap per element from inside the Rcpp headers (wrap.h:200, range_wrap_dispatch___generic), where our overload isn't visible yet, so the generic fallback fires its static assertion. It's the same visibility problem that keeps Rcpp::List::create(args...) from compiling for nested tuples (see the commit message of #1310).

Taking a tuple array as an argument is fine, the Exporter side handles it. Only returning one fails.

Rcpp's documented way to extend wrap for a new type is to include RcppCommon.h, declare the overload, then include Rcpp.h, so the declaration is visible to the templates in the Rcpp headers. The
generated code includes Rcpp.h first through the other interop headers, so this would need the include order in compile_functions() (R/expose.R) rearranged. Untested.

Tested on macOS with CmdStan 2.40.0, Rcpp 1.1.2, on the v1.0 branch with the fix for #1001 (#1310) in. Pre-existing: the old tuple header failed the same way.

Lingua principale
R
Stelle
162
Fork
69
Merge medio
1g 9h
PR unite (30g)
48

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stan-dev/cmdstanr

Tutte le issue di stan-dev/cmdstanr

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.