Skip to content

do something more careful than eval_const_expr #1417

Closed

Description

@kevina

Eval_const_expr is used in the front end in several places. This code quasi-duplicates stuff that trans should probably be doing (in Graydon's words).

Any evaluation of compile-time values should likely be moved to a pass somewhere in the middle end. I assume there is a way to get a compile-time value out of LLVM, but I'm not sure.

Activity

  1. brson commented on Jan 5, 2012

    @brson
    Contributor

    I don't know how to manage that. trans is rightly letting LLVM do the same work that eval_const_expr does, but eval_const_expr is used for analysis passes that don't have access to LLVM.

  2. graydon commented on Jan 31, 2012

    @graydon
    Contributor

    Which analysis passes? I'm mostly concerned that the choice of what to evaluate in either place seems ad-hoc, and it's not clear which subsets of the expression language ought to be viable as constants in which context. We should get a clear picture of those. If the result is we do some eval in duplicate (or in 2 phases) that's ok.

  3. brson commented on Jan 31, 2012

    @brson
    Contributor

    It's used by enum_variants to get the discriminant, which is used in many places. for example the discriminant is written to the metadata.

    It's used in type checking, also to check properties of enum discriminants.

    It also looks like it's used for reachability testing in alt expressions.

  4. added a commit that references this issue on Nov 10, 2023
  5. added a commit that references this issue on Feb 28, 2025
  6. added a commit that references this issue on Feb 28, 2025
  7. added 2 commits that reference this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions