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

Sync Fork from Upstream Repo #12

Merged
merged 74 commits into from
Aug 15, 2020
Merged

Sync Fork from Upstream Repo #12

merged 74 commits into from
Aug 15, 2020

Conversation

sthagen
Copy link
Owner

@sthagen sthagen commented Aug 15, 2020

No description provided.

sostock and others added 30 commits July 30, 2020 10:23
* Fix allunique(::StepRangeLen)
* Add specialized unique(::AbstractRange) method
Defining

    struct MyInt <: Integer
        x::Int
    end
    (::Type{T})(x::MyInt) where T<:Integer = T(x.x)

triggers about 830 unique method invalidations. This fixes the majority
of them, but it's a lot of type-annotation.
When inlining declines to inline something, it instead turns them into
:invoke statements. These are then turned into direct (non-inlined)
calls by codegen or otherwise receive a fast path at runtime. While
inlining has evolved quite a bit, this code has stayed much the same
since it was introduced four years ago and doesn't seem to make much
sense as is. In particular:

1. For the non-`invoke()` case we were doing an extra method look that
seems entirely superfluous, because we already had to do the very same
method lookup just to reach this point. The only thing this path was
doing at that point was creating a "compilable" specialization (which
might use a slightly different signature). We might as well do that
directly.

2. For the invoke case, we were pro-actively adding the specialization
to the `->invokes` dispatch cache. However, this doesn't make much sense
a priori either, because the bail path does not go through the runtime
`invoke()` code that uses that cache (it did many years ago when this
code was introduced, but hasn't in a long time). There does not seem
to be a good reason to believe that this signature will be any more
likely than any other to be invoked using the runtime mechanism.

This cleans up that path by getting rid of both the superfluous method
lookup and the superfluous addition to the `->invokes` cache. There
should be a slight performance improvement as well from avoiding
this superfluous work, but the bail path is less common than one
might expect (the vast majority of call sites are inlined) and in
measurements the effect seems to be in the noise. Nevertheless,
it seems like a nice simplification and is conceptually clearer.
Includes build fixes to ensure it is built thread-safe. Fixes #35796 regression.
We might print ANSI color codes around ERROR now, making this test unreliable.
Co-authored-by: tylebrow <tyler.brown@gartner.com>
`nnz` counts the number of elements stored in the `SparseMatrixCSC`. "Structural nonzeros" is a tautology.
* Document returned LLVM type for a few functions
* Require and assert `Vboxed` to be of type `T_prjlvalue`
* Remove unused branch/specialization of `maybe_decay_tracked`
* Add function to cast known-untracked value.
- enables building with TSAN for the runtime library as well as Julia code
- updates the handling of `SANITIZE=1` in Make.inc
- moves sanitizer to late in the pipeline, copies what Clang does
- cleans up `options.h`, and `julia_internal.h` w.r.t sanitizers
- update devdocs for sanitizer
- adds a patch for TSAN to deal with Julia's usage of address spaces
- don't use COPY_STACKS with TSAN
- don't use DEEPBIND by default if a sanitizer is enabled
This provides a fallback `eltype` method specialized for imprecise
NamedType types. Formerly we were calling the generic eltype fallback
`eltype(::Type) = Any`, but relying on the generic fallback makes
code vulnerable to invalidation when new `eltype` methods are added.
Since this affects any poorly-inferred keyword-arg function,
it's best to isolate this by defining a specialization.
Defining

    struct MyInt <: Integer
        x::Int
    end
    (::Type{T})(x::MyInt) where T<:Integer = T(x.x)

triggers about 830 unique method invalidations. This fixes the majority
of them, but it's a lot of type-annotation.
- move locks array to thread-local state
- move tid,prio to occupy existing alignment padding
)

Also make sure the warning print something more useful if the version file can't be found and don't print an error about file not found.
This was missed from #36756 and was deleted in #36776 .
- it's been used as an alias to `Core.Const` and so there's been two 
ways to construct them, i.e. via `Const`'s constructor and 
`AbstractEvalCall`
- I think this indirection is unnecessary, but rather just confusing so 
rename all the `AbstractEvalConstant` to `Const`
- use ThreadSynchronizer type alias in ReentrantLock
- tweak the `timedwait` documentation; in particular, rename the `testcb`
  argument to `callback`
- clarify an "Special note for Threads.Condition" to not reference a
  variable `c` that was never defined
Some cleanup and comment for addrspace tracking in codegen
CameronBieganek and others added 27 commits August 11, 2020 10:47
Move the code that inlines results from `@pure` function earlier.
It doesn't depend on any of the method analysis, so doing that
work was just wasted time.
…6970)

The metadata on the load may be striped by LLVM when moving code around
This allows much easier debugging of imaging mode codegen
without hacks like specifying a dummy output and manually running
module init functions.

Also allows specializing codegen to give result more similar to
code in actual sysimg in this debugging mode. Ref #36974.
…e vectors out of the loops in order to get a speedup in some cases where type inference otherwise takes tuple types. (#36975)
Co-authored-by: Ian <i.r.butterworth@gmail.com>
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
* fix 28188: filename lost in cmd interpolation

* move test to test/misc.jl
…_tfunc (#36926)

* Avoid constructing an array only to splat it to make a tuple in tuple_tfunc

* use ntuple
Removes ambiguity:
```
julia> Base.OrderStyle(Union{})
ERROR: MethodError: Base.OrderStyle(::Type{Union{}}) is ambiguous. Candidates:
```
This error is relevant as with current `unique!` definition that relies on `OrderStyle` one can have a problem in corner cases. E.g.:
```
julia> [i for i in ["1"] if i isa Int]
0-element Array{Union{},1}
```

Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
Also add a few missing llvm eltypes for load and GEPs.
Make alignment of tag more obvious for LLVM and
add a few optimization passes after GC lowering to let LLVM
delete some write barriers.

This fixes a regression from LLVM < 5 where the pass ordering makes this
happen automatically.
These were left over from when our IR wasn't quite linear yet
and it was possible to have to evaluate another slot deep in
the nesting context. Since that's not true anymore, these
arguments are all unused.
This should make this previously non-atomic mutex threadsafe.

Fixes #35117
This defines how much time we waste before letting another process run.
Until we have performance measurements, this should probably be small.

Closes #36952
The most common argument type for `to_indices` is a tuple of `Int`,
yet we rely on the `Integer` fallback. This makes it vulnerable to
invalidation by methods like https://github.com/JuliaMath/Interpolations.jl/blob/bcd05a3f0843661104589c31da8d257fecdbe265/src/Interpolations.jl#L273
which would rather convert non-`Int` integers.
This prevents approximately 80 MethodInstance invalidations.
@sthagen sthagen merged commit 049f588 into sthagen:master Aug 15, 2020
sthagen pushed a commit that referenced this pull request Apr 20, 2022
Follows up JuliaLang#44708 -- in that PR I missed the most obvious optimization
opportunity, i.e. we can safely eliminate `isdefined` checks when all
fields are defined at allocation site.
This change allows us to eliminate capturing closure constructions when
the body and callsite of capture closure is available within a optimized
frame, e.g.:
```julia
function abmult(r::Int, x0)
    if r < 0
        r = -r
    end
    f = x -> x * r
    return @inline f(x0)
end
```
```diff
diff --git a/_master.jl b/_pr.jl
index ea06d865b75..c38f221090f 100644
--- a/_master.jl
+++ b/_pr.jl
@@ -1,24 +1,19 @@
 julia> @code_typed abmult(-3, 3)
 CodeInfo(
-1 ── %1  = Core.Box::Type{Core.Box}
-│    %2  = %new(%1, r@_2)::Core.Box
-│    %3  = Core.isdefined(%2, :contents)::Bool
-└───       goto #3 if not %3
+1 ──       goto #3 if not true
 2 ──       goto #4
 3 ──       $(Expr(:throw_undef_if_not, :r, false))::Any
-4 ┄─ %7  = (r@_2 < 0)::Any
-└───       goto #9 if not %7
-5 ── %9  = Core.isdefined(%2, :contents)::Bool
-└───       goto #7 if not %9
+4 ┄─ %4  = (r@_2 < 0)::Any
+└───       goto #9 if not %4
+5 ──       goto #7 if not true
 6 ──       goto #8
 7 ──       $(Expr(:throw_undef_if_not, :r, false))::Any
-8 ┄─ %13 = -r@_2::Any
-9 ┄─ %14 = φ (#4 => r@_2, #8 => %13)::Any
-│    %15 = Core.isdefined(%2, :contents)::Bool
-└───       goto #11 if not %15
+8 ┄─ %9  = -r@_2::Any
+9 ┄─ %10 = φ (#4 => r@_2, #8 => %9)::Any
+└───       goto #11 if not true
 10 ─       goto #12
 11 ─       $(Expr(:throw_undef_if_not, :r, false))::Any
-12 ┄ %19 = (x0 * %14)::Any
+12 ┄ %14 = (x0 * %10)::Any
 └───       goto #13
-13 ─       return %19
+13 ─       return %14
 ) => Any
```
sthagen pushed a commit that referenced this pull request Jun 29, 2022
When calling `jl_error()` or `jl_errorf()`, we must check to see if we
are so early in the bringup process that it is dangerous to attempt to
construct a backtrace because the data structures used to provide line
information are not properly setup.

This can be easily triggered by running:

```
julia -C invalid
```

On an `i686-linux-gnu` build, this will hit the "Invalid CPU Name"
branch in `jitlayers.cpp`, which calls `jl_errorf()`.  This in turn
calls `jl_throw()`, which will eventually call `jl_DI_for_fptr` as part
of the backtrace printing process, which fails as the object maps are
not fully initialized.  See the below `gdb` stacktrace for details:

```
$ gdb -batch -ex 'r' -ex 'bt' --args ./julia -C invalid
...
fatal: error thrown and no exception handler available.
ErrorException("Invalid CPU name "invalid".")

Thread 1 "julia" received signal SIGSEGV, Segmentation fault.
0xf75bd665 in std::_Rb_tree<unsigned int, std::pair<unsigned int const, JITDebugInfoRegistry::ObjectInfo>, std::_Select1st<std::pair<unsigned int const, JITDebugInfoRegistry::ObjectInfo> >, std::greater<unsigned int>, std::allocator<std::pair<unsigned int const, JITDebugInfoRegistry::ObjectInfo> > >::lower_bound (__k=<optimized out>, this=0x248) at /usr/local/i686-linux-gnu/include/c++/9.1.0/bits/stl_tree.h:1277
1277    /usr/local/i686-linux-gnu/include/c++/9.1.0/bits/stl_tree.h: No such file or directory.
 #0  0xf75bd665 in std::_Rb_tree<unsigned int, std::pair<unsigned int const, JITDebugInfoRegistry::ObjectInfo>, std::_Select1st<std::pair<unsigned int const, JITDebugInfoRegistry::ObjectInfo> >, std::greater<unsigned int>, std::allocator<std::pair<unsigned int const, JITDebugInfoRegistry::ObjectInfo> > >::lower_bound (__k=<optimized out>, this=0x248) at /usr/local/i686-linux-gnu/include/c++/9.1.0/bits/stl_tree.h:1277
 #1  std::map<unsigned int, JITDebugInfoRegistry::ObjectInfo, std::greater<unsigned int>, std::allocator<std::pair<unsigned int const, JITDebugInfoRegistry::ObjectInfo> > >::lower_bound (__x=<optimized out>, this=0x248) at /usr/local/i686-linux-gnu/include/c++/9.1.0/bits/stl_map.h:1258
 #2  jl_DI_for_fptr (fptr=4155049385, symsize=symsize@entry=0xffffcfa8, slide=slide@entry=0xffffcfa0, Section=Section@entry=0xffffcfb8, context=context@entry=0xffffcf94) at /cache/build/default-amdci5-4/julialang/julia-master/src/debuginfo.cpp:1181
 #3  0xf75c056a in jl_getFunctionInfo_impl (frames_out=0xffffd03c, pointer=4155049385, skipC=0, noInline=0) at /cache/build/default-amdci5-4/julialang/julia-master/src/debuginfo.cpp:1210
 #4  0xf7a6ca98 in jl_print_native_codeloc (ip=4155049385) at /cache/build/default-amdci5-4/julialang/julia-master/src/stackwalk.c:636
 #5  0xf7a6cd54 in jl_print_bt_entry_codeloc (bt_entry=0xf0798018) at /cache/build/default-amdci5-4/julialang/julia-master/src/stackwalk.c:657
 #6  jlbacktrace () at /cache/build/default-amdci5-4/julialang/julia-master/src/stackwalk.c:1090
 #7  0xf7a3cd2b in ijl_no_exc_handler (e=0xf0794010) at /cache/build/default-amdci5-4/julialang/julia-master/src/task.c:605
 #8  0xf7a3d10a in throw_internal (ct=ct@entry=0xf070c010, exception=<optimized out>, exception@entry=0xf0794010) at /cache/build/default-amdci5-4/julialang/julia-master/src/task.c:638
 #9  0xf7a3d330 in ijl_throw (e=0xf0794010) at /cache/build/default-amdci5-4/julialang/julia-master/src/task.c:654
 #10 0xf7a905aa in ijl_errorf (fmt=fmt@entry=0xf7647cd4 "Invalid CPU name \"%s\".") at /cache/build/default-amdci5-4/julialang/julia-master/src/rtutils.c:77
 #11 0xf75a4b22 in (anonymous namespace)::createTargetMachine () at /cache/build/default-amdci5-4/julialang/julia-master/src/jitlayers.cpp:823
 #12 JuliaOJIT::JuliaOJIT (this=<optimized out>) at /cache/build/default-amdci5-4/julialang/julia-master/src/jitlayers.cpp:1044
 #13 0xf7531793 in jl_init_llvm () at /cache/build/default-amdci5-4/julialang/julia-master/src/codegen.cpp:8585
 #14 0xf75318a8 in jl_init_codegen_impl () at /cache/build/default-amdci5-4/julialang/julia-master/src/codegen.cpp:8648
 #15 0xf7a51a52 in jl_restore_system_image_from_stream (f=<optimized out>) at /cache/build/default-amdci5-4/julialang/julia-master/src/staticdata.c:2131
 #16 0xf7a55c03 in ijl_restore_system_image_data (buf=0xe859c1c0 <jl_system_image_data> "8'\031\003", len=125161105) at /cache/build/default-amdci5-4/julialang/julia-master/src/staticdata.c:2184
 #17 0xf7a55cf9 in jl_load_sysimg_so () at /cache/build/default-amdci5-4/julialang/julia-master/src/staticdata.c:424
 #18 ijl_restore_system_image (fname=0x80a0900 "/build/bk_download/julia-d78fdad601/lib/julia/sys.so") at /cache/build/default-amdci5-4/julialang/julia-master/src/staticdata.c:2157
 #19 0xf7a3bdfc in _finish_julia_init (rel=rel@entry=JL_IMAGE_JULIA_HOME, ct=<optimized out>, ptls=<optimized out>) at /cache/build/default-amdci5-4/julialang/julia-master/src/init.c:741
 #20 0xf7a3c8ac in julia_init (rel=<optimized out>) at /cache/build/default-amdci5-4/julialang/julia-master/src/init.c:728
 #21 0xf7a7f61d in jl_repl_entrypoint (argc=<optimized out>, argv=0xffffddf4) at /cache/build/default-amdci5-4/julialang/julia-master/src/jlapi.c:705
 #22 0x080490a7 in main (argc=3, argv=0xffffddf4) at /cache/build/default-amdci5-4/julialang/julia-master/cli/loader_exe.c:59
```

To prevent this, we simply avoid calling `jl_errorf` this early in the
process, punting the problem to a later PR that can update guard
conditions within `jl_error*`.
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.