Skip to content

What is considered a "read"? #2151

Description

@ehuss

#2067 added a chapter on divergence with the rule expr.block.diverging that says:

A block is considered to be diverging if all reachable control flow paths contain a diverging expression, unless that expression is a place expression that is not read from.

But I don't think the reference has a clear definition of what it means to "read" from a place expression. What are the rules for what is considered a "read"? Is this unique to divergence checking?

Closure capture has has a bunch of rules of what it considers a "read" (or more often, what is not considered a read). I believe there are slight differences for various reasons. For example, a reference does not seem to be read for the purpose of divergence, but for the purpose of closure capture it does seem to be considered a read and is captured. There are various things around fake reads that I have forgotten how they work. I don't know if the rules are fundamentally different, or if there is some commonality.

I'll take a wild guess as to what is not considered a read based on expr_guaranteed_to_constitute_read_for_never:

  • A borrow expression.
  • The left-hand side of an assignment.
  • The base of a field projection that doesn't itself constitute a read.
  • The scrutinee of a match expression where at least one arm's pattern does not force a read.
  • The initializer of a let statement where the pattern does not force a read.
  • The scrutinee of a let condition where the pattern does not force a read.

(Of course non-place is always "read".)

I don't know if there are other considerations or how things like discriminants get involved.

It could also include details on which patterns force a read, which I think is is_guaranteed_to_constitute_read_for_never, which is more or less the following aren't reads:

  • _ wildcard
  • | or patterns where at least one alternative doesn't force a read

See also some recent things:

cc @jackh726

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions