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

Only evaluate fexpr in fexpr(kw=...) once #21519

Merged
merged 2 commits into from
Apr 27, 2017
Merged

Only evaluate fexpr in fexpr(kw=...) once #21519

merged 2 commits into from
Apr 27, 2017

Conversation

martinholters
Copy link
Member

Lower e.g. get_inner()(kw=1) to

SSAValue(n) = get_inner()
((Core.kwfunc)(SSAValue(n)))((Base.vector_any)(:kw, 1), SSAValue(n))

instead of

((Core.kwfunc)(get_inner()))((Base.vector_any)(:kw, 1), get_inner())

as the latter would call get_inner twice.

Fixes #21518.

@martinholters martinholters changed the title Only evalate fexpr in fexpr(kw=...) once Only evaluate fexpr in fexpr(kw=...) once Apr 24, 2017
@tkelman tkelman added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Apr 24, 2017
,(if has-kw
(let ((f (make-ssavalue)))
`(block
(= ,f, fexpr)
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to insert this only if (not (sym-ref? fexpr)), to keep the IR simpler.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. I hope my non-existent lisp skills can take me there...

Lower e.g. `get_inner()(kw=1)` to
```
SSAValue(n) = get_inner()
((Core.kwfunc)(SSAValue(n)))((Base.vector_any)(:kw, 1), SSAValue(n))
```
instead of
```
((Core.kwfunc)(get_inner()))((Base.vector_any)(:kw, 1), get_inner())
```
as the latter would call `get_inner` twice.

Fixes #21518.
@martinholters
Copy link
Member Author

@JeffBezanson does this look ok to you?

@@ -275,3 +275,12 @@ end
f21510(; a::ANY = 2) = a
@test f21510(a=:b) == :b
@test f21510() == 2

# issue #21518
a = 0
Copy link
Contributor

@tkelman tkelman Apr 26, 2017

Choose a reason for hiding this comment

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

can this be made a let and still accomplish the test?

or name it a21518

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, let should work.

@JeffBezanson
Copy link
Member

@martinholters Yes this should work, thanks! I really appreciate your help here.

(if (null? stmts)
(let ((f (if (sym-ref? fexpr) fexpr (make-ssavalue))))
`(block
,(if (eq? f fexpr) () `(= ,f, fexpr))
Copy link
Member

@JeffBezanson JeffBezanson Apr 26, 2017

Choose a reason for hiding this comment

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

A slightly better way to write this is ,@(if (eq? f fexpr) '() `((= ,f, fexpr))), which will insert nothing at all when no assignment is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, ok, will update.

@martinholters
Copy link
Member Author

I really appreciate your help here.

I was wondering whether reviewing my PR would be about as much work as doing it yourself. So I guess not quite 😄

@martinholters
Copy link
Member Author

Updated. Should be squashed when merged.

@JeffBezanson
Copy link
Member

I consider this a very worthwhile investment in our "bus number" :)

@JeffBezanson JeffBezanson merged commit 2d803f3 into master Apr 27, 2017
@martinholters martinholters deleted the mh/fix_21518 branch April 27, 2017 05:11
@martinholters
Copy link
Member Author

Not the best time to ask with 0.5.2 almost ready, but... should we backport this? The bug does affect 0.5, but I don't think it will be hit very often and it has a simple work-around.

@StefanKarpinski
Copy link
Member

Does the patch apply fairly cleanly? If so, I don't see why not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants