-
Notifications
You must be signed in to change notification settings - Fork 63
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
Overhaul special printing macros #1594
Conversation
b634cc9
to
d36f60d
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1594 +/- ##
==========================================
- Coverage 87.15% 87.04% -0.11%
==========================================
Files 115 115
Lines 29576 29593 +17
==========================================
- Hits 25776 25760 -16
- Misses 3800 3833 +33 ☔ View full report in Codecov by Sentry. |
I would go for 2). Assuming that it doesn't take too much time to find out the name, I don't see a benefit from caching. Especially not, if one has to check every time if this is still the right name. |
d36f60d
to
8d5ec4c
Compare
Printing is relatively slow anyway, so this shouldn't make any notable difference. @ fieker confirmed that 1) is a bad idea (see oscar-system/Oscar.jl#3288 (comment)). So I will continue with 2). This PR is now ready from my POV. Everything still is non-breaking. Once this is released, I will update some things downstream that use this code (in a more or less wrong/weird way). And in the next breaking release, I would like to then do some technically breaking changes to this (that won't affect our projects due to the prior changes). |
Just a quick note, as a variant 3, one could "validated caching": that is, once a name has been found, cache it, but also store that this was a name determined via searching This has two advantages:
|
AbstractAlgebra.set_name! | ||
AbstractAlgebra.extra_name | ||
AbstractAlgebra.find_name | ||
``` |
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.
What is really missing is IMHO a text that explains
- how these things interact (in particular: what has precedence over what when it comes to determining a name)
- how to use the macros in
show
functions (e.g. to place them first; in which order; possibly how they related to (supercompact), oneline and detailed printing)
That's not an objection to this PR which starts to untangle and document thing, documenting each function and macro certainly is already helpful; but it is still difficult (if it is possible at all) to get the full picture just from reading those. So we need something to tie it all together
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 precedence is in the docstring of get_name
.
And examples of how to use everything are in the markdown doc page.
5b3d6a3
to
d5a2065
Compare
My 2 pennies:
|
d5a2065
to
44ed594
Compare
One change is that the name search is no longer called for every print, but only for compact and supercompact printing (to make it more performant). And in your case, it would choose the lexicographic first valid name for the object. So in your example it would keep |
I'll add an example.
Only a slight modification: We now first check for compact/supercompact properties before looking up a name. Without caching, this is more performant. Other than that, no changes |
44ed594
to
92022d1
Compare
Co-authored-by: Max Horn <max@quendi.de>
This is now updated to @fingolfin's wish with 3. julia> R, x = polynomial_ring(QQ, 4)
(Multivariate polynomial ring in 4 variables over rationals, AbstractAlgebra.Generic.MPoly{Rational{BigInt}}[x1, x2, x3, x4])
julia> show(IOContext(stdout, :compact => true), R)
R
julia> A = R
Multivariate polynomial ring in 4 variables x1, x2, x3, x4
over rationals
julia> show(IOContext(stdout, :compact => true), R)
R
julia> show(IOContext(stdout, :compact => true), A)
R
julia> R = 4
4
julia> show(IOContext(stdout, :compact => true), A)
A @fingolfin is this as you want it? |
a6cec6b
to
1bd06db
Compare
@lgoettgens that looks good (and yes I forget the check whether the variable content is still identical to the object -- but you guessed my intention correctly and compensated for my mistake, thank you :-) ) |
1bd06db
to
84dbaa3
Compare
I'll take this as approval. |
The succeeding matching CI verifies that oscar-system/Oscar.jl#3318 adapts Oscar for this PR to be non-breaking. |
Co-authored-by: Max Horn <max@quendi.de>
Inspired by oscar-system/Oscar.jl#3288 (comment).
This PR contains the following minor changes:
get_name
as an alternative tofind_name
in downstream packages, that does the same steps as the printing to find a name (e.g. first look into attribute storage before finding a new name in the global namespace).find_name
should get changed to being private once all call-sites useget_name
.One fundamental change/question is the following:
It was motivated by oscar-system/Oscar.jl#3288 (comment), where we tried to enable
@show_name
for multivariate polynomial rings. The issue was that rings print the name that was first assigned to them (to be correct: the lexicographic first name at the moment when the firstshow
function of the ring was called). This led to the following problem:In Doctest1 (inside say
DocModule1
) we haveR, _ = polynomial_ring(QQ, 3)
. Later, in Doctest2 (inside sayDocModule2
), we haveS, _ = polynomial_ring(QQ, 3)
. As this object gets cached, it remembered its initial nameR
and prints asR
even though it is only known asS
in the current scope (DocModule2.R
is not assigned).Furthermore, the following is unintuitive:
I would expect this now to be printed using the only valid name of the object
B
.After talking to @thofma, there seems to be 3 ways how to handle name finding:
show
is called. Current functionality, leads to the issue explained above.set_name!
explicitly) and instead find a name to print each time it is needed. This is currently implemented in this PR. The only issue I can think of is that printing of an object (say in variableR
) changes by executingA = R
, asR
now has the nameA
(again the lexicographic first one gets chosen).show
is called. When looking up a name from the cache, verify that the name still points to the same object. If yes, be happy and take this name. If not, find a new name and put this into the cache.Before I spend more time on this, I would like to know which of these three is the wished functionality.
Pinging @fieker @fingolfin @thofma @joschmitt to leave their opinion on this here (as you either worked on or suffered due to this code).