All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: Re: [PATCH i-g-t 7/7] scripts/cocci: Add iterators.cocci
Date: Tue, 25 Nov 2025 00:40:12 +0200	[thread overview]
Message-ID: <aSTezLxIt39WVdQK@intel.com> (raw)
In-Reply-To: <aSTS9ENX7KARW9lb@intel.com>

On Mon, Nov 24, 2025 at 11:49:40PM +0200, Ville Syrjälä wrote:
> On Thu, Nov 20, 2025 at 09:14:15PM +0200, Ville Syrjala wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > Coccinelle often chokes on magic iterator macros. We
> > can lend it a hand by explicitly declaring those macros
> > as iterators. Start collecting them in
> > scripts/iterators.cocci which people can easily include
> > in their cocci scripts.
> > 
> > The "struct dummy" is there because coccinelle doesn't
> > like an empty script. Dunno if there's a cleaner way
> > around that?
> > 
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  scripts/iterators.cocci | 53 +++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 53 insertions(+)
> >  create mode 100644 scripts/iterators.cocci
> > 
> > diff --git a/scripts/iterators.cocci b/scripts/iterators.cocci
> > new file mode 100644
> > index 000000000000..90d3ae437a15
> > --- /dev/null
> > +++ b/scripts/iterators.cocci
> > @@ -0,0 +1,53 @@
> > +// SPDX-License-Identifier: MIT
> > +//
> > +// Use with
> > +// #include "scripts/iterators.cocci"
> > +// at the start of your cocci script
> > +
> > +@@
> > +iterator name for_each_collection_data;
> > +iterator name for_each_combination;
> > +iterator name for_each_connected_output;
> > +iterator name for_each_connector_mode;
> > +iterator name for_each_ctx_engine;
> > +iterator name for_each_disconnected_output;
> > +iterator name for_each_format;
> > +iterator name for_each_if;
> > +iterator name for_each_output;
> > +iterator name for_each_pipe;
> > +iterator name for_each_pipe_static;
> > +iterator name for_each_pipe_with_single_output;
> > +iterator name for_each_pipe_with_valid_output;
> > +iterator name for_each_plane_on_pipe;
> > +iterator name for_each_prime_number;
> > +iterator name for_each_sriov_enabled_vf;
> > +iterator name for_each_sriov_num_vfsfor_each_sriov_vf;
> > +iterator name for_each_sriov_num_vfs_in_rangefor_each_sriov_vf_in_range;
> > +iterator name for_each_sriov_vf;
> > +iterator name for_each_sriov_vf_in_range;
> > +iterator name for_each_subset;
> > +iterator name for_each_subset;
> > +iterator name for_each_sysfs_gt_dirfd;
> > +iterator name for_each_sysfs_gt_path;
> > +iterator name for_each_sysfs_tile_dirfd;
> > +iterator name for_each_tiling;
> > +iterator name for_each_valid_output_on_pipe;
> > +iterator name for_each_variation_nr;
> > +iterator name for_each_variation_r;

> > +iterator name igt_for_each_drm_client;
> > +iterator name igt_list_for_each_entry;
> > +iterator name igt_list_for_each_entry_reverse;
> > +iterator name igt_list_for_each_entry_safe;
> > +iterator name igt_list_for_each_entry_safe_reverse;

And now that I think about it, I seem to recall cocci having
some kind of builtin heuristic for this...

Indeed, parsing_c/parsing_hacks.ml says:
let regexp_foreach = Str.regexp_case_fold
  ".*\\(for_?each\\|for_?all\\|iterate\\|loop\\|walk\\|scan\\|each\\|for\\)"

So I guess we don't actually need to declare any of the
iterators above. IIRC I generated that list with a simple
'grep for_each', more or less just in case.

> > +iterator name igt_dynamic;
> > +iterator name igt_dynamic_f;
> > +iterator name igt_fixture;
> > +iterator name igt_fork;
> > +iterator name igt_require;
> > +iterator name igt_subtest;
> > +iterator name igt_subtest_f;
> > +iterator name igt_subtest_group;
> > +iterator name igt_subtest_with_dynamic;
> > +iterator name igt_subtest_with_dynamic_f;
> 
> Couple of other needed iterators I apparently forgot to include here:
> 
> +iterator name igt_until_timeout;
> +iterator name igt_while_interruptible;

All of this stuff I had to add manually to actually make
cocci parse the code succesfully. And we can see none of it
will match that heuristic regexp.

> 
> I should also check if cocci supports regexp with iterator names since
> that could reduce this list quite a bit...

Doesn't seem to be the case. But at least I can reduce
the list due to the builtin heuristic.

> 
> > +@@
> > +struct dummy
> > -- 
> > 2.49.1
> 
> -- 
> Ville Syrjälä
> Intel

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2025-11-24 22:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20 19:14 [PATCH i-g-t 0/7] igt: Help out coccinelle Ville Syrjala
2025-11-20 19:14 ` [PATCH i-g-t 1/7] igt: Make igt_fixture look like an iterator Ville Syrjala
2025-12-03 17:26   ` Kamil Konieczny
2025-11-20 19:14 ` [PATCH i-g-t 2/7] igt: Make igt_subtest_group " Ville Syrjala
2025-11-20 19:14 ` [PATCH i-g-t 3/7] igt: Make igt_main look more like a function Ville Syrjala
2025-11-20 19:14 ` [PATCH i-g-t 4/7] igt: Make igt_simple_main " Ville Syrjala
2025-11-20 19:14 ` [PATCH i-g-t 5/7] igt: Make igt_main*() look like normal function definition Ville Syrjala
2025-11-20 19:14 ` [PATCH i-g-t 6/7] igt: Make igt_simple_main*() " Ville Syrjala
2025-11-20 19:14 ` [PATCH i-g-t 7/7] scripts/cocci: Add iterators.cocci Ville Syrjala
2025-11-24 21:49   ` Ville Syrjälä
2025-11-24 22:40     ` Ville Syrjälä [this message]
2025-12-04 12:56       ` Hajda, Andrzej
2025-12-09 17:00         ` Ville Syrjälä
2025-11-20 19:51 ` ✓ Xe.CI.BAT: success for igt: Help out coccinelle Patchwork
2025-11-20 20:05 ` ✗ i915.CI.BAT: failure " Patchwork
2025-11-21  0:40 ` ✓ Xe.CI.Full: success " Patchwork
2025-11-24 18:12 ` [PATCH i-g-t 0/7] " Peter Senna Tschudin
2025-11-24 20:57   ` Jani Nikula
2025-11-24 21:37     ` Peter Senna Tschudin
2025-11-24 21:39   ` Ville Syrjälä
2025-11-24 21:53     ` Peter Senna Tschudin
2025-11-25 13:49   ` Kamil Konieczny
2025-11-25  8:38 ` ✓ Xe.CI.BAT: success for igt: Help out coccinelle (rev2) Patchwork
2025-11-25  9:10 ` ✓ i915.CI.BAT: " Patchwork
2025-11-25 11:55 ` ✗ Xe.CI.Full: failure " Patchwork
2025-11-25 13:44 ` [PATCH i-g-t 0/7] igt: Help out coccinelle Kamil Konieczny
2025-11-25 17:12   ` Ville Syrjälä
2025-11-25 17:53 ` ✗ i915.CI.Full: failure for igt: Help out coccinelle (rev2) Patchwork
2025-12-03 17:38 ` [PATCH i-g-t 0/7] igt: Help out coccinelle Kamil Konieczny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aSTezLxIt39WVdQK@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.