Skip to content

Feature request: isconstant function or macro #50176

Open
@ojwoodford

Description

@ojwoodford

It would be useful to have an isconstant function or macro which returns true if the input is a constant, otherwise returns false. What do I mean by "constant"? I mean that if v is not a constant, then somefunc(Val(v)) will trigger a dynamic dispatch, otherwise it won't.

Having such a function/macro would enable at least two useful things:

  • Compile-time branch to faster code if a value is constant. See this example.
  • Make constant propagation regressions in core Julia easy to detect in unit tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions