Skip to content

Commit

Permalink
[Merge] Lexical subs are no longer experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
Father Chrysostomos committed May 20, 2016
2 parents 738155d + db62956 commit a50cb9d
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 134 deletions.
12 changes: 0 additions & 12 deletions feature.h
Expand Up @@ -76,12 +76,6 @@
FEATURE_IS_ENABLED("evalbytes")) \
)

#define FEATURE_POSTDEREF_IS_ENABLED \
( \
CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
FEATURE_IS_ENABLED("postderef") \
)

#define FEATURE_ARYBASE_IS_ENABLED \
( \
CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_511 \
Expand Down Expand Up @@ -109,12 +103,6 @@
FEATURE_IS_ENABLED("refaliasing") \
)

#define FEATURE_LEXSUBS_IS_ENABLED \
( \
CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
FEATURE_IS_ENABLED("lexsubs") \
)

#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
( \
CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_523 \
Expand Down
10 changes: 3 additions & 7 deletions lib/B/Deparse.t
Expand Up @@ -1941,12 +1941,11 @@ my($a, $b, $c) = @_;
####
# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
# lexical subroutine
use feature 'lexical_subs';
# CONTEXT use feature 'lexical_subs';
no warnings "experimental::lexical_subs";
my sub f {}
print f();
>>>>
use feature 'lexical_subs';
BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x15"}
my sub f {
BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x15"}
Expand All @@ -1957,20 +1956,17 @@ print f();
####
# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
# lexical "state" subroutine
use feature 'state', 'lexical_subs';
# CONTEXT use feature 'state', 'lexical_subs';
no warnings 'experimental::lexical_subs';
state sub f {}
print f();
>>>>
use feature 'lexical_subs';
BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x15"}
CORE::state sub f {
state sub f {
BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x15"}
use feature 'state';
}
BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x15"}
use feature 'state';
print f();
####
# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
Expand Down
33 changes: 21 additions & 12 deletions lib/feature.pm
Expand Up @@ -5,7 +5,7 @@

package feature;

our $VERSION = '1.43';
our $VERSION = '1.44';

our %feature = (
fc => 'feature_fc',
Expand All @@ -14,12 +14,10 @@ our %feature = (
switch => 'feature_switch',
bitwise => 'feature_bitwise',
evalbytes => 'feature_evalbytes',
postderef => 'feature_postderef',
array_base => 'feature_arybase',
signatures => 'feature_signatures',
current_sub => 'feature___SUB__',
refaliasing => 'feature_refaliasing',
lexical_subs => 'feature_lexsubs',
postderef_qq => 'feature_postderef_qq',
unicode_eval => 'feature_unieval',
unicode_strings => 'feature_unicode',
Expand All @@ -30,7 +28,7 @@ our %feature_bundle = (
"5.11" => [qw(array_base say state switch unicode_strings)],
"5.15" => [qw(current_sub evalbytes fc say state switch unicode_eval unicode_strings)],
"5.23" => [qw(current_sub evalbytes fc postderef_qq say state switch unicode_eval unicode_strings)],
"all" => [qw(array_base bitwise current_sub evalbytes fc lexical_subs postderef postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)],
"all" => [qw(array_base bitwise current_sub evalbytes fc postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)],
"default" => [qw(array_base)],
);

Expand All @@ -48,6 +46,10 @@ $feature_bundle{"5.24"} = $feature_bundle{"5.23"};
$feature_bundle{"5.25"} = $feature_bundle{"5.23"};
$feature_bundle{"5.26"} = $feature_bundle{"5.23"};
$feature_bundle{"5.9.5"} = $feature_bundle{"5.10"};
my %noops = (
postderef => 1,
lexical_subs => 1,
);

our $hint_shift = 26;
our $hint_mask = 0x1c000000;
Expand Down Expand Up @@ -248,17 +250,21 @@ This feature is available from Perl 5.16 onwards.
=head2 The 'lexical_subs' feature
B<WARNING>: This feature is still experimental and the implementation may
change in future versions of Perl. For this reason, Perl will
warn when you use the feature, unless you have explicitly disabled the
warning:
In Perl versions prior to 5.26, this feature enabled
declaration of subroutines via C<my sub foo>, C<state sub foo>
and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
no warnings "experimental::lexical_subs";
This feature is available from Perl 5.18 onwards. From Perl 5.18 to 5.24,
it was classed as experimental, and Perl emitted a warning for its
usage, except when explicitly disabled:
This enables declaration of subroutines via C<my sub foo>, C<state sub foo>
and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
no warnings "experimental::lexical_subs";
This feature is available from Perl 5.18 onwards.
As of Perl 5.26, use of this feature no longer triggers a warning, though
the C<experimental::lexical_subs> warning category still exists (for
compatibility with code that disables it). In addition, this syntax is
not only no longer experimental, but it is enabled for all Perl code,
regardless of what feature declarations are in scope.
=head2 The 'postderef' and 'postderef_qq' features
Expand Down Expand Up @@ -493,6 +499,9 @@ sub __common {
next;
}
if (!exists $feature{$name}) {
if (exists $noops{$name}) {
next;
}
unknown_feature($name);
}
if ($import) {
Expand Down
20 changes: 0 additions & 20 deletions pod/perldiag.pod
Expand Up @@ -2221,14 +2221,6 @@ has been removed. The C<postderef> feature may meet your needs better.
use feature "signatures";
sub foo ($left, $right) { ... }

=item Experimental "%s" subs not enabled

(F) To use lexical subs, you must first enable them:

no warnings 'experimental::lexical_subs';
use feature 'lexical_subs';
my sub foo { ... }

=item Explicit blessing to '' (assuming package main)

(W misc) You are blessing a reference to a zero length string. This has
Expand Down Expand Up @@ -5868,18 +5860,6 @@ will deny it.
(F) The function indicated isn't implemented on this architecture,
according to the probings of Configure.

=item The lexical_subs feature is experimental

(S experimental::lexical_subs) This warning is emitted if you
declare a sub with C<my> or C<state>. Simply suppress the warning
if you want to use the feature, but know that in doing so you
are taking the risk of using an experimental feature which may
change or be removed in a future Perl version:

no warnings "experimental::lexical_subs";
use feature "lexical_subs";
my sub foo { ... }

=item The regex_sets feature is experimental

(S experimental::regex_sets) This warning is emitted if you
Expand Down
18 changes: 6 additions & 12 deletions pod/perlexperiment.pod
Expand Up @@ -46,18 +46,6 @@ See L<perlapi/PL_keyword_plugin> for the mechanism.

Introduced in Perl 5.11.2

=item Lexical subroutines

Introduced in Perl 5.18

See also: L<perlsub/Lexical Subroutines>

Using this feature triggers warnings in the category
C<experimental::lexical_subs>.

The ticket for this feature is
L<[perl #120085]|https://rt.perl.org/rt3/Ticket/Display.html?id=120085>.

=item Regular Expression Set Operations

Introduced in Perl 5.18
Expand Down Expand Up @@ -249,6 +237,12 @@ Introduced in Perl 5.20.0

Accepted in Perl 5.24.0

=item Lexical subroutines

Introduced in Perl 5.18.0

Accepted in Perl 5.26.0

=back

=head2 Removed features
Expand Down
23 changes: 7 additions & 16 deletions pod/perlsub.pod
Expand Up @@ -1056,20 +1056,20 @@ using the CPAN module Sentinel or something similar.
=head2 Lexical Subroutines
X<my sub> X<state sub> X<our sub> X<subroutine, lexical>

B<WARNING>: Lexical subroutines are still experimental. The feature may be
modified or removed in future versions of Perl.

Lexical subroutines are only available under the C<use feature
'lexical_subs'> pragma, which produces a warning unless the
"experimental::lexical_subs" warnings category is disabled.

Beginning with Perl 5.18, you can declare a private subroutine with C<my>
or C<state>. As with state variables, the C<state> keyword is only
available under C<use feature 'state'> or C<use 5.010> or higher.

Prior to Perl 5.26, lexical subroutines were deemed experimental and were
available only under the C<use feature 'lexical_subs'> pragma. They also
produced a warning unless the "experimental::lexical_subs" warnings
category was disabled.

These subroutines are only visible within the block in which they are
declared, and only after that declaration:

# Include these two lines if your code is intended to run under Perl
# versions earlier than 5.26.
no warnings "experimental::lexical_subs";
use feature 'lexical_subs';

Expand Down Expand Up @@ -1102,9 +1102,6 @@ containing block to the next.
So, in general, "state" subroutines are faster. But "my" subs are
necessary if you want to create closures:

no warnings "experimental::lexical_subs";
use feature 'lexical_subs';

sub whatever {
my $x = shift;
my sub inner {
Expand All @@ -1125,9 +1122,6 @@ subroutine of the same name.
The two main uses for this are to switch back to using the package sub
inside an inner scope:

no warnings "experimental::lexical_subs";
use feature 'lexical_subs';

sub foo { ... }

sub bar {
Expand All @@ -1143,9 +1137,6 @@ and to make a subroutine visible to other packages in the same scope:

package MySneakyModule;

no warnings "experimental::lexical_subs";
use feature 'lexical_subs';

our sub do_something { ... }

sub do_something_with_caller {
Expand Down
36 changes: 20 additions & 16 deletions regen/feature.pl
Expand Up @@ -27,11 +27,9 @@ BEGIN
switch => 'switch',
bitwise => 'bitwise',
evalbytes => 'evalbytes',
postderef => 'postderef',
array_base => 'arybase',
current_sub => '__SUB__',
refaliasing => 'refaliasing',
lexical_subs => 'lexsubs',
postderef_qq => 'postderef_qq',
unicode_eval => 'unieval',
unicode_strings => 'unicode',
Expand Down Expand Up @@ -65,8 +63,7 @@ BEGIN
evalbytes current_sub fc postderef_qq)],
);

# not actually used currently
my @experimental = qw( lexical_subs );
my @noops = qw( postderef lexical_subs );


###########################################################################
Expand Down Expand Up @@ -189,9 +186,9 @@ sub longest {
qq'\$feature_bundle{"$_"} = \$feature_bundle{"$Aliases{$_}"};\n';
};

#print $pm "my \%experimental = (\n";
#print $pm " $_ => 1,\n", for @experimental;
#print $pm ");\n";
print $pm "my \%noops = (\n";
print $pm " $_ => 1,\n", for @noops;
print $pm ");\n";

print $pm <<EOPM;
Expand Down Expand Up @@ -369,7 +366,7 @@ sub longest {
__END__
package feature;
our $VERSION = '1.43';
our $VERSION = '1.44';
FEATURES
Expand Down Expand Up @@ -563,17 +560,21 @@ =head2 The 'fc' feature
=head2 The 'lexical_subs' feature
B<WARNING>: This feature is still experimental and the implementation may
change in future versions of Perl. For this reason, Perl will
warn when you use the feature, unless you have explicitly disabled the
warning:
In Perl versions prior to 5.26, this feature enabled
declaration of subroutines via C<my sub foo>, C<state sub foo>
and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
no warnings "experimental::lexical_subs";
This feature is available from Perl 5.18 onwards. From Perl 5.18 to 5.24,
it was classed as experimental, and Perl emitted a warning for its
usage, except when explicitly disabled:
This enables declaration of subroutines via C<my sub foo>, C<state sub foo>
and C<our sub foo> syntax. See L<perlsub/Lexical Subroutines> for details.
no warnings "experimental::lexical_subs";
This feature is available from Perl 5.18 onwards.
As of Perl 5.26, use of this feature no longer triggers a warning, though
the C<experimental::lexical_subs> warning category still exists (for
compatibility with code that disables it). In addition, this syntax is
not only no longer experimental, but it is enabled for all Perl code,
regardless of what feature declarations are in scope.
=head2 The 'postderef' and 'postderef_qq' features
Expand Down Expand Up @@ -781,6 +782,9 @@ sub __common {
next;
}
if (!exists $feature{$name}) {
if (exists $noops{$name}) {
next;
}
unknown_feature($name);
}
if ($import) {
Expand Down
7 changes: 1 addition & 6 deletions t/lib/croak/toke
Expand Up @@ -99,29 +99,24 @@ Missing $ on loop variable at - line 1.
# NAME Missing name in "my sub"
use feature 'lexical_subs'; my sub;
EXPECT
The lexical_subs feature is experimental at - line 1.
Missing name in "my sub" at - line 1.
########
# NAME Missing name in "our sub"
use feature 'lexical_subs'; our sub;
EXPECT
The lexical_subs feature is experimental at - line 1.
Missing name in "our sub" at - line 1.
########
# NAME Missing name in "state sub"
use 5.01; use feature 'lexical_subs';
use 5.01;
state sub;
EXPECT
The lexical_subs feature is experimental at - line 2.
Missing name in "state sub" at - line 2.
########
# NAME my sub pack::foo
use feature 'lexical_subs', 'state';
my sub foo::bar;
state sub foo::bear;
EXPECT
The lexical_subs feature is experimental at - line 2.
The lexical_subs feature is experimental at - line 3.
"my" subroutine &foo::bar can't be in a package at - line 2, near "my sub foo::bar"
"state" subroutine &foo::bear can't be in a package at - line 3, near "state sub foo::bear"
Execution of - aborted due to compilation errors.
Expand Down
4 changes: 0 additions & 4 deletions t/lib/warnings/op
Expand Up @@ -997,15 +997,11 @@ sub phred { 2 };
state sub jorge { 1 }
sub jorge () { 2 } # should *not* produce redef warnings by default
EXPECT
The lexical_subs feature is experimental at - line 3.
Prototype mismatch: sub fred () vs none at - line 4.
Constant subroutine fred redefined at - line 4.
The lexical_subs feature is experimental at - line 5.
Prototype mismatch: sub george: none vs () at - line 6.
The lexical_subs feature is experimental at - line 7.
Prototype mismatch: sub phred () vs none at - line 8.
Constant subroutine phred redefined at - line 8.
The lexical_subs feature is experimental at - line 9.
Prototype mismatch: sub jorge: none vs () at - line 10.
########
# op.c
Expand Down

0 comments on commit a50cb9d

Please sign in to comment.