This is an archive of the discontinued LLVM Phabricator instance.

[FileCheck] Fix --dump-input annotation sort per input line
ClosedPublic

Authored by jdenny on Apr 6 2020, 4:24 PM.

Details

Summary

Without this patch, --dump-input annotations on a single input line
are sorted by the associated directive's check-file line. That seemed
fine because that's often identical to the order in which FileCheck
looks for matches for those directives.

The first problem is that an --implicit-check-not pattern has no
check-file line. The logical equivalent is sorting in command-line
order, but that's not implemented.

The second problem is that, unlike a directive, an
--implicit-check-not pattern applies at many points, between many
different pairs of directives. However, sorting in command-line order
gathers all its associated diagnostics together at one point in an
input line's list of annotations.

In general, it seems to be easier to understand FileCheck's logic when
annotations on a single input line are sorted in the order FileCheck
produced the associated diagnostics, so this patch makes that change.
As documented in the patch, the annotation sort order is also
especially relevant to CHECK-LABEL, CHECK-NOT, and CHECK-DAG, so
this patch updates or extends tests to check the sort makes sense for
them. (However, the sort for CHECK-DAG annotations should not
actually be altered by this patch.)

Diff Detail

Event Timeline

jdenny created this revision.Apr 6 2020, 4:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2020, 4:24 PM
thopre added inline comments.Apr 8 2020, 9:31 AM
llvm/test/FileCheck/dump-input-annotations.txt
586–600

With 3 CHECK directives, I would expect 4 blocks of implicit checks being tested:

  1. - before directive 1
  2. - between directive 1 and directive 2
  3. - between directive 2 and directive 3
  4. - after directive 3

Unless I misunderstood, I would expect directive #3 to fail, i.e. "again" is found between "wor" and '!'. However the implicit check that fail is shown after the third CHECK directive.

jdenny marked an inline comment as done.Apr 8 2020, 11:01 AM
jdenny added inline comments.
llvm/test/FileCheck/dump-input-annotations.txt
586–600

After applying this patch, the annotations per input line are listed in the order FileCheck produces them (that is, temporal order). First, FileCheck matches check:1 (the first CHECK directive), as show in the annotation on test file line 588. Then...

With 3 CHECK directives, I would expect 4 blocks of implicit checks being tested:

  • before directive 1

... FileCheck searches for the implicit patterns here. However, here is the empty string before "hello", so the search range for each implicit pattern is just an "X", as show in the annotations on test file lines 589-591.

Next, FileCheck matches check:2, as shown on test file line 592, and then...

  • between directive 1 and directive 2

... FileCheck searches for the implicit patterns here, as shown in the annotations on test file lines 593-595.

Next, FileCheck matches check:3, as shown on test file line 596, and then...

  • between directive 2 and directive 3

... FileCheck searches for the implicit patterns here, as shown in the annotations on test file lines 597-599. The third implicit pattern matches, and that's an error, so FileCheck terminates.

Thus, FileCheck never tries to match EOF, and...

  • after directive 3

... FileCheck never tries to match the implicit patterns here.

Unless I misunderstood, I would expect directive #3 to fail, i.e. "again" is found between "wor" and '!'.

That's what happened.

However the implicit check that fail is shown after the third CHECK directive.

Because FileCheck doesn't know where to look for the implicit patterns until after matching the next CHECK directive.

thopre accepted this revision.Apr 8 2020, 4:07 PM
thopre marked an inline comment as done.

LGTM. Thanks for this, I haven't used feature so far but that seems very useful with this patch.

llvm/test/FileCheck/dump-input-annotations.txt
586–600

Ah yes of course, it all makes sense. Thanks!

This revision is now accepted and ready to land.Apr 8 2020, 4:07 PM
jdenny added a comment.Apr 8 2020, 4:57 PM

LGTM. Thanks for this, I haven't used feature so far but that seems very useful with this patch.

Cool. Thanks for the review.

(By the way, some time ago I started developing patches to show variable captures as annotations on input lines. I've found that really helpful when debugging. They need more work, such as adding support for numeric variables. I'll try to get those into phabricator soon.)

thopre added a comment.Apr 9 2020, 1:18 AM

LGTM. Thanks for this, I haven't used feature so far but that seems very useful with this patch.

Cool. Thanks for the review.

(By the way, some time ago I started developing patches to show variable captures as annotations on input lines. I've found that really helpful when debugging. They need more work, such as adding support for numeric variables. I'll try to get those into phabricator soon.)

So you mean it show the value when it's captured as opposed to when it's used like what -vv shows? Or is there more to it?

jdenny added a comment.Apr 9 2020, 4:01 PM

(By the way, some time ago I started developing patches to show variable captures as annotations on input lines. I've found that really helpful when debugging. They need more work, such as adding support for numeric variables. I'll try to get those into phabricator soon.)

So you mean it show the value when it's captured as opposed to when it's used like what -vv shows? Or is there more to it?

As you say, substitutions/uses are printed already as diagnostics. One of my patches adds them to -dump-input annotations, where I find them to be useful too.

Another patch adds the definitions/captures both to the diagnostics and to -dump-input annotations.

(Of course, verbose diagnostics are suppressed when -dump-input is specified, so you won't get tons of this stuff twice.)

Finally, upon a failed match, another patch lists variables that the pattern is intended to capture. Someone pointed out once that, if you write a capturing expression without meaning to because the syntax of the language you're matching happens to look like FileCheck capturing syntax, it can be very confusing when the match fails. This patch should help.

This revision was automatically updated to reflect the committed changes.