Skip to content
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

Deprecate utf16_is_*, utf16_get_supplementary, is_utf8_*, add @unexportedwarning macro, add tests #11976

Closed
wants to merge 5 commits into from

Conversation

ScottPJones
Copy link
Contributor

Although these were undocumented, unexported functions internal to the utf16.jl code, they got used in the JSON package.
(I will also submit a PR to fix JSON)

@pao
Copy link
Member

pao commented Jul 1, 2015

I believe policy is not to add deprecations for unexported/undocumented internal functions, though I may be out of date on that.

@ScottPJones
Copy link
Contributor Author

@pao I'm just doing what I was told to do!

@pao
Copy link
Member

pao commented Jul 1, 2015

Yeah, I see that now--I hit this issue before I saw the comments on the commit. Carry on.

@pao
Copy link
Member

pao commented Jul 1, 2015

But let's add a cf 9071f14#commitcomment-11953239

@ScottPJones
Copy link
Contributor Author

If somebody can merge this quickly, I'd appreciate it, so it can make JSON happy again!

@tkelman
Copy link
Contributor

tkelman commented Jul 1, 2015

Best to cross-reference everything since discussions happen in multiple places - merging #11551 broke JSON.jl.

I think the @deprecate macro causes the old name to be exported, so you could instead manually put the old method name and a depwarn without exporting it, not sure it matters too much.

@ScottPJones
Copy link
Contributor Author

I wasn't aware of that technique, I've only used @deprecate before.

@ScottPJones
Copy link
Contributor Author

@tkelman Is this what you were thinking of?

function utf16_is_surrogate(chr::UInt16)
    depwarn("utf16_is_surrogate was undocumented and unexported, and has been removed")
    Base.is_surrogate_codeunit(chr)
end
function utf16_get_supplementary(lead::UInt16, trail::UInt16)
    depwarn("utf16_get_supplementary was undocumented and unexported, and has been removed")
    Base.get_supplementary(lead, trail)
end

I have this ready to push to this PR, if you think it is better.
I also have another PR, JuliaIO/JSON.jl#111 to fix that as well.
If somebody could merge these in, I'd appreciate it.

@IainNZ
Copy link
Member

IainNZ commented Jul 1, 2015

@tkelman why would we deprecate these if they weren't exported? If packages need to touch these then I'd rather formally export an equivalent in 0.4, and make it work on 0.3 via Compat.

@ScottPJones
Copy link
Contributor Author

@IainNZ In the registered packages, only JSON.jl uses these, and they are used exactly once each,
however unregistered packages might be using them (if they built off of JSON.jl, for example.
Probably be safer to deprecate AND fix JSON.jl.

@tkelman
Copy link
Contributor

tkelman commented Jul 1, 2015

Technically a deprecation isn't absolutely required if the breakage can be solved via Compat, or these look short enough that they're just pasted in as one-liners for the JSON use case. Let's see what else was using the deleted/renamed functions from #11551.

If we do the manual deprecation without exporting, then I would still want to keep the warning message like a conventional depwarn with a message about what to replace

julia/base/deprecated.jl

Lines 493 to 494 in e063f77

depwarn(string("chol(a::AbstractMatrix, uplo::Symbol) is deprecated, ",
"use chol(a::AbstractMatrix, uplo::Union{Val{:L},Val{:U}}) instead"), :chol)

@ScottPJones
Copy link
Contributor Author

@tkelman, as far as I can tell by grepping, it's just those 2 occurrences in JSON.jl/src/Parser.jl, in all registered packages.

@kshyatt kshyatt added the unicode Related to unicode characters and encodings label Jul 2, 2015
@ScottPJones
Copy link
Contributor Author

I finally pushed the changes I'd made last week to use depwarn.
@tkelman, is this what you wanted, so that the definitions would not be exported by @deprecate?

@tkelman
Copy link
Contributor

tkelman commented Jul 7, 2015

sure, but you didn't do

keep the warning message like a conventional depwarn with a message about what to replace

@IainNZ
Copy link
Member

IainNZ commented Jul 8, 2015

Still not seeing the point of doing this, feel like it should should just be allowed to break in whatever hypothetical user code out that there that is using this undocumented, unexported feature.

@tkelman
Copy link
Contributor

tkelman commented Jul 8, 2015

Considering the important case of JSON has been fixed, I'm inclined to agree for now, did any of the PackageEvaluator results show anything that looked like it was caused by this?

@IainNZ
Copy link
Member

IainNZ commented Jul 8, 2015

I didn't see anything, but its a bit of a mess on 0.4 anyway that this is probably the least of anyones worries. Could put something NEWS.md if really paranoid?

@ScottPJones
Copy link
Contributor Author

The problem there is, I didn't really think they should call the new functions (which are slightly different, to be able to handle UTF-16 stored in UTF-16 or in UTF-8 (i.e. CESU-8)).
I'll go ahead and put something in that gives them the new names, with a stern warning! 😀

It took me longer that I thought for, busy with kids. I see other people have commented.
I wanted to also have this deprecated, because it looked like there might be a number of unregistered forks of the JSON code, so better safe than sorry, and anyway, all this will disappear when 0.5 comes out, right?

@ScottPJones
Copy link
Contributor Author

This now does depwarn as @tkelman wanted, and also adds tests (along with adding a new test/deprecated.jl file where people can add tests to make sure that the deprecations they added actually are working (and help us with coverage).

@ScottPJones
Copy link
Contributor Author

This is mergeable again, and should help increase the testing coverage.

@tkelman
Copy link
Contributor

tkelman commented Jul 14, 2015

no, there's a conflict, needs a rebase

@ScottPJones
Copy link
Contributor Author

Darn, I had it all up-to-date before we went away this weekend! I feel like Job sometimes, continuously dealing with merge conflicts! It should be fine now (Jeff had added some deprecations, not sure why git couldn't handle the merge)

@ScottPJones
Copy link
Contributor Author

Tests passed now, all ready again.

@ScottPJones
Copy link
Contributor Author

Bump: this deprecates the usage of 6 undocumented, unexported functions in the UTF-8 and UTF-16 handling code, that have already been used in packages, that have been replaced by more generic functions. It also adds tests for all 6, and shows a way of adding coverage tests for the deprecations themselves (as I've seen occurrences of bugs getting introduced in the deprecation code itself).

@@ -539,6 +539,63 @@ end

export MathConst, @math_const

# 11551
function utf16_is_surrogate(chr::UInt16)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of (almost) exactly repeated code. Should really use a for loop and a macro, at least for all the single-arg cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, good point! Thanks! (I'm just not yet good at macros, but this is probably easy enough for me to learn how quickly)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be worth the trouble. Since JSON has been fixed, the need for this PR is questionable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found other places, added the deprecations for is_utf8_start & is_utf8_continuation,
and I think it sets a good precedent for people to add unit tests for deprecations.

@ScottPJones ScottPJones changed the title Deprecate utf16_is_surrogate and utf16_get_supplementary Deprecate utf16_is_*, utf16_get_supplementary, is_utf_*, add @unexportedwarning macro, add tests Jul 30, 2015
@ScottPJones ScottPJones changed the title Deprecate utf16_is_*, utf16_get_supplementary, is_utf_*, add @unexportedwarning macro, add tests Deprecate utf16_is_*, utf16_get_supplementary, is_utf8_*, add @unexportedwarning macro, add tests Jul 30, 2015
@ScottPJones
Copy link
Contributor Author

Bump: This passes, all done with a macro which can be used for any future deprecations of unexported functions, and unit tests.

These functions were undocumented and unexported, and were not generic.
They have been replaced by other, generic functions, that will work on unsigned values of any size.
Although it is not normal to have to deprecate unexported functions, these are being used in some packages (notably JSON.jl, which is used by many other packages)
This will allow people to easily deprecate functions that were supposed to be private,
but got used in packages (like Base.indentation, Base.unindent, Base.is_utf_start, etc.)
@ScottPJones
Copy link
Contributor Author

Bump? I'd love to have this facility to easily deprecate functions that have been used outside of Base, which where unexported and undocumented (meant to be essentially private).

@StefanKarpinski
Copy link
Member

It took me quite a while to figure out what this PR is even doing since it doesn't explain anywhere. It seems to be doing for non-exported names what the @deprecate macro does for exported names.

  1. The implementation a wholesale copy-pasta of the definition of @deprecate which is not ok.
  2. I don't want to get into maintaining deprecations of unexported things.

If someone used something in Base that wasn't exported and it gets removed, then their code will break and they can fix it.

@tknopp
Copy link
Contributor

tknopp commented Aug 11, 2015

@StefanKarpinski: See 9071f14#commitcomment-11953239 for the origins of this.
I also do not see the point of deprecating unexported functions.

@quinnj
Copy link
Member

quinnj commented Aug 11, 2015

Yeah, even though I originally whined about it, we definitely don't need to deprecate un-exported methods. As I suggested there, it's certainly a good faith effort to search existing packages and notify authors, but we definitely don't need to deprecate.

@ScottPJones
Copy link
Contributor Author

we definitely don't need to deprecate un-exported methods.

This already bit me in a big way once, and the other deprecation I put in this PR is for another function that is used in at least one package. With this, I can remove unexported functions from base, without having to worry about causing lots of breakage.
Unless or until Julia gets some way of indicating that a function is not meant to be accessible outside the module it is defined in, this will be a constant problem (having people use functions that they stumble across in Base [or in other packages unexported functions]).
I've found many, many places just in the registered packages where unexported functions are being used, to say nothing of unregistered packages or people's unpublished source code.

Another thing is that just because something is not exported, doesn't mean that it is not meant to be used outside of the module (which is why the accessibility or private distinction is important).
I've seen a number of functions that are not exported, not because they are not meant to be used outside of the module, but to avoid name pollution.

A good counter-example is Base.compile.
If 0.4 had been frozen before we decided to rename Base.compile as Base.compilecache, then we would have needed to deprecate it.

Finally, deprecations only need to be maintained for one release cycle.
After that, they should really be removed, or changed to simply give a fatal error (with the explanation that the old function was deprecated).

About the copy-pasta of the @deprecate macro, that was simply the easiest way to implement it, after @tkelman said it should really be a macro, but I can refactor that tonight after I get home.

@tknopp
Copy link
Contributor

tknopp commented Aug 16, 2015

@StefanKarpinski: Do you have objections closing this.

@StefanKarpinski
Copy link
Member

No, fine by me. There's a pattern here.

@tknopp
Copy link
Contributor

tknopp commented Aug 16, 2015

Discussion moved to #12647

@tknopp tknopp closed this Aug 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unicode Related to unicode characters and encodings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants