Skip to content

Tracking issue for RFC 2344, "Allow loop in constant evaluation" #52000

Closed
@Centril

Description

@Centril
Contributor

This is a tracking issue for the RFC "Allow loop in constant evaluation" (rust-lang/rfcs#2344).

Steps:

  • Implement the RFC (cc @rust-lang/compiler -- can anyone write up mentoring instructions?)
    Adjust documentation (see instructions on forge)
    Stabilization PR (see instructions on forge)

Unresolved questions:

  • Should we add a true recursion check that hashes the interpreter state and detects if it has reached the same state again?
    • This will slow down const evaluation enormously and for complex iterations is essentially useless because it'll take forever (e.g. counting from 0 to u64::max_value())

Activity

added
B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.
T-langRelevant to the language team
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Jul 2, 2018
added
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
on Jul 2, 2018
brunocodutra

brunocodutra commented on Jul 21, 2018

@brunocodutra
Contributor

This feature seems simple enough for me to tackle as my first attempt to contribute to rust, at least getting it to work appears to be as simple as removing the check against loops in constant functions.

I believe the real work actually goes into implementing the lint for potential infinite loops. I'm going to tackle this next and I'd really appreciate some mentorship along the way.

oli-obk

oli-obk commented on Jul 21, 2018

@oli-obk
Contributor

Implementing this feature is blocked on a bunch of definitely not beginner level things. But there's ongoing preliminary work happening, so this isn't standing still even if nothing happens on the issue.

If we'd just remove the check against loops, we'd end up with amusingly broken code, because most of the const checking code only knows it needs to prevent writing multiple times to a variable... which loops can do without naming the variable twice.

Anyway, guarding against infinite loops has been partially implemented, and if you're interested in doing some work there, we're tracking one of the issues in #52475

brunocodutra

brunocodutra commented on Jul 21, 2018

@brunocodutra
Contributor

Thanks for pointing me to the right direction, I'll definitely have a look for something I can help with.

jkarns275

jkarns275 commented on Aug 23, 2018

@jkarns275

Would an iteration limit be an acceptable solution to the the infinite loop problem? If the iteration limit is actually reached the code can just be compiled instead!

Though this may be deceptive since the const fns wouldn't really be const if the limit is reached.

estebank

estebank commented on Aug 23, 2018

@estebank
Contributor

Though this may be deceptive since the const fns wouldn't really be const if the limit is reached.

It could be a compilation error, which would let the const fn continue to be const (code that fails to compile has no bearing in execution time ^_^).

jkarns275

jkarns275 commented on Aug 23, 2018

@jkarns275

True! Perhaps it would be worth adding a compilation option of some sort that would make it just a warning for edge cases.
Edit: reading this half a year later and i have no idea what i meant

83 remaining items

Loading
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-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nikomatsakis@joshtriplett@RalfJung@oli-obk@Centril

        Issue actions

          Tracking issue for RFC 2344, "Allow `loop` in constant evaluation" · Issue #52000 · rust-lang/rust