<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Paul,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks for your question, for some reason I was thinking of CHECK-DAG matching as trying line by line instead of looking for the first match from the start of the block. To answer the first question, the first CHECK-DAG would fail to match altogether since
 the regex would match 10 12 as you pointed out which wouldn't satisfy the operation. I don't think we should skip and try matching again as it is difficult in the general case (think about CHECK-DAG: [[#NUMVAR:]]{{.*}}[[#NUMVAR+1]] and how to deal with the
 same input 10 12 13).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
So my point is completely moot, for a valid input either a DAG match is found and it's a legitimate match, or a match is not found and the failure will be on the line with the use of a variable defined on the same line which would not be too surprising. My
 apologies for the confusion.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
So my questions should thus be:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<ul>
<li>are we fine with false negative (failing on valid input due to regex engine not understanding numeric values)</li><li>can you think of any situation that would lead to a false positive (directive match on invalid input) besides CHECK-NOT?</li></ul>
<div><br>
</div>
<div>Best regards,</div>
<div><br>
</div>
<div>Thomas<br>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Robinson, Paul <paul.robinson@sony.com><br>
<b>Sent:</b> 15 June 2020 15:33<br>
<b>To:</b> jh7370.2008@my.bristol.ac.uk <jh7370.2008@my.bristol.ac.uk>; Thomas Preud'homme <thomasp@graphcore.ai>; 'llvm-dev@lists.llvm.org' <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> RE: [llvm-dev] FileCheck: using numeric variable defined on same line with caveats</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:Wingdings}
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Consolas}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.x_MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
p.x_msonormal0, li.x_msonormal0, div.x_msonormal0
        {margin-right:0in;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
span.x_EmailStyle18
        {font-family:"Calibri",sans-serif;
        color:windowtext}
.x_MsoChpDefault
        {font-family:"Calibri",sans-serif}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
ol
        {margin-bottom:0in}
ul
        {margin-bottom:0in}
-->
</style>
<div lang="EN-US" link="blue" vlink="purple">
<div class="x_WordSection1">
<p class="x_MsoNormal">Before addressing the CHECK-NOT case, I’m still unclear about the DAG case.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">What should the first DAG line match?  The regex matching would first attempt to match “10 12” but the expression evaluation would fail; so the DAG candidate wouldn’t match; does this mean the DAG matching does not continue searching,
 and the test fails?  Or would we restart the search…. where?  With “0 12” (skipping only one character from the previous fail)?  In that case it would ultimately match “12 13” from the first line.  Or would it skip the entire previous candidate, and start
 searching at “ 13”?  In which case it would ultimately match “10 11” on the second line.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">In any case (if the first DAG ultimately matches something), the third DAG line would match the first previously unmatched text in the DAG search range, which would be either “10 “ or “10 12 13” from the first line, depending on the answer
 to the previous paragraph.</p>
<p class="x_MsoNormal">--paulr</p>
<p class="x_MsoNormal"> </p>
<div style="border:none; border-left:solid blue 1.5pt; padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>
On Behalf Of </b>James Henderson via llvm-dev<br>
<b>Sent:</b> Monday, June 15, 2020 4:08 AM<br>
<b>To:</b> Thomas Preud'homme <thomasp@graphcore.ai><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] FileCheck: using numeric variable defined on same line with caveats</p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div>
<div>
<p class="x_MsoNormal">I think I already gave my opinion on one of the previous patches, regarding CHECK-NOT, which approximately came to the same conclusion as what you've got here, so +1 from me. I also think the CHECK-DAG example is not one to care about.
 It seems to me that there's no guarantee what <span style="font-family:Consolas">
CHECK-DAG: [[LINE_AFTER_FOO:.*]]</span> would match, as, if I followed it correctly, CHECK-DAGs don't have any guarantee of order within a group, so it could match either the next line after BEGIN, the line after 
<span style="font-family:Consolas">[[#VAR1:]] [[#VAR1+1]]</span> or indeed any line before END.</p>
</div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<div>
<p class="x_MsoNormal">James</p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div>
<div>
<p class="x_MsoNormal">On Thu, 11 Jun 2020 at 12:29, Thomas Preud'homme via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:</p>
</div>
<blockquote style="border:none; border-left:solid #CCCCCC 1.0pt; padding:0in 0in 0in 6.0pt; margin-left:4.8pt; margin-right:0in">
<div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">Hi,</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">TL;DR: Is it ok to allow numeric variables used on same line as defined except for CHECK-NOT and with false negatives?</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">FileCheck does not currently allow a numeric variable from being used on the same line they were defined. I have a tentative patch to add that support but it comes with caveats so before going
 through review I'd like to get consensus on whether those caveats are acceptable.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">== The problem ==</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">The problem with matching variables defined on the same line is that the matching is done separately from checking the numeric relation, because numeric relation cannot be expressed in regex.
 That is, when matching [[#VAR:]] [[#VAR+1]] FileCheck is first matching the input against ([0-9]+) ([0-9]+) and then the value of the two captured integer are checked.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">This can lead to at times confusing or downward wrong outcomes. Consider the following input with the CHECK pattern mentioned above:</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">10 12 13</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">The regex would match numbers 10 and 12 and fail the CHECK directive despite 12 and 13 verifying the +1 relation. This could happen as a result of a change in the input after a new commit has
 landed. In the case of a CHECK directive, it would make the test regress and a developer would need to tighten the pattern somehow, for instance by chaning it for [[#VAR:]] [[#VAR+1]]{{$}}. Now in the context of a CHECK-NOT this could be a change from input
 10 12 14 to 10 12 13 and the pattern would still fail to match and thus the test still pass despite the compiler having regressed.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">== Proposed "solution" ==</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">Given the above, we can summarize the risks of supporting numeric expression using a variable defined on the same line to:</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<ul type="disc">
<li class="x_MsoNormal" style="color:black; mso-list:l0 level1 lfo1"><span style="font-size:12.0pt">test regression on positive matching directives (CHECK, CHECK-NEXT, ...)</span></li><li class="x_MsoNormal" style="color:black; mso-list:l0 level1 lfo1"><span style="font-size:12.0pt">silent compiler regression on negative matching directives (CHECK-NOT)</span></li></ul>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">I am therefore proposing to prevent using numeric variables defined on the same line for negative matching directives but allow it for positive matching directives with a note in the documentation
 to be careful to make the pattern as tight as possible.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">== CHECK-DAG case ==</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">CHECK-DAG is interesting because despite it being a positive matching directive, there's a risk with CHECK-DAG in case a test rely on the way CHECK-DAG is implemented. Consider the following
 directives which rely on each directive being matched in order:</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">CHECK: BEGIN</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">CHECK-DAG: [[#VAR1:]] [[#VAR1+1]]</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">CHECK-DAG: FOO</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">CHECK-DAG: [[LINE_AFTER_FOO:.*]]</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">CHECK: END</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">CHECK-NOT: [[LINE_AFTER_FOO]] BAZ</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">This could be written if the line checked by the first CHECK-DAG is guaranteed to always be either before FOO or after the line after FOO. Now consider the following input that verifies this
 invariant:</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">BEGIN</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">10 12 13</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">FOO 10 11</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">FOOBAR</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">END</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; font-family:Consolas; color:black">10 12 13 FOOBAR BAZ</span><span style="font-size:12.0pt; color:black"></span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">The expectation from the test author relying on the CHECK-DAG behavior would be for LINE_AFTER_FOO to have the value FOOBAR once the CHECK-DAG block has matched. However due to the caveats mentioned
 above it would end up being set to "10 12 13"  and thus the CHECK-NOT would pass because "10 12 13" is not followed by "BAZ". That's far fetched though, I'm not convinced we should worry about this beyond documenting CHECK-DAG as being able to match in any
 order.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">Thoughts?</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">Best regards,</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black">Thomas</span></p>
</div>
</div>
</div>
<p class="x_MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></p>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>