develooper Front page | perl.perl5.porters | Postings from June 2022

Re: Pre-RFC: yield true feature

Thread Previous | Thread Next
From:
Tony Cook
Date:
June 7, 2022 05:03
Subject:
Re: Pre-RFC: yield true feature
Message ID:
Yp7bIeNihF87ZisF@venus.tony.develop-help.com
On Tue, Jun 07, 2022 at 09:16:22AM +0900, Yuki Kimoto wrote:
> 2022-6-7 7:07 Neil Bowers <neilb@neilb.org> wrote:
> 
> > This is a retrospective Pre-RFC for a proposal from Curtis, for which he
> > submitted a draft RFC[1]. We nearly missed it when reviewing proposals
> > in-flight in our PSC meeting last week, and decided to trigger a discussion
> > here, to reinforce the process.
> >
> > ...
> >
> > [1] https://github.com/Perl/RFCs/pull/16
> >
> >
> I want to hear the haarg' proposal a little more.
> 
> >There is another model that could be used. could always ignore the return
> value from the file if the feature was enabled. This is simpler than the
> previous option, but accomplishes essentially the same thing. It still
> needs special handling in , but doesn't need to care about an implicit vs
> explicit return. In practice, the return value from a ed file is not usable
> for anything. The only impact it will have on perl's behavior is throwing
> an error for a false value. This is better done by throwing a real error.
> If there is no real purpose for returning an explicit value, why complicate
> the model by trying to handle specially?
> 
> Does this mean changing the behavior of "use", "require", "do" in the
> "yield_true"
> feature?

There would be no change for "do", it doesn't require truthiness.

Simply removing the requirement is close to trivial (below), but I'd
expect it to break some downstream tests.  It breaks a small number of
tests in core, including one for parent.pm.

Tony

diff --git a/pp_ctl.c b/pp_ctl.c
index 86f5f2c343..3f4fe43a15 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1702,22 +1702,13 @@ S_pop_eval_context_maybe_croak(pTHX_ PERL_CONTEXT *cx, SV *errsv, int action)
     CX_POP(cx);
 
     if (do_croak) {
-        const char *fmt;
         HV *inc_hv = GvHVn(PL_incgv);
 
-        if (action == 1) {
-            (void)hv_delete_ent(inc_hv, namesv, G_DISCARD, 0);
-            fmt = "%" SVf " did not return a true value";
-            errsv = namesv;
-        }
-        else {
         (void)hv_store_ent(inc_hv, namesv, &PL_sv_undef, 0);
-            fmt = "%" SVf "Compilation failed in require";
         if (!errsv)
             errsv = newSVpvs_flags("Unknown error\n", SVs_TEMP);
-        }
 
-        Perl_croak(aTHX_ fmt, SVfARG(errsv));
+        Perl_croak(aTHX_ "%" SVf "Compilation failed in require", SVfARG(errsv));
     }
 }
 
@@ -4610,7 +4601,6 @@ PP(pp_leaveeval)
     U8 gimme;
     PERL_CONTEXT *cx;
     OP *retop;
-    int failed;
     CV *evalcv;
     bool keep;
 
@@ -4622,11 +4612,6 @@ PP(pp_leaveeval)
     oldsp = PL_stack_base + cx->blk_oldsp;
     gimme = cx->blk_gimme;
 
-    /* did require return a false value? */
-    failed =    CxOLD_OP_TYPE(cx) == OP_REQUIRE
-             && !(gimme == G_SCALAR
-                    ? SvTRUE_NN(*PL_stack_sp)
-                    : PL_stack_sp > oldsp);
 
     if (gimme == G_VOID) {
         PL_stack_sp = oldsp;
@@ -4654,7 +4639,7 @@ PP(pp_leaveeval)
     CvDEPTH(evalcv) = 0;
 
     /* pop the CXt_EVAL, and if a require failed, croak */
-    S_pop_eval_context_maybe_croak(aTHX_ cx, NULL, failed);
+    S_pop_eval_context_maybe_croak(aTHX_ cx, NULL, 0);
 
     if (!keep)
         CLEAR_ERRSV();

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About