-
-
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
WIP/RFC: metadata implemented, REPL-help ported, user-made doc now possible (issue #3988) #5572
Conversation
(Sorry the rebasing I did added lots of people to this pull-request. I'll not do that next time.) |
Unfortunately the PR still has an unclear history and is not mergeable as-is. |
@pao: Sorry, I'm a git noob: what should I do? I could restart and make a new pull request without all the history-garbage coming from the rebasing? |
You can do that by resetting to master ( I always recommend making a backup branch first ( (It's not the only way to cleanup history. You can probably also eliminate the extra commits by deleting them in an interactive rebase, |
Taking a bunch of changes and sculpting them into targeted, logically separate commits is probably best done the way @pao recommends with |
Thanks for those explanations! I'll try them once I finish with the |
One concern I have with this approach is that there is no clear way to clean up the dictionary --- it never releases references to anything. It also seems like we'd need to add special handling of this dictionary if we ever separately compile packages. A package would have to store its part of the dictionary, which would need to be merged in when loaded. That's doable, but why not just leave the per-package data in place instead of merging? |
@pao & @StefanKarpinski : I tidied up the commits: you should be able to have a look at it now. (I did it with a I updated the original message to reflect all the features of the pull-request. @JeffBezanson : I think that the main point is whether we are happy with the function-interface to the metadata. We can always swap the backend later if there are problems. @stevengj and I had some discussion about the backend in #3988 along the lines of your concern. This pull-request implements more or less as @stevengj suggested. I think the good thing about this backend is that it's super trivial. So why not go with this for now? Concerning improvement of the backend: The The nice thing about getting a metadata system into master would be that folks could start working on a proper documentation system. |
I just saw that the Travis-build failed for this. This seems to be a bug with running in directory This looks quite like this closed issue: |
Filed an issue for |
Even after #5648 is fixed, for reasons I could not debug, the tests for help.jl were failing in parallel. So now help.jl gets tested separately in serial. Other than that, I would appreciate some comments on whether the metadata strategy as implemented in here has a future or not. Just say "no" if you see no future and maybe suggest/implement something else. (Again, note, my implementation of the REPL-help system is just thought as an interim solution, albeit fully functional. This is about metadata handling.) |
@JeffBezanson, as a practical matter we are unlikely to be using the metadata for anything but documentation of |
I cannot reproduce the Travis error, even when building from a fresh clone (gcc 4.8.2, arch linux 64-bit). |
A I really wish we could make some more progress on this. |
Yes, lets make 0.4 the "documentation release". |
As @stevengj says, do we really need a weak reference dict? AFAIK modules persist once loaded, thus all their contents also persist. So the only time metadata should be garbage collected is when a user attaches it to type instances which then go out of scope. (or are there other cases?) Whilst bad, there are easier ways to shoot oneself in the foot. Plus the user could define another metadata storage for a specific type with this PR.
Also, we probably want an object-id dict, because otherwise attaching metadata to instances of some mutable types (e.g. Also, note that Jeff seemed to be opposed the other type of metadata storage, add a special field to most types as I suggested above: https://groups.google.com/d/msg/julia-dev/kBTqHsyP_0E/bgAltGuF9c4J |
end | ||
|
||
function getdoc(obj, default) | ||
metadata = getmeta(obj, nothing) |
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.
It might be nice to simplify this pattern by defining getmeta(obj, key, default)
to return getmeta(obj)[key]
if it exists and default
otherwise.
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.
Thanks for looking at this! Yes that would probably be good. I tried to model the interface on associative collections, so this could be good.
I put a This solves @JeffBezanson concern of releasing references to both mutable and immutables as they get garbage collected (as far as I understand it and the This does not solve @JeffBezanson concern of keeping the metadata with the package it belongs to. When loading a package the |
Maybe a |
Honestly, keeping metadata with the package seems like backend implementation detail that could be fixed later. |
2ef98c5
to
0388647
Compare
data is stored in the ObjectIdDict Base.META. However, interaction should be done through the functions: getmeta, setmeta! & hasmeta 2) Ported the existing REPL-help system over to work with this system. - `help` and `?` work as before (except 3-objects don't work, see test/help.jl) - user-made help is now possible through a `@doc`-macro and `doc`-function - Documentation of objects is kept in the metadata storage. Documentation of non-objects, e.g. keywords, and macros is kept in: `Base.Help.NONOBJ_DICT`. Tests in test/metadata.jl and test/help.jl Issues: - every now and then I get a `ERROR: BoundsError()` when initializing the help from helpdb.jl - There is a strange bug with the help test running in parallel: -> fixed the test by moving the help.jl test into a serial execution at the end
currently a very crude implementation but it seems to work. Made changes to the interface as @stevengj suggested. Oddness: APROPOS_DICT cannot be a WeakObjectIdDict for some reason
…LLVM crashes and seg-faults.
Test are passing/failing somewhat eratically, probably due to the WeakObjectIdDict.
Superseded by #8791 |
(updated 30 Jan)
I added basic support to associate metadata with most objects using @stevengj's suggested global dict as backend. It is really rather quite trivial but seems to work fine (except below issues). I use a function interface to the
META
dict so the backend could be changed. So, main thing here is whether we're happy with that function-interface or not.As illustration of its power ;-), I ported the existing REPL-help system over into this system and it works as before, except that user-made help is now possible. I'll post a usage-demo to #3988. The help system as in this pull-request is not meant to stay like that. It's thought as a transitional state to something fancy.
So:
Added basic support to associate metadata to most objects. The data is stored in the
ObjectIdDict
Base.META
. However, interaction should be done through the functions:getmeta
,setmeta!
&hasmeta
Ported the existing REPL-help system over to work with this system.
help
and?
work as before (except 3-objects don't work, see test/help.jl)@doc
-macro anddoc
-functionDocumentation of non-objects, e.g. keywords, and macros
is kept in:
Base.Help.NONOBJ_DICT
.Issues:
ERROR: BoundsError()
when initializing the help from helpdb.jleval
not picking up its documentation, no idea why.&&
, etc.copy
,deepcopy
,sizeof