Skip to content

Commit

Permalink
Remove the tombstone-related code from pad.h + pad.c
Browse files Browse the repository at this point in the history
This was a short-lived experimental feature intended to implement
removal of lexical symbols, in order to provide syntax like
`no builtin ...` or to remove implied imported builtins on a change of
prevailing `use VERSION`. The model of removing a lexical has proven to
be too subtle and complex to implement as well as raising various
awkward questions about the semantics, so we decided to remove it again
in Perl 5.39.8. There is now no longer any code that uses
PADNAMEf_TOMBSTONE.

As PADNAMEf_TOMBSTONE was only added in earlier in the 5.39.x developent
series, there is no need to retain the constants in .h files for
compatibility or to reserve the numbers for them. They have never
appeared in a stable release of Perl.
  • Loading branch information
leonerd committed Mar 6, 2024
1 parent c3de8c0 commit 4870fd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 39 deletions.
45 changes: 14 additions & 31 deletions pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ Perl_cv_undef_flags(pTHX_ CV *cv, U32 flags)
SV ** const curpad = AvARRAY(comppad);
for (ix = PadnamelistMAX(comppad_name); ix > 0; ix--) {
PADNAME * const name = namepad[ix];
if (name && PadnamePV(name) && *PadnamePV(name) == '&' &&
!PadnameIsTOMBSTONE(name)) {
if (name && PadnamePV(name) && *PadnamePV(name) == '&') {
CV * const innercv = MUTABLE_CV(curpad[ix]);
if (PadnameIsOUR(name) && CvCLONED(&cvbody)) {
assert(!innercv);
Expand Down Expand Up @@ -540,7 +539,7 @@ pad (via L<perlapi/pad_alloc>) and
then stores a name for that entry. C<name> is adopted and
becomes the name entry; it must already contain the name
string. C<typestash> and C<ourstash> and the C<padadd_STATE>
and C<padadd_TOMBSTONE> flags get added to C<name>.
flag gets added to C<name>.
None of the other processing of L<perlapi/pad_add_name_pvn>
is done. Returns the offset of the allocated pad slot.
Expand Down Expand Up @@ -574,9 +573,6 @@ S_pad_alloc_name(pTHX_ PADNAME *name, U32 flags, HV *typestash,
assert(HvSTASH_IS_CLASS(PL_curstash));
class_add_field(PL_curstash, name);
}
if (flags & padadd_TOMBSTONE) {
PadnameFLAGS(name) |= PADNAMEf_TOMBSTONE;
}

padnamelist_store(PL_comppad_name, offset, name);
if (PadnameLEN(name) > 1)
Expand All @@ -603,7 +599,6 @@ flags can be OR'ed together:
padadd_STATE variable will retain value persistently
padadd_NO_DUP_CHECK skip check for lexical shadowing
padadd_FIELD specifies that the lexical is a field for a class
padadd_TOMBSTONE sets the PadnameIsTOMBSTONE flag on the new name
=cut
*/
Expand All @@ -617,13 +612,13 @@ Perl_pad_add_name_pvn(pTHX_ const char *namepv, STRLEN namelen,

PERL_ARGS_ASSERT_PAD_ADD_NAME_PVN;

if (flags & ~(padadd_OUR|padadd_STATE|padadd_NO_DUP_CHECK|padadd_FIELD|padadd_TOMBSTONE))
if (flags & ~(padadd_OUR|padadd_STATE|padadd_NO_DUP_CHECK|padadd_FIELD))
Perl_croak(aTHX_ "panic: pad_add_name_pvn illegal flag bits 0x%" UVxf,
(UV)flags);

name = newPADNAMEpvn(namepv, namelen);

if ((flags & (padadd_NO_DUP_CHECK|padadd_TOMBSTONE)) == 0) {
if ((flags & (padadd_NO_DUP_CHECK)) == 0) {
ENTER;
SAVEFREEPADNAME(name); /* in case of fatal warnings */
/* check for duplicate declaration */
Expand All @@ -641,23 +636,16 @@ Perl_pad_add_name_pvn(pTHX_ const char *namepv, STRLEN namelen,
if (!PL_min_intro_pending)
PL_min_intro_pending = offset;
PL_max_intro_pending = offset;
if(!(flags & padadd_TOMBSTONE)) {
/* if it's not a simple scalar, replace with an AV or HV */
assert(SvTYPE(PL_curpad[offset]) == SVt_NULL);
assert(SvREFCNT(PL_curpad[offset]) == 1);
if (namelen != 0 && *namepv == '@')
sv_upgrade(PL_curpad[offset], SVt_PVAV);
else if (namelen != 0 && *namepv == '%')
sv_upgrade(PL_curpad[offset], SVt_PVHV);
else if (namelen != 0 && *namepv == '&')
sv_upgrade(PL_curpad[offset], SVt_PVCV);
assert(SvPADMY(PL_curpad[offset]));
}
else {
/* tombstone has no SV */
SvREFCNT_dec(PL_curpad[offset]);
PL_curpad[offset] = NULL;
}
/* if it's not a simple scalar, replace with an AV or HV */
assert(SvTYPE(PL_curpad[offset]) == SVt_NULL);
assert(SvREFCNT(PL_curpad[offset]) == 1);
if (namelen != 0 && *namepv == '@')
sv_upgrade(PL_curpad[offset], SVt_PVAV);
else if (namelen != 0 && *namepv == '%')
sv_upgrade(PL_curpad[offset], SVt_PVHV);
else if (namelen != 0 && *namepv == '&')
sv_upgrade(PL_curpad[offset], SVt_PVCV);
assert(SvPADMY(PL_curpad[offset]));
DEBUG_Xv(PerlIO_printf(Perl_debug_log,
"Pad addname: %ld \"%s\" new lex=0x%" UVxf "\n",
(long)offset, PadnamePV(name),
Expand Down Expand Up @@ -904,7 +892,6 @@ S_pad_check_dup(pTHX_ PADNAME *name, U32 flags, const HV *ourstash)
if (pn
&& PadnameLEN(pn) == PadnameLEN(name)
&& !PadnameOUTER(pn)
&& !PadnameIsTOMBSTONE(pn)
&& ( COP_SEQ_RANGE_LOW(pn) == PERL_PADSEQ_INTRO
|| COP_SEQ_RANGE_HIGH(pn) == PERL_PADSEQ_INTRO)
&& memEQ(PadnamePV(pn), PadnamePV(name), PadnameLEN(name)))
Expand Down Expand Up @@ -1171,10 +1158,6 @@ S_pad_findlex(pTHX_ const char *namepv, STRLEN namelen, U32 flags, const CV* cv,
fake_offset = 0;
*out_name = name_p[offset]; /* return the name */

if (PadnameIsTOMBSTONE(*out_name))
/* is this a lexical import that has been deleted? */
return NOT_IN_PAD;

if (PadnameIsFIELD(*out_name) && !fieldok)
croak("Field %" SVf " is not accessible outside a method",
SVfARG(PadnameSV(*out_name)));
Expand Down
8 changes: 0 additions & 8 deletions pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ typedef enum {
* sub, but only one level up */
#define padadd_FIELD 0x10 /* set PADNAMEt_FIELD */
#define padfind_FIELD_OK 0x20 /* pad_findlex is permitted to see fields */
#define padadd_TOMBSTONE 0x40 /* set PadnameIsTOMBSTONE on the new entry */

/* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
* whether PL_comppad and PL_curpad are consistent and whether they have
Expand Down Expand Up @@ -263,11 +262,6 @@ Whether this is a "state" variable.
Whether this is a "field" variable. PADNAMEs where this is true will
have additional information available via C<PadnameFIELDINFO>.
=for apidoc m|bool|PadnameIsTOMBSTONE|PADNAME * pn
Whether this pad entry is a tombstone. Such an entry indicates that a
previously-valid pad entry has now been deleted within this scope, and
should be ignored.
=for apidoc m|HV *|PadnameTYPE|PADNAME * pn
The stash associated with a typed lexical. This returns the C<%Foo::> hash
for C<my Foo $bar>.
Expand Down Expand Up @@ -360,7 +354,6 @@ Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
#define PadnameIsSTATE(pn) (PadnameFLAGS(pn) & PADNAMEf_STATE)
#define PadnameLVALUE(pn) (PadnameFLAGS(pn) & PADNAMEf_LVALUE)
#define PadnameIsFIELD(pn) (PadnameFLAGS(pn) & PADNAMEf_FIELD)
#define PadnameIsTOMBSTONE(pn) (PadnameFLAGS(pn) & PADNAMEf_TOMBSTONE)

#define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_LVALUE)
#define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_STATE)
Expand All @@ -371,7 +364,6 @@ Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()>
#define PADNAMEf_TYPED 0x08 /* for B; unused by core */
#define PADNAMEf_OUR 0x10 /* for B; unused by core */
#define PADNAMEf_FIELD 0x20 /* field var */
#define PADNAMEf_TOMBSTONE 0x40 /* padname has been deleted */

/* backward compatibility */
#ifndef PERL_CORE
Expand Down

0 comments on commit 4870fd2

Please sign in to comment.