Skip to content

[IDE] Don't walk to ExplicitCast expr twice in ModelASTWalker #18663

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

Merged
merged 1 commit into from
Aug 14, 2018

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Aug 13, 2018

Explicit cast expressions (i.e. as, as!, as?, and is) appear twice in SequenceExpr. For instance, a as B is parsed as:

  (sequence_expr
    (unresolved_declref_expr name='a')
    (coerce_expr writtenType='B')
    (coerce_expr writtenType='B'))

This patch prevents ModelASTWalker from walking into them twice.

rdar://problem/43135727

@rintaro rintaro requested review from akyrtzi and nkcsgexi August 13, 2018 06:09
@rintaro
Copy link
Member Author

rintaro commented Aug 13, 2018

@swift-ci Please smoke test

@akyrtzi
Copy link
Contributor

akyrtzi commented Aug 13, 2018

Why are there 2 cast exprs, is this really necessary ? Are these 2 different ExplicitCastExpr* pointers or the same one showing up twice ?

for(unsigned i = 0, e = SE->getElements().size(); i != e; ++i) {
auto subExpr = SE->getElement(i);

if (i % 2 != 0 && isa<ExplicitCastExpr>(subExpr))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the pointer for the expression appears twice, can we use a pointer set here to exclude duplications? or do we actually create the same expression twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. 👍

@rintaro
Copy link
Member Author

rintaro commented Aug 13, 2018

Why are there 2 cast exprs, is this really necessary ? Are these 2 different ExplicitCastExpr* pointers or the same one showing up twice ?

They are the 2 pointers to the same object. I think we can make not showing up 2 times, but it need non trivial changes to the pipeline.

@jrose-apple
Copy link
Contributor

I suspect this is to make the even/odd aspect of SequenceExpr work.

@rintaro
Copy link
Member Author

rintaro commented Aug 13, 2018

I suspect this is to make the even/odd aspect of SequenceExpr work.

Yeah, but I think we can make it like { operand, 'as Ty', nullptr, '+', operand } if we carefully allow nullptr in SequenceExpr. (I'm not saying it's worth to do it at this point)

Explict cast expressions (i.e. 'as', 'as!`, 'as?', and 'is') appear twice in
'SequenceExpr'. For instance, 'a as B' is parsed as:
  (sequence_expr
    (unresolved_declref_expr name='a')
    (coerce_expr writtenType='B')
    (coerce_expr writtenType='B'))
This patch prevents ModelASTWalker from walking into them twice.

rdar://problem/43135727
@rintaro
Copy link
Member Author

rintaro commented Aug 13, 2018

@swift-ci Please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants