Skip to content
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

Rust: Include self parameters in the CFG #18041

Merged
merged 4 commits into from
Nov 21, 2024
Merged

Conversation

paldepind
Copy link
Contributor

Currently self parameters are not included in the CFG. This PR adds them.

This example:

    fn add(&mut self, a: i64, b: i64) {
        self.n += a + b;
    }

results in this CFG (previously the 2nd and 3rd node where not there):

flowchart TD
1["enter add"]
10["BlockExpr"]
11["self"]
12["FieldExpr"]
13["... += ..."]
14["ExprStmt"]
15["a"]
16["... + ..."]
17["b"]
2["exit add"]
3["exit add (normal)"]
4["SelfParam"]
5["self"]
6["a"]
7["Param"]
8["b"]
9["Param"]

1 --> 5
3 --> 2
4 --> 6
5 --> 4
6 -- match --> 7
7 --> 8
8 -- match --> 9
9 --> 14
10 --> 3
11 --> 12
12 --> 15
13 --> 10
14 --> 11
15 --> 17
16 --> 13
17 --> 16
Loading

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Nov 20, 2024
i = 0 and
result = this.getParamList().getSelfParam()
or
result = this.getParamList().getParam(i - this.getNumberOfSelfParams())
Copy link
Contributor

Choose a reason for hiding this comment

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

The indices of getChildNode need not be consecutive, nor start from 0, so I would just do result = this.getParamList().getParam(i - 1)

or
i = this.getParamList().getNumberOfParams() and
i = this.getParamList().getNumberOfParams() + this.getNumberOfSelfParams() and
Copy link
Contributor

Choose a reason for hiding this comment

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

And here it would then be i = this.getParamList().getNumberOfParams() + 1.

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

LGTM. Please do a DCA run before merging ;-)

@paldepind
Copy link
Contributor Author

DCA looks fine I think. There seems to be an extraction error for googleapis-tonic, but that must be unrelated.

@paldepind paldepind merged commit 8c74478 into github:main Nov 21, 2024
15 checks passed
@paldepind paldepind deleted the rust-cfg-self branch November 21, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants