Skip to content

Reading a deleted namespace scalar recreates its stash entry #1980

Closed

Description

@fglock

Summary

Deleting a package namespace from its parent stash does not keep that namespace deleted after a qualified scalar is read. This makes Text::Template 1.61's _scrubpkg cleanup assertion fail in t/basic.t on both PerlOnJava backends. System Perl passes the assertion, and the complete upstream suite passes there (22 files, 184 tests). The failure is included in archived CPAN run 20261104-151051-20617.

Root cause

RuntimeStash.deleteNamespace removes the namespace's current slots and marks the package freed. But stash enumeration in HashSpecialVariable reconstructs child-package entries from any qualified global slot it finds. A later read such as $Cleanup::GEN0::test creates an undefined scalar slot; enumeration then infers GEN0:: as a live child stash from that slot and exposes it again. The enumeration path does not honor the freed-stash marker, so this implicit scalar autovivification makes exists $Cleanup::{"GEN0::"} true again. The standalone script in the comment reproduces the behavior without a CPAN dependency.

Expected behavior

Reading an undefined scalar below a namespace deleted from its parent stash must not recreate that child namespace entry. Perl leaves the child absent in the same sequence.

Activity

  1. added
    bug
    area:runtime
    on Nov 5, 2026
  2. fglock commented on Nov 5, 2026

    @fglock
    OwnerAuthor

    Minimal regression script:

    no strict;
    $Cleanup::GEN0::test = 1;
    my $hash = $Cleanup::{"GEN0::"};
    for my $key (keys %$hash) { undef $hash->{$key} }
    %$hash = ();
    delete $Cleanup::{"GEN0::"};
    my $value = $Cleanup::GEN0::test; # undefined read must not recreate GEN0::
    die "deleted namespace reappeared"
        if $value || exists $Cleanup::{"GEN0::"};

    Expected: exits successfully. System Perl does; PerlOnJava currently dies with deleted namespace reappeared on both backends.

  3. fglock commented on Nov 11, 2026

    @fglock
    OwnerAuthor

    State: active
    Agent/session: Codex root-runtime-semantics-20261111
    Scope: #1980 deleted namespace scalar lookup recreating a stash child.
    Work: fix/runtime-semantics-2007-2017-2006-1980, based on 308a379fc; added a freed-namespace visibility filter to HashSpecialVariable direct stash lookup and enumeration, using the existing package marker.
    Checkpoint: 2026-11-11 UTC. The 2-assertion deleted_namespace_scalar_read.t passes on system Perl and both PerlOnJava backends. Full nice -n 19 timeout 3600 make passes. The edit is in lookup/enumeration helpers; inspection of PR #1938 head 6e6606203887746bb42719d75b4a757cfbf39c2e found its HashSpecialVariable delta is an unrelated comment in the deletion path. Link and runtime evidence: /tmp/deleted_namespace_scalar_read_perl_2.log, /tmp/runtime_semantics_final_jvm.log, /tmp/runtime_semantics_final_interpreter.log, /tmp/runtime_semantics_make_4.log.
    Blockers: none identified; review overlap on PR #1938 before merge.
    Next: include in the combined pull request after final tree review.

  4. fglock commented on Nov 12, 2026

    @fglock
    OwnerAuthor

    Resolved in merged PR #2028. Deleted child namespaces remain absent from stash lookup and enumeration after an undefined scalar read. The focused regression passes on system Perl and both PerlOnJava backends. Closing this report.

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

    area:runtimebug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions