<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font size="4"><font face="monospace">This isn't intended to
        prohibit allocation of locals in blocks; it is to detect when
        two different mechanisms are used to allocate locals together. 
        Are you getting this error?  <br>
        <br>
        We define allocateLocal in CodeBuilder.  In the base (Direct)
        code builder, when you call allocateLocal, it bumps up a high
        water mark (topLocal).  There is no way to "deallocate" a local;
        this is an allocation that is global to the Code attribute being
        built.  <br>
        <br>
        In the various BlockBuilder implementations, they implement
        their own allocateLocal to:<br>
        <br>
         - start counting initially at the high water mark of their
        parent;<br>
         - let the user allocate locals starting at that high water
        mark;<br>
         - when the block is finished, we reclaim all of the locals
        allocate in the block, by dropping back down to the starting
        high water mark.<br>
        <br>
        The problem is that these two mechanisms -- the "global"
        allocation of DirectCodeBuilder and the "local" allocation of
        BlockCodeBuilder don't know about each other's work.  Here's an
        example of what could go wrong:<br>
        <br>
        .withCode(db -> { <br>
            int x = db.allocateLocal(TypeKind.INT); // OK, global
        allocation<br>
            db.aconst_1();<br>
            db.ifThen(bb -> { <br>
                // both the DirectCodeBuilder and BlockCodeBuilder (db
        and bb) are in scope here<br>
                int y = bb.allocateLocal(TypeKind.INT);  // OK, local
        allocation<br>
                int z = db.allocateLocal(TypeKind.INT);  // conflict!<br>
            });<br>
        });<br>
        <br>
        The problem is that I used both mechanisms inside the block.  It
        would be ok to exclusively use db, or exclusively use bb, to
        allocate locals, but not both at once.  The error you've found
        detects this conflict and throws, albeit with a not so helpful
        error message. <br>
        <br>
        Overall I think using both mechanisms at once will be rare,
        because its rare to mix using both the "tip" and "root" builders
        at the same time -- that's usually a bug.  <br>
        <br>
        If a transform needs locals for its work, it should allocate a
        local from the root builder in the (stateful) transform
        atStart() method.  <br>
        <br>
      </font></font><br>
    <div class="moz-cite-prefix">On 9/13/2022 9:06 AM, Adam Sotona
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CY4PR1001MB2150E75E8A498E41E1ECA3288C479@CY4PR1001MB2150.namprd10.prod.outlook.com">
      
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}div.WordSection1
        {page:WordSection1;}</style>
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-US">Hi,<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I have a question
            related to an older fragment of code in
            BlockCodeBuilderImpl, that actively prohibits allocation of
            locals in BlockCodeBuilder:<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">   
          </span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#336BDD;mso-fareast-language:EN-GB">public</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">
          </span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#336BDD;mso-fareast-language:EN-GB">void</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">
            <b>end</b>() {<o:p></o:p></span></p>
        <p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">       
          </span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#CE54B8;mso-fareast-language:EN-GB">terminal</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">.with((LabelTarget)
          </span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#CE54B8;mso-fareast-language:EN-GB">endLabel</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">);<o:p></o:p></span></p>
        <p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">       
          </span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#336BDD;mso-fareast-language:EN-GB">if</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB"> (</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#CE54B8;mso-fareast-language:EN-GB">terminalMaxLocals</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB"> !=
            topLocal(</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#CE54B8;mso-fareast-language:EN-GB">terminal</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">)) {<o:p></o:p></span></p>
        <p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">           
          </span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#336BDD;mso-fareast-language:EN-GB">throw</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">
          </span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#336BDD;mso-fareast-language:EN-GB">new</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">
            IllegalStateException(</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:#1E9347;mso-fareast-language:EN-GB">"Interference
            in local variable slot management"</span><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">);<o:p></o:p></span></p>
        <p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">        }<o:p></o:p></span></p>
        <p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Courier
            New";color:black;mso-fareast-language:EN-GB">    }<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Do we really want to
            prevent locals allocated and valid in the context of
            BlockCodeBuilder only?<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Thanks,<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Adam<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
      </div>
    </blockquote>
    <br>
  </body>
</html>