Skip to content

Commit 15cbd20

Browse files
Tony Cookap
authored andcommitted
re-enable (feature guarded) switch and re-enable smartmatch with a new feature guard
Also remove any deprecation warnings and corresponding documentation
2 parents befe450 + 576c1f4 commit 15cbd20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+7593
-2795
lines changed

MANIFEST

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6131,6 +6131,8 @@ t/lib/feature/multidimensional Tests for enabling/disabling $foo{$x, $y} => $fo
61316131
t/lib/feature/nonesuch Tests for enabling/disabling nonexistent feature
61326132
t/lib/feature/removed Tests for enabling/disabling removed feature
61336133
t/lib/feature/say Tests for enabling/disabling say feature
6134+
t/lib/feature/smartmatch Tests for enabling/disabling smartmatch feature
6135+
t/lib/feature/switch Tests for enabling/disabling switch feature
61346136
t/lib/h2ph.h Test header file for h2ph
61356137
t/lib/h2ph.pht Generated output from h2ph.h by h2ph, for comparison
61366138
t/lib/locale/latin1 Part of locale.t in Latin 1
@@ -6432,6 +6434,7 @@ t/op/signatures.t See if sub signatures work
64326434
t/op/sigsystem.t See if system and SIGCHLD handlers play together nicely
64336435
t/op/sleep.t See if sleep works
64346436
t/op/smartkve.t See if smart deref for keys/values/each works
6437+
t/op/smartmatch.t See if the ~~ operator works
64356438
t/op/sort.t See if sort works
64366439
t/op/splice.t See if splice works
64376440
t/op/split.t See if split works
@@ -6455,6 +6458,7 @@ t/op/substr_thr.t See if substr works in another thread
64556458
t/op/svflags.t See if POK is set as expected.
64566459
t/op/svleak.pl Test file for svleak.t
64576460
t/op/svleak.t See if stuff leaks SVs
6461+
t/op/switch.t See if switches (given/when) work
64586462
t/op/symbolcache.t See if undef/delete works on stashes with functions
64596463
t/op/sysio.t See if sysread and syswrite work
64606464
t/op/taint.t See if tainting works

cop.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,21 +1127,27 @@ struct context {
11271127
and a static array of context names in pp_ctl.c */
11281128
#define CXTYPEMASK 0xf
11291129
#define CXt_NULL 0 /* currently only used for sort BLOCK */
1130-
#define CXt_BLOCK 1
1130+
#define CXt_WHEN 1
1131+
#define CXt_BLOCK 2
1132+
/* When micro-optimising :-) keep GIVEN next to the LOOPs, as these 5 share a
1133+
jump table in pp_ctl.c
1134+
The first 4 don't have a 'case' in at least one switch statement in pp_ctl.c
1135+
*/
1136+
#define CXt_GIVEN 3
11311137

11321138
/* be careful of the ordering of these five. Macros like CxTYPE_is_LOOP,
11331139
* CxFOREACH compare ranges */
1134-
#define CXt_LOOP_ARY 2 /* for (@ary) { ...; } */
1135-
#define CXt_LOOP_LAZYSV 3 /* for ('a'..'z') { ...; } */
1136-
#define CXt_LOOP_LAZYIV 4 /* for (1..9) { ...; } */
1137-
#define CXt_LOOP_LIST 5 /* for (1,2,3) { ...; } */
1138-
#define CXt_LOOP_PLAIN 6 /* while (...) { ...; }
1140+
#define CXt_LOOP_ARY 4 /* for (@ary) { ...; } */
1141+
#define CXt_LOOP_LAZYSV 5 /* for ('a'..'z') { ...; } */
1142+
#define CXt_LOOP_LAZYIV 6 /* for (1..9) { ...; } */
1143+
#define CXt_LOOP_LIST 7 /* for (1,2,3) { ...; } */
1144+
#define CXt_LOOP_PLAIN 8 /* while (...) { ...; }
11391145
or plain block { ...; } */
1140-
#define CXt_SUB 7
1141-
#define CXt_FORMAT 8
1142-
#define CXt_EVAL 9 /* eval'', eval{}, try{} */
1143-
#define CXt_SUBST 10
1144-
#define CXt_DEFER 11
1146+
#define CXt_SUB 9
1147+
#define CXt_FORMAT 10
1148+
#define CXt_EVAL 11 /* eval'', eval{}, try{} */
1149+
#define CXt_SUBST 12
1150+
#define CXt_DEFER 13
11451151
/* SUBST doesn't feature in all switch statements. */
11461152

11471153
/* private flags for CXt_SUB and CXt_FORMAT */

dist/Safe/Safe.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package Safe;
33
use 5.003_11;
44
use Scalar::Util qw(reftype refaddr);
55

6-
$Safe::VERSION = "2.47";
6+
$Safe::VERSION = "2.46";
77

88
# *** Don't declare any lexicals above this point ***
99
#

dist/Safe/t/safeops.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ plan(tests => scalar @op + 3);
4545
sub testop {
4646
my ($op, $opname, $code) = @_;
4747
pass("$op : skipped") and return if $code =~ /^SKIP/;
48-
pass("$op : skipped") and return if $code eq "//" && $] < 5.010;
48+
pass("$op : skipped") and return if $code =~ m://|~~: && $] < 5.010;
4949
my $c = new Safe;
5050
$c->deny_only($op);
5151
$c->reval($code);
@@ -453,6 +453,7 @@ dor $x // $y
453453
dorassign $x //= $y
454454
once SKIP {use feature 'state'; state $foo = 42;}
455455
say SKIP {use feature 'say'; say "foo";}
456+
smartmatch no warnings 'deprecated'; $x ~~ $y
456457
aeach SKIP each @t
457458
akeys SKIP keys @t
458459
avalues SKIP values @t

dump.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,8 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
14481448
case OP_DORASSIGN:
14491449
case OP_ANDASSIGN:
14501450
case OP_ARGDEFELEM:
1451+
case OP_ENTERGIVEN:
1452+
case OP_ENTERWHEN:
14511453
case OP_ENTERTRY:
14521454
case OP_ONCE:
14531455
S_opdump_indent(aTHX_ o, level, bar, file, "OTHER");

embed.fnc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,9 @@ ARdp |OP * |newFOROP |I32 flags \
22132213
|NN OP *expr \
22142214
|NULLOK OP *block \
22152215
|NULLOK OP *cont
2216+
ARdp |OP * |newGIVENOP |NN OP *cond \
2217+
|NN OP *block \
2218+
|PADOFFSET defsv_off
22162219
: Used in scope.c
22172220
eopx |GP * |newGP |NN GV * const gv
22182221
Adm |GV * |newGVgen |NN const char *pack
@@ -2357,6 +2360,8 @@ ERXopx |char * |new_warnings_bitfield \
23572360
|NULLOK char *buffer \
23582361
|NN const char * const bits \
23592362
|STRLEN size
2363+
ARdp |OP * |newWHENOP |NULLOK OP *cond \
2364+
|NN OP *block
23602365
ARdp |OP * |newWHILEOP |I32 flags \
23612366
|I32 debuggable \
23622367
|NULLOK LOOP *loop \
@@ -4861,6 +4866,7 @@ RST |bool |is_handle_constructor \
48614866
Ti |bool |is_standard_filehandle_name \
48624867
|NN const char *fhname
48634868
S |OP * |listkids |NULLOK OP *o
4869+
S |bool |looks_like_bool|NN const OP *o
48644870
S |OP * |modkids |NULLOK OP *o \
48654871
|I32 type
48664872
S |void |move_proto_attr|NN OP **proto \
@@ -4870,6 +4876,11 @@ S |void |move_proto_attr|NN OP **proto \
48704876
S |OP * |my_kid |NULLOK OP *o \
48714877
|NULLOK OP *attrs \
48724878
|NN OP **imopsp
4879+
S |OP * |newGIVWHENOP |NULLOK OP *cond \
4880+
|NN OP *block \
4881+
|I32 enter_opcode \
4882+
|I32 leave_opcode \
4883+
|PADOFFSET entertarg
48734884
RS |OP * |new_logop |I32 type \
48744885
|I32 flags \
48754886
|NN OP **firstp \
@@ -4893,6 +4904,8 @@ S |bool |process_special_blocks \
48934904
|NN const char * const fullname \
48944905
|NN GV * const gv \
48954906
|NN CV * const cv
4907+
S |OP * |ref_array_or_hash \
4908+
|NULLOK OP *cond
48964909
S |OP * |refkids |NULLOK OP *o \
48974910
|I32 type
48984911
S |OP * |scalarboolean |NN OP *o
@@ -5071,6 +5084,7 @@ p |UV |_to_upper_title_latin1 \
50715084
#if defined(PERL_IN_PP_CTL_C)
50725085
RS |PerlIO *|check_type_and_open \
50735086
|NN SV *name
5087+
S |void |destroy_matcher|NN PMOP *matcher
50745088
RSd |OP * |docatch |Perl_ppaddr_t firstpp
50755089
S |bool |doeval_compile |U8 gimme \
50765090
|NULLOK CV *outside \
@@ -5084,12 +5098,21 @@ RS |OP * |dofindlabel |NN OP *o \
50845098
|NN OP **oplimit
50855099
S |MAGIC *|doparseform |NN SV *sv
50865100
RS |I32 |dopoptoeval |I32 startingblock
5101+
RS |I32 |dopoptogivenfor|I32 startingblock
50875102
RS |I32 |dopoptolabel |NN const char *label \
50885103
|STRLEN len \
50895104
|U32 flags
50905105
RS |I32 |dopoptoloop |I32 startingblock
50915106
RS |I32 |dopoptosub_at |NN const PERL_CONTEXT *cxstk \
50925107
|I32 startingblock
5108+
RS |I32 |dopoptowhen |I32 startingblock
5109+
S |OP * |do_smartmatch |NULLOK HV *seen_this \
5110+
|NULLOK HV *seen_other \
5111+
|const bool copied
5112+
RS |PMOP * |make_matcher |NN REGEXP *re
5113+
RS |bool |matcher_matches_sv \
5114+
|NN PMOP *matcher \
5115+
|NN SV *sv
50935116
RST |bool |num_overflow |NV value \
50945117
|I32 fldsize \
50955118
|I32 frcsize
@@ -6194,11 +6217,13 @@ CTp |Malloc_t|mem_log_realloc \
61946217
Cipx |void |cx_popblock |NN PERL_CONTEXT *cx
61956218
Cipx |void |cx_popeval |NN PERL_CONTEXT *cx
61966219
Cipx |void |cx_popformat |NN PERL_CONTEXT *cx
6220+
Cipx |void |cx_popgiven |NN PERL_CONTEXT *cx
61976221
Cipx |void |cx_poploop |NN PERL_CONTEXT *cx
61986222
Cipx |void |cx_popsub |NN PERL_CONTEXT *cx
61996223
Cipx |void |cx_popsub_args |NN PERL_CONTEXT *cx
62006224
Cipx |void |cx_popsub_common \
62016225
|NN PERL_CONTEXT *cx
6226+
Cipx |void |cx_popwhen |NN PERL_CONTEXT *cx
62026227
Cipx |PERL_CONTEXT *|cx_pushblock \
62036228
|U8 type \
62046229
|U8 gimme \
@@ -6211,6 +6236,8 @@ Cipx |void |cx_pushformat |NN PERL_CONTEXT *cx \
62116236
|NN CV *cv \
62126237
|NULLOK OP *retop \
62136238
|NULLOK GV *gv
6239+
Cipx |void |cx_pushgiven |NN PERL_CONTEXT *cx \
6240+
|NULLOK SV *orig_defsv
62146241
Cipx |void |cx_pushloop_for|NN PERL_CONTEXT *cx \
62156242
|NN void *itervarp \
62166243
|NULLOK SV *itersave
@@ -6222,6 +6249,7 @@ Cipx |void |cx_pushsub |NN PERL_CONTEXT *cx \
62226249
|bool hasargs
62236250
Cipx |void |cx_pushtry |NN PERL_CONTEXT *cx \
62246251
|NULLOK OP *retop
6252+
Cipx |void |cx_pushwhen |NN PERL_CONTEXT *cx
62256253
Cipx |void |cx_topblock |NN PERL_CONTEXT *cx
62266254
Cipx |U8 |gimme_V
62276255
#endif /* !defined(PERL_NO_INLINE_FUNCTIONS) */

embed.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@
425425
# define newDEFSVOP() Perl_newDEFSVOP(aTHX)
426426
# define newFORM(a,b,c) Perl_newFORM(aTHX_ a,b,c)
427427
# define newFOROP(a,b,c,d,e) Perl_newFOROP(aTHX_ a,b,c,d,e)
428+
# define newGIVENOP(a,b,c) Perl_newGIVENOP(aTHX_ a,b,c)
428429
# define newGVOP(a,b,c) Perl_newGVOP(aTHX_ a,b,c)
429430
# define newGVREF(a,b) Perl_newGVREF(aTHX_ a,b)
430431
# define newGVgen_flags(a,b) Perl_newGVgen_flags(aTHX_ a,b)
@@ -480,6 +481,7 @@
480481
# define newTRYCATCHOP(a,b,c,d) Perl_newTRYCATCHOP(aTHX_ a,b,c,d)
481482
# define newUNOP(a,b,c) Perl_newUNOP(aTHX_ a,b,c)
482483
# define newUNOP_AUX(a,b,c,d) Perl_newUNOP_AUX(aTHX_ a,b,c,d)
484+
# define newWHENOP(a,b) Perl_newWHENOP(aTHX_ a,b)
483485
# define newWHILEOP(a,b,c,d,e,f,g) Perl_newWHILEOP(aTHX_ a,b,c,d,e,f,g)
484486
# define newXS(a,b,c) Perl_newXS(aTHX_ a,b,c)
485487
# define newXS_flags(a,b,c,d,e) Perl_newXS_flags(aTHX_ a,b,c,d,e)
@@ -1351,6 +1353,7 @@
13511353
# define ck_scmp(a) Perl_ck_scmp(aTHX_ a)
13521354
# define ck_select(a) Perl_ck_select(aTHX_ a)
13531355
# define ck_shift(a) Perl_ck_shift(aTHX_ a)
1356+
# define ck_smartmatch(a) Perl_ck_smartmatch(aTHX_ a)
13541357
# define ck_sort(a) Perl_ck_sort(aTHX_ a)
13551358
# define ck_spair(a) Perl_ck_spair(aTHX_ a)
13561359
# define ck_split(a) Perl_ck_split(aTHX_ a)
@@ -1545,9 +1548,11 @@
15451548
# define is_handle_constructor S_is_handle_constructor
15461549
# define is_standard_filehandle_name S_is_standard_filehandle_name
15471550
# define listkids(a) S_listkids(aTHX_ a)
1551+
# define looks_like_bool(a) S_looks_like_bool(aTHX_ a)
15481552
# define modkids(a,b) S_modkids(aTHX_ a,b)
15491553
# define move_proto_attr(a,b,c,d) S_move_proto_attr(aTHX_ a,b,c,d)
15501554
# define my_kid(a,b,c) S_my_kid(aTHX_ a,b,c)
1555+
# define newGIVWHENOP(a,b,c,d,e) S_newGIVWHENOP(aTHX_ a,b,c,d,e)
15511556
# define newMETHOP_internal(a,b,c,d) S_newMETHOP_internal(aTHX_ a,b,c,d)
15521557
# define new_logop(a,b,c,d) S_new_logop(aTHX_ a,b,c,d)
15531558
# define no_fh_allowed(a) S_no_fh_allowed(aTHX_ a)
@@ -1556,6 +1561,7 @@
15561561
# define opslab_slot_offset S_opslab_slot_offset
15571562
# define pmtrans(a,b,c) S_pmtrans(aTHX_ a,b,c)
15581563
# define process_special_blocks(a,b,c,d) S_process_special_blocks(aTHX_ a,b,c,d)
1564+
# define ref_array_or_hash(a) S_ref_array_or_hash(aTHX_ a)
15591565
# define refkids(a,b) S_refkids(aTHX_ a,b)
15601566
# define scalar_mod_type S_scalar_mod_type
15611567
# define scalarboolean(a) S_scalarboolean(aTHX_ a)
@@ -1631,14 +1637,20 @@
16311637
# endif
16321638
# if defined(PERL_IN_PP_CTL_C)
16331639
# define check_type_and_open(a) S_check_type_and_open(aTHX_ a)
1640+
# define destroy_matcher(a) S_destroy_matcher(aTHX_ a)
1641+
# define do_smartmatch(a,b,c) S_do_smartmatch(aTHX_ a,b,c)
16341642
# define docatch(a) S_docatch(aTHX_ a)
16351643
# define doeval_compile(a,b,c,d) S_doeval_compile(aTHX_ a,b,c,d)
16361644
# define dofindlabel(a,b,c,d,e,f) S_dofindlabel(aTHX_ a,b,c,d,e,f)
16371645
# define doparseform(a) S_doparseform(aTHX_ a)
16381646
# define dopoptoeval(a) S_dopoptoeval(aTHX_ a)
1647+
# define dopoptogivenfor(a) S_dopoptogivenfor(aTHX_ a)
16391648
# define dopoptolabel(a,b,c) S_dopoptolabel(aTHX_ a,b,c)
16401649
# define dopoptoloop(a) S_dopoptoloop(aTHX_ a)
16411650
# define dopoptosub_at(a,b) S_dopoptosub_at(aTHX_ a,b)
1651+
# define dopoptowhen(a) S_dopoptowhen(aTHX_ a)
1652+
# define make_matcher(a) S_make_matcher(aTHX_ a)
1653+
# define matcher_matches_sv(a,b) S_matcher_matches_sv(aTHX_ a,b)
16421654
# define num_overflow S_num_overflow
16431655
# define path_is_searchable S_path_is_searchable
16441656
# define run_user_filter(a,b,c) S_run_user_filter(aTHX_ a,b,c)
@@ -2223,17 +2235,21 @@
22232235
# define cx_popblock(a) Perl_cx_popblock(aTHX_ a)
22242236
# define cx_popeval(a) Perl_cx_popeval(aTHX_ a)
22252237
# define cx_popformat(a) Perl_cx_popformat(aTHX_ a)
2238+
# define cx_popgiven(a) Perl_cx_popgiven(aTHX_ a)
22262239
# define cx_poploop(a) Perl_cx_poploop(aTHX_ a)
22272240
# define cx_popsub(a) Perl_cx_popsub(aTHX_ a)
22282241
# define cx_popsub_args(a) Perl_cx_popsub_args(aTHX_ a)
22292242
# define cx_popsub_common(a) Perl_cx_popsub_common(aTHX_ a)
2243+
# define cx_popwhen(a) Perl_cx_popwhen(aTHX_ a)
22302244
# define cx_pushblock(a,b,c,d) Perl_cx_pushblock(aTHX_ a,b,c,d)
22312245
# define cx_pusheval(a,b,c) Perl_cx_pusheval(aTHX_ a,b,c)
22322246
# define cx_pushformat(a,b,c,d) Perl_cx_pushformat(aTHX_ a,b,c,d)
2247+
# define cx_pushgiven(a,b) Perl_cx_pushgiven(aTHX_ a,b)
22332248
# define cx_pushloop_for(a,b,c) Perl_cx_pushloop_for(aTHX_ a,b,c)
22342249
# define cx_pushloop_plain(a) Perl_cx_pushloop_plain(aTHX_ a)
22352250
# define cx_pushsub(a,b,c,d) Perl_cx_pushsub(aTHX_ a,b,c,d)
22362251
# define cx_pushtry(a,b) Perl_cx_pushtry(aTHX_ a,b)
2252+
# define cx_pushwhen(a) Perl_cx_pushwhen(aTHX_ a)
22372253
# define cx_topblock(a) Perl_cx_topblock(aTHX_ a)
22382254
# define gimme_V() Perl_gimme_V(aTHX)
22392255
# endif /* !defined(PERL_NO_INLINE_FUNCTIONS) */

ext/Opcode/Opcode.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Opcode 1.68;
1+
package Opcode 1.69;
22

33
use strict;
44

@@ -436,6 +436,11 @@ These are a hotchpotch of opcodes still waiting to be considered
436436
entertry leavetry -- can be used to 'hide' fatal errors
437437
entertrycatch poptry catch leavetrycatch -- similar
438438
439+
entergiven leavegiven
440+
enterwhen leavewhen
441+
break continue
442+
smartmatch
443+
439444
pushdefer
440445
441446
custom -- where should this go

0 commit comments

Comments
 (0)