From 96c0a5d5db756f577fd6aeceb9b87084287b95c5 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Fri, 1 Mar 2024 11:24:18 +0100 Subject: [PATCH] Streamline Signature.is_generic in bootstrap Should probably be an attribute, set at build time, but this will do for now. --- src/Perl6/bootstrap.c/BOOTSTRAP.nqp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Perl6/bootstrap.c/BOOTSTRAP.nqp b/src/Perl6/bootstrap.c/BOOTSTRAP.nqp index 1581b3c63c..e162c0da97 100644 --- a/src/Perl6/bootstrap.c/BOOTSTRAP.nqp +++ b/src/Perl6/bootstrap.c/BOOTSTRAP.nqp @@ -2064,15 +2064,24 @@ BEGIN { Signature.HOW.add_attribute(Signature, Attribute.new(:name<$!count>, :type(Num), :package(Signature))); Signature.HOW.add_attribute(Signature, Attribute.new(:name<$!code>, :type(Code), :package(Signature))); Signature.HOW.add_attribute(Signature, Attribute.new(:name<$!readonly>, :type(int), :package(Signature))); - Signature.HOW.add_method(Signature, 'is_generic', nqp::getstaticcode(sub ($self) { - # If any parameter is generic, so are we. - my @params := nqp::getattr($self, Signature, '@!params'); - for @params { - my $is_generic := $_.is_generic(); - if $is_generic { return $is_generic } - } - return nqp::hllboolfor(0, "Raku"); - })); + + Signature.HOW.add_method(Signature, 'is_generic', nqp::getstaticcode(sub ( + $self + ) { # XXX this should be an attribute, set at build time + + # If any parameter is generic, so are we. + my @params := nqp::getattr($self, Signature, '@!params'); + my int $m := nqp::elems(@params); + my int $i; + while $i < $m { + nqp::atpos(@params, $i).is_generic + ?? (return 1) + !! ++$i; + } + + 0 + })); + Signature.HOW.add_method(Signature, 'instantiate_generic', nqp::getstaticcode(sub ($self, $type_environment) { # Go through parameters, builidng new list. If any # are generic, instantiate them. Otherwise leave them