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

RFC: A resettable Lazy alternative #11536

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SomeTroglodyte
Copy link
Collaborator

An experiment: What if there were a way to tell a by lazy { ... } field that its cached value is obsolete?

This is just the tool and its unit tests... But if liked, we could refactor some existing fields - see resetAdjacentToRiverTransient? Should be oodles of candidates, but that was the only direct example I could find.

Notes:

  • Can't reflect-hack the existing Lazy as it forgets its initializer lambda as soon as it is tripped
  • Not 100% compatible as inheriting from Lazy directly breaks it - the compiler no longer does as it is told, the Lazy thing must have hardcoded support one cannot modify - we inherit and we're no longer actually instantiated even if the constructor call is explicit. The field gets a SafePublicationLazyImpl delegate instead.
  • Won't get the Lazy optimization that a tripped lazy will get its delegate replaced by the much faster InitializedLazyImpl stub - one, need to keep knowledge about initializer, two, that seems to be done compiler-hardcoded too: There's a writeReplace method but I don't see where it is called, actually it can't really be legally called as it is private...

Copy link

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant