Improving support for code positions with opposite SmPL dependencies
Hello,
I suggest to take another look at questionable data processing according to a script variant (like the following) for the semantic patch language also together with the software combination “Coccinelle 1.1.1-00676-g99513ec1”.
@find disable decl_init@
identifier var;
position call_pos, declaration_pos;
type t;
@@
t * var@declaration_pos;
... when != var
my_test@call_pos(&var)
@test_switch disable decl_init@
identifier find.var;
position find.call_pos, find.declaration_pos;
type find.t;
@@
t * var@declaration_pos;
... when != var
my_test@call_pos(&var)
<+... var ...+>
@adjustment1 depends on test_switch@
position find.call_pos;
@@
-my_test@call_pos
+test_case1
@adjustment2 depends on !test_switch disable decl_init@ identifier find.var;
position find.call_pos, find.declaration_pos; type find.t;
@@
-t * var@declaration_pos;
... when != var
-my_test@call_pos
+test_case2
(
-&var
)
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci test2-switch_opposite_dependencies-20240208.cocci …
meta: semantic error: position cannot be inherited over modifications: call_pos
File "test2-switch_opposite_dependencies-20240208.cocci", line 28, column 44, charpos = 572
around = ';',
whole content = position find.call_pos, find.declaration_pos;
Will source code transformations become better supported according to opposite SmPL dependencies?
By the way:
I observed also that another test case can work as expected (in principle) if the specification “virtual test_switch” is used instead of the shown second SmPL rule.
Regards,
Markus
Quoted 16 lines · Markus Elfring
Hello,
I suggest to take another look at questionable data processing according to a script variant (like the following) for the semantic patch language also together with the software combination “Coccinelle 1.1.1-00676-g99513ec1”.
@find disable decl_init@
identifier var;
positioncall_pos,declaration_pos;
type t;
@@
t * var@declaration_pos;
... when != var
my_test@call_pos(&var)
Quoted 9 lines
@test_switch disable decl_init@
identifier find.var;
position find.call_pos, find.declaration_pos;
type find.t;
@@
t * var@declaration_pos;
... when != var
my_test@call_pos(&var)
<+... var ...+>
I have no idea what "questionable data processing" could mean.
I don't really know what you are trying to do, but the:
<+... var ...+>
seems unnecessary. Maybe just
... when exists
var
Furthermore, I don't see the point of repeating:
t * var@declaration_pos;
... when != var
Once you have the position call_pos, I don't think that adds anything.
Likewise in the adjustment2 rule below.
julia
Quoted 41 lines
@adjustment1 depends on test_switch@
position find.call_pos;
@@(quoted diff) +1
-1-my_test@call_pos +test_case1@adjustment2 depends on !test_switch disable decl_init@ identifier find.var;
position find.call_pos, find.declaration_pos; type find.t;
@@(quoted diff) +1
-3-t * var@declaration_pos; ... when != var -my_test@call_pos +test_case2 ( -&var )Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci
test2-switch_opposite_dependencies-20240208.cocci…
meta: semantic error: position cannot be inherited over modifications:call_pos
File "test2-switch_opposite_dependencies-20240208.cocci", line 28, column 44, charpos = 572
around = ';',
whole content = position find.call_pos, find.declaration_pos;Will source code transformations become better supported according to opposite SmPL dependencies?
By the way:
I observed also that another test case can work as expected (in principle) if the specification “virtual test_switch” is used instead of the shown second SmPL rule.Regards,
Markus
Quoted 8 lines
I don't really know what you are trying to do, but the:
<+... var ...+>
seems unnecessary. Maybe just
... when exists
var
Would such source code search specifications be equivalent finally?
Quoted 8 lines
Furthermore, I don't see the point of repeating:
t * var@declaration_pos;
... when != varOnce you have the position
call_pos, I don't think that adds anything.Likewise in the adjustment2 rule below.
This development concern is more relevant for the clarification approach “Supporting transformations better according to reduced number of function call parameters”.
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2024-02/msg00017.html
Quoted 10 lines
Quoted 10 lines
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci
test2-switch_opposite_dependencies-20240208.cocci…
meta: semantic error: position cannot be inherited over modifications:call_pos
File "test2-switch_opposite_dependencies-20240208.cocci", line 28, column 44, charpos = 572
around = ';',
whole content = position find.call_pos, find.declaration_pos;Will source code transformations become better supported according to opposite SmPL dependencies?
I would appreciate more constructive feedback for this test result.
Regards,
Markus
Quoted 35 lines · Markus Elfring
Quoted 8 lines
I don't really know what you are trying to do, but the:
<+... var ...+>
seems unnecessary. Maybe just
... when exists
varWould such source code search specifications be equivalent finally?
Quoted 8 lines
Furthermore, I don't see the point of repeating:
t * var@declaration_pos;
... when != varOnce you have the position
call_pos, I don't think that adds anything.Likewise in the adjustment2 rule below.
This development concern is more relevant for the clarification approach “Supporting transformations better according to reduced number of function call parameters”.
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2024-02/msg00017.htmlQuoted 8 lines
Quoted 8 lines
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci
test2-switch_opposite_dependencies-20240208.cocci…
meta: semantic error: position cannot be inherited over modifications:call_pos
File "test2-switch_opposite_dependencies-20240208.cocci", line 28, column 44, charpos = 572
around = ';',
whole content = position find.call_pos, find.declaration_pos;
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Will source code transformations become better supported according to opposite SmPL dependencies?
I would appreciate more constructive feedback for this test result.
Once you make transformations, the positions of the changed code have changed.
julia
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci
test2-switch_opposite_dependencies-20240208.cocci…
meta: semantic error: position cannot be inherited over modifications:call_pos
File "test2-switch_opposite_dependencies-20240208.cocci", line 28, column 44, charpos = 572
around = ';',
whole content = position find.call_pos, find.declaration_pos;
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Will source code transformations become better supported according to opposite SmPL dependencies?
I would appreciate more constructive feedback for this test result.
Once you make transformations, the positions of the changed code have changed.
I propose to take the specification “adjustment2 depends on !test_switch” better into account .
This case distinction is already working as expected for the specification “virtual test_switch” according to another test case variant.
How will the handling of “if … else …” constructs evolve further for SmPL code?
Regards,
Markus
Quoted 13 lines · Markus Elfring
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci
test2-switch_opposite_dependencies-20240208.cocci…
meta: semantic error: position cannot be inherited over modifications:call_pos
File "test2-switch_opposite_dependencies-20240208.cocci", line 28, column 44, charpos = 572
around = ';',
whole content = position find.call_pos, find.declaration_pos;Will source code transformations become better supported according to opposite SmPL dependencies?
I would appreciate more constructive feedback for this test result.
Quoted 7 lines
Quoted 2 lines
Once you make transformations, the positions of the changed code have changed.
I propose to take the specification “adjustment2 depends on !test_switch” better into account .
This case distinction is already working as expected for the specification “virtual test_switch” according to another test case variant.
And? The fact that one case is the negation of the other doesn't do anything to imply that eg multiple matches cannot occur in the same function.
Quoted 1 line
How will the handling of “if … else …” constructs evolve further for SmPL code?
It won't.
julia
Quoted 20 lines · Julia Lawall
Quoted 16 lines · Markus Elfring
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci
test2-switch_opposite_dependencies-20240208.cocci…
meta: semantic error: position cannot be inherited over modifications:call_pos
File "test2-switch_opposite_dependencies-20240208.cocci", line 28, column 44, charpos = 572
around = ';',
whole content = position find.call_pos, find.declaration_pos;Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Will source code transformations become better supported according to opposite SmPL dependencies?
I would appreciate more constructive feedback for this test result.
Once you make transformations, the positions of the changed code have changed.
Quoted 10 lines
Quoted 4 lines
I propose to take the specification “adjustment2 depends on !test_switch” better into account .
This case distinction is already working as expected for the specification “virtual test_switch” according to another test case variant.And? The fact that one case is the negation of the other doesn't do anything to imply that eg multiple matches cannot occur in the same function.
Quoted 1 line
How will the handling of “if … else …” constructs evolve further for SmPL code?
You need to figure out how to put the two cases in the different branches of a single disjunction.
julia
Quoted 4 lines
Quoted 1 line
Quoted 1 line
How will the handling of “if … else …” constructs evolve further for SmPL code?
You need to figure out how to put the two cases in the different branches of a single disjunction.
I got the impression that SmPL disjunctions would not be relevant so far for the discussed test case.
Regards,
Markus
Quoted 7 lines · Markus Elfring
Quoted 4 lines
Quoted 1 line
Quoted 1 line
How will the handling of “if … else …” constructs evolve further for SmPL code?
You need to figure out how to put the two cases in the different branches of a single disjunction.
I got the impression that SmPL disjunctions would not be relevant so far for the discussed test case.
Perhaps, but it is.
julia
Quoted 4 lines
Quoted 1 line
Quoted 1 line
How will the handling of “if … else …” constructs evolve further for SmPL code?
You need to figure out how to put the two cases in the different branches of a single disjunction.
Further development ideas can hopefully be clarified better also with the help of the following SmPL script example.
@selection disable decl_init@
identifier var;
type t;
@@
(t * var;
... when != var
-my_test
+test_case1
(&var)
... when exists
var
|
-t * var;
... when != var
-my_test
+test_case2
(
-&var
)
)
May I expect that the same data processing result will be produced
if “a virtual item” is replaced by another SmPL rule in the following SmPL script variant?
virtual test_switch
@find@
position pos;
@@
my_test@pos(...)
@adjustment1 depends on test_switch@
position find.pos;
@@
-my_test@pos
+test_case1
@adjustment2 depends on !test_switch@
position find.pos;
@@
-my_test@pos
+test_case2
Regards,
Markus
Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
Once you make transformations, the positions of the changed code have changed.
I propose to take the specification “adjustment2 depends on !test_switch” better into account .
This case distinction is already working as expected for the specification “virtual test_switch” according to another test case variant.And? The fact that one case is the negation of the other doesn't do anything to imply that eg multiple matches cannot occur in the same function.
I would appreciate that the SmPL design pattern “depends on test_switch” and a companion rule depends on the negation would work for more use cases. I find it essential for the convenient selection of desirable source code transformations. Can they occasionally become safer if SmPL position variables are applied accordingly?
Quoted 3 lines
Quoted 1 line
How will the handling of “if … else …” constructs evolve further for SmPL code?
It won't.
Does this kind of feedback indicate just another communication difficulty?
Regards,
Markus
Quoted 8 lines · Markus Elfring
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Once you make transformations, the positions of the changed code have changed.
I propose to take the specification “adjustment2 depends on !test_switch” better into account .
This case distinction is already working as expected for the specification “virtual test_switch” according to another test case variant.
Quoted 7 lines
Quoted 2 lines
And? The fact that one case is the negation of the other doesn't do anything to imply that eg multiple matches cannot occur in the same function.
I would appreciate that the SmPL design pattern “depends on test_switch” and a companion rule depends on the negation would work for more use cases. I find it essential for the convenient selection of desirable source code transformations. Can they occasionally become safer if SmPL position variables are applied accordingly?
No. I already explained why. The position can have changed. Coccinelle has no way to know that.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
How will the handling of “if … else …” constructs evolve further for SmPL code?
It won't.
Does this kind of feedback indicate just another communication difficulty?
No, you asked for and if then else and there are no plans to provide it.
You have to figure out how to express what you want in a single disjunction. Do all the matching needed to decide which case you have first. Mark the terms with positions accordingly. Then make a disjunction that involves one position or another.
julia
Quoted 6 lines
Quoted 4 lines
I would appreciate that the SmPL design pattern “depends on test_switch” and a companion rule depends on the negation would work for more use cases. I find it essential for the convenient selection of desirable source code transformations. Can they occasionally become safer if SmPL position variables are applied accordingly?
No. I already explained why. The position can have changed.
At which place by which SmPL rule?
Quoted 1 line
Coccinelle has no way to know that.
I suggest to reconsider this view a bit more.
The dependencies were intentionally specified for two SmPL rules so that only one of them should perform a desired transformation.
Why does the Coccinelle software behave differently if the specification “virtual test_switch” is not used for a test case?
Regards,
Markus