cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] Searching for repeated source code with SmPL?
@ 2024-05-06 10:08 Markus Elfring
  2024-05-06 10:09 ` Julia Lawall
                   ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-06 10:08 UTC (permalink / raw)
  To: cocci

Hello,

Source code parts can occasionally be repeated.

* Loops
  The control flow can contain ordinary loops.

* Recursion
  A function may be called by itself.


Such constructs trigger special consequences also for further data processing
with higher level technologies.

+ Computation tree logic

+ Linear temporal logic


I am still looking for clarifications so that the Coccinelle software
can be applied in safer ways.


Regular expressions support some search operators for quantification.
A notation is accordingly supported for the specification of a minimum number
of matches which would be bigger than one item.

I imagine that such functionality would be helpful also for the semantic patch language.
How will the chances evolve to extend corresponding quantifiers anyhow?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/23f7738a7881b02d016d278ee293cfd4a126fcab/docs/manual/cocci_syntax.tex#L793
https://github.com/coccinelle/coccinelle/blob/755250323b80f27701e78d325cc83509197b33b1/docs/manual/cocci_syntax.tex#L793

I would appreciate if multiple occurrences of code elements can be better detected
and transformed.

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 10:08 [cocci] Searching for repeated source code with SmPL? Markus Elfring
@ 2024-05-06 10:09 ` Julia Lawall
  2024-05-06 11:03   ` Markus Elfring
                     ` (2 more replies)
  2024-05-11  7:15 ` Markus Elfring
  2024-05-22  8:20 ` Markus Elfring
  2 siblings, 3 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-06 10:09 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci



On Mon, 6 May 2024, Markus Elfring wrote:

> Hello,
>
> Source code parts can occasionally be repeated.
>
> * Loops
>   The control flow can contain ordinary loops.
>
> * Recursion
>   A function may be called by itself.
>
>
> Such constructs trigger special consequences also for further data processing
> with higher level technologies.
>
> + Computation tree logic
>
> + Linear temporal logic
>
>
> I am still looking for clarifications so that the Coccinelle software
> can be applied in safer ways.
>
>
> Regular expressions support some search operators for quantification.
> A notation is accordingly supported for the specification of a minimum number
> of matches which would be bigger than one item.
>
> I imagine that such functionality would be helpful also for the semantic patch language.
> How will the chances evolve to extend corresponding quantifiers anyhow?
> https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/23f7738a7881b02d016d278ee293cfd4a126fcab/docs/manual/cocci_syntax.tex#L793
> https://github.com/coccinelle/coccinelle/blob/755250323b80f27701e78d325cc83509197b33b1/docs/manual/cocci_syntax.tex#L793
>
> I would appreciate if multiple occurrences of code elements can be better detected
> and transformed.

I have no intention of adding regular expressions.  Be more concrete about
what you are not able to do.

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 10:09 ` Julia Lawall
@ 2024-05-06 11:03   ` Markus Elfring
  2024-05-06 12:10   ` Markus Elfring
  2024-05-11 15:36   ` Markus Elfring
  2 siblings, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-06 11:03 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> Source code parts can occasionally be repeated.
>>
>> * Loops
>>   The control flow can contain ordinary loops.
>>
>> * Recursion
>>   A function may be called by itself.
>>
>>
>> Such constructs trigger special consequences also for further data processing
>> with higher level technologies.
>>
>> + Computation tree logic
>>
>> + Linear temporal logic
>>
>>
>> I am still looking for clarifications so that the Coccinelle software
>> can be applied in safer ways.
>>
>>
>> Regular expressions support some search operators for quantification.
>> A notation is accordingly supported for the specification of a minimum number
>> of matches which would be bigger than one item.
>>
>> I imagine that such functionality would be helpful also for the semantic patch language.
>> How will the chances evolve to extend corresponding quantifiers anyhow?
>> https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/23f7738a7881b02d016d278ee293cfd4a126fcab/docs/manual/cocci_syntax.tex#L793
>> https://github.com/coccinelle/coccinelle/blob/755250323b80f27701e78d325cc83509197b33b1/docs/manual/cocci_syntax.tex#L793
>>
>> I would appreciate if multiple occurrences of code elements can be better detected
>> and transformed.
>
> I have no intention of adding regular expressions.

Please take another look at provided information from my clarification approach
so that undesirable misunderstandings can be better avoided.

* Regular expressions are supported already by the Coccinelle software.

  + They can be applied for advanced SmPL constraints.

  + Embedded scripts for programming languages like “OCaml” and “Python”
    occasionally benefit from this technique.


> Be more concrete about what you are not able to do.

The semantic patch language supports a few “Dot variants” so far.
I am looking for further possibilities according to item quantification.
How should a search be performed for source code which would occur twice at least
(without taking repetition because of loops and recursion into account)?

How would a notation “{2,}” look like in SmPL?
https://en.wikipedia.org/wiki/Regular_expression#Basic_concepts

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 10:09 ` Julia Lawall
  2024-05-06 11:03   ` Markus Elfring
@ 2024-05-06 12:10   ` Markus Elfring
  2024-05-06 12:16     ` Julia Lawall
  2024-05-11 15:36   ` Markus Elfring
  2 siblings, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-06 12:10 UTC (permalink / raw)
  To: Julia Lawall, cocci

> Be more concrete about what you are not able to do.

Would you find another specific search use case easier to clarify?

Example:
How would you like to determine that an if statement was specified three times
within an function implementation while the corresponding compound statement
should contain a variable assignment and a goto statement (at the end)?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 12:10   ` Markus Elfring
@ 2024-05-06 12:16     ` Julia Lawall
  2024-05-06 12:40       ` Markus Elfring
  0 siblings, 1 reply; 36+ messages in thread
From: Julia Lawall @ 2024-05-06 12:16 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci



On Mon, 6 May 2024, Markus Elfring wrote:

> > Be more concrete about what you are not able to do.
>
> Would you find another specific search use case easier to clarify?
>
> Example:
> How would you like to determine that an if statement was specified three times
> within an function implementation while the corresponding compound statement
> should contain a variable assignment and a goto statement (at the end)?

If you really are concerned about three identical if statements plced
anywhere, you can record their positions and then count them.  But it
doesn't seem like a genuinely useful thing to do.

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 12:16     ` Julia Lawall
@ 2024-05-06 12:40       ` Markus Elfring
  0 siblings, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-06 12:40 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> Example:
>> How would you like to determine that an if statement was specified three times
>> within an function implementation while the corresponding compound statement
>> should contain a variable assignment and a goto statement (at the end)?
>
> If you really are concerned about three identical if statements plced anywhere,
It can be usual to repeat if statements which would be similar also because of
known design patterns like error detection and exception handling.


> you can record their positions and then count them.

The Coccinelle software counts source code parts already for the supported “Dot variants”,
doesn't it?

How do you think about extensions for SmPL quantifiers?


> But it doesn't seem like a genuinely useful thing to do.

The beginning of another source code analysis can help to achieve a better understanding
for desirable transformations.

Regards,
Markus


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 10:08 [cocci] Searching for repeated source code with SmPL? Markus Elfring
  2024-05-06 10:09 ` Julia Lawall
@ 2024-05-11  7:15 ` Markus Elfring
  2024-05-22  8:20 ` Markus Elfring
  2 siblings, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-11  7:15 UTC (permalink / raw)
  To: cocci

> Source code parts can occasionally be repeated.
>
> * Loops
>   The control flow can contain ordinary loops.
>
> * Recursion
>   A function may be called by itself.
>
>
> Such constructs trigger special consequences also for further data processing
> with higher level technologies.
>
> + Computation tree logic
>
> + Linear temporal logic
>
>
> I am still looking for clarifications so that the Coccinelle software
> can be applied in safer ways.

Would you like to acknowledge that data processing is influenced also
according to handling of loops and recursion by the means of the provided
technology “computation tree logic with variables and witnesses”?

Do you find a paper like “Cycle Detection in Computation Tree Logic”
interesting for corresponding adjustments?
https://www.fabiomogavero.com/publications/jarticles/2018/fmmps(ic18).pdf
https://dx.doi.org/10.1016/j.ic.2018.09.007

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 10:09 ` Julia Lawall
  2024-05-06 11:03   ` Markus Elfring
  2024-05-06 12:10   ` Markus Elfring
@ 2024-05-11 15:36   ` Markus Elfring
  2024-05-11 16:04     ` Julia Lawall
  2 siblings, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-11 15:36 UTC (permalink / raw)
  To: Julia Lawall, cocci

…
>> I would appreciate if multiple occurrences of code elements can be better detected
>> and transformed.
> Be more concrete about what you are not able to do.

I hope that indicated communication (and data processing) difficulties can be adjusted
a bit more.

See also another source code example:

void my_test(void)
{
 my_action(1);
 my_action(2);
 my_action(3);
}


See also a corresponding analysis approach by the means of a tiny script
for the semantic patch language:

@display@
@@
 my_action(...);
 <+...
*my_action(...);
 ...+>


Why is no diff output generated by the software combination “Coccinelle 1.2-00008-g75525032”
so far?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 15:36   ` Markus Elfring
@ 2024-05-11 16:04     ` Julia Lawall
  2024-05-11 16:35       ` Markus Elfring
  2024-05-12  6:48       ` Markus Elfring
  0 siblings, 2 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-11 16:04 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Julia Lawall, cocci

[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]



On Sat, 11 May 2024, Markus Elfring wrote:

> …
> >> I would appreciate if multiple occurrences of code elements can be better detected
> >> and transformed.
> …
> > Be more concrete about what you are not able to do.
>
> I hope that indicated communication (and data processing) difficulties can be adjusted
> a bit more.
>
> See also another source code example:
>
> void my_test(void)
> {
>  my_action(1);
>  my_action(2);
>  my_action(3);
> }
>
>
> See also a corresponding analysis approach by the means of a tiny script
> for the semantic patch language:
>
> @display@
> @@
>  my_action(...);
>  <+...
> *my_action(...);
>  ...+>
>
>
> Why is no diff output generated by the software combination “Coccinelle 1.2-00008-g75525032”
> so far?

Your semantic patch needs to be:

@display@
@@
 my_action(...);
 <+... when any
*my_action(...);
 ...+>

Without that, a call to my_action is forbidden in the region matched by
the <+... ...+>.  Because any kind of dot thing matches the shortest path
between what comes before and what comes after (here the end of the
function).

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 16:04     ` Julia Lawall
@ 2024-05-11 16:35       ` Markus Elfring
  2024-05-11 16:37         ` Julia Lawall
  2024-05-12  6:48       ` Markus Elfring
  1 sibling, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-11 16:35 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> Why is no diff output generated by the software combination “Coccinelle 1.2-00008-g75525032”
>> so far?
>
> Your semantic patch needs to be:
>
> @display@
> @@
>  my_action(...);
>  <+... when any
> *my_action(...);
>  ...+>
>
> Without that, a call to my_action is forbidden in the region matched by
> the <+... ...+>.  Because any kind of dot thing matches the shortest path
> between what comes before and what comes after (here the end of the function).

Thanks for this quick feedback.

It seems that we expect different data processing also for the shown test case.

The SmPL construct “<+... … ...+>” supports a search for code parts
which occur at least once.
Thus it seems that the specified search pattern needs be duplicated before
if you would like to find code which should occur at least twice.
I would appreciate if undesirable duplication of search patterns can be avoided here.

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 16:35       ` Markus Elfring
@ 2024-05-11 16:37         ` Julia Lawall
  2024-05-11 17:02           ` Markus Elfring
  0 siblings, 1 reply; 36+ messages in thread
From: Julia Lawall @ 2024-05-11 16:37 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]



On Sat, 11 May 2024, Markus Elfring wrote:

> >> Why is no diff output generated by the software combination “Coccinelle 1.2-00008-g75525032”
> >> so far?
> >
> > Your semantic patch needs to be:
> >
> > @display@
> > @@
> >  my_action(...);
> >  <+... when any
> > *my_action(...);
> >  ...+>
> >
> > Without that, a call to my_action is forbidden in the region matched by
> > the <+... ...+>.  Because any kind of dot thing matches the shortest path
> > between what comes before and what comes after (here the end of the function).
>
> Thanks for this quick feedback.
>
> It seems that we expect different data processing also for the shown test case.
>
> The SmPL construct “<+... … ...+>” supports a search for code parts
> which occur at least once.
> Thus it seems that the specified search pattern needs be duplicated before
> if you would like to find code which should occur at least twice.
> I would appreciate if undesirable duplication of search patterns can be avoided here.

If you want to find code that occurs at least twice, isn't it most natural
to make a pattern that shows the thing occurring twice?

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 16:37         ` Julia Lawall
@ 2024-05-11 17:02           ` Markus Elfring
  2024-05-11 17:12             ` Julia Lawall
  0 siblings, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-11 17:02 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> I would appreciate if undesirable duplication of search patterns can be avoided here.
>
> If you want to find code that occurs at least twice, isn't it most natural
> to make a pattern that shows the thing occurring twice?

Obviously, yes.

Our development views seem to differ in the desire to express such
a data processing task in a more succinct way also by the means of
the semantic patch language.

Which SmPL constructs can indicate a minimum occurrence number (≥ 2) accordingly?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 17:02           ` Markus Elfring
@ 2024-05-11 17:12             ` Julia Lawall
  2024-05-11 17:21               ` Markus Elfring
  0 siblings, 1 reply; 36+ messages in thread
From: Julia Lawall @ 2024-05-11 17:12 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 616 bytes --]



On Sat, 11 May 2024, Markus Elfring wrote:

> >> I would appreciate if undesirable duplication of search patterns can be avoided here.
> >
> > If you want to find code that occurs at least twice, isn't it most natural
> > to make a pattern that shows the thing occurring twice?
>
> Obviously, yes.
>
> Our development views seem to differ in the desire to express such
> a data processing task in a more succinct way also by the means of
> the semantic patch language.
>
> Which SmPL constructs can indicate a minimum occurrence number (≥ 2) accordingly?

There is no dedicated construct for that purpose.

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 17:12             ` Julia Lawall
@ 2024-05-11 17:21               ` Markus Elfring
  2024-05-11 17:33                 ` Julia Lawall
  0 siblings, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-11 17:21 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> Which SmPL constructs can indicate a minimum occurrence number (≥ 2) accordingly?
>
> There is no dedicated construct for that purpose.

Will chances grow to extend involved software components?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 17:21               ` Markus Elfring
@ 2024-05-11 17:33                 ` Julia Lawall
  0 siblings, 0 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-11 17:33 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]



On Sat, 11 May 2024, Markus Elfring wrote:

> >> Which SmPL constructs can indicate a minimum occurrence number (≥ 2) accordingly?
> >
> > There is no dedicated construct for that purpose.
>
> Will chances grow to extend involved software components?

No.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-11 16:04     ` Julia Lawall
  2024-05-11 16:35       ` Markus Elfring
@ 2024-05-12  6:48       ` Markus Elfring
  2024-05-12  7:34         ` Julia Lawall
  1 sibling, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-12  6:48 UTC (permalink / raw)
  To: Julia Lawall, cocci

> Your semantic patch needs to be:
>
> @display@
> @@
>  my_action(...);
>  <+... when any
> *my_action(...);
>  ...+>
>
> Without that, a call to my_action is forbidden in the region matched by
> the <+... ...+>.  Because any kind of dot thing matches the shortest path
> between what comes before and what comes after (here the end of the function).

Can the Coccinelle software inform better about the case that the shortest
path constraint was “accidentally overlooked” in a SmPL script?


There are further development challenges to consider.
See also a corresponding transformation approach by the means of
another tiny script for the semantic patch language:

@adjustment@
@@
 my_action(
-          ...
+          0
          );
 <+... when any
-my_action(...);
 ...+>


Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch use_one_test_call.cocci repeated_three_calls.c
…
previous modification:

  <<< 0
CONTEXT

According to environment 0:


current modification:
MINUS

According to environment 0:


adjustment: already tagged token:
C code context
File "repeated_three_calls.c", line 4, column 12, charpos = 48
  around = ')',
  whole content =  my_action(2);


Can the data processing be improved anyhow?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  6:48       ` Markus Elfring
@ 2024-05-12  7:34         ` Julia Lawall
  2024-05-12  8:01           ` Markus Elfring
  2024-05-12 11:24           ` Markus Elfring
  0 siblings, 2 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-12  7:34 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 1689 bytes --]



On Sun, 12 May 2024, Markus Elfring wrote:

> > Your semantic patch needs to be:
> >
> > @display@
> > @@
> >  my_action(...);
> >  <+... when any
> > *my_action(...);
> >  ...+>
> >
> > Without that, a call to my_action is forbidden in the region matched by
> > the <+... ...+>.  Because any kind of dot thing matches the shortest path
> > between what comes before and what comes after (here the end of the function).
>
> Can the Coccinelle software inform better about the case that the shortest
> path constraint was “accidentally overlooked” in a SmPL script?
>
>
> There are further development challenges to consider.
> See also a corresponding transformation approach by the means of
> another tiny script for the semantic patch language:
>
> @adjustment@
> @@
>  my_action(
> -          ...
> +          0
>           );
>  <+... when any
> -my_action(...);
>  ...+>
>
>
> Test result:
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch use_one_test_call.cocci repeated_three_calls.c
> …
> previous modification:
>
>   <<< 0
> CONTEXT
>
> According to environment 0:
>
>
> current modification:
> MINUS
>
> According to environment 0:
>
>
> adjustment: already tagged token:
> C code context
> File "repeated_three_calls.c", line 4, column 12, charpos = 48
>   around = ')',
>   whole content =  my_action(2);
>
>
> Can the data processing be improved anyhow?

The current semantic pach allows the first my_action to match anywhere,
including the second my_action, third, etc.  So if you have changes in
both, then there will be contradictory changes to the code.

Probably you should start with ... when != my_action(...) to be sure to
get the first one.

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  7:34         ` Julia Lawall
@ 2024-05-12  8:01           ` Markus Elfring
  2024-05-12  8:10             ` Julia Lawall
  2024-05-12 11:24           ` Markus Elfring
  1 sibling, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-12  8:01 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> Can the data processing be improved anyhow?
>
> The current semantic pach allows the first my_action to match anywhere,
> including the second my_action, third, etc.  So if you have changes in both,
> then there will be contradictory changes to the code.

I suggest to reconsider such information in more detail according to
the presented transformation approach.


> Probably you should start with ... when != my_action(...) to be sure to
> get the first one.

I would expect that only the first function call should be matched by
the initial SmPL search pattern (without an extra when constraint).
Should subsequent repeated calls be taken into account only for the shown
deletion attempt?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  8:01           ` Markus Elfring
@ 2024-05-12  8:10             ` Julia Lawall
  2024-05-12  8:33               ` Markus Elfring
  0 siblings, 1 reply; 36+ messages in thread
From: Julia Lawall @ 2024-05-12  8:10 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci



On Sun, 12 May 2024, Markus Elfring wrote:

> >> Can the data processing be improved anyhow?
> >
> > The current semantic pach allows the first my_action to match anywhere,
> > including the second my_action, third, etc.  So if you have changes in both,
> > then there will be contradictory changes to the code.
>
> I suggest to reconsider such information in more detail according to
> the presented transformation approach.
>
>
> > Probably you should start with ... when != my_action(...) to be sure to
> > get the first one.
>
> I would expect that only the first function call should be matched by
> the initial SmPL search pattern (without an extra when constraint).

Why would you expect that?  Coccinelle looks through your function and
matches the pattern anywhere it can.  The matches are independent of each
other.

julia

> Should subsequent repeated calls be taken into account only for the shown
> deletion attempt?
>
> Regards,
> Markus
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  8:10             ` Julia Lawall
@ 2024-05-12  8:33               ` Markus Elfring
  2024-05-12  9:17                 ` Julia Lawall
  0 siblings, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-12  8:33 UTC (permalink / raw)
  To: Julia Lawall, cocci

>>> Probably you should start with ... when != my_action(...) to be sure to
>>> get the first one.
>>
>> I would expect that only the first function call should be matched by
>> the initial SmPL search pattern (without an extra when constraint).
>
> Why would you expect that?

I expect here that specific source code starts a known statement list.


> Coccinelle looks through your function and matches the pattern anywhere it can.

Can this software distinguish also better statement sequences accordingly?


> The matches are independent of each other.

* They can occasionally occur in different scopes.

* Statement sequences (which include discussed repetitions) should be “interrupted”
  by other source code.

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  8:33               ` Markus Elfring
@ 2024-05-12  9:17                 ` Julia Lawall
  2024-05-12  9:30                   ` Markus Elfring
  2024-05-13  9:34                   ` Markus Elfring
  0 siblings, 2 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-12  9:17 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 1164 bytes --]



On Sun, 12 May 2024, Markus Elfring wrote:

> >>> Probably you should start with ... when != my_action(...) to be sure to
> >>> get the first one.
> >>
> >> I would expect that only the first function call should be matched by
> >> the initial SmPL search pattern (without an extra when constraint).
> >
> > Why would you expect that?
>
> I expect here that specific source code starts a known statement list.

Coccinelle takes a pattern expressed as a CTL formula and every node in
the control flow graph and tries to match the pattern at each node.  The
matching at one node is independent of the matching at another node.  If
there are conflicting matches that result in conflicting transformations,
then it generates an error message.

julia


>
>
> > Coccinelle looks through your function and matches the pattern anywhere it can.
>
> Can this software distinguish also better statement sequences accordingly?
>
>
> > The matches are independent of each other.
>
> * They can occasionally occur in different scopes.
>
> * Statement sequences (which include discussed repetitions) should be “interrupted”
>   by other source code.
>
> Regards,
> Markus
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  9:17                 ` Julia Lawall
@ 2024-05-12  9:30                   ` Markus Elfring
  2024-05-13  9:34                   ` Markus Elfring
  1 sibling, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-12  9:30 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> I expect here that specific source code starts a known statement list.
>
> Coccinelle takes a pattern expressed as a CTL formula and every node in
> the control flow graph and tries to match the pattern at each node.
> The matching at one node is independent of the matching at another node.
> If there are conflicting matches that result in conflicting transformations,
> then it generates an error message.

Do we stumble on conflicts for more desirable data processing also
according to involved computation tree logic variants?

The mentioned nodes should occasionally mark the beginning
and a corresponding end of a code sequence.
Will code sequences (as statement lists in the discussed test case)
become better supported in the way as known units (or building blocks)?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  7:34         ` Julia Lawall
  2024-05-12  8:01           ` Markus Elfring
@ 2024-05-12 11:24           ` Markus Elfring
  2024-05-12 12:53             ` Julia Lawall
  1 sibling, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-12 11:24 UTC (permalink / raw)
  To: Julia Lawall, cocci

> Probably you should start with ... when != my_action(...) to be sure to
> get the first one.

Should any SmPL search item which is specified at the beginning of
an SmPL rule be handled by the Coccinelle software as the first source
code filter also without an extra when constraint?

Can it be checked if such a primary condition is really evaluated
in the desired order?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12 11:24           ` Markus Elfring
@ 2024-05-12 12:53             ` Julia Lawall
  2024-05-12 13:07               ` Markus Elfring
  0 siblings, 1 reply; 36+ messages in thread
From: Julia Lawall @ 2024-05-12 12:53 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci



On Sun, 12 May 2024, Markus Elfring wrote:

> > Probably you should start with ... when != my_action(...) to be sure to
> > get the first one.
>
> Should any SmPL search item which is specified at the beginning of
> an SmPL rule be handled by the Coccinelle software as the first source
> code filter also without an extra when constraint?

No.  Surely you don't want that.  If you ask to replace all X's by Y, then
you normally want to replace all of them.

> Can it be checked if such a primary condition is really evaluated
> in the desired order?

No idea what this means.  "desired order" is just something that exists in
the head of the person who wrote the rule.  Coccinelle doesn't know that.

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12 12:53             ` Julia Lawall
@ 2024-05-12 13:07               ` Markus Elfring
  2024-05-12 13:13                 ` Julia Lawall
  0 siblings, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-12 13:07 UTC (permalink / raw)
  To: Julia Lawall, cocci

>>> Probably you should start with ... when != my_action(...) to be sure to
>>> get the first one.
>>
>> Should any SmPL search item which is specified at the beginning of
>> an SmPL rule be handled by the Coccinelle software as the first source
>> code filter also without an extra when constraint?
>
> No.  Surely you don't want that.  If you ask to replace all X's by Y,
> then you normally want to replace all of them.

Such a transformation depends on context code which should be replaced finally.


>> Can it be checked if such a primary condition is really evaluated
>> in the desired order?
>
> No idea what this means.  "desired order" is just something that exists in
> the head of the person who wrote the rule.  Coccinelle doesn't know that.

I am trying out to determine once more if the presented use case can work
also without an extra when constraint.

The following SmPL script variant can generate a reasonable diff output
for a test case.


@adjustment@
@@
 ... when != my_action(...)
 my_action(
-          ...
+          0
          );
 <+... when any
-my_action(...);
 ...+>


But I find the shown duplication of SmPL code questionable and therefore improvable.

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12 13:07               ` Markus Elfring
@ 2024-05-12 13:13                 ` Julia Lawall
  2024-05-12 13:22                   ` Markus Elfring
  2024-05-12 14:51                   ` Markus Elfring
  0 siblings, 2 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-12 13:13 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci



On Sun, 12 May 2024, Markus Elfring wrote:

> >>> Probably you should start with ... when != my_action(...) to be sure to
> >>> get the first one.
> >>
> >> Should any SmPL search item which is specified at the beginning of
> >> an SmPL rule be handled by the Coccinelle software as the first source
> >> code filter also without an extra when constraint?
> >
> > No.  Surely you don't want that.  If you ask to replace all X's by Y,
> > then you normally want to replace all of them.
>
> Such a transformation depends on context code which should be replaced finally.
>
>
> >> Can it be checked if such a primary condition is really evaluated
> >> in the desired order?
> >
> > No idea what this means.  "desired order" is just something that exists in
> > the head of the person who wrote the rule.  Coccinelle doesn't know that.
>
> I am trying out to determine once more if the presented use case can work
> also without an extra when constraint.
>
> The following SmPL script variant can generate a reasonable diff output
> for a test case.
>
>
> @adjustment@
> @@
>  ... when != my_action(...)
>  my_action(
> -          ...
> +          0
>           );
>  <+... when any
> -my_action(...);
>  ...+>
>
>
> But I find the shown duplication of SmPL code questionable and therefore improvable.

The language is as it is.  You can express various things by adding more
or less information.

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12 13:13                 ` Julia Lawall
@ 2024-05-12 13:22                   ` Markus Elfring
  2024-05-12 14:51                   ` Markus Elfring
  1 sibling, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-12 13:22 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> @adjustment@
>> @@
>>  ... when != my_action(...)
>>  my_action(
>> -          ...
>> +          0
>>           );
>>  <+... when any
>> -my_action(...);
>>  ...+>
>>
>>
>> But I find the shown duplication of SmPL code questionable and therefore improvable.
>
> The language is as it is.  You can express various things by adding more
> or less information.

I got the impression that undesirable software limitations are indicated here.

See also the software development principle “Do not repeat yourself”:
https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12 13:13                 ` Julia Lawall
  2024-05-12 13:22                   ` Markus Elfring
@ 2024-05-12 14:51                   ` Markus Elfring
  2024-05-12 14:57                     ` Julia Lawall
  1 sibling, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-12 14:51 UTC (permalink / raw)
  To: Julia Lawall, cocci

> The language is as it is.  You can express various things by adding more
> or less information.

The previous SmPL script example indicated special SmPL code design possibilities.
Thus I would like to apply such development experiences to another SmPL script variant.


// See also:
// qca_read_fw_build_info()
// drivers/bluetooth/btqca.c
@replacement@
identifier exit, result;
statement s;
@@
 ... when != if (...) { ... when any result = -EILSEQ; goto exit; }
(if (...)
-{
-   result = -EILSEQ;
    goto
-        exit
+        e_ilseq
    ;
-}
|if (...)
 {
 ... when any
-   result = -EILSEQ;
    goto
-        exit
+        e_ilseq
    ;
 }
)
 ...
 exit:
 s
 return result;
+
+e_ilseq:
+result = -EILSEQ;
+goto exit;


Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_common_code_for_EILSEQ-4.cocci
…
minus: parse error:
  File "use_common_code_for_EILSEQ-4.cocci", line 8, column 37, charpos = 162
  around = 'result',
  whole content =  ... when != if (...) { ... when any result = -EILSEQ; goto exit; }


Unfortunately, it seems that I stumble once more on questionable software limitations.

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12 14:51                   ` Markus Elfring
@ 2024-05-12 14:57                     ` Julia Lawall
  0 siblings, 0 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-12 14:57 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 1364 bytes --]



On Sun, 12 May 2024, Markus Elfring wrote:

> > The language is as it is.  You can express various things by adding more
> > or less information.
>
> The previous SmPL script example indicated special SmPL code design possibilities.
> Thus I would like to apply such development experiences to another SmPL script variant.
>
>
> // See also:
> // qca_read_fw_build_info()
> // drivers/bluetooth/btqca.c
> @replacement@
> identifier exit, result;
> statement s;
> @@
>  ... when != if (...) { ... when any result = -EILSEQ; goto exit; }

There is currently no way to nest whens.

julia

> (if (...)
> -{
> -   result = -EILSEQ;
>     goto
> -        exit
> +        e_ilseq
>     ;
> -}
> |if (...)
>  {
>  ... when any
> -   result = -EILSEQ;
>     goto
> -        exit
> +        e_ilseq
>     ;
>  }
> )
>  ...
>  exit:
>  s
>  return result;
> +
> +e_ilseq:
> +result = -EILSEQ;
> +goto exit;
>
>
> Test result:
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/janitor> spatch --parse-cocci use_common_code_for_EILSEQ-4.cocci
> …
> minus: parse error:
>   File "use_common_code_for_EILSEQ-4.cocci", line 8, column 37, charpos = 162
>   around = 'result',
>   whole content =  ... when != if (...) { ... when any result = -EILSEQ; goto exit; }
>
>
> Unfortunately, it seems that I stumble once more on questionable software limitations.
>
> Regards,
> Markus
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-12  9:17                 ` Julia Lawall
  2024-05-12  9:30                   ` Markus Elfring
@ 2024-05-13  9:34                   ` Markus Elfring
  1 sibling, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-13  9:34 UTC (permalink / raw)
  To: Julia Lawall, cocci

>> I expect here that specific source code starts a known statement list.
>
> Coccinelle takes a pattern expressed as a CTL formula and every node in
> the control flow graph and tries to match the pattern at each node.
…

Which filter criteria does the applied computation tree logic variant need
to recognise an item as the beginning of a sequence?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-06 10:08 [cocci] Searching for repeated source code with SmPL? Markus Elfring
  2024-05-06 10:09 ` Julia Lawall
  2024-05-11  7:15 ` Markus Elfring
@ 2024-05-22  8:20 ` Markus Elfring
  2024-05-22  8:24   ` Julia Lawall
  2 siblings, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-22  8:20 UTC (permalink / raw)
  To: cocci

> Source code parts can occasionally be repeated.

Would you like to clarify how the data processing for scripts of
the semantic patch language should be influenced by the program
parameter “--no-loops”?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/477e7e12478bd317aa97ee79857d185601ab6f33/docs/manual/spatch_options.tex#L365
https://github.com/coccinelle/coccinelle/blob/477e7e12478bd317aa97ee79857d185601ab6f33/docs/manual/spatch_options.tex#L365

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-22  8:20 ` Markus Elfring
@ 2024-05-22  8:24   ` Julia Lawall
  2024-05-22  8:44     ` Markus Elfring
  2024-05-22 13:12     ` Markus Elfring
  0 siblings, 2 replies; 36+ messages in thread
From: Julia Lawall @ 2024-05-22  8:24 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci

[-- Attachment #1: Type: text/plain, Size: 620 bytes --]



On Wed, 22 May 2024, Markus Elfring wrote:

> > Source code parts can occasionally be repeated.
>
> Would you like to clarify how the data processing for scripts of
> the semantic patch language should be influenced by the program
> parameter “--no-loops”?
> https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/477e7e12478bd317aa97ee79857d185601ab6f33/docs/manual/spatch_options.tex#L365
> https://github.com/coccinelle/coccinelle/blob/477e7e12478bd317aa97ee79857d185601ab6f33/docs/manual/spatch_options.tex#L365

--noloops mean that the back edge of a loop is ignored.  It can greatly
reduce running time.

julia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-22  8:24   ` Julia Lawall
@ 2024-05-22  8:44     ` Markus Elfring
  2024-05-22 13:12     ` Markus Elfring
  1 sibling, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-22  8:44 UTC (permalink / raw)
  To: Julia Lawall, cocci

>>> Source code parts can occasionally be repeated.
>>
>> Would you like to clarify how the data processing for scripts of
>> the semantic patch language should be influenced by the program
>> parameter “--no-loops”?
>> https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/477e7e12478bd317aa97ee79857d185601ab6f33/docs/manual/spatch_options.tex#L365
>> https://github.com/coccinelle/coccinelle/blob/477e7e12478bd317aa97ee79857d185601ab6f33/docs/manual/spatch_options.tex#L365
>
> --noloops mean that the back edge of a loop is ignored.

Do “back edges” occasionally need special treatment according to the evaluation
of computation tree logic variants?


> It can greatly reduce running time.

Such information is good to know for more desirable run time characteristics.

* Will the software evolve any further also for better detection of
  duplicate source code?

* How good are statement sequences actually handled so far?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-22  8:24   ` Julia Lawall
  2024-05-22  8:44     ` Markus Elfring
@ 2024-05-22 13:12     ` Markus Elfring
  2024-05-22 15:34       ` Julia Lawall
  1 sibling, 1 reply; 36+ messages in thread
From: Markus Elfring @ 2024-05-22 13:12 UTC (permalink / raw)
  To: Julia Lawall, cocci

> --noloops mean that the back edge of a loop is ignored.

Should the program parameter “--no-loops” influence also the handling
of Linux “iterators” (like “list_for_each_entry_safe”) anyhow?

Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-22 13:12     ` Markus Elfring
@ 2024-05-22 15:34       ` Julia Lawall
  2024-05-22 16:06         ` Markus Elfring
  0 siblings, 1 reply; 36+ messages in thread
From: Julia Lawall @ 2024-05-22 15:34 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Julia Lawall, cocci

[-- Attachment #1: Type: text/plain, Size: 266 bytes --]



On Wed, 22 May 2024, Markus Elfring wrote:

> > --noloops mean that the back edge of a loop is ignored.
>
> Should the program parameter “--no-loops” influence also the handling
> of Linux “iterators” (like “list_for_each_entry_safe”) anyhow?

No idea.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [cocci] Searching for repeated source code with SmPL?
  2024-05-22 15:34       ` Julia Lawall
@ 2024-05-22 16:06         ` Markus Elfring
  0 siblings, 0 replies; 36+ messages in thread
From: Markus Elfring @ 2024-05-22 16:06 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

>>> --noloops mean that the back edge of a loop is ignored.
>>
>> Should the program parameter “--no-loops” influence also the handling
>> of Linux “iterators” (like “list_for_each_entry_safe”) anyhow?
>
> No idea.

How do you think about to take another look at further diff outputs
which can be generated by a simple SmPL script example?

Analysing statement sequences in consistent ways (with SmPL)?
https://lore.kernel.org/cocci/4c2812f7-d54d-412b-ac79-c650ceedcecd@web.de/
https://sympa.inria.fr/sympa/arc/cocci/2024-05/msg00076.html


Source files for corresponding clarification opportunities:

* ath6kl_set_multicast_list()
  https://elixir.bootlin.com/linux/v6.9.1/source/drivers/net/wireless/ath/ath6kl/main.c#L1232

* batadv_frag_merge_packets()
  https://elixir.bootlin.com/linux/v6.9.1/source/net/batman-adv/fragmentation.c#L258

* iavf_reset_task()
  https://elixir.bootlin.com/linux/v6.9.1/source/drivers/net/ethernet/intel/iavf/iavf_main.c#L3097

* bch_pending_bdevs_cleanup()
  https://elixir.bootlin.com/linux/v6.9.1/source/drivers/md/bcache/super.c#L2691


Regards,
Markus

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2024-05-22 16:06 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 10:08 [cocci] Searching for repeated source code with SmPL? Markus Elfring
2024-05-06 10:09 ` Julia Lawall
2024-05-06 11:03   ` Markus Elfring
2024-05-06 12:10   ` Markus Elfring
2024-05-06 12:16     ` Julia Lawall
2024-05-06 12:40       ` Markus Elfring
2024-05-11 15:36   ` Markus Elfring
2024-05-11 16:04     ` Julia Lawall
2024-05-11 16:35       ` Markus Elfring
2024-05-11 16:37         ` Julia Lawall
2024-05-11 17:02           ` Markus Elfring
2024-05-11 17:12             ` Julia Lawall
2024-05-11 17:21               ` Markus Elfring
2024-05-11 17:33                 ` Julia Lawall
2024-05-12  6:48       ` Markus Elfring
2024-05-12  7:34         ` Julia Lawall
2024-05-12  8:01           ` Markus Elfring
2024-05-12  8:10             ` Julia Lawall
2024-05-12  8:33               ` Markus Elfring
2024-05-12  9:17                 ` Julia Lawall
2024-05-12  9:30                   ` Markus Elfring
2024-05-13  9:34                   ` Markus Elfring
2024-05-12 11:24           ` Markus Elfring
2024-05-12 12:53             ` Julia Lawall
2024-05-12 13:07               ` Markus Elfring
2024-05-12 13:13                 ` Julia Lawall
2024-05-12 13:22                   ` Markus Elfring
2024-05-12 14:51                   ` Markus Elfring
2024-05-12 14:57                     ` Julia Lawall
2024-05-11  7:15 ` Markus Elfring
2024-05-22  8:20 ` Markus Elfring
2024-05-22  8:24   ` Julia Lawall
2024-05-22  8:44     ` Markus Elfring
2024-05-22 13:12     ` Markus Elfring
2024-05-22 15:34       ` Julia Lawall
2024-05-22 16:06         ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).