Skip to content

Commit

Permalink
Don't use separate method for recursing
Browse files Browse the repository at this point in the history
- basically reverts ed65d73
- apparently, objects in a Match structure *can* be visited multiple
  times, and when they do, create a different result in the structure.

Since the SUBMATCH method did *not* check for visitedness, this resulted
in a different value being returned, which upset a lot of modules in the
ecosystem.  Not sure I want to rework the Match object to make it lazy
anymore.  :-(
  • Loading branch information
lizmat committed Jun 14, 2020
1 parent 6f6b2df commit 219199b
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions src/core.c/Match.pm6
Expand Up @@ -40,29 +40,6 @@ my class Match is Capture is Cool does NQPMatchRole {
self
}

# Version of MATCH that does *not* need to check for being set up already
# as this will only be called from within MATCH-CAPTURES, which by
# definition is called only when the Match object is not set up yet.
method SUBMATCH() is implementation-detail {
nqp::if( # must still set up
nqp::islt_i(
nqp::getattr_i(self,Match,'$!pos'),
nqp::getattr_i(self,Match,'$!from')
) || nqp::isnull(my $rxsub := nqp::getattr(self,Match,'$!regexsub'))
|| nqp::isnull(my $CAPS := nqp::tryfindmethod($rxsub,'CAPS'))
|| nqp::isnull(my $captures := $CAPS($rxsub))
|| nqp::not_i($captures.has-captures),
nqp::stmts( # no captures
nqp::bindattr(self,Capture,'@!list',$EMPTY_LIST),
nqp::bindattr(self,Capture,'%!hash',$EMPTY_HASH),
nqp::bindattr(self,Match,'$!match',NQPdidMATCH) # mark as set up
),
self!MATCH-CAPTURES($captures) # go reify all the captures
);

self
}

method !MATCH-CAPTURES(Mu $captures --> Nil) {
# Initialize capture lists.
my $list := nqp::findmethod($captures,'prepare-raku-list')($captures);
Expand All @@ -88,7 +65,7 @@ my class Match is Capture is Cool does NQPMatchRole {
(my $cursor := nqp::atpos($cs,$i)),
nqp::unless(
nqp::isnull_s(nqp::getattr_s($cursor,$?CLASS,'$!name')),
nqp::push($dest,$cursor.SUBMATCH) # recurse
nqp::push($dest,$cursor.MATCH) # recurse
)
)
);
Expand All @@ -106,7 +83,7 @@ my class Match is Capture is Cool does NQPMatchRole {
nqp::not_i(nqp::isnull_s($name))
&& nqp::isge_i(nqp::chars($name),1),
nqp::stmts( # has a name
(my $match := $cursor.SUBMATCH), # recurse
(my $match := $cursor.MATCH), # recurse
nqp::if(
nqp::iseq_s($name,'$!from')
|| nqp::iseq_s($name,'$!to'),
Expand Down

0 comments on commit 219199b

Please sign in to comment.