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

Safety data-flow #2143

Merged
merged 15 commits into from
Mar 30, 2022
Merged

Safety data-flow #2143

merged 15 commits into from
Mar 30, 2022

Conversation

carterkozak
Copy link
Contributor

==COMMIT_MSG==
Implement Safety flow checks
==COMMIT_MSG==

This is likely fairly slow, and probably needs optimization.
Needs more test coverage.

Borrowed heavily from error-prone null checks
@changelog-app
Copy link

changelog-app bot commented Mar 29, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Implement Safety flow checks

Check the box to generate changelog(s)

  • Generate changelog entry

@carterkozak carterkozak changed the title Ckozak/safety dance Safety data-flow Mar 29, 2022
@carterkozak carterkozak marked this pull request as ready for review March 29, 2022 20:59
Copy link
Contributor

@fawind fawind left a comment

Choose a reason for hiding this comment

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

Generally looks good, left some smaller comments. But happy to roll this out and iterate based on what we see on the excavators!

if (target instanceof FieldAccessNode) {
FieldAccessNode fieldAccess = (FieldAccessNode) target;
updates.set(fieldAccess, safety);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a complete list or should we handle the case when target is not an instance of these three types?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess with the current impl, we just update the store with an empty update and just stop propagating safety information which sounds fine!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it's an exhaustive list:
https://github.com/typetools/checker-framework/blob/090d02424e6d825d45406b959010dd0ac81fbac2/dataflow/src/main/java/org/checkerframework/dataflow/cfg/node/AssignmentNode.java#L37-L39

We might as well fail in the case of an unknown target, that way we're forced to update the code to handle new types if they're added.

private Safety fieldInitializerSafetyIfAvailable(VarSymbol accessed) {
if (!traversed.add(accessed)) {
// Initializer circularity
return Safety.UNKNOWN;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate a bit on this traversed guard? Is it to avoid loops when running the flow on the field initializer?

}

@Override
public TransferResult<Safety, AccessPathStore<Safety>> visitNarrowingConversion(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: visitWideningConversion and visitNarrowingConversion uses the same code. Maybe we can extract or delegate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I'll include visitTypeCast as well

}

@SuppressWarnings("checkstyle:CyclomaticComplexity")
private Safety fieldSafety(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: These two methods are a bit out-of-place. Maybe we move them further down below the method that uses them?

}

@CheckReturnValue
private static TransferResult<Safety, AccessPathStore<Safety>> updateRegularStore(
Copy link
Contributor

Choose a reason for hiding this comment

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

This took me a while to grok so think a comment on when we need to update the store and when we don't would be helpful!

@fawind
Copy link
Contributor

fawind commented Mar 30, 2022

👍

@bulldozer-bot bulldozer-bot bot merged commit 6607d55 into develop Mar 30, 2022
@bulldozer-bot bulldozer-bot bot deleted the ckozak/safety_dance branch March 30, 2022 17:13
@svc-autorelease
Copy link
Collaborator

Released 4.84.0

This was referenced Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants