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

Make application/julia a text MIME #18441

Merged
merged 9 commits into from
Oct 3, 2016
Merged

Conversation

TotalVerb
Copy link
Contributor

Add application/julia as a text MIME, and sort the list of text MIMEs.

I wonder if istextmime could be made a little more intelligent. All mime types with text should be text MIMEs, right?

@stevengj
Copy link
Member

istextmime should return true for anything that should be represented by a String (as opposed to raw binary data), and as far as I can tell this is true for anything in text/ ... indeed, according to RFC6557, which seems to be routinely ignored today thanks to UTF-8, the default charset of text/* data is ASCII.

(I personally hate the fact that programming languages are supposedly in the "application" namespace and not in "text". But IANA does not seem particularly consistent here.... see text/ecmascript vs application/javascript, and those are basically the same language!)

@TotalVerb
Copy link
Contributor Author

TotalVerb commented Sep 11, 2016

Note that text/ecmascript is marked OBSOLETE while application/ecmascript is COMMON. Furthermore, the quoted text there is listed as being considered outdated and having been replaced with UTF-8.

@TotalVerb
Copy link
Contributor Author

TotalVerb commented Sep 11, 2016

I suspect this definition would work as well:

istextmime{T}(::MIME{T}) = startswith(string(T), "text/") || T in [... list of other mimes ...]

Constant-folding during specialization should make performance equivalent to presently; if that does not happen then I suspect marking some things Base.@pure will work.

@TotalVerb
Copy link
Contributor Author

The @textmime macro can be retained in the event a package needs to monkey-patch a text MIME in, although I don't think this is considered a public API.

@nalimilan
Copy link
Member

FWIW, the Freedesktop.org shared MIME database has a <sub-class-of type="text/plain"/> attribute identifying text files. Can be useful as a reference, in particular if we want to ensure before each release that we haven't missed new MIME types (e.g. for new languages).

@@ -81,7 +81,7 @@ istextmime(m::AbstractString) = istextmime(MIME(m))
reprmime(m::AbstractString, x) = reprmime(MIME(m), x)
stringmime(m::AbstractString, x) = stringmime(MIME(m), x)

for mime in ["text/vnd.graphviz", "text/latex", "text/calendar", "text/n3", "text/richtext", "text/x-setext", "text/sgml", "text/tab-separated-values", "text/x-vcalendar", "text/x-vcard", "text/cmd", "text/css", "text/csv", "text/html", "text/javascript", "text/markdown", "text/plain", "text/vcard", "text/xml", "application/atom+xml", "application/ecmascript", "application/json", "application/rdf+xml", "application/rss+xml", "application/xml-dtd", "application/postscript", "image/svg+xml", "application/x-latex", "application/xhtml+xml", "application/javascript", "application/xml", "model/x3d+xml", "model/x3d+vrml", "model/vrml"]
for mime in ["application/atom+xml", "application/ecmascript", "application/javascript", "application/julia", "application/json", "application/postscript", "application/rdf+xml", "application/rss+xml", "application/x-latex", "application/xhtml+xml", "application/xml", "application/xml-dtd", "image/svg+xml", "model/vrml", "model/x3d+vrml", "model/x3d+xml", "text/calendar", "text/cmd", "text/css", "text/csv", "text/html", "text/javascript", "text/latex", "text/markdown", "text/n3", "text/plain", "text/richtext", "text/sgml", "text/tab-separated-values", "text/vcard", "text/vnd.graphviz", "text/x-setext", "text/x-vcalendar", "text/x-vcard", "text/xml"]
Copy link
Contributor

Choose a reason for hiding this comment

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

should line wrap this while we're at it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a standard way to wrap long for loops? I just pushed to the beginning of line here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally follow the matlab convention of indenting line continuations of block openers one level deeper than the body of the block

@TotalVerb
Copy link
Contributor Author

TotalVerb commented Sep 13, 2016

There seems to be demand for a more advanced change. I'm playing around with turning istextmime into a trait, and then dispatching on this trait instead of the clunky @textmime macro. Unfortunately, returning a Bool is currently not good enough (this is essentially #17880), because the return type is known to be a constant too late, and the type instability in reprmime cannot be removed (though LLVM can remove the dead code).

So the new change implements istextmime using a lower-level mimetypetype trait (name could/should be changed to something more descriptive, but I couldn't figure out what). It turns out that this actually simplifies the code quite a bit at this point. While I was working on this, I moved docstrings over from helpdb.jl. In fact, these docstrings mostly duplicated the big comment near the top about text vs. binary mimes.

Remaining issues:

  • Do I need to deprecate @textmime (as I've done here), or should I just rip it out? There exist usages in the wild.
  • What (if anything) should be exported?
  • Does this pessimize performance at all? I wonder if nanosoldier has multimedia benchmarks.

@TotalVerb
Copy link
Contributor Author

Hmm, it looks like the trait did not avoid the ::Union{Array{UInt8,1},String} pessimization of reprmime's return type. I guess the implementation of istextmime might be too complicated. Will try a @pure annotation.

@TotalVerb
Copy link
Contributor Author

The compiler really doesn't like the complexity of the mimetypetype function; adding Base.@pure did not seem to help. My suspicion is that stringmime and reprmime are fairly infrequently used in performance-critical situations, and that when they are the cost of allocation would dominate the cost of the type instability. Perhaps this performance issue can be tolerated until #14324 can be implemented.

Alternatively, we can put the text/ mime types back into the list to maintain.

macro textmime(mime)
Base.depwarn(string("`@textmime mime` is deprecated; use ",
Copy link
Contributor

Choose a reason for hiding this comment

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

if deprecated, it should probably move to deprecated.jl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It needs to be in the Multimedia module though.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, is it not exported from there? could be eval'ed into that module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@kshyatt kshyatt added the io Involving the I/O subsystem: libuv, read, write, etc. label Sep 13, 2016
@TotalVerb
Copy link
Contributor Author

I doubt the performance is an issue, so I think this should be good to go now?

@stevengj
Copy link
Member

I guess so. I have to be honest that I'm not a huge fan of the whole traits technique in cases like this; it seems like an overly complicated way to determine something at compile time that is unlikely to ever be performance-sensitive.

@TotalVerb
Copy link
Contributor Author

@stevengj Well, due to inference limitations these traits aren't even working properly. (We need #14324 to remove the type instability with traits, and with booleans we need #17880). I'm happy to do this with booleans if people like that better.

@TotalVerb
Copy link
Contributor Author

In fact, the original approach was with booleans; then I switched to traits because I ran into #17880, and then I discovered that the functions was too complex for even traits to fix the type instability...

@stevengj
Copy link
Member

Speaking for myself, I'd prefer booleans.

@TotalVerb
Copy link
Contributor Author

@stevengj Just pushed a boolean version. The boolean version is far simpler too, and probably also has lower compilation overhead. I like it also.

@TotalVerb
Copy link
Contributor Author

TotalVerb commented Sep 14, 2016

Oops, I need to fix the deprecated @textmime macro too. Is there a file to test deprecated stuff, or is this generally not done?

@stevengj
Copy link
Member

I don't think we generally add tests for deprecations.

# Deprecate @textmime into the Multimedia module, #18441
eval(Multimedia, :(macro textmime(mime)
Base.depwarn(string("`@textmime mime` is deprecated; use ",
"`Base.Multimedia.mimetypetype(::MIME{mime}) = ",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the deprecation now be Base.istextmime(::MIME{mime}) = true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. The code is correct, but I forgot to update the text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@TotalVerb
Copy link
Contributor Author

Is this good to squash and merge?

@stevengj stevengj merged commit bc9b6ef into JuliaLang:master Oct 3, 2016
Sacha0 added a commit to Sacha0/julia that referenced this pull request May 14, 2017
@Sacha0 Sacha0 added deprecation This change introduces or involves a deprecation needs news A NEWS entry is required for this change labels May 14, 2017
@tkelman tkelman removed the needs news A NEWS entry is required for this change label May 16, 2017
tkelman pushed a commit that referenced this pull request May 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation This change introduces or involves a deprecation io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants