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

WIP: Add @code_llvm macro #5779

Closed
wants to merge 1 commit into from
Closed

WIP: Add @code_llvm macro #5779

wants to merge 1 commit into from

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Feb 12, 2014

This allows you to do:

In  [74]: @code_llvm 1 + 1

define i64 @"julia_+672"(i64, i64) {
top:
  %2 = add i64 %1, %0, !dbg !2075
  ret i64 %2, !dbg !2075
}

Reference issue: #5674

I based this entirely after the implementation of @which, but it seems like it could be a bit cleaner. If we get some more thorough review here I can accordingly add the other code_ macros.

This allows you to do:
```julia
In  [74]: @code_llvm 1 + 1

define i64 @"julia_+672"(i64, i64) {
top:
  %2 = add i64 %1, %0, !dbg !2075
  ret i64 %2, !dbg !2075
}
```
Reference issue: #5674

I based this entirely after the implementation of `@which`, but it seems like it could be a bit cleaner. If we get some more thorough review here I can accordingly add the other code_ macros.
@StefanKarpinski
Copy link
Sponsor Member

In general, I think it would be good to make all the function versions of these kinds of things take fun, types arguments and then have corresponding macro versions that operate on expressions applied to actual values. We're pretty close to this now – I think the main exception is that the which function takes a tuple of values instead of a tuple of types.

@StefanKarpinski
Copy link
Sponsor Member

Also, this is lovely.

@JeffBezanson
Copy link
Sponsor Member

I do like the idea of this, but this should clearly share code with which.
It may not be obvious that this shows the code only of the outermost called function; @code_llvm sin(cos(x)) looks like it will show the code for calling cos then sin. This problem is less serious for which since it's clear that which is only telling you about one method.

@quinnj
Copy link
Member Author

quinnj commented Feb 13, 2014

Yeah, I had a drive tonight and realized we need a _fun_arg_split internal function that does the expression splitting for @which and @code_ macros.

In terms of just showing the outermost function only, I guess my natural expectation was that it would indeed only show the outermost.

In  [79]: macroexpand(:(@code_llvm sin(cos(1))))

Out [79]: :(code_llvm(sin,(typeof(cos(1)),)))

AKA what's the llvm for calling sin with the argument I pass it, in this case it's the result of cos(1), though I see what you're saying. In any case, we can add a doc snippet about the behavior of outermost. Unless there's a way we can allow showing everything? Recursive code_llvm calls with the results appended?

@StefanKarpinski
Copy link
Sponsor Member

One option would be to show code for all of the function calls in the expression in some order, but that would probably be a lot of code.

@mbauman
Copy link
Sponsor Member

mbauman commented Feb 17, 2014

I didn't mean to supersede this, but I happened to stumble upon a solution that completely shares code with @which that works for @edit and @less (as I intended) as well as all these @code_* flavors. Of course, my solution still has the @code_llvm sin(cos(x)) problem that @JeffBezanson talks about. #5832

@ivarne
Copy link
Sponsor Member

ivarne commented Feb 17, 2014

I would love to be proven wrong, but I do not think it is possible to present the information Jeff wants in a way that would be intuitive in a terminal interface. I think it would be a job for Julia Studio, iJulia and Julietta to rewrite these macros to be more useful in their rich environments. The documentation @mbauman wrote, says very clear that only the outer function is considered.

@quinnj
Copy link
Member Author

quinnj commented Feb 17, 2014

Subsumed by #5832.

@quinnj quinnj closed this Feb 17, 2014
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.

5 participants