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

Extend functionality to verify method purity checks #191

Open
paplorinc opened this issue Sep 23, 2022 · 0 comments
Open

Extend functionality to verify method purity checks #191

paplorinc opened this issue Sep 23, 2022 · 0 comments

Comments

@paplorinc
Copy link

paplorinc commented Sep 23, 2022

An immutable class already implies that its methods are pure, but sometimes we're only interested in the purity of a single method of an otherwise mutable class.

Basically we would need to check that for the same params (fields?) the return value is the same.

  • We should allow reads of immutable class state, but not of mutable ones (unless configured explicitly to allow that);
  • We should allow field writes of newly created objects (the ones we can trace) but not class state (except for lazy init maybe);
  • We should allow (configurable?) static reads, but not writes;

Open question:

  • Can we handle reflective calls reliably?
  • What's a pure constructor?
    • doesn't write static state
    • doesn't call impure methods (e.g. Random)
    • can write local state and throw exception
  • Whitelistable native calls with several severities:
    • String::internand Object.getClass are basically caching
    • System::arraycopy is basically pure, but instead of returning it modifies the inputs
    • Unlike e.g. System::nanoTime which is never pure
  • When does UNSAFE usage invalidate purity?
  • Is it pure if throwing depends only on local state (i.e. is predictable)?
    • Can non-empty void methods therefore be pure?
  • Check asserts or logging or caching?
  • Class init and static init blocks - similar to caching
  • Local purity - if run on the same computer (architecture), it returns the same result?
  • Are utility classes (no class state, just static methods) immutable, if any of the methods mutates the parameters (e.g. Arrays#sort)
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

No branches or pull requests

1 participant