-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C#: Extract string interpolation alignment and format. #19089
base: main
Are you sure you want to change the base?
C#: Extract string interpolation alignment and format. #19089
Conversation
04621bd
to
acec97d
Compare
a783354
to
d9fb137
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the trailing comment?
} | ||
|
||
query predicate texts(InterpolatedStringExpr expr, StringLiteral literal) { | ||
expr.getAText() = literal // and inSpecificSource(expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this select the insert part of e
instead of e
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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."
(denotedE
in 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,
This 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, we would need 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.
Effectively, this change means that we break dataflow for string interpolation expressions, when the upgrade and downgrade scripts are used.
Another alternative could have been to make a tree like
This would make it easier to make backwards compatible upgrade- and downgrade scripts, but I think the chosen design is better as it more closely resembles the structure of the code.
Other relevant implementation details
name
to{name,align:format}
in the example.DCA looks un-eventfull.