C#: Extract string interpolation alignment and format.#19089
C#: Extract string interpolation alignment and format.#19089michaelnebel merged 9 commits intogithub:mainfrom
Conversation
04621bd to
acec97d
Compare
a783354 to
d9fb137
Compare
hvitved
left a comment
There was a problem hiding this comment.
LGTM, great work. Some small questions.
| import csharp | ||
|
|
||
| query predicate inserts(InterpolatedStringExpr expr, Expr e) { | ||
| expr.getAnInsert() = e // and inSpecificSource(expr) |
There was a problem hiding this comment.
Remove the trailing comment?
| } | ||
|
|
||
| query predicate texts(InterpolatedStringExpr expr, StringLiteral literal) { | ||
| expr.getAText() = literal // and inSpecificSource(expr) |
There was a problem hiding this comment.
Remove the trailing comment?
| where | ||
| expressions(e, k, t) and | ||
| if k = 138 then kind = 106 else kind = k | ||
| select e, kind, t |
There was a problem hiding this comment.
Should this select the insert part of e instead of e?
There was a problem hiding this comment.
I considered doing that as well, but it requires that we also make changes to the expr_parent relation as well (this is what I am vaguely hinting in the PR description).
Basically, I am worried that I break some DB invariant by changing the parent/child relationship as a part of the script.
Should we attempt to make the better downgrade script? It requires
(1) Removing the insert expressions from the expressions relation
(2) Adjust the expr_parent relation
(3) Consider if we need to do something with the new dangling align and format expressions.
This is possible using the |
Uh, I was not aware of that! Thank you! |
|
@hvitved : Proper upgrade and downgrade scripts have been added, since your last review and you review comments have been addressed (the last three commits). |
This PR fixes an issue with missing extraction of alignment and format clauses from string interpolation expressions as described here.
Prior to this change, when we extracted a string interpolation expression
$"Hello {name,align:format}. Welcome."(denotedEin the graphs below), it looked like this in the expressions relationWith this change we introduce a new expression for `{name:align:format}, which we call a string interpolation insert expression. The expression tree for extracting a string interpolation expression now looks like,
graph TD; id1["#quot;Hello #quot;"] id2["{name,align:format}"] id3["#quot;. Welcome.#quot;"] id4["name"] id5["align"] id6["format"] E--0-->id1 E--1-->id2 E--2-->id3 id2--0-->id4 id2--1-->id5 id2--2-->id6This change in the expression tree of string interpolation expressions makes it impossible/difficult to make a proper upgrade/downgrade script, as we introduce a new kind of expression and alter the parent/child relationship.That is, to make a proper upgrade script, wewouldneed to introduce new expressions and alter- and add new entries in the expressions and expr_parent relations.We might be able to do it a bit better in the downgrade script, but I have chosen just to change the kind of the expressions to unknown.Conversely the downgrade script needs to remove some elements from expressions and expr_parent and also do so minor edge contraction on expr_parent.Effectively, this change means that we break dataflow for string interpolation expressions, when the upgrade and downgrade scripts are used.The up- and downgrade scripts have been tested manually on the database that can produced from the testcase. I tested that
Other relevant implementation details
nameto{name,align:format}in the example.DCA looks un-eventfull.