Skip to content

Magic v2: Viral value magic - #24508

Open
leonerd wants to merge 4 commits into
Perl:bleadfrom
leonerd:magic-v2-phase2
Open

Magic v2: Viral value magic#24508
leonerd wants to merge 4 commits into
Perl:bleadfrom
leonerd:magic-v2-phase2

Conversation

@leonerd

@leonerd leonerd commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This PR builds on top of the general "Magic v2" to add viral value magic; as outlined in PPC0036.

@leonerd leonerd added the defer-next-dev This PR should not be merged yet, but await the next development cycle label Jun 25, 2026
@leonerd leonerd changed the title Magic v2 phase2 Magic v2: Viral value magic Jun 25, 2026
@leonerd
leonerd force-pushed the magic-v2-phase2 branch 3 times, most recently from f6f60ec to e7256b0 Compare June 26, 2026 14:13
Comment thread perl.h Outdated
Comment thread op.c
@tonycoz

tonycoz commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

look at only the final 3 commits

There's a few commits before those that aren't in #24163 (I wondered where the op.c change came from.)

Comment thread util.c Outdated
}

SV *ex = vmess(pat, args);
PERL_ARGS_ASSERT_VWARN;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert should be above the vmess() call, it's pointless below it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oops. I don't recall moving that but maybe that was a recent(ish) blead fix that has been broken by some rebase operation over the past few months. I shall fix that.

@leonerd

leonerd commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

look at only the final 3 commits

There's a few commits before those that aren't in #24163 (I wondered where the op.c change came from.)

Ahyes, those are some post-phase1 fixups to other files to use the new magic system in static locations, just as a demonstration that it works. I intend to submit those as little fixes after the first branch is merged, before this one. github doesn't easily allow me to make even a draft PR between two moving points in a branch, so that was the best I could do. Those will be out of this PR by the time it becomes ready.

@leonerd

leonerd commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Since it seems nobody's going to review this while it's drafted I shall undraft it. I don't imagine there's a danger anyone will accidentally merge it ahead of time anyway. ;)

@leonerd leonerd added the do not merge Don't merge this PR, at least for now label Jul 8, 2026
@leonerd
leonerd marked this pull request as ready for review July 8, 2026 17:45
@leonerd
leonerd force-pushed the magic-v2-phase2 branch 2 times, most recently from d2cdd7c to 39731be Compare July 13, 2026 13:00
@leonerd

leonerd commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Are there any reviewers for this?

Comment thread doio.c
Comment on lines 1278 to +1282
/* ideally we could just remove the magic from the SV but we don't get the SV here */
SvREFCNT_dec(mg->mg_obj);
mg->mg_obj = NULL;

return 0;
MgAUXSV_set(mg, NULL);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment out of date

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahyes; though that's part of #24547. I'll see what I can do there.

Comment thread ext/PerlIO-encoding/encoding.xs Outdated
Comment on lines +59 to +65
GCC_DIAG_IGNORE_DECL(-Wmissing-field-initializers);
static const struct MagicFunctions magicfuncs_perlencoding = {
.ver = 2,
.shape = MGv2s_BASE,
.debug_name = "PerlIO::encoding/tag",
};
GCC_DIAG_RESTORE_DECL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the discussion I'm not sure this still needs to be here,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahyes; also part of #24547

Comment thread perl.h
Comment thread perl.h
/* Macros for valuemagic support */
/* TODO: allow these to be conditional like the taint ones are */
#define VALUEMAGIC_CLEAR \
#if defined(NO_VALUEMAGIC_SUPPORT)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should -DNO_TAINT_SUPPORT implicitly -DNO_VALUEMAGIC_SUPPORT? This would simplify checks like in magic2_value.t

It would also later allow value magic without taint

@tonycoz

tonycoz commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Except for the minor issues I mentioned it looks good to me.

Comment thread configpm
Comment on lines +627 to +631
#
# unless ($defines =~ m/\b(NO_VALUEMAGIC_SUPPORT)\b/) {
# my $valuemagic_support = 'define';
# s/^(valuemagic_support=['"])(["'])/$1$valuemagic_support$2/m;
# }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there was some discussion of this recently: on the fragility of using compiler -D switches to control this type of feature instead of Configure defines.

But I couldn't find it.

I don't know if you saw it, or if you agree or not... but it seems relevant to this (wishing I could find it)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leont enlightened me, it was #23306

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahyes, I vaguely recalled it. That's why for example, the newly-added variable in intrpvar.h isn't #ifdef-guarded. That way the structure always has the same shape. The only thing that the macro guards are the actual bits of code that implement the behaviour.

If the value magic feature is compiled out, stub implementations of the propagate and unpropagate functions are still built anyway, which just do nothing. So I think it should be fairly safe if, for example, a CPAN module gets built with a different set of flags than the core binary. Structure layouts all match, but the relevant behaviour just won't happen unless all the parts line up.

Comment on lines +151 to +152
/* we can't make this one `static` because -Wc++-compat gets upset if we do */
extern const struct ScalarValueMagicFunctions magicfuncs_value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to predeclare the function instead. Not that it's a big deal.

@leonerd
leonerd force-pushed the magic-v2-phase2 branch 6 times, most recently from b2bea2c to 9ba1201 Compare July 27, 2026 10:30
@leonerd
leonerd force-pushed the magic-v2-phase2 branch 2 times, most recently from 8585c94 to 1475f03 Compare July 28, 2026 11:02
@Leont

Leont commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Much like taint support, this probably should be controlled by a configuration flag.

@Leont

Leont commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Oh I now see there is a NO_VALUEMAGIC_SUPPORT define (which is half of the work). Much like taint that design is a mistake and really really needs a configuration flag. And probably it should be an opt-in feature instead of opt-out.

@leonerd leonerd removed the do not merge Don't merge this PR, at least for now label Jul 28, 2026
@tonycoz

tonycoz commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

I saw some IRC discussion related to adding a ./Configure flag - is that happening?

@Leont

Leont commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

I saw some IRC discussion related to adding a ./Configure flag - is that happening?

The real discussion there was about whether is should be enabled by default or not. In my opinion it should not (or at least for now).

@leonerd

leonerd commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Yes, I'm looking into both of these today. It seems to be a short excursion via learning how metaconfig works ;)

My plan is to end up with two PRs, to add two new configuration options; one for this and one for taint while I'm there. Likely the defaults will be taint on, valuemagic off; but either can be adjusted:

./Configure -[D|U]usevaluemagic -[D|U]usetaint ...

(It probably doesn't make sense to enable valuemagic while disabling taint as I suspect that in itself will break, so there might need to be some interlocking logic for that situation.)

leonerd added 4 commits August 3, 2026 16:33
Currently unused by the rest of the code.

This commit is extracted separately simply so it can be placed at the
very start of the branch. A full rebuild is needed either side of this
commit, so by being at the beginning this makes rebase, bisect, and
other operations easier as now you don't have to `make clean`.
Adds a new SVs_VMG flag + associated macros; use the SvVMAGICAL flag to
fast-path sv_has_valuemagic() if appropriate

Use the sv_has_valuemagic() function to know whether to call
mg_propagate() in sv_setsv_flags()
Much like -DNO_TAINT_SUPPORT, this is optional and not default, but will
disable value magic support in exchange for getting that little extra
performance boost by not having to worry about it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants