Mailing List Archive

use v5.x and builtin export problems
The existing plan for "use v5.40" and the builtin functions has some problems.

builtin is intended to have version bundles similar to features, which
would include all of the stable builtin functions for that version.
And we wanted "use v5.40;" to import the builtin bundle for that
version. Currently, multiple "use vX.XX;" statements can be used, and
using an older version after a newer one will reset all features to
match that older version. This presents a problem for the builtin
functions.

Going to an older version would require removing the builtin
functions. In fact, going to a newer version could require removing
builtin functions as well (we've removed features from version bundles
before). But builtin functions are exported as lexical subs. We don't
currently have a well defined concept of removing a lexical. Paul has
implemented a version of this, but its behavior is rather confusing
and the semantics of it aren't obviously correct.

Removing a lexical is a weird feature and I'm not convinced we want it
to be part of the language. If it's something we really want, I think
it needs much more thought and needs to work generally (at least in
concept), not just be an implementation detail of builtin. I feel that
the current implementation is definitely wrong, but fixes to it would
conflict with things others have argued for.

If we can't remove lexicals, builtin::unimport isn't possible, and
importing builtin via use vX.XX can't work with the current semantics
of use vX.XX because they require the ability for changes to be
undone. Even if removing lexicals was possible, those semantics don't
cleanly allow the "reset to defaults" behavior of "use vX.XX".

I see a few possible solutions
1. Make removing lexicals make sense.
2. Don't use lexical exports for builtin. They would need a
different mechanism, likely a new type of visibility. This would end
up similar to how 'say' currently works.
3. Stop allowing "use vX.XX" to be used multiple times in the same
scope. If there is only ever a single transition from 5.8 semantics to
5.new semantics, we never have to remove builtins.

I've already explained that I don't think removing lexicals makes much
sense, and doesn't apply cleanly to "use vX.XX".

For solution #2, we would need to extend the experimental phase of
builtin exports. builtin itself can still become stable. This would
result in builtin being another special case internally, which is not
really in line with its original design goals. But there have been
some general concerns about lexical subs being confusing regarding
shadowing and redefinition. Problems that become worse with exporting
as it makes the lexical nature less obvious.

My preference is solution #3. I don't think there is actually a
valuable use case for using multiple version declarations in the same
file. And if there really is a need, they can be kept in entirely
separate scopes. Doing this would mean deprecating any use of "use
X.XX" in an overlapping scope. And if either version used was >= 5.40,
throw an error. I feel this would also allow simplifying the
documentation for use, which is currently rather long and confusing. I
would like to deprecate and eventually disallow this even if you are
going from an older to a newer version, as it would allow functions to
be removed from a builtin version bundle.

The next dev release is the cut off for contentious changes, on Feb
20. I think this needs to be resolved in some way before then. If not,
I think builtin exports would need to be returned to experimental
status.
Re: use v5.x and builtin export problems [ In reply to ]
On Wed, Feb 7, 2024 at 5:22?AM Graham Knop <haarg@haarg.org> wrote:

> My preference is solution #3. I don't think there is actually a
> valuable use case for using multiple version declarations in the same
> file. And if there really is a need, they can be kept in entirely
> separate scopes. Doing this would mean deprecating any use of "use
> X.XX" in an overlapping scope. And if either version used was >= 5.40,
> throw an error. I feel this would also allow simplifying the
> documentation for use, which is currently rather long and confusing. I
> would like to deprecate and eventually disallow this even if you are
> going from an older to a newer version, as it would allow functions to
> be removed from a builtin version bundle.
>

I agree -- I don't see a strongly compelling argument for needing to
support this usecase.
As long as attempting to downgrade or unimport the pragma gives a sensible
and understandable error, this should be fine to simply not allow.
Re: use v5.x and builtin export problems [ In reply to ]
On Wed, Feb 7, 2024 at 10:19?PM Karen Etheridge <perl@froods.org> wrote:

> On Wed, Feb 7, 2024 at 5:22?AM Graham Knop <haarg@haarg.org> wrote:
>
>> My preference is solution #3. I don't think there is actually a
>> valuable use case for using multiple version declarations in the same
>> file. And if there really is a need, they can be kept in entirely
>> separate scopes. Doing this would mean deprecating any use of "use
>> X.XX" in an overlapping scope. And if either version used was >= 5.40,
>> throw an error. I feel this would also allow simplifying the
>> documentation for use, which is currently rather long and confusing. I
>> would like to deprecate and eventually disallow this even if you are
>> going from an older to a newer version, as it would allow functions to
>> be removed from a builtin version bundle.
>>
>
> I agree -- I don't see a strongly compelling argument for needing to
> support this usecase.
> As long as attempting to downgrade or unimport the pragma gives a sensible
> and understandable error, this should be fine to simply not allow.
>
>
+1 - there is no reason to use the use VERSION pragma multiple times in the
same scope (I'm hard pressed to even think of a reason to use it multiple
times in the same file) that can't be trivially replaced with changing the
specific features that you want activated/deactivated.

-Dan
Re: use v5.x and builtin export problems [ In reply to ]
On Wed, 7 Feb 2024 at 14:21, Graham Knop <haarg@haarg.org> wrote:

> My preference is solution #3. I don't think there is actually a
> valuable use case for using multiple version declarations in the same
> file. And if there really is a need, they can be kept in entirely
> separate scopes. Doing this would mean deprecating any use of "use
> X.XX" in an overlapping scope. And if either version used was >= 5.40,
> throw an error. I feel this would also allow simplifying the
> documentation for use, which is currently rather long and confusing. I
> would like to deprecate and eventually disallow this even if you are
> going from an older to a newer version, as it would allow functions to
> be removed from a builtin version bundle.
>

+1 for #3.

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"
Re: use v5.x and builtin export problems [ In reply to ]
On Wed, 7 Feb 2024 14:21:41 +0100
Graham Knop <haarg@haarg.org> wrote:

> My preference is solution #3. I don't think there is actually a
> valuable use case for using multiple version declarations in the same
> file. And if there really is a need, they can be kept in entirely
> separate scopes. Doing this would mean deprecating any use of "use
> X.XX" in an overlapping scope. And if either version used was >= 5.40,
> throw an error. I feel this would also allow simplifying the
> documentation for use, which is currently rather long and confusing. I
> would like to deprecate and eventually disallow this even if you are
> going from an older to a newer version, as it would allow functions to
> be removed from a builtin version bundle.

All: Wow, I am pleasantly surprised at all the positive response to
this idea.

We chatted quite a while on last week's PSC meeting about this issue,
and while I agreed this seemed to be the only sensible solution, I was
slightly disappointed that this seems to be the reality, and somewhat
fearful of what the larger reaction to it would be. But it feels like
we are in overall agreement.

Anticipating this situation, I've been maintaining a branch with some
commits that implement increasing sections of this newly-restricted
behaviour:

https://github.com/leonerd/perl5/tree/use-VERSION-restrictions

It's still in need of more implementation, more tests, and more
description in the commit messages; but it looks likely the direction
we'll be going in so I will continue to work on it in the hope that it
can be merge-ready sometime next week.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: use v5.x and builtin export problems [ In reply to ]
On Thu, 8 Feb 2024 13:59:45 +0000
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:

> Anticipating this situation, I've been maintaining a branch with some
> commits that implement increasing sections of this newly-restricted
> behaviour:
>
> https://github.com/leonerd/perl5/tree/use-VERSION-restrictions
>
> It's still in need of more implementation, more tests, and more
> description in the commit messages; but it looks likely the direction
> we'll be going in so I will continue to work on it in the hope that it
> can be merge-ready sometime next week.

I now have the first bit of this ready for review/merge.

In Perl 5.36 we added a deprecation warning for downgrading a
`use VERSION` back past 5.11 again. Here's a PR to make it fatal, as we
said we would in 5.40:

https://github.com/Perl/perl5/pull/21954

Hopefully shouldn't need much review on the decision because we already
said two years ago that we'd do this; this is just the formality of
actually doing it.

If we can get this in soon that'll pave the way for adding other
warnings/errors to do with swapping `use VERSION`.

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
Re: use v5.x and builtin export problems [ In reply to ]
On Fri, 9 Feb 2024 12:44:10 +0000
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:

> In Perl 5.36 we added a deprecation warning for downgrading a
> `use VERSION` back past 5.11 again. Here's a PR to make it fatal, as
> we said we would in 5.40:
>
> https://github.com/Perl/perl5/pull/21954
>
> Hopefully shouldn't need much review on the decision because we
> already said two years ago that we'd do this; this is just the
> formality of actually doing it.
>
> If we can get this in soon that'll pave the way for adding other
> warnings/errors to do with swapping `use VERSION`.

And now as promised, the next stage:

https://github.com/Perl/perl5/pull/21980

--
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/