-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement memoization #6887
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
Implement memoization #6887
Conversation
in the parentheses is computed only the first time and is cached for subsequent recalculuations. | ||
The memoized program expands to the following code: | ||
``` | ||
class C(x: T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing [T]
(and in all other examples)
(I need this now! 😄) class C[T](x: T) {
var someState : Boolean = false //somewhere this is modified
def costly(x : T) : Int = {
if (someState) ???
else ???
}
def f(y: Int) = memo(costly(x)) * y
} How do we prevent this? Is there a way for the compiler to verify the function is pure? |
@soronpo There is not currently a mechanism to indicate that a function is pure. There might be in the future, but it will take a while to get there. The problem you outline is exactly the same for a lazy val, so not specific to |
Implement `memo(...)` function which caches its argument on first evaluation and re-uses the cached value afterwards. The cache is placed next to the method enclosing the memo(...) call. `memo` is a member of package `compiletime`.
Maybe we should always set the positions of these generated definitions automatically from the symbol's span. It's an easy trap to fall into.
Stale symbol errors can happen when inspecting symbols while comparing the trees before and after pickling.
... and also make it work on several nested levels together.
Restricting `entered` and `enteredAfter` to class members is more a trap to fall into than a helpful check.
Superseded by #6967 |
Implement
memo(...)
function which caches its argument on first evaluationand re-uses the cached value afterwards. The cache is placed next to the
method enclosing the memo(...) call.
memo
is a member of packagecompiletime
.