-
Notifications
You must be signed in to change notification settings - Fork 33
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
rename variables by default to avoid execute()
clashes in linked libs
#672
Conversation
I'm open to using some other naming strategy, there was some talk about maybe prepending everything with something like |
Okay, the current rename function now does the following: if the variable name x is "bad" (at the moment this means it contains characters that aren't allowed, or x == "minpoly") a transformation is applied to replace bad characters in a meaningful way, if this still results in a "bad" variable name then x is replaced with some default string (this is all left in place from the previous hack) |
Oh dear, this causes basically all doctests to fail from renamed variables. I'm guessing this means that the previous version of |
docs/src/alghom.md
Outdated
@@ -39,11 +39,11 @@ julia> L = FiniteField(3, 2, "a") | |||
|
|||
julia> R, (x, y, z, w) = polynomial_ring(L[1], ["x", "y", "z", "w"]; | |||
ordering=:negdegrevlex) | |||
(Singular Polynomial Ring (9,a),(x,y,z,w),(ds(4),C), spoly{n_GF}[x, y, z, w]) | |||
(Singular Polynomial Ring (9,@OSCAR@a@1),(@OSCAR@x@1,@OSCAR@y@1,@OSCAR@z@1,@OSCAR@w@1),(ds(4),C), spoly{n_GF}[x, y, z, w]) |
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 don't think we should update the variable names here. Instead I would perform this kind of renaming in Oscar.jl
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.
Here in the docstring? Or altogether?
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 at least agree that if I am renaming the variables in Singular.jl, then prepending @OSCAR@
is not the right approach. I went with this because Singular.jl already had a helper function to rename "bad" variable names. I can create one in Oscar.jl, but when to call it becomes an issue. Because this issue is not just with computing primary decomposition from Singular, we could potentially run into these name clashes any time we call the Singular library.
Unrelated, at the moment this renaming is causing a segfault in the tests, during one of the calls to libSingular.algExt_GetMinpoly
, trying to figure out what is going on with that.
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.
Looking into this more, the renaming is sort of a fundamental part of Singular.jl. The type constructors convert to a "good" list of variable names and write them to the Singular objects that they wrap, while maintaining a vector of the corresponding symbols used for the variable names in Julia. I think it would probably break some things to remove this from Singular.jl, and would require some type piracy to handle all of this from the Oscar.jl side.
I think Hans has helped identify the source of the segfault, but regardless, I would honestly vote for just considering every variable name bad, and replace it by def*<number>
where def
is the (already implemented) default taken by rename_symbol
. The reasons being,
- it's infeasible to predict all of the possible identifiers that will create a clash in the Singular library and
- from the Julia side, we shouldn't care what Singular is calling these variables internally.
There are only 3 times when we might see these Singular variable names, and it will always be I think an issue that should be fixed:
- We have Singular actually printing the output for some reason.
- We have a badly defined print routine for an object that is pulling the variable names from the wrapped Singular object instead of from the list of julia symbols the object is using.
- We for some reason are creating a julia object directly from a pointer to a Singular object, in this case it reads the variable names from Singular.
Related to 2. above, the Singular.jl polynomial rings have a bad print routine that shows the wrapped variable names (and is in general unintelligeable):
julia> using Singular;
julia> F, (a,) = FunctionField(QQ,["a"]);
julia> K, a = AlgebraicExtensionField(F, a^2 + 1);
julia> R, (x, y, z) = polynomial_ring(K, ["x", "y", "z"])
(Singular Polynomial Ring (0,a_1),(x_1,y_1,z_1),(dp(3),C), spoly{n_algExt}[x, y, z])
julia> R.S
3-element Vector{Symbol}:
:x
:y
:z
This is in my version that renames all variables, though this occured previously whenever a variable was renamed; we see that the original symbols are properly saved, but the print routine gives us... I'm not even sure what. (But this occurs in Singular.jl, Oscar.jl does not have this problem).
end | ||
|
||
@testset "PolyRing.ordering.fancy" begin | ||
function test_monomials(l) | ||
for i in 2:length(l) | ||
@test l[i-1] > l[i] | ||
@test l[i] < l[rand(1:i-1)] |
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.
Why was this removed?
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.
Hmm, as near as I can tell, we check that each l[i] < l[i-1]
, then also that l[i] < l[j]
for some random j in 1:i-1
. It seems this second test is redundant, or am I missing something? For example when i=2
this just checks that l[2] < l[1]
twice, correct? I can add this one back, no problem.
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.
(as for why I messed with it in this pull request, I needed to fix the other ordering tests because of the variable names, and was looking at this one to compare.)
What is the status of this? Do you still have concerns/objections @fingolfin? |
I'm out of town at a conference, but will be back this weekend - I've been having issues with weird test failures. I've fixed a lot that were based on comparing strings, I've tried to make them a bit more generic. But one that's failing now is the |
Okay, I am working through this (hopefully last?) failing test, and I think I need some advice about what the purpose of the test is. This is here.
So the call to
The problem is that, when the variable for the finite field gets renamed, then So what is this test checking? If it is just checking that Now, it would be nice if |
This was fixed on the Oscar side in oscar-system/Oscar.jl#2662 |
This should fix oscar-system/Oscar.jl#1905 with variable names clashing with names used in Singular libraries.
We now append an
#<number>
to all variables by default (we also remove a potential infinite loop in the previous version of the hack).