Supporting transformations better according to reduced number of function call parameters
Hello,
One kind of collateral evolution is well-known:
The number of function call parameters can occasionally be reduced.
https://refactoring.com/catalog/changeFunctionDeclaration.html
https://softwareengineering.stackexchange.com/questions/331803/techniques-for-minimising-number-of-function-arguments
Corresponding change possibilities can depend then on the detail if references to previous data items would occur in subsequent control flow (or not).
I got the impression that the data processing with the semantic patch language has got special algorithmic properties.
1. Something needs to be searched in the source code.
2. It should be determined if further variables are used behind a selected source code position.
3. The desired transformation can hopefully be performed after a precondition was checked.
Thus I imagine that it would be nice to take additional techniques better into account for the avoidance of duplicate data processing.
I hope that topics (like the following) can influence the situation accordingly.
* Support source code scopes
2023-10-23
https://github.com/coccinelle/coccinelle/issues/322
* Support additional code path information
2020-12-04
https://github.com/coccinelle/coccinelle/issues/238
* Support for SmPL rule groups
2019-04-07
https://github.com/coccinelle/coccinelle/issues/164
* Determination for the number of named function parameters with SmPL 2016-01-07
https://github.com/coccinelle/coccinelle/issues/56
Regards,
Markus
Quoted 5 lines
Corresponding change possibilities can depend then on the detail if references to previous data items would occur in subsequent control flow (or not).
I got the impression that the data processing with the semantic patch language has got special algorithmic properties.
Update candidates will be searched by an initial SmPL rule. The search pattern needs to refer to variable declarations so that their positions can be reused for subsequent queries.
Selected variable identifiers will be specified for an “appendix” which indicates the potential for further usage of them in another SmPL rule. How do you think about to support a software extension so that the complete SmPL code from the first rule can be applied once more (as a known submatch) without repeating it?
The submatch probably contains statements which should also be reusable for desired change specifications including the deletion of variable declarations that would not be needed any more in a function implementation.
Will development interests grow accordingly?
Regards,
Markus
Quoted 16 lines · Markus Elfring
Quoted 5 lines
Corresponding change possibilities can depend then on the detail if references to previous data items would occur in subsequent control flow (or not).
I got the impression that the data processing with the semantic patch language has got special algorithmic properties.Update candidates will be searched by an initial SmPL rule. The search pattern needs to refer to variable declarations so that their positions can be reused for subsequent queries.
Selected variable identifiers will be specified for an “appendix” which indicates the potential for further usage of them in another SmPL rule. How do you think about to support a software extension so that the complete SmPL code from the first rule can be applied once more (as a known submatch) without repeating it?
Quoted 4 lines
The submatch probably contains statements which should also be reusable for desired change specifications including the deletion of variable declarations that would not be needed any more in a function implementation.
Will development interests grow accordingly?
I don't really understand what you are asking about, but there are files iteration.cocci and python_iteration.cocci in the demos directory. This makes it possible to rerun some semantic patch code.
julia
Quoted 4 lines
Quoted 1 line
Will development interests grow accordingly?
I don't really understand what you are asking about, but there are files
iteration.cocciandpython_iteration.cocciin the demos directory.
Will the understanding improve also together with a script variant (like the following) for the semantic patch language?
@find disable decl_init@
expression action;
identifier var;
position call_pos, declaration_pos;
type t;
@@
t * var@declaration_pos;
... when != var
when any
action@call_pos(..., &var, ...)
@further_usage disable decl_init@
expression find.action;
identifier find.var;
position find.call_pos, find.declaration_pos;
type find.t;
@@
t * var@declaration_pos;
... when != var
when any
action@call_pos(..., &var, ...)
<+... var ...+>
@display depends on !further_usage disable decl_init@ expression find.action;
identifier find.var;
position find.call_pos, find.declaration_pos; type find.t;
@@
*t * var@declaration_pos;
... when != var
when any
*action@call_pos(..., &var, ...)
Regards,
Markus
Quoted 2 lines
Will the understanding improve also together with a script variant (like the following) for the semantic patch language?
@selection disable decl_init@
expression action;
identifier var;
position call_pos, declaration_pos;
type t;
@@
(t * var@declaration_pos;
... when != var
when any
action@call_pos(..., &var, ...)
... when exists
var
|
*t * var@declaration_pos;
... when != var
when any
*action@call_pos(..., &var, ...)
)
Are there any opportunities left over to increase the avoidance of duplicate data processing also together with the application of SmPL disjunctions?
Regards,
Markus
Quoted 22 lines · Markus Elfring
Quoted 2 lines
Will the understanding improve also together with a script variant (like the following) for the semantic patch language?
@selection disable decl_init@
expression action;
identifier var;
positioncall_pos,declaration_pos;
type t;
@@
(t * var@declaration_pos;
... when != var
when any
action@call_pos(..., &var, ...)
... when exists
var
|
*t * var@declaration_pos;
... when != var
when any
*action@call_pos(..., &var, ...)
)
Quoted 2 lines
Are there any opportunities left over to increase the avoidance of duplicate data processing also together with the application of SmPL disjunctions?
I think you would want the disjunction to start with the call to action.
julia
Quoted 22 lines
Quoted 22 lines
Quoted 2 lines
Will the understanding improve also together with a script variant (like the following) for the semantic patch language?
@selection disable decl_init@
expression action;
identifier var;
positioncall_pos,declaration_pos;
type t;
@@
(t * var@declaration_pos;
... when != var
when any
action@call_pos(..., &var, ...)
... when exists
var
|
*t * var@declaration_pos;
... when != var
when any
*action@call_pos(..., &var, ...)
)
Quoted 4 lines
Quoted 2 lines
Are there any opportunities left over to increase the avoidance of duplicate data processing also together with the application of SmPL disjunctions?
I think you would want the disjunction to start with the call to action.
No, not for this use case.
The case distinction is essential here that a variable declaration must be preserved for one function/macro call while it may eventually be considered for deletion according to an other function/macro call variant.
The semantic patch language supports some metavariable types.
Special restrictions can be achieved by combining them with the means of conjunctions.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/4965f42eb94d2d67f7375c66b268997457cbcefb/docs/manual/cocci_syntax.tex#L1041
Can it be that a branch of a SmPL disjunction can not directly benefit from metavariable matches in previous branches by reusing their contents so far?
Regards,
Markus
Quoted 33 lines · Markus Elfring
Quoted 22 lines
Quoted 22 lines
Quoted 2 lines
Will the understanding improve also together with a script variant (like the following) for the semantic patch language?
@selection disable decl_init@
expression action;
identifier var;
positioncall_pos,declaration_pos;
type t;
@@
(t * var@declaration_pos;
... when != var
when any
action@call_pos(..., &var, ...)
... when exists
var
|
*t * var@declaration_pos;
... when != var
when any
*action@call_pos(..., &var, ...)
)Quoted 4 lines
Quoted 2 lines
Are there any opportunities left over to increase the avoidance of duplicate data processing also together with the application of SmPL disjunctions?
I think you would want the disjunction to start with the call to action.
No, not for this use case.
The case distinction is essential here that a variable declaration must be preserved for one function/macro call while it may eventually be considered for deletion according to an other function/macro call variant.
Quoted 6 lines
The semantic patch language supports some metavariable types.
Special restrictions can be achieved by combining them with the means of conjunctions.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/4965f42eb94d2d67f7375c66b268997457cbcefb/docs/manual/cocci_syntax.tex#L1041Can it be that a branch of a SmPL disjunction can not directly benefit from metavariable matches in previous branches by reusing their contents so far?
I don't think it is useful to do anything for this.
It may be simpler to just make a change, and then delete all variables that are never used in a separate rule, given that normally all variables are used, so unused ones are likely ones that you made be unused.
julia
Quoted 4 lines
Quoted 4 lines
The case distinction is essential here that a variable declaration must be preserved for one function/macro call while it may eventually be considered for deletion according to an other function/macro call variant.
Quoted 8 lines
Quoted 6 lines
The semantic patch language supports some metavariable types.
Special restrictions can be achieved by combining them with the means of conjunctions.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/4965f42eb94d2d67f7375c66b268997457cbcefb/docs/manual/cocci_syntax.tex#L1041Can it be that a branch of a SmPL disjunction can not directly benefit from metavariable matches in previous branches by reusing their contents so far?
I don't think it is useful to do anything for this.
I assume that additional users can influence the software evolution in proposed directions.
Would you like to confirm that metavariables are used within SmPL disjunction branches in independent ways so far?
Quoted 3 lines
It may be simpler to just make a change, and then delete all variables that are never used in a separate rule, given that normally all variables are used, so unused ones are likely ones that you made be unused.
Programming interfaces are evolving.
Thus it can happen that one of possible code adjustments should only be applied if a corresponding precondition is fulfilled.
Regards,
Markus
Quoted 1 line
I don't think it is useful to do anything for this.
Can the following SmPL script example point further opportunities out to improve the software documentation?
@special_selection disable decl_init@
expression action;
identifier var;
position call_pos, declaration_pos;
declaration declaration1;
statement statement1;
type t;
@@
(
(t * var@declaration_pos;
&declaration1
)
... when != var
when any
(action@call_pos(..., &var, ...);
&statement1
)
... when exists
var
|
*declaration1
... when != var
when any
*statement1
)
Regards,
Markus
Quoted 4 lines
Quoted 2 lines
Can it be that a branch of a SmPL disjunction can not directly benefit from metavariable matches in previous branches by reusing their contents so far?
I don't think it is useful to do anything for this.
We are struggling with challenges according to further evolution for the discussed software.
Some source code search patterns can be expressed in a way so that they can be directly evaluated by the provided “engine”.
We occasionally stumble on capability limitations of this software component.
But such an evaluation provides a data processing result at least which subsequent SmPL rules can pick up for further computations. A search pattern can eventually be split into a combination of smaller ones which can hopefully be better evaluated then.
Will the support accordingly grow for “advanced SmPL dependencies”?
https://github.com/coccinelle/coccinelle/issues/353
Regards,
Markus