Skip to content

Checker misses a global mutated inside a callee while a view of it is live (§9.1c globals are places, §21.1 Rule 1) #1819

Closed

Description

@ehartford

Repro

var G: str = "ab" ++ "cd"
fn change(): G = "wx" ++ "yz"
fn show(r: &str):
    change()
    print(r)
fn main:
    show(G)

and, with a container:

var G: Vec[str] = Vec.new()
fn grow():
    for i in 0..64: G.push(f"item{i}")
fn show(r: &str):
    grow()
    print(r)
fn main:
    G.push("first" ++ "!")
    show(G[0])

with check accepts both (fix-lang stage1; the installed compiler).

Spec

§9.1c: "Globals are places; §21.1's access rules apply." In each program a view of G's storage is live across a call whose callee mutates G — §21.1 Rule 1's invalidation. The same program over a local is refused ("cannot mutate s while r is a live view into it"); the checker does not see a global mutated inside a callee.

What each representation does with it (both read freed memory in one of the two)

Expected

A call whose callee (transitively) writes a global is a write of that global at the call site for §21.1: refused while a view whose origin is that global's storage is live — with the §9.1c global-mutation facts the race proof already collects per global.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions