-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Compiler support for optimizing PersistentDict #51993
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
module OptimizedGenerics | ||
|
||
# This file defines interfaces that are recognized and optimized by the compiler | ||
# They are intended to be used by data structure implementations that wish to | ||
# opt into some level of compiler optimizations. These interfaces are | ||
# EXPERIMENTAL and currently intended for use by Base only. They are subject | ||
# to change or removal without notice. It is undefined behavior to add methods | ||
# to these generics that do not conform to the specified interface. | ||
# | ||
# The intended way to use these generics is that data structures will provide | ||
# appropriate implementations for a generic. In the absence of compiler | ||
# optimizations, these behave like regular methods. However, the compiler is | ||
# semantically allowed to perform certain structural optimizations on | ||
# appropriate combinations of these intrinsics without proving correctness. | ||
|
||
# Compiler-recognized generics for immutable key-value stores (dicts, etc.) | ||
""" | ||
module KeyValue | ||
|
||
Implements a key-value like interface where the compiler has liberty to perform | ||
the following transformations. The core optimization semantically allowed for | ||
the compiler is: | ||
|
||
get(set(x, key, val), key) -> (val,) | ||
|
||
where the compiler will recursively look through `x`. Keys are compared by | ||
topolarity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
egality. | ||
|
||
Implementations must observe the following constraints: | ||
|
||
1. It is undefined behavior for `get` not to return the exact (by egality) val | ||
stored for a given `key`. | ||
""" | ||
module KeyValue | ||
""" | ||
set(collection, [key [, val]]) | ||
set(T, collection, key, val) | ||
|
||
Set the `key` in `collection` to `val`. If `val` is omitted, deletes the | ||
value from the collection. If `key` is omitted as well, deletes all elements | ||
of the collection. | ||
""" | ||
function set end | ||
|
||
""" | ||
get(collection, key) | ||
|
||
Retrieve the value corresponding to `key` in `collection` as a single | ||
element tuple or `nothing` if no value corresponding to the key was found. | ||
`key`s are compared by egal. | ||
""" | ||
function get end | ||
end | ||
|
||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we need some kind of a mutability check on
key
, since PersistentDict allows mutable keys but does not behave very sensibly for them.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.
Can you expand what you mean by doesn't behave sensible? Or open a separate issue?
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.
The main problem for this optimization is:
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.
We could make it an IdDict equivalent.
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.
That still leaves types like
IdDict
out in the cold, since it is an immutable struct, that references mutable contents to compute the hash. There isisidentityfree
that solves that issue though, if desired.