Skip to content

Allow the same .stanfunctions file to be #included multiple times #1450

@WardBrian

Description

@WardBrian

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 once in 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 #include statements 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requestgood first issueGood for newcomersparsingissues related to the parser and syntax errorstypechecker

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions