-
-
Notifications
You must be signed in to change notification settings - Fork 48
Description
This came up at StanCon as a common pain point when trying to organize groups of functions.
Suppose you have functions foo, bar, and baz living in files of the same names. foo is used by bar and by baz.
If you #include bar.stan and #include foo.stan in the same file, then you will end up with two (transitive) includes of foo.stan, and this will lead to a typechecker error for re-definition of the function foo.
Some solutions:
-
Add something like
#pragma oncein C++. This is the most explicit version, but it is probably my least favorite since it introduces a whole new verbiage -
Automatically de-duplicate files that end with
.stanfunctions. Note that we don't want to deduplcate arbitrary#includestatements since they may not actually live in the same scope and therefore it would be okay. Therefore, restricting to .stanfunctions file extensions ensures this is only doing something where it matters. Downside: introduces a semantic difference in the language based on the file extensions used. -
Allow duplicate function definitions if both definitions are from the same ultimate file. This would require some extra location logic in the typechecker.