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

RFC: lower a' as var"'"(a) #34634

Merged
merged 5 commits into from
May 1, 2020

Conversation

simeonschaub
Copy link
Member

@simeonschaub simeonschaub commented Feb 2, 2020

As proposed by @JeffBezanson in #33683, this changes the lowering of a' to __adjoint__(a) var"'"(a), where var"'" can be shadowed by the user. This should be less breaking than that PR, so could someone trigger PkgEval?

@maleadt
Copy link
Member

maleadt commented Feb 3, 2020

@nanosoldier runtests(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected. A full report can be found here. cc @maleadt

@simeonschaub
Copy link
Member Author

Doesn't seem like any of the failures were caused by this PR, so that's definitely a good sign!

@JeffBezanson JeffBezanson added the triage This should be discussed on a triage call label Feb 3, 2020
@JeffBezanson
Copy link
Member

The implementation is correct. I think the main thing to do is decide whether we like this approach, and if so apply it consistently to this kind of syntax, and address it in the manual.

@JeffBezanson JeffBezanson added needs docs Documentation for this change is required needs news A NEWS entry is required for this change labels Feb 3, 2020
@KristofferC
Copy link
Member

KristofferC commented Feb 3, 2020

This would mean https://github.com/simonster/TwoBasedIndexing.jl could make a comeback? Let's go!

@yuyichao
Copy link
Contributor

yuyichao commented Feb 3, 2020

What's the point of letting a local name override a syntax? Overriding a global name in a local scope is certainly fine but this one seems to be all about syntax. If it was not about syntax then the user should have just picked a different function name instead, i.e. the user should just use my_adjoint(a) rather than a'. However, syntax customization was exactly what macro is for. A huge advantage of macros is that it is easy to spot where it is applied so it is very easy to realize when customized syntax rule applies. This change just completely changes things and seems to allow a global assignment to suddenly change the meaning of a syntax with absolutely no visual clue about it. Say a @innocent_macro that is expanded to :($(esc(__adjoint__)) = my_adjoint) or a global assignment in a different file.

It seems that the syntax customization can already be done by having a macro enclosing the part with customized syntax and the existing approach seems to be way clearer.

@JeffBezanson
Copy link
Member

Yes, but I can already write + = print...

@yuyichao
Copy link
Contributor

yuyichao commented Feb 3, 2020

Right, that's fine and that's why I said.

Overriding a global name in a local scope is certainly fine but this one seems to be all about syntax.

+ isn't a syntax.

@yuyichao
Copy link
Contributor

yuyichao commented Feb 3, 2020

Also, the bigger difference is that for builtin functions, they aren't much better names than user defined ones so while you can do push! = my_push! or + = my_add, there are alternative names and operators that can be used so we are in no way encouraging people to actually override them. I wouldn't say the fact that a few very fundamental and commonly used names being overridable is a plus either, but since they aren't being overriden in real life frequent enough and there isn't enough reason for people to do it, it doesn't matter very much and are basically examples of "don't shot yourself in the foot". This is also how scope works right now so unless the rule of scope changes it doesn't make much sense to special case a few commonly used functions.

However, the whole point of this change seems to be that people actually want to override this where the syntax was originally not overridable without using a macro. If no one actually want to use this to make a implicit syntax change then I'm certainly fine with that but in that case the lowering might as well not be changed.

@JeffBezanson
Copy link
Member

Making a distinction between ' being syntax and ! and + not feels a little arbitrary to me. Should we make x' call var"'" instead?

@simeonschaub
Copy link
Member Author

simeonschaub commented Feb 3, 2020

Are you talking about applying this to every call, that currently gets lowered to a Base function, or would we draw a line somewhere? Out of the top of my head, I can think of getindex, setindex!, getproperty, setproperty!, the whole broadcasting machinery and cat, hcat and vcat, but I'm sure there are others.

@yuyichao
Copy link
Contributor

yuyichao commented Feb 3, 2020

Making a distinction between ' being syntax and ! and + not feels a little arbitrary to me. Should we make x' call var"'" instead?

If the argument is consistency, I'm certainly fine with lowering a' to a call of var"'"(a). The fact that this allow someone to override things and write confusing code is unfortunate but that's OK. Edit: though this argument works better if there are more generic postfix operators. The fact that ' is already special in this regard makes the distinction not as arbitrary anymore...

This however shouldn't be applied to other syntaxes, especially getindex and setindex!. Edit: and basically all the other syntaxes mentioned above.

@simeonschaub
Copy link
Member Author

Thinking about it some more, I agree that lowering to var"'" makes more sense than __adjoint__, because if we decide that we want to support unicode modifiers for ', as described in #34507, it would be inconsistent, if one was lowered as __adjoint__ and the other as var"'ᵀ".

@simeonschaub simeonschaub changed the title RFC: lower a' as __adjoint__(a) RFC: lower a' as var"'"(a) Feb 4, 2020
@simeonschaub
Copy link
Member Author

simeonschaub commented Feb 4, 2020

There seems to be consensus, that it makes more sense to lower to var"'", so I made that change.

@simeonschaub
Copy link
Member Author

simeonschaub commented Feb 4, 2020

Would it make sense to merge the docstrings for ' and adjoint into one?

NEWS.md Outdated Show resolved Hide resolved
@c42f
Copy link
Member

c42f commented Feb 11, 2020

I agree that declaring a' more syntaxy than a + b seems pretty arbitrary so I think we should make this change to lowering for a little extra consistency. Unfortunately it doesn't actually bring the main benefits in consistency without parsing a' as Expr(:call, Symbol("'"), a) but I guess that's a julia-2.0 thing.

I reviewed the translation table in lowering. I was somewhat surprised, but adjoint seems to be the only "clearly function-like" syntax we should apply this treatment to.

@c42f
Copy link
Member

c42f commented Feb 18, 2020

Would it make sense to merge the docstrings for ' and adjoint into one?

Yes I think so. See the docstring for => as an analogy. [edit: also ]

@simeonschaub simeonschaub force-pushed the lower_'_as___adjoint__ branch from 0a120a9 to 9b94ef3 Compare February 21, 2020 14:19
@simeonschaub
Copy link
Member Author

I merged the two docstrings and added another example. I also thought, I'd add a sentence, that explains how adjoint behaves for number types, because that was missing before.

@c42f c42f removed needs docs Documentation for this change is required needs news A NEWS entry is required for this change labels Feb 26, 2020
@Keno Keno removed the triage This should be discussed on a triage call label Feb 27, 2020
@simeonschaub
Copy link
Member Author

I think this should be mostly done now. Or are there still issues that need to be addressed?

Copy link
Member

@c42f c42f left a comment

Choose a reason for hiding this comment

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

Personally I think this is a small improvement of consistency and it's worth doing.

@c42f
Copy link
Member

c42f commented Mar 4, 2020

I wasn't on the triage call though so I asked about it last week in #triage on slack. Jeff said the following:

We decided that it's ok, but the main motivation seems to be adding unicode suffixes to ', which is a bit breaking.

So I'm not sure whether triage was in favor of just merging this, only merging if unicode suffixes go ahead, or just ambivalent.

@simeonschaub
Copy link
Member Author

Any news on this?

@StefanKarpinski StefanKarpinski added the triage This should be discussed on a triage call label Apr 16, 2020
@MasonProtter
Copy link
Contributor

MasonProtter commented Apr 25, 2020

Regarding

We decided that it's ok, but the main motivation seems to be adding unicode suffixes to ', which is a bit breaking.

that can come later if we worry about it being breaking. As it stands, I'd argue that shadowing is good enough, i.e. allowing

julia> let var"'" = transpose, v = rand(ComplexF64, 5)
         v'v
      end
1.6027508097762602 + 3.5821371834839146im

@JeffBezanson JeffBezanson removed the triage This should be discussed on a triage call label Apr 30, 2020
@JeffBezanson
Copy link
Member

Ok, fine, I guess I have a bit of a soft spot for local operators 😛 This can be rebased and merged.

@simeonschaub simeonschaub force-pushed the lower_'_as___adjoint__ branch from 9b94ef3 to f5762f7 Compare April 30, 2020 21:52
@simeonschaub
Copy link
Member Author

Should be ready to merge now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.