{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/29546","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546/events","html_url":"https://github.com/JuliaLang/julia/pull/29546","id":367424071,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIwODY1MjQw","number":29546,"title":"Delegate mightalias(::ReinterpretArray, ::ReinterpretArray) to parent","user":{"login":"tkf","id":29282,"node_id":"MDQ6VXNlcjI5Mjgy","avatar_url":"https://avatars3.githubusercontent.com/u/29282?v=4","gravatar_id":"","url":"https://api.github.com/users/tkf","html_url":"https://github.com/tkf","followers_url":"https://api.github.com/users/tkf/followers","following_url":"https://api.github.com/users/tkf/following{/other_user}","gists_url":"https://api.github.com/users/tkf/gists{/gist_id}","starred_url":"https://api.github.com/users/tkf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkf/subscriptions","organizations_url":"https://api.github.com/users/tkf/orgs","repos_url":"https://api.github.com/users/tkf/repos","events_url":"https://api.github.com/users/tkf/events{/privacy}","received_events_url":"https://api.github.com/users/tkf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-10-06T05:01:03Z","updated_at":"2018-10-17T03:10:54Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/29546","html_url":"https://github.com/JuliaLang/julia/pull/29546","diff_url":"https://github.com/JuliaLang/julia/pull/29546.diff","patch_url":"https://github.com/JuliaLang/julia/pull/29546.patch"},"body":"It fixes #29545, i.e., it makes the following snippet work\r\n\r\n```julia\r\nbuffer = zeros(UInt8, 4 * sizeof(Int))\r\nmid = length(buffer) ÷ 2\r\nx1 = reinterpret(Int, @view buffer[1:mid])\r\nx2 = reinterpret(Int, @view buffer[mid+1:end])\r\nx1 .= x2\r\n```\r\n\r\nHowever, this PR still has some problems.  For example, it does not support `mightalias(::ReinterpretArray, ::SubArray)`.  But defining `mightalias(::ReinterpretArray, ::AbstractArray)` and `mightalias(::AbstractArray, ::ReinterpretArray)` would cause the ambiguity problem (and not DRY).\r\n\r\nA general question is: How one can ensure that `mightalias` is symmetric (i.e., `mightalias(a, b) == mightalias(b, a)`) and easily overloadable?  One possibility is to define a function (say)\r\n\r\n```julia\r\nsymmetric_mightalias(a, b) = mightalias(a, b) && mightalias(b, a)\r\n```\r\n\r\nand document that the first argument of `mightalias` has to specify the type user defined (to reduce ambiguity).\r\n\r\nNote that `symmetric_mightalias` has to be exposed as a public (non-overloadable) API so that it can be called from user's `mightalias`:\r\n\r\n```julia\r\nmightalias(a::ReinterpretArray, b::AbstractArray) = symmetric_mightalias(parent(a), b)\r\n```\r\n\r\nIs it a sane approach?  I'm pretty sure this is a generic problem solved in Julia community ages ago.\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/430474259","html_url":"https://github.com/JuliaLang/julia/pull/29546#issuecomment-430474259","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/29546","id":430474259,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDQ3NDI1OQ==","user":{"login":"tkf","id":29282,"node_id":"MDQ6VXNlcjI5Mjgy","avatar_url":"https://avatars3.githubusercontent.com/u/29282?v=4","gravatar_id":"","url":"https://api.github.com/users/tkf","html_url":"https://github.com/tkf","followers_url":"https://api.github.com/users/tkf/followers","following_url":"https://api.github.com/users/tkf/following{/other_user}","gists_url":"https://api.github.com/users/tkf/gists{/gist_id}","starred_url":"https://api.github.com/users/tkf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkf/subscriptions","organizations_url":"https://api.github.com/users/tkf/orgs","repos_url":"https://api.github.com/users/tkf/repos","events_url":"https://api.github.com/users/tkf/events{/privacy}","received_events_url":"https://api.github.com/users/tkf/received_events","type":"User","site_admin":false},"created_at":"2018-10-17T03:10:54Z","updated_at":"2018-10-17T03:10:54Z","author_association":"CONTRIBUTOR","body":"Thanks a lot for detailed reply. Yes, I should have looked into the pre-existing discussion for why the current implementation is chosen. I'll look into #25890 to catch up.\r\n\r\n`aliasingroot` sounds interesting but how do you get rid of infinite recursion?  I suppose you meant something like\r\n\r\n```julia\r\nmightalias(a::Array, b::Array) = # dataids-based analysis\r\nmightalias(a::AbstractArray, b::AbstractArray) =\r\n    mightalias(aliasingroot(a), aliasingroot(b))  # possible recursion\r\n\r\nfunction aliasingroot(a::AbstractArray)  # maybe use @generated to check .parent field?\r\n    if parent(a) === a\r\n        return a\r\n    else\r\n        return aliasingroot(parent(a))\r\n    end\r\nend\r\n\r\naliasingroot(a::SubArray) = a\r\n```\r\n\r\nBut if you define a new \"root\" array type `MyArray` (i.e., without `.parent`) then you need to make sure `mightalias(a::MyArray, b::AbstractArray)` and `mightalias(a::AbstractArray, b::MyArray)` are defined to avoid infinite recursion.\r\n\r\nOne \"solution\" I can think of is to decouple \"calling API\" and \"overloading API\", like:\r\n\r\n```julia\r\n# Calling API:\r\nmightalias(a::AbstractArray, b::AbstractArray) = __mightalias__(aliasingroot(a), aliasingroot(b))\r\n\r\n# Overloading API:\r\n__mightalias__(::AbstractArray, ::AbstractArray) = # dataids-based analysis\r\n__mightalias__(a::SubArray, b::SubArray) = ...\r\n```\r\n\r\nWith this, I still need to define `Base.__mightalias__(a::MyArray, b::AbstractArray)` and `Base.__mightalias__(a::AbstractArray, b::MyArray)` if I want to make it more efficient but there is no infinite recursion by default.\r\n"}}
{"actor":{"display_login":"tkf"}}