Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Concerns around type safety for usage of expressions
@ 2019-11-22  9:24 Markus Elfring
  2019-11-22  9:27 ` Julia Lawall
  0 siblings, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2019-11-22  9:24 UTC (permalink / raw)
  To: Coccinelle

Hello,

The semantic patch language supports source code searches also for uses
of specific data types. Such restricted searches can occasionally be nice.
But we would like to find more software variations often enough.
The consequence is that metavariables of the kind “expression” will usually
be applied. But it becomes uncertain then to which data types the found
expressions will be resolved finally.

We would like to achieve considerably safe software transformations.
Use cases occur then where the correct application of data types
is essential. (The introduction of false positives is undesirable here.)

How much can SmPL scripts help for corresponding changes?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22  9:24 [Cocci] Concerns around type safety for usage of expressions Markus Elfring
@ 2019-11-22  9:27 ` Julia Lawall
  2019-11-22  9:45   ` Markus Elfring
  0 siblings, 1 reply; 16+ messages in thread
From: Julia Lawall @ 2019-11-22  9:27 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

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



On Fri, 22 Nov 2019, Markus Elfring wrote:

> Hello,
>
> The semantic patch language supports source code searches also for uses
> of specific data types. Such restricted searches can occasionally be nice.
> But we would like to find more software variations often enough.
> The consequence is that metavariables of the kind “expression” will usually
> be applied. But it becomes uncertain then to which data types the found
> expressions will be resolved finally.
>
> We would like to achieve considerably safe software transformations.
> Use cases occur then where the correct application of data types
> is essential. (The introduction of false positives is undesirable here.)
>
> How much can SmPL scripts help for corresponding changes?

You can specify the type of an expression rather than just expression.

The ability of Coccinlle to find the types depends on whether header files
are needed and whether Coccinelle can find those header files.

If a type is specified and Coccinelle cannot detetermine that an
expression has the required type, the match will fail.

julia

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22  9:27 ` Julia Lawall
@ 2019-11-22  9:45   ` Markus Elfring
  2019-11-22  9:50     ` Julia Lawall
  0 siblings, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2019-11-22  9:45 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

> You can specify the type of an expression rather than just expression.

How is this approach different from the search for “specific data types”
(which I know already)?

I came along an use case where a generic source code search can find
update candidates. But it would be nice if safety concerns can be handled
then by using the determined data types somehow.

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22  9:45   ` Markus Elfring
@ 2019-11-22  9:50     ` Julia Lawall
  2019-11-22 10:00       ` Markus Elfring
  0 siblings, 1 reply; 16+ messages in thread
From: Julia Lawall @ 2019-11-22  9:50 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

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



On Fri, 22 Nov 2019, Markus Elfring wrote:

> > You can specify the type of an expression rather than just expression.
>
> How is this approach different from the search for “specific data types”
> (which I know already)?

I have no idea what you are referring to.

julia

>
> I came along an use case where a generic source code search can find
> update candidates. But it would be nice if safety concerns can be handled
> then by using the determined data types somehow.
>
> Regards,
> Markus
>

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22  9:50     ` Julia Lawall
@ 2019-11-22 10:00       ` Markus Elfring
  2019-11-22 10:34         ` Julia Lawall
  0 siblings, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2019-11-22 10:00 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

>>> You can specify the type of an expression rather than just expression.
>>
>> How is this approach different from the search for “specific data types”
>> (which I know already)?
>
> I have no idea what you are referring to.

Do you find it easier to clarify transformation possibilities around
applications of a macro like “COPY_ARRAY”?
https://github.com/git/git/blob/d966095db01190a2196e31195ea6fa0c722aa732/git-compat-util.h#L889

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22 10:00       ` Markus Elfring
@ 2019-11-22 10:34         ` Julia Lawall
  2019-11-22 10:44           ` Markus Elfring
  0 siblings, 1 reply; 16+ messages in thread
From: Julia Lawall @ 2019-11-22 10:34 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

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



On Fri, 22 Nov 2019, Markus Elfring wrote:

> >>> You can specify the type of an expression rather than just expression.
> >>
> >> How is this approach different from the search for “specific data types”
> >> (which I know already)?
> >
> > I have no idea what you are referring to.
>
> Do you find it easier to clarify transformation possibilities around
> applications of a macro like “COPY_ARRAY”?
> https://github.com/git/git/blob/d966095db01190a2196e31195ea6fa0c722aa732/git-compat-util.h#L889

I still don't understand what you are asking.  Maybe it would be more
understandable if you would propose a semantic patch.

julia

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22 10:34         ` Julia Lawall
@ 2019-11-22 10:44           ` Markus Elfring
       [not found]             ` <alpine.DEB.2.21.1911221155320.2793@hadrien>
  0 siblings, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2019-11-22 10:44 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

>> Do you find it easier to clarify transformation possibilities around
>> applications of a macro like “COPY_ARRAY”?
>> https://github.com/git/git/blob/d966095db01190a2196e31195ea6fa0c722aa732/git-compat-util.h#L889
>
> I still don't understand what you are asking.

I hope that also this communication difficulty will be resolved.


> Maybe it would be more understandable if you would propose a semantic patch.

Some SmPL scripts are still in corresponding review queues.

Another example:
“[PATCH] coccinelle: improve array.cocci” from 2019-11-18
https://public-inbox.org/git/0d9cf772-268d-bd00-1cbb-0bbbec9dfc9a@web.de/

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
       [not found]             ` <alpine.DEB.2.21.1911221155320.2793@hadrien>
@ 2019-11-22 11:20               ` Markus Elfring
  2019-11-22 12:53                 ` Julia Lawall
  0 siblings, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2019-11-22 11:20 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

>> Another example:
>> “[PATCH] coccinelle: improve array.cocci” from 2019-11-18
>> https://public-inbox.org/git/0d9cf772-268d-bd00-1cbb-0bbbec9dfc9a@web.de/
>
> OK, so you already know how to express type constraints for things.

Where do you see that I did this?


> So what are you actually asking?

I hope that another clarification variant can also help.

How can the C data type be determined for an expression metavariable
so that it could be used for subsequent source code searches?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22 11:20               ` Markus Elfring
@ 2019-11-22 12:53                 ` Julia Lawall
  2019-11-22 13:17                   ` Markus Elfring
  2019-11-22 14:56                   ` Markus Elfring
  0 siblings, 2 replies; 16+ messages in thread
From: Julia Lawall @ 2019-11-22 12:53 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

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



On Fri, 22 Nov 2019, Markus Elfring wrote:

> >> Another example:
> >> “[PATCH] coccinelle: improve array.cocci” from 2019-11-18
> >> https://public-inbox.org/git/0d9cf772-268d-bd00-1cbb-0bbbec9dfc9a@web.de/
> >
> > OK, so you already know how to express type constraints for things.
>
> Where do you see that I did this?

T *ptr for example.

>
>
> > So what are you actually asking?
>
> I hope that another clarification variant can also help.
>
> How can the C data type be determined for an expression metavariable
> so that it could be used for subsequent source code searches?

@@
type T;
T x;
@@

Now after matching x, you can use both x and T.  If Coccinelle cannot
figure out the type of an expression, x will not be able to match that
expression.

julia

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22 12:53                 ` Julia Lawall
@ 2019-11-22 13:17                   ` Markus Elfring
  2019-11-22 14:56                   ` Markus Elfring
  1 sibling, 0 replies; 16+ messages in thread
From: Markus Elfring @ 2019-11-22 13:17 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

>>>> Another example:
>>>> “[PATCH] coccinelle: improve array.cocci” from 2019-11-18
>>>> https://public-inbox.org/git/0d9cf772-268d-bd00-1cbb-0bbbec9dfc9a@web.de/
>>>
>>> OK, so you already know how to express type constraints for things.
>>
>> Where do you see that I did this?
>
> T *ptr for example.

It seems that you saw a a bit of SmPL code which I proposed to delete.

I suggest to take another look at the corresponding discussion.
https://public-inbox.org/git/d291ec11-c0f3-2918-193d-49fcbd65a18e@web.de/


I assume that this feedback might fit also to the clarification request
for the topic “Data processing with pointer types/expressions”.
https://lore.kernel.org/cocci/f1522779-5d10-a1d1-0555-795af612d8b3@web.de/
https://systeme.lip6.fr/pipermail/cocci/2019-November/006609.html


>> How can the C data type be determined for an expression metavariable
>> so that it could be used for subsequent source code searches?
>
> @@
> type T;
> T x;
> @@
>
> Now after matching x, you can use both x and T.

Such information can be fine itself.


> If Coccinelle cannot figure out the type of an expression,
> x will not be able to match that expression.

This aspect can become more interesting.

* Do you suggest here to use such type metavariables together with
  expression metavariables?

* Can the data type determination become better documented?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22 12:53                 ` Julia Lawall
  2019-11-22 13:17                   ` Markus Elfring
@ 2019-11-22 14:56                   ` Markus Elfring
  2019-11-22 15:10                     ` Julia Lawall
  1 sibling, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2019-11-22 14:56 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

> T *ptr for example.

1. Does this information for a “type constraint” distract from my questions?

2. Can the data type become restricted not only by the detail
   that it refers to a pointer?

3. Why should such a SmPL specification matter for the handling of expressions?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22 14:56                   ` Markus Elfring
@ 2019-11-22 15:10                     ` Julia Lawall
  2019-11-22 15:19                       ` Markus Elfring
  2019-11-23  7:55                       ` [Cocci] Checking influence of variability with SmPL Markus Elfring
  0 siblings, 2 replies; 16+ messages in thread
From: Julia Lawall @ 2019-11-22 15:10 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

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



On Fri, 22 Nov 2019, Markus Elfring wrote:

> > T *ptr for example.
>
> 1. Does this information for a “type constraint” distract from my questions?
>
> 2. Can the data type become restricted not only by the detail
>    that it refers to a pointer?

You can put any type, such as int x;.  You can also put parts of types
such as expression * x; or struct x;

>
> 3. Why should such a SmPL specification matter for the handling of
> expressions?

Only expressions have types.

julia

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Concerns around type safety for usage of expressions
  2019-11-22 15:10                     ` Julia Lawall
@ 2019-11-22 15:19                       ` Markus Elfring
  2019-11-23  7:55                       ` [Cocci] Checking influence of variability with SmPL Markus Elfring
  1 sibling, 0 replies; 16+ messages in thread
From: Markus Elfring @ 2019-11-22 15:19 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

>> 2. Can the data type become restricted not only by the detail
>>    that it refers to a pointer?
>
> You can put any type, such as int x;.  You can also put parts of types
> such as expression * x; or struct x;

This information fits to my wording for restricted searches, doesn't it?


>> 3. Why should such a SmPL specification matter for the handling of
>> expressions?
>
> Only expressions have types.

I can agree to this information mostly.
(“Types” can become relevant also for other items.)

Does the Coccinelle software know the corresponding data type then?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Checking influence of variability with SmPL
  2019-11-22 15:10                     ` Julia Lawall
  2019-11-22 15:19                       ` Markus Elfring
@ 2019-11-23  7:55                       ` Markus Elfring
  2019-11-23 19:36                         ` Julia Lawall
  1 sibling, 1 reply; 16+ messages in thread
From: Markus Elfring @ 2019-11-23  7:55 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

Hello,

Metavariables of the semantic patch language provide common information.

1. A fixed type (or kind)
2. An entity which can be variable.

These properties can be distinguished further.

Another example:
char c;

Such SmPL code looks like the specification of a fixed data type selection for
the C programming language.
Do you know anything that could be still variable for such an item?

The situation is different for metavariable kinds like the following.

* identifier
* struct
* expression


We would like to achieve source code transformations which can be compiled
(or not). How often will it matter then how these selections will be applied?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Checking influence of variability with SmPL
  2019-11-23  7:55                       ` [Cocci] Checking influence of variability with SmPL Markus Elfring
@ 2019-11-23 19:36                         ` Julia Lawall
  2019-11-24 10:40                           ` Markus Elfring
  0 siblings, 1 reply; 16+ messages in thread
From: Julia Lawall @ 2019-11-23 19:36 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Coccinelle

On Sat, 23 Nov 2019, Markus Elfring wrote:

> Hello,
>
> Metavariables of the semantic patch language provide common information.
>
> 1. A fixed type (or kind)
> 2. An entity which can be variable.
>
> These properties can be distinguished further.
>
> Another example:
> char c;
>
> Such SmPL code looks like the specification of a fixed data type selection for
> the C programming language.
> Do you know anything that could be still variable for such an item?

What do you mean by still variable?  c can match 'a' 'b' 'x', etc.  It can
also match a variable that has type char or a function call that returns a
value of type char, etc.  There are a lot of possibilities.

>
> The situation is different for metavariable kinds like the following.
>
> * identifier
> * struct
> * expression

An expression metavariable matches an expression of any type.  A struct
metavariable matches an expression that has struct type (for any struct
type).  A char metavariable matches an expression that has char type.

identifier doesn't fit in this discussion.  It only matches identifiers,
not arbitrary expressions.

> We would like to achieve source code transformations which can be compiled
> (or not).

No idea what you mean by compiled.  Compiled by what compiler?

> How often will it matter then how these selections will be applied?

What selections?

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Checking influence of variability with SmPL
  2019-11-23 19:36                         ` Julia Lawall
@ 2019-11-24 10:40                           ` Markus Elfring
  0 siblings, 0 replies; 16+ messages in thread
From: Markus Elfring @ 2019-11-24 10:40 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

> An expression metavariable matches an expression of any type.

Thanks for such an acknowledgement.

* Can this fact trigger corresponding challenges for safe transformations
  by the semantic patch language?

* Would you occasionally like to determine the corresponding data type then?


> A struct metavariable matches an expression that has struct type (for any
> struct type).  A char metavariable matches an expression that has char type.

I find this information very interesting for further clarification.

* Is a data type conversion performed by the Coccinelle software?

* Where should the explanation be found in the documentation for such
  software behaviour?


> identifier doesn't fit in this discussion.  It only matches identifiers,
> not arbitrary expressions.

I find that this metavariable will handle more variations for an item
by itself than the specification of a single C data type according to
this attempt for a property comparison.


>> We would like to achieve source code transformations which can be compiled
>> (or not).
>
> No idea what you mean by compiled.

I wonder about such a feedback.


> Compiled by what compiler?

You can choose an appropriate program, can't you?


>> How often will it matter then how these selections will be applied?
>
> What selections?

The source code will be filtered according to the specified metavariables.

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, back to index

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22  9:24 [Cocci] Concerns around type safety for usage of expressions Markus Elfring
2019-11-22  9:27 ` Julia Lawall
2019-11-22  9:45   ` Markus Elfring
2019-11-22  9:50     ` Julia Lawall
2019-11-22 10:00       ` Markus Elfring
2019-11-22 10:34         ` Julia Lawall
2019-11-22 10:44           ` Markus Elfring
     [not found]             ` <alpine.DEB.2.21.1911221155320.2793@hadrien>
2019-11-22 11:20               ` Markus Elfring
2019-11-22 12:53                 ` Julia Lawall
2019-11-22 13:17                   ` Markus Elfring
2019-11-22 14:56                   ` Markus Elfring
2019-11-22 15:10                     ` Julia Lawall
2019-11-22 15:19                       ` Markus Elfring
2019-11-23  7:55                       ` [Cocci] Checking influence of variability with SmPL Markus Elfring
2019-11-23 19:36                         ` Julia Lawall
2019-11-24 10:40                           ` Markus Elfring

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git