Swift: add DataFlow::Content for arrays#13741
Conversation
|
Some more checking to do about |
|
Also this needs a DCA run. But probably not before the above fixes have been implemented. |
|
Oh, one more thing: We need to add |
geoffw0
left a comment
There was a problem hiding this comment.
Sorry for not looking at this sooner.
This looks great. Thank you for including models-as-data support (ArrayElement), there are a number of models that should benefit from using this in the near future.
|
|
||
| var matrix = [[source()]] | ||
| sink(arg: matrix[0]) | ||
| sink(arg: matrix[0][0]) // $ flow=645 |
There was a problem hiding this comment.
Does assignment to a multi-dimensional array work as well?
var matrix2 = [[1]]
matrix2[0][0] = source()
sink(arg: matrix2[0][0])
There was a problem hiding this comment.
No, it doesn't, and now that I look at the cases I based this off of I'm not sure we handle nested fields or tuples properly either...
There was a problem hiding this comment.
Mmm. Then we should probably create an issue for this (in all content types) rather than trying to address it for just arrays here?
There was a problem hiding this comment.
After adding some tests it seems to work for nested fields... I'm not sure why, though.
There was a problem hiding this comment.
This is because of "reverse reads": if readStep(n2.(PostUpdateNode).getPreUpdateNode(), f, n1.(PostUpdateNode).getPreUpdateNode()) then the dataflow library generates storeStep(n1, f, n2). So if this doesn't work for array content then it's either because the post-update/pre-update isn't working, or because the readStep isn't working.
There was a problem hiding this comment.
I think it's actually that there's a step through an InOutExpr between the store and read step:
# 650| getElement(11): [AssignExpr] ... = ...
# 650| getDest(): [SubscriptExpr] ...[...]
# 650| getBase(): [InOutExpr] &...
# 650| getSubExpr(): [SubscriptExpr] ...[...]
# 650| getBase(): [InOutExpr] &...
# 650| getSubExpr(): [DeclRefExpr] matrix2
| var arr3 = [1] | ||
| var arr4 = arr2 + arr3 | ||
| sink(arg: arr3[0]) | ||
| sink(arg: arr4[0]) // $ MISSING: flow=642 |
There was a problem hiding this comment.
Would a model of Array.+(_:_:) in ArraySummaries fix this case?
| sink(arg: arr4[0]) // $ MISSING: flow=642 | ||
|
|
||
| var arr5 = Array(repeating: source(), count: 2) | ||
| sink(arg: arr5[0]) // $ MISSING: flow=654 |
There was a problem hiding this comment.
Again it's possible a model of the initializer is all we need here. It can wait as follow-up.
|
DCA shows a 6.6x analysis slowdown, which hopefully @MathiasVP s suggestion will fix. We can tolerate some slowdown for an improvement like this. |
|
New DCA run LGTM. Not a hint of performance issues. Good work! |
| component.getName() = "ArrayElement" and | ||
| content instanceof Content::ArrayContent |
There was a problem hiding this comment.
Should this be pulled into its own predicate to follow the structure of parseField?
There was a problem hiding this comment.
It's a considerably simpler case than parseField, I'd be happy either way TBH.
| any(Argument arg | modifiable(arg)).getExpr(), any(MemberRefExpr ref).getBase(), | ||
| any(ApplyExpr apply).getQualifier(), any(TupleElementExpr te).getSubExpr() | ||
| any(ApplyExpr apply).getQualifier(), any(TupleElementExpr te).getSubExpr(), | ||
| any(SubscriptExpr se).getBase(), any(InOutExpr ioe).getSubExpr() |
There was a problem hiding this comment.
Would a better fix maybe be to hide InOutExpr from the AST entirely?
There was a problem hiding this comment.
Maybe - we might break some other things by doing that... I can try it though
MathiasVP
left a comment
There was a problem hiding this comment.
One small comment. We should probably also have a new DCA run to double check the impact of hiding InOutExprs from the main AST.
geoffw0
left a comment
There was a problem hiding this comment.
LGTM. Would be good to wait for a final 👍 from @MathiasVP as well.
Would really like to have #13741 (comment) addressed as well before we merge. And also another DCA run afterwards. |
|
DCA looks clean |
geoffw0
left a comment
There was a problem hiding this comment.
I think this is ready to merge (I keep forgetting I don't have array content already on main...)
No description provided.