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: improve inlined line numbers, take 2 #16335

Merged
merged 4 commits into from
May 19, 2016
Merged

RFC: improve inlined line numbers, take 2 #16335

merged 4 commits into from
May 19, 2016

Conversation

JeffBezanson
Copy link
Member

This is a rebased and edited version of #14949. To reduce the scope a bit, I changed it to store file names and function names instead of references to LambdaInfos. The goal is to get something mergeable as soon as possible, as this change has several important fixes from @carnaval :

  1. It fixes the formatting of our LLVM debug info and represents inlined functions properly.
  2. It changes the representation of source location info in our IR.
  3. It adds the ability to represent any number of nested inlined functions in backtraces.

I want to get these changes in even if the backtraces are not perfect yet. We can improve it later, either by adding back the LambdaInfo (or Method) references or by keeping a mapping from filename and line number to Methods.

I will merge #15583 into this branch, so we can take advantage of some of this for macro code locations as well.

@@ -759,6 +769,10 @@ extern "C" void jl_register_fptrs(uint64_t sysimage_base, void **fptrs, jl_lambd
sysimg_fvars_n = n;
}

#ifdef _OS_LINUX_
#include <link.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

top of file, around L53-54?

@JeffBezanson JeffBezanson force-pushed the jb/linenums2 branch 2 times, most recently from 91a3866 to 748b043 Compare May 12, 2016 23:56
@JeffBezanson
Copy link
Member Author

I'm not sure how to handle locations from macro expansions. My guess is that there is not good support for the filename magically switching in the middle of a function, so for now I handled it the same way as an inlined function (since that seems to work well), with the inlined function name being macro expansion.

@JeffBezanson JeffBezanson mentioned this pull request May 12, 2016
4 tasks
@JeffBezanson JeffBezanson changed the title WIP: improve inlined line numbers, take 2 RFC: improve inlined line numbers, take 2 May 13, 2016
@toivoh
Copy link
Contributor

toivoh commented May 13, 2016

Will there be a way for Julia code examining the AST to figure or which file that lines from a macro expansion came from?

@StefanKarpinski
Copy link
Member

I'm not sure how to handle locations from macro expansions.

I think ultimately the only way to handle generated code sanely will be to keep generated ASTs and be able to step through them. The julia program should have a command-line argument --keep-source=[yes|no] which defaults to "yes" in interactive mode and defaults to "no" in non-interactive mode.

@JeffBezanson
Copy link
Member Author

Will there be a way for Julia code examining the AST to figure or which file that lines from a macro expansion came from?

Yes, there are push_loc and pop_loc for blocks from a different file.

@timholy
Copy link
Member

timholy commented May 13, 2016

Big fan of this effort.

there are push_loc and pop_loc for blocks from a different file.

Awesome! Doesn't yet seem documented in this PR, though. Might need a small section in devdocs or something.

@@ -4286,7 +4277,7 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
#ifndef LLVM34
SP = dbuilder.createFunction((DIDescriptor)dbuilder.getCU(),
#else
SP = dbuilder.createFunction(CU,
SP = dbuilder.createFunction(topfile,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this works. If the function isn't associated to a compile unit, it might not end up being represented in the binary.

@JeffBezanson JeffBezanson force-pushed the jb/linenums2 branch 2 times, most recently from 85fb83c to b4e7b6f Compare May 16, 2016 20:13
@JeffBezanson
Copy link
Member Author

Dev docs added and comments addressed. Should be ready to merge.

have_backtrace = true
break
end
end

@test have_backtrace

# Test location information for inlined code (ref issues #1334 #12544)
Copy link
Contributor

Choose a reason for hiding this comment

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

if the results of these all changed, can we change them to test the affirmative of what they should be now, instead of deleting them altogether?

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 yes, will do.

@tkelman
Copy link
Contributor

tkelman commented May 17, 2016

This breaks building against LLVM 3.3, if we're still concerned with trying to keep that working for testing/perf comparison.
https://gist.github.com/02d8c53f6c9e5962cb738292478646bb

@carnaval
Copy link
Contributor

Thanks a lot. I got sidetracked with the memory issues and was starting to lose faith ;). Glad to see a lot of it was salvageable. Allocating our own jit sections was an easy win if we don't care too much about W^X but I'm not sure that'll be the consensus.

@JeffBezanson
Copy link
Member Author

Yeah the allocation part is definitely important to work on, but should just be done separately. I suspect it's probably ok to use RWX pages by default, with a switch to disable them.

@JeffBezanson
Copy link
Member Author

It would make me happy to remove all the LLVM version ifdefs. If we have ifdefs for some LLVM version, but it's not tested in CI and even most developers never run it, is it really supported? The readability and maintainability gains would be significant.

However currently I'm having trouble building with LLVM 3.3. I get errors about std::unique_ptr and such. There must be another switch I need to flip.

@tkelman
Copy link
Contributor

tkelman commented May 17, 2016

CXXFLAGS=-std=c++11

I agree that it would help clean things up, but 3.7 is still a pretty bad compiler perf regression relative to 3.3 isn't it? Though I see a failure at the end of bootstrap that was introduced by one of the codegen rewrites in March (#15556), so maybe it's already broken and not salvagable.

@yuyichao
Copy link
Contributor

You need CXXFLAGS+=' -std=c++0x' to compile with llvm 3.3 with gcc. I've also seen issue about linker confused by '@' in the symbol table though.

@JeffBezanson
Copy link
Member Author

Thanks.

3.7 is still a pretty bad compiler perf regression relative to 3.3 isn't it?

Yes it is. But we already decided to make that tradeoff.

@tkelman
Copy link
Contributor

tkelman commented May 17, 2016

On master, as a default build configuration. We don't have every-commit CI for lots of nominally supported configurations, ARM, FreeBSD, etc. We haven't deleted all of the LLVM 3.3 code yet, so the decision of whether or not to keep that a possible option for testing hasn't totally been finalized.

@yuyichao
Copy link
Contributor

I believe @vtjnash is testing it on Mac, which doesn't require much special configuration due to clang being permissive about c++11 features and @ not being a special character for the linker. (FWIW g++ 6.1 use gnu++14 by default so the CXXFLAGS setting shouldn't be necessary anymore)

@JeffBezanson
Copy link
Member Author

OK, LLVM 3.3 build restored to at least as working as it was before.

carnaval and others added 4 commits May 18, 2016 16:43
- add location info to empty blocks; fixes #15280
- remove file names from non-initial `line` nodes
- emit `(meta push_loc filename)` and `(meta pop_loc)` around nested
  blocks from different files, to handle macros
- fix line number of `catch` blocks
@JeffBezanson JeffBezanson merged commit 999f1b5 into master May 19, 2016
@JeffBezanson JeffBezanson deleted the jb/linenums2 branch May 19, 2016 17:39
@vtjnash
Copy link
Member

vtjnash commented May 20, 2016

Is this the cause of the new failure in genstdlib?

WARNING: missing docs for signature:

    lookup(pointer::Union{Ptr{Void}, UInt}) -> StackFrame

@tkelman
Copy link
Contributor

tkelman commented May 20, 2016

81d2c46

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.

9 participants