<div dir="ltr">Hi,<div><br></div><div>I also like proposed grammar. One minor correction, I guess you want to allow pattern use with parameters as well:</div><div><br></div><div><span style="font-size:12.8px"> PATTERN_USE <- '[[' '@' IDENT </span><span style="font-size:12.8px">ARGLIST?</span><span style="font-size:12.8px"> </span><span style="font-size:12.8px">']]' ;</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 31, 2016 at 10:56 PM, Vedant Kumar via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> At first I thought that `register(n)` was some sort of macro, but if it is suppose to be equivalent to the example above of what we do “today”, then using “register(“1”)” is supposed to “capture” the ‘r’ part of the register on the first match.<br>
<br>
<br>
</span>This is a problem with my suggested gramamr (specifically: it doesn't provide a<br>
way to use defined patterns to capture text for later reference).  Fred brought<br>
up that he was confused by this too.<br>
<br>
One way to fix it is to use '@' before using patterns. I'll recap the suggested<br>
grammar and work through another example. Here's how you'd define a pattern:<br>
<br>
  CHECK-DEFINE-PATTERN: car(make, model, year): {{Found a }} make model {{, from }} year<br>
<br>
And here's how you'd use it, *without* capturing the text into a variable:<br>
<br>
  CHECK: [[@car("Honda", "Accord", "2009")]]<br>
<br>
(Note, this matches the text: "Found a Honda Accord, from 2009".)<br>
<br>
To use a pattern and capture the matched text in "MY_CAR", you'd write:<br>
<br>
  CHECK: [[MY_CAR @car("Honda", "Accord", "2009")]]<br>
<br>
This gives us an unambiguous way to capture text matched via a defined pattern,<br>
which is visually distinct from how normal regex-based capturing works.<br>
<br>
Note that subsequent uses of "MY_CAR" should work as expected (i.e, you can do<br>
'[[MY_CAR]]' later in the test).<br>
<br>
Revised grammar:<br>
<span class=""><br>
   ACTION <- CHECK ':' MATCH '\n' ;<br>
   ACTION <- CHECK-DEFINE-PATTERN ':' IDENT PARAMLIST? ':' PATTERN_ELEMENT* '\n' ;<br>
   PARAMLIST <- '(' IDENT (',' IDENT)* ')' ;<br>
</span>   PATTERN_ELEMENT <- IDENT | REGEX;<br>
   MATCH <- (TEXT | REGEX | PATTERN_USE | VAR)* ;<br>
   REGEX <- '{{' POSIX_REGEX '}}' ;<br>
   PATTERN_USE <- '[[' '@' IDENT ']]' ;<br>
   VAR <- '[[' IDENT ':' POSIX_REGEX ']]' ;<br>
   VAR <- '[[' IDENT '@' IDENT ARGLIST? ']]' ;<br>
<span class="">   ARGLIST <- '(' ARG (',' ARG)* ')' ;<br>
   ARG <- "([^"]|\\")*" ;<br>
<br>
</span>vedant<br>
<div class="HOEnZb"><div class="h5"><br>
> On Aug 31, 2016, at 9:11 AM, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com">mehdi.amini@apple.com</a>> wrote:<br>
><br>
>><br>
>> On Aug 24, 2016, at 4:46 PM, Vedant Kumar via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>>><br>
>>> On Aug 24, 2016, at 2:04 AM, Elena Lepilkina <<a href="mailto:Elena.Lepilkina@synopsys.com">Elena.Lepilkina@synopsys.com</a>> wrote:<br>
>>><br>
>>> Hi all,<br>
>>><br>
>>> Some discussions and comments were made in reviews. Much time has already passed since last comment and uploading changed patches. I made small summary report about features here, because there are some doubts about syntax of some features and changes in patches and it'll be great to know more opinions.<br>
>>><br>
>>> 1. FileCheck Enhancement - CHECK-WORD (<a href="https://reviews.llvm.org/D22353" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22353</a>)<br>
>>> I replace special directives by flag --check-word, which turns on mode for each directive in file.  It's obvious that this mode can be replaced using \b assert, but current regexp library doesn't have support of this assert and I have no answer to question about possibility of change current library.<br>
>>> There was the discussion about that such mode can be made default, but there were doubts about necessity of a lot of work for changing existing tests.<br>
>>> And I made experiment which proves that a lot of old tests will be failed with such mode on.<br>
>>> Expected Passes    : 15810<br>
>>> Expected Failures  : 125<br>
>>> Unsupported Tests  : 195<br>
>>> Unexpected Passes  : 4<br>
>>> Unexpected Failures: 1128<br>
>><br>
>> I would rather not introduce churn in our tests by turning on --check-word by<br>
>> default. I'm also not convinced that turning on --check-word at the test level<br>
>> is the right move: having a CHECK-WORD directive is more flexible, and not a<br>
>> serious inconvenience (as compared to writing "CHECK").<br>
>><br>
>><br>
>>><br>
>>> 2. FileCheck Enhancement - pattern templates ( <a href="https://reviews.llvm.org/D22403" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22403</a>)<br>
>>> There are some doubts about syntax of templates. I agree that use of  \#, \:, \= is quite different from usual characters in FileCheck and was chosen because of same approach for escaping in regexp. Adrian Prantl suggested to use double-brackets "[[" to escape.<br>
>>> Old syntax:<br>
>>> \#(template_name) - use of template 'template_name'. It can occur in CHECK-PATTERN line, when description of one template includes other templates described before. (Without quote, I don't know how escape # here)<br>
>>> \:(Variable_name)- template variable with name 'variable_name'<br>
>>> \:(variable_name)\=(value) - current value of template variable(it's needed when you use template with variables).<br>
>>> Suggested new syntax:<br>
>>> [[#template_name]] - use of template 'template_name'. It can occur in CHECK-PATTERN line, when description of one template includes other templates described before. (Without quote, I don't know how escape # here)<br>
>>> [[:Variable_name]] - template variable with name 'variable_name'<br>
>>> [[:variable_name=value]] - current value of template variable(it's needed when you use template with variables).<br>
>>> It'll be great to hear more opinions and suggestions about syntax. May be someone has really good ideas. Then I'll be able to change it.<br>
>><br>
>> First, I want to recap the FileCheck workflow Elena is proposing:<br>
>><br>
>>  1. Define patterns using the CHECK-DEFINE-PATTERN directive. Defined patterns<br>
>>     have a name and may optionally have parameters.<br>
>><br>
>>  2. Use defined patterns in the usual CHECK* directives.<br>
>><br>
>> This is similar to how FileCheck patterns work already. The difference is<br>
>> that the patterns are defined using a dedicated directive, *not* when the<br>
>> pattern is first encountered. E.g, here is what you can do today:<br>
>><br>
>>  // RUN: echo "%r1 %r2" | FileCheck %s<br>
>>  // CHECK: %[[register:[a-z]+]]1<br>
>>  // CHECK-SAME: %[[register]]2<br>
>><br>
>> With the proposed changes, we'll be able to write something like:<br>
>><br>
>>  // RUN: echo "%cmp %cmp" | FileCheck %s<br>
>>  // CHECK-DEFINE-PATERN: register(n): {{[a-z]+}}n<br>
>>  // CHECK: %[[register("1")]]<br>
>>  // CHECK-SAME: %[[register("2")]]<br>
><br>
> At first I thought that `register(n)` was some sort of macro, but if it is suppose to be equivalent to the example above of what we do “today”, then using “register(“1”)” is supposed to “capture” the ‘r’ part of the register on the first match.<br>
> So you cannot reuse “register()” later to capture another expression. For instance:<br>
><br>
>  // RUN: FileCheck %s<br>
>  // CHECK-DEFINE-PATERN: register(n): {{[a-z]+}}n<br>
>  // CHECK: %[[register("1")]]<br>
>  // CHECK-SAME: %[[register("2")]]<br>
>  // CHECK: %[[register("1")]]<br>
>  // CHECK-SAME: %[[register("2")]]<br>
> %r1 %r2<br>
> %reg1 %reg2 #will fail here.<br>
><br>
><br>
> If true, I find this confusing, if not, I missed something in your example.<br>
><br>
> —<br>
> Mehdi<br>
><br>
><br>
><br>
>><br>
>> I saw "something like" because we haven't decided on the syntax for defining<br>
>> and using patterns (that's what this thread is for). Briefly, here's the syntax<br>
>> I'd like to use:<br>
>><br>
>>  // Defining patterns.<br>
>>  CHECK-DEFINE-PATERN: <Name>(<Ident>, ...)?: <Pattern><br>
>><br>
>>  Where <Pattern> is a list of <PatternElement>, and a <PatternElement> is<br>
>>  either a regex ('{{' POSIX_REGEX '}}') or an argument identifier (IDENT).<br>
>><br>
>>  // Using patterns.<br>
>>  CHECK: [[<Name>(<Argument>, ...)?]]<br>
>><br>
>> Fleshing this out some more, here is my candidate grammar (see the end of this<br>
>> email for the current grammar):<br>
>><br>
>>  ACTION <- CHECK ':' MATCH '\n' ;<br>
>>  ACTION <- CHECK-DEFINE-PATTERN ':' IDENT PARAMLIST? ':' PATTERN_ELEMENT* '\n' ;<br>
>>  PARAMLIST <- '(' IDENT (',' IDENT)* ')' ;<br>
>>  PATTERN_ELEMENT <- IDENT ;<br>
>>  PATTERN_ELEMENT <- REGEX ;<br>
>>  MATCH <- ;<br>
>>  MATCH <- TEXT MATCH ;<br>
>>  MATCH <- REGEX MATCH ;<br>
>>  MATCH <- VAR MATCH ;<br>
>>  REGEX <- '{{' POSIX_REGEX '}}' ;<br>
>>  VAR <- '[[' IDENT ':' POSIX_REGEX ']]' ;<br>
>>  VAR <- '[[' IDENT ARGLIST? ']]' ;<br>
>>  ARGLIST <- '(' ARG (',' ARG)* ')' ;<br>
>>  ARG <- "([^"]|\\")*" ;<br>
>><br>
>><br>
>>> 3. FileCheck Enhancement - repeats in regular expressions (<a href="https://reviews.llvm.org/D22454" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22454</a>), FileCheck Enhancement - Including files (<a href="https://reviews.llvm.org/D22500" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22500</a>), FileCheck Enhancement - Expressions repeat for CHECK and CHECK-NEXT(<a href="https://reviews.llvm.org/D22501" rel="noreferrer" target="_blank">https://reviews.<wbr>llvm.org/D22501</a>), FileCheck Enhancement - CHECK-LABEL-DAG(<a href="https://reviews.llvm.org/D22502" rel="noreferrer" target="_blank">https://<wbr>reviews.llvm.org/D22502</a>), FileCheck Enhancement - prefixes-regular expressions (<a href="https://reviews.llvm.org/D22503" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22503</a>)<br>
>>> There were no comments about these enhancements at all. Your opinions are very important.<br>
>><br>
>> I personally am waiting for some version of D22403 to land in-tree before<br>
>> starting on the other reviews. This would help me gauge what others in the<br>
>> community are thinking and what they need.<br>
>><br>
>>><br>
>>> I hope that some of these changes will be useful for FileCheck users, so I need your opinions to get opportunity for review to be resumed.<br>
>><br>
>> thanks,<br>
>> vedant<br>
>><br>
>> Original FileCheck grammar (shamelessly copied from the grammar Adrian posted<br>
>> to D22403):<br>
>><br>
>>  ACTION <- CHECK ':' MATCH '\n' ;<br>
>>  MATCH <- ;<br>
>>  MATCH <- TEXT MATCH ;<br>
>>  MATCH <- REGEX MATCH ;<br>
>>  MATCH <- VAR MATCH ;<br>
>>  REGEX <- '{{' POSIX_REGEX '}}' ;<br>
>>  VAR <- '[[' IDENT ':' POSIX_REGEX ']]' ;<br>
>>  VAR <- '[[' IDENT ']]' ;<br>
>><br>
>><br>
>>><br>
>>> -----Original Message-----<br>
>>> From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@<wbr>lists.llvm.org</a>] On Behalf Of Elena Lepilkina via llvm-dev<br>
>>> Sent: Wednesday, July 20, 2016 4:52 PM<br>
>>> To: <a href="mailto:vsk@apple.com">vsk@apple.com</a><br>
>>> Cc: <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>>> Subject: Re: [llvm-dev] RFC: FileCheck Enhancements<br>
>>><br>
>>> List of last patches:<br>
>>><br>
>>> 1. FileCheck Enhancement - CHECK-WORD (llvm-commits was added later as diff update) - <a href="https://reviews.llvm.org/D22353" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22353</a> 2. FileCheck Enhancement - pattern templates(llvm-commits was added later as diff update) - <a href="https://reviews.llvm.org/D22403" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22403</a> 3. FileCheck Enhancement - repeats in regular expressions (new review with llvm-commits) - <a href="https://reviews.llvm.org/D22454" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22454</a> 4. FileCheck Enhancement - Including files (new review with llvm-commits) - <a href="https://reviews.llvm.org/D22500" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22500</a><br>
>>> 5. FileCheck Enhancement - Expressions repeat for CHECK and CHECK-NEXT (new review with llvm-commits)   - <a href="https://reviews.llvm.org/D22501" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22501</a><br>
>>> 6. FileCheck Enhancement - CHECK-LABEL-DAG (new review with llvm-commits)  - <a href="https://reviews.llvm.org/D22502" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22502</a> 7. FileCheck Enhancement - prefixes-regular expressions (new review with llvm-commits) - <a href="https://reviews.llvm.org/D22503" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22503</a><br>
>>><br>
>>> Thanks,<br>
>>> Elena.<br>
>>><br>
>>> -----Original Message-----<br>
>>> From: <a href="mailto:vsk@apple.com">vsk@apple.com</a> [mailto:<a href="mailto:vsk@apple.com">vsk@apple.com</a>]<br>
>>> Sent: Tuesday, July 19, 2016 8:42 PM<br>
>>> To: Elena Lepilkina <<a href="mailto:Elena.Lepilkina@synopsys.com">Elena.Lepilkina@synopsys.com</a>><br>
>>> Cc: Dean Michael Berris <<a href="mailto:dean.berris@gmail.com">dean.berris@gmail.com</a>>; Mehdi Amini <<a href="mailto:mehdi.amini@apple.com">mehdi.amini@apple.com</a>>; <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>>> Subject: Re: [llvm-dev] RFC: FileCheck Enhancements<br>
>>><br>
>>> Hi Elena,<br>
>>><br>
>>><br>
>>>> On Jul 19, 2016, at 6:36 AM, Elena Lepilkina via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>>><br>
>>>> Hi all,<br>
>>>><br>
>>>> I made new patches for most of changes with llvm-commits subscriber. But two patches were updated, because there are a lot of comments (patch for CHECK-WORD and patch for templates pattern). Will it be ok?<br>
>>><br>
>>> IMO it's fine to keep some of the original reviews if you don't want to discard/recreate their state.<br>
>>><br>
>>> Please list the most up-to-date set of Phab URL's here, with a little note next to the ones which did not initially CC llvm-commits.<br>
>>><br>
>>> Thanks again for working on this!<br>
>>><br>
>>> vedant<br>
>>><br>
>>>><br>
>>>> Thanks, Elena.<br>
>>>><br>
>>>> -----Original Message-----<br>
>>>> From: llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@<wbr>lists.llvm.org</a>] On Behalf Of<br>
>>>> Dean Michael Berris via llvm-dev<br>
>>>> Sent: Tuesday, July 19, 2016 6:53 AM<br>
>>>> To: Mehdi Amini <<a href="mailto:mehdi.amini@apple.com">mehdi.amini@apple.com</a>><br>
>>>> Cc: via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
>>>> Subject: Re: [llvm-dev] RFC: FileCheck Enhancements<br>
>>>><br>
>>>><br>
>>>>> On 19 Jul 2016, at 04:18, Mehdi Amini via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
>>>>><br>
>>>>> We had a long thread about that a few weeks (months?) ago: the conclusion (as I remember) was roughly a guideline to “always start a new revision to have a proper mailing-list thread starting with context (i.e. patch description)”<br>
>>>>> (and my dissident minority opinion that it is only worth it if there<br>
>>>>> hasn’t been significant round of reviews going on on the existing<br>
>>>>> revision)<br>
>>>>><br>
>>>><br>
>>>> Pardon me for missing that discussion, this may have already been asked before: but is it possible to make arcanist default subscribe the correct commits mailing list in the process? This should make it at least harder to forget.<br>
>>>><br>
>>>> Cheers<br>
>>>> ______________________________<wbr>_________________<br>
>>>> LLVM Developers mailing list<br>
>>>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
>>>> ______________________________<wbr>_________________<br>
>>>> LLVM Developers mailing list<br>
>>>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
>>><br>
>>> ______________________________<wbr>_________________<br>
>>> LLVM Developers mailing list<br>
>>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
>><br>
>> ______________________________<wbr>_________________<br>
>> LLVM Developers mailing list<br>
>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>