From 8f568c669b49b98cb4b30990e7b135b31d35da26 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Fri, 19 Apr 2024 16:55:24 +0200 Subject: [PATCH] RakuAST: detect passing single literal to native rw arg at compile time Not sure why the old frontend handles this case of having a single such argument specially. Let's match it until we know more. --- src/Raku/ast/call.rakumod | 9 ++++++++- src/Raku/ast/literals.rakumod | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Raku/ast/call.rakumod b/src/Raku/ast/call.rakumod index 10541d9dc3..dbc98a0ae6 100644 --- a/src/Raku/ast/call.rakumod +++ b/src/Raku/ast/call.rakumod @@ -256,6 +256,8 @@ class RakuAST::Call::Name } method PERFORM-CHECK(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) { + my int $ARG_IS_LITERAL := 32; + if self.is-resolved && ( nqp::istype(self.resolution, RakuAST::CompileTimeValue) || nqp::can(self.resolution, 'maybe-compile-time-value') @@ -268,12 +270,17 @@ class RakuAST::Call::Name my @types; my @flags; my $ok := 1; - for self.IMPL-UNWRAP-LIST(self.args.args) { + my @args := self.IMPL-UNWRAP-LIST(self.args.args); + for @args { my $type := $_.type; nqp::push(@types, $type); $ok := 0 if $type =:= Mu; # Don't know the type nqp::push(@flags, nqp::objprimspec($type)); } + if nqp::elems(@types) == 1 && nqp::istype(@args[0], RakuAST::Literal) { + my $rev := @args[0].native-type-flag; + @flags[0] := nqp::defined($rev) ?? $rev +| $ARG_IS_LITERAL !! 0; + } if $ok { my $ct_result := nqp::p6trialbind($sig, @types, @flags); if $ct_result == -1 { diff --git a/src/Raku/ast/literals.rakumod b/src/Raku/ast/literals.rakumod index b8896c6b9d..b1ea774962 100644 --- a/src/Raku/ast/literals.rakumod +++ b/src/Raku/ast/literals.rakumod @@ -30,6 +30,7 @@ class RakuAST::Literal method expression() { self } method type() { $!value.WHAT } + method native-type-flag() { Nil } method compile-time-value() { $!value } method IMPL-CAN-INTERPRET() { True } method IMPL-INTERPRET(RakuAST::IMPL::InterpContext $ctx) { $!value } @@ -64,6 +65,8 @@ class RakuAST::Constant class RakuAST::IntLiteral is RakuAST::Literal { + method native-type-flag() { 1 } + method IMPL-EXPR-QAST(RakuAST::IMPL::QASTContext $context) { my $value := self.value; $context.ensure-sc($value); @@ -81,6 +84,8 @@ class RakuAST::IntLiteral class RakuAST::NumLiteral is RakuAST::Literal { + method native-type-flag() { 2 } + method IMPL-EXPR-QAST(RakuAST::IMPL::QASTContext $context) { my $value := self.value; $context.ensure-sc($value); @@ -115,6 +120,8 @@ class RakuAST::MapLiteral class RakuAST::StrLiteral is RakuAST::Literal { + method native-type-flag() { 3 } + method IMPL-EXPR-QAST(RakuAST::IMPL::QASTContext $context) { my $value := self.value; $context.ensure-sc($value);