Skip to content

Standardise interface for accessing the owner of a symbol #4455

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 6 commits into from
Mar 29, 2019

Conversation

thomasspriggs
Copy link
Contributor

@thomasspriggs thomasspriggs commented Mar 29, 2019

Without the functions added by this PR, the only way to access the
owner of a symbol for static fields and java methods is through
symbol.type.get(ID_C_class). When this technique is used by downstream
repositories, they are vulnerable to being broken by upstream changes to
how this information is stored in JBMC. The intention of this PR is
that the two new functions added will be the standard interface to this
symbol -> owner link. This means that future changes to how this
information is stored can be made without breaking downstream
repositories by changing these two functions.

This PR includes changes to use the two new functions. This is preparatory
work ready for moving the link from being stored in a comment
on a symbols type, to the symbol itself, as discussed with @smowton

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Without the functions added by this commit, the only way to access the
owner of a symbol for static fields and java methods is through
`symbol.type.get(ID_C_class)`. When this technique is used by downstream
repositories, they are vulnerable to being broken by upstream changes to
how this information is stored in JBMC. The intension of this commit is
that the two new functions added will be the standard interface to this
symbol -> owner link. This means that future changes to how this
information is stored can be made without breaking downstream
repositories by changing these two functions.
This commit replaces access to `symbol.type.get(ID_C_class)`. With calls
to the `owning_class` function and access to
`symbol.type.set(ID_C_class, class_id)` with calls to
`set_owning_class`. This allows for changes to how the owner of a symbol
is stored by changing these two functions only, rather than by changing
all the places where `ID_C_class` was previously accessed directly. This
is preparatory work for moving this link from being stored in a comment
on a symbols type, to the symbol itself.
Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

What is meant by the "owner of a symbol?" For a given symbol x, Is it the class that x is a member of? But then those aren't separate symbols, they would just be members of a struct type. So I'm confused.

Edit: the only owner of a symbol that we have is the symbol table.

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

Code changes look good, but I think to make this robust, it needs a unit test that actually goes through the java parser and checks the properties of a real static symbol. At a minimum java class with a static field and a static method.

@@ -419,6 +419,8 @@ void java_bytecode_convert_methodt::convert(
get_method_identifier(class_symbol.name, m);

method_id=method_identifier;
set_owning_class(
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Lower down (line 537) you have a writeable ref for this symbol already which is used to update the type. It might be nicer to keep the mutation in one place and do this call down there

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 tried putting it lower down and things didn't work properly. I guess it must be read back somewhere between the two locations.

@tautschnig tautschnig dismissed their stale review March 29, 2019 11:05

Discussed offline how the terminology might be changed.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: bd2bacd).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/106300980
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

@thomasspriggs
Copy link
Contributor Author

I have

  • Renamed owning_class to declaring_class, as discussed with @tautschnig
  • Added unit tests covering the java parsing setting declaring_class as requested by @thk123

@thomasspriggs thomasspriggs merged commit 18da0b1 into diffblue:develop Mar 29, 2019
@thomasspriggs thomasspriggs deleted the tas/id_c_class branch March 29, 2019 15:37
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

⚠️
This PR failed Diffblue compatibility checks (cbmc commit: 65e3d31).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/106341108
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.

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.

6 participants