Skip to content

Commit 997b49f

Browse files
authored
Backports for 1.10.2 (#53405)
Backported PRs: - [x] #53205 <!-- Profile: add notes to `print()` docs --> - [x] #53170 <!-- Remove outdated discussion about externally changing module bindings --> - [x] #53228 <!-- SubArray: avoid invalid elimination of singleton indices --> - [x] #51361 <!-- code_warntype docs: more neutral reference to @code_warntype --> - [x] #50480 <!-- Document --heap-size-hint in Command-line Interface --> - [x] #53301 <!-- Fix typo in `Sys.total_memory` docstring. --> - [x] #53354 <!-- fix code coverage bug in tail position and `else` --> - [x] #53388 <!-- Fix documentation: thread pool of main thread --> - [x] #53429 <!-- Subtype: skip slow-path in `local_∀_∃_subtype` if inputs contain no ∃ typevar. --> - [x] #53437 <!-- Add debug variant of loader_trampolines.o --> Need manual backport: - [ ] #52505 <!-- fix alignment of emit_unbox_store copy --> - [ ] #53373 <!-- fix sysimage-native-code=no option with pkgimages --> - [ ] #53439 <!-- staticdata: fix assert from partially disabled native code --> Contains multiple commits, manual intervention needed: - [ ] #52913 <!-- Added docstring for Artifacts.jl --> - [ ] #53218 <!-- Fix interpreter_exec.jl test --> Non-merged PRs with backport label: - [ ] #53424 <!-- yet more atomics & cache-line fixes on work-stealing queue --> - [ ] #53125 <!-- coverage: count coverage where explicitly requested by inference only --> - [ ] #52694 <!-- Reinstate similar for AbstractQ for backward compatibility --> - [ ] #51479 <!-- prevent code loading from lookin in the versioned environment when building Julia -->
2 parents 7790d6f + 5d971b9 commit 997b49f

File tree

26 files changed

+203
-88
lines changed

26 files changed

+203
-88
lines changed

Diff for: base/compiler/ssair/inlining.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,9 @@ function ssa_substitute!(insert_node!::Inserter,
18111811
spvals_ssa::Union{Nothing, SSAValue},
18121812
linetable_offset::Int32, boundscheck::Symbol)
18131813
subst_inst[:flag] &= ~IR_FLAG_INBOUNDS
1814-
subst_inst[:line] += linetable_offset
1814+
if subst_inst[:line] != 0
1815+
subst_inst[:line] += linetable_offset
1816+
end
18151817
return ssa_substitute_op!(insert_node!, subst_inst,
18161818
val, arg_replacements, spsig, spvals, spvals_ssa, boundscheck)
18171819
end

Diff for: base/compiler/ssair/passes.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,12 @@ function try_inline_finalizer!(ir::IRCode, argexprs::Vector{Any}, idx::Int,
12051205
ssa_rename[ssa.id]
12061206
end
12071207
stmt′ = ssa_substitute_op!(InsertBefore(ir, SSAValue(idx)), inst, stmt′, argexprs, mi.specTypes, mi.sparam_vals, sp_ssa, :default)
1208+
newline = inst[:line]
1209+
if newline != 0
1210+
newline += linetable_offset
1211+
end
12081212
ssa_rename[idx′] = insert_node!(ir, idx,
1209-
NewInstruction(inst; stmt=stmt′, line=inst[:line]+linetable_offset),
1213+
NewInstruction(inst; stmt=stmt′, line=newline),
12101214
attach_after)
12111215
end
12121216

Diff for: base/subarray.jl

+8-6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ _maybe_reshape_parent(A::AbstractArray, ::NTuple{1, Bool}) = reshape(A, Val(1))
127127
_maybe_reshape_parent(A::AbstractArray{<:Any,1}, ::NTuple{1, Bool}) = reshape(A, Val(1))
128128
_maybe_reshape_parent(A::AbstractArray{<:Any,N}, ::NTuple{N, Bool}) where {N} = A
129129
_maybe_reshape_parent(A::AbstractArray, ::NTuple{N, Bool}) where {N} = reshape(A, Val(N))
130+
# The trailing singleton indices could be eliminated after bounds checking.
131+
rm_singleton_indices(ndims::Tuple, J1, Js...) = (J1, rm_singleton_indices(IteratorsMD._splitrest(ndims, index_ndims(J1)), Js...)...)
132+
rm_singleton_indices(::Tuple{}, ::ScalarIndex, Js...) = rm_singleton_indices((), Js...)
133+
rm_singleton_indices(::Tuple) = ()
134+
130135
"""
131136
view(A, inds...)
132137
@@ -173,15 +178,12 @@ julia> view(2:5, 2:3) # returns a range as type is immutable
173178
3:4
174179
```
175180
"""
176-
function view(A::AbstractArray{<:Any,N}, I::Vararg{Any,M}) where {N,M}
181+
function view(A::AbstractArray, I::Vararg{Any,M}) where {M}
177182
@inline
178183
J = map(i->unalias(A,i), to_indices(A, I))
179184
@boundscheck checkbounds(A, J...)
180-
if length(J) > ndims(A) && J[N+1:end] isa Tuple{Vararg{Int}}
181-
# view([1,2,3], :, 1) does not need to reshape
182-
return unsafe_view(A, J[1:N]...)
183-
end
184-
unsafe_view(_maybe_reshape_parent(A, index_ndims(J...)), J...)
185+
J′ = rm_singleton_indices(ntuple(Returns(true), Val(ndims(A))), J...)
186+
unsafe_view(_maybe_reshape_parent(A, index_ndims(J′...)), J′...)
185187
end
186188

187189
# Ranges implement getindex to return recomputed ranges; use that for views, too (when possible)

Diff for: base/sysinfo.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ free_memory() = ccall(:uv_get_available_memory, UInt64, ())
276276
277277
Get the total memory in RAM (including that which is currently used) in bytes.
278278
This amount may be constrained, e.g., by Linux control groups. For the unconstrained
279-
amount, see `Sys.physical_memory()`.
279+
amount, see `Sys.total_physical_memory()`.
280280
"""
281281
function total_memory()
282282
constrained = ccall(:uv_get_constrained_memory, UInt64, ())

Diff for: cli/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LIB_DOBJS := $(BUILDDIR)/loader_lib.dbg.obj
4747
# If this is an architecture that supports dynamic linking, link in a trampoline definition
4848
ifneq (,$(wildcard $(SRCDIR)/trampolines/trampolines_$(ARCH).S))
4949
LIB_OBJS += $(BUILDDIR)/loader_trampolines.o
50-
LIB_DOBJS += $(BUILDDIR)/loader_trampolines.o
50+
LIB_DOBJS += $(BUILDDIR)/loader_trampolines.dbg.obj
5151
endif
5252

5353
default: release
@@ -64,6 +64,8 @@ $(BUILDDIR)/loader_exe.dbg.obj : $(SRCDIR)/loader_exe.c $(HEADERS) $(JULIAHOME)/
6464
@$(call PRINT_CC, $(CC) $(DEBUGFLAGS) $(LOADER_CFLAGS) -c $< -o $@)
6565
$(BUILDDIR)/loader_trampolines.o : $(SRCDIR)/trampolines/trampolines_$(ARCH).S $(HEADERS) $(SRCDIR)/trampolines/common.h
6666
@$(call PRINT_CC, $(CC) $(SHIPFLAGS) $(LOADER_CFLAGS) $< -c -o $@)
67+
$(BUILDDIR)/loader_trampolines.dbg.obj : $(SRCDIR)/trampolines/trampolines_$(ARCH).S $(HEADERS) $(SRCDIR)/trampolines/common.h
68+
@$(call PRINT_CC, $(CC) $(DEBUGFLAGS) $(LOADER_CFLAGS) $< -c -o $@)
6769

6870
# Debugging target to help us see what kind of code is being generated for our trampolines
6971
dump-trampolines: $(SRCDIR)/trampolines/trampolines_$(ARCH).S
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
193abc96d1ea3a83096ba8401acbc5fa
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17f7567be44c2ff3e2c567311cd716191127d0d0f9a4a226d7c06003a5b455343dd8e308032f942bb0a5b95e4b5defc530cc2cda9dfff482aab6f688080c20e7

Diff for: deps/checksums/NetworkOptions-aab83e5dd900c874826d430e25158dff43559d78.tar.gz/md5

-1
This file was deleted.

Diff for: deps/checksums/NetworkOptions-aab83e5dd900c874826d430e25158dff43559d78.tar.gz/sha512

-1
This file was deleted.

Diff for: doc/src/manual/command-line-interface.md

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ The following is a complete list of command-line switches available when launchi
142142
|`--output-incremental={yes\|no*}` |Generate an incremental output file (rather than complete)|
143143
|`--trace-compile={stderr,name}` |Print precompile statements for methods compiled during execution or save to a path|
144144
|`--image-codegen` |Force generate code in imaging mode|
145+
|`--heap-size-hint=<size>` |Forces garbage collection if memory usage is higher than that value. The memory hint might be specified in megabytes (e.g., 500M) or gigabytes (e.g., 1G)|
145146

146147

147148
!!! compat "Julia 1.1"

Diff for: doc/src/manual/multi-threading.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ julia> using Base.Threads
116116
julia> nthreadpools()
117117
2
118118
119-
julia> threadpool()
120-
:default
119+
julia> threadpool() # the main thread is in the interactive thread pool
120+
:interactive
121121
122122
julia> nthreads(:default)
123123
3
@@ -133,6 +133,10 @@ julia> nthreads()
133133
The zero-argument version of `nthreads` returns the number of threads
134134
in the default pool.
135135

136+
!!! note
137+
Depending on whether Julia has been started with interactive threads,
138+
the main thread is either in the default or interactive thread pool.
139+
136140
Either or both numbers can be replaced with the word `auto`, which causes
137141
Julia to choose a reasonable default.
138142

Diff for: doc/src/manual/variables-and-scoping.md

+1-25
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,7 @@ Each module introduces a new global scope, separate from the global scope of all
6767
is no all-encompassing global scope. Modules can introduce variables of other modules into their
6868
scope through the [using or import](@ref modules) statements or through qualified access using the
6969
dot-notation, i.e. each module is a so-called *namespace* as well as a first-class data structure
70-
associating names with values. Note that while variable bindings can be read externally, they can only
71-
be changed within the module to which they belong. As an escape hatch, you can always evaluate code
72-
inside that module to modify a variable; this guarantees, in particular, that module bindings cannot
73-
be modified externally by code that never calls `eval`.
74-
75-
```jldoctest
76-
julia> module A
77-
a = 1 # a global in A's scope
78-
end;
79-
80-
julia> module B
81-
module C
82-
c = 2
83-
end
84-
b = C.c # can access the namespace of a nested global scope
85-
# through a qualified access
86-
import ..A # makes module A available
87-
d = A.a
88-
end;
89-
90-
julia> module D
91-
b = a # errors as D's global scope is separate from A's
92-
end;
93-
ERROR: UndefVarError: `a` not defined
94-
```
70+
associating names with values.
9571

9672
If a top-level expression contains a variable declaration with keyword `local`,
9773
then that variable is not accessible outside that expression.

Diff for: src/jltypes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ JL_DLLEXPORT jl_array_t *jl_find_free_typevars(jl_value_t *v)
215215
}
216216

217217
// test whether a type has vars bound by the given environment
218-
static int jl_has_bound_typevars(jl_value_t *v, jl_typeenv_t *env) JL_NOTSAFEPOINT
218+
int jl_has_bound_typevars(jl_value_t *v, jl_typeenv_t *env) JL_NOTSAFEPOINT
219219
{
220220
while (1) {
221221
if (jl_is_typevar(v)) {

Diff for: src/julia-syntax.scm

+47-34
Original file line numberDiff line numberDiff line change
@@ -4338,7 +4338,7 @@ f(x) = yt(x)
43384338
(car s)
43394339
(loop (cdr s))))))
43404340
`(pop_exception ,restore-token))))
4341-
(define (emit-return x)
4341+
(define (emit-return tail x)
43424342
(define (emit- x)
43434343
(let* ((tmp (if ((if (null? catch-token-stack) valid-ir-return? simple-atom?) x)
43444344
#f
@@ -4347,8 +4347,12 @@ f(x) = yt(x)
43474347
(begin (emit `(= ,tmp ,x)) tmp)
43484348
x)))
43494349
(define (actually-return x)
4350-
(let* ((x (if rett
4351-
(compile (convert-for-type-decl (emit- x) rett #t lam) '() #t #f)
4350+
(let* ((x (begin0 (emit- x)
4351+
;; if we are adding an implicit return then mark it as having no location
4352+
(if (not (eq? tail 'explicit))
4353+
(emit '(line #f)))))
4354+
(x (if rett
4355+
(compile (convert-for-type-decl x rett #t lam) '() #t #f)
43524356
x))
43534357
(x (emit- x)))
43544358
(let ((pexc (pop-exc-expr catch-token-stack '())))
@@ -4487,7 +4491,7 @@ f(x) = yt(x)
44874491
(eq? (car e) 'globalref))
44884492
(underscore-symbol? (cadr e)))))
44894493
(error (string "all-underscore identifier used as rvalue" (format-loc current-loc))))
4490-
(cond (tail (emit-return e1))
4494+
(cond (tail (emit-return tail e1))
44914495
(value e1)
44924496
((symbol? e1) (emit e1) #f) ;; keep symbols for undefined-var checking
44934497
((and (pair? e1) (eq? (car e1) 'outerref)) (emit e1) #f) ;; keep globals for undefined-var checking
@@ -4533,7 +4537,7 @@ f(x) = yt(x)
45334537
(else
45344538
(compile-args (cdr e) break-labels))))
45354539
(callex (cons (car e) args)))
4536-
(cond (tail (emit-return callex))
4540+
(cond (tail (emit-return tail callex))
45374541
(value callex)
45384542
(else (emit callex)))))
45394543
((=)
@@ -4550,7 +4554,7 @@ f(x) = yt(x)
45504554
(if (not (eq? rr rhs))
45514555
(emit `(= ,rr ,rhs)))
45524556
(emit `(= ,lhs ,rr))
4553-
(if tail (emit-return rr))
4557+
(if tail (emit-return tail rr))
45544558
rr)
45554559
(emit-assignment lhs rhs))))))
45564560
((block)
@@ -4603,7 +4607,7 @@ f(x) = yt(x)
46034607
(if file-diff (set! filename last-fname))
46044608
v)))
46054609
((return)
4606-
(compile (cadr e) break-labels #t #t)
4610+
(compile (cadr e) break-labels #t 'explicit)
46074611
#f)
46084612
((unnecessary)
46094613
;; `unnecessary` marks expressions generated by lowering that
@@ -4618,7 +4622,8 @@ f(x) = yt(x)
46184622
(let ((v1 (compile (caddr e) break-labels value tail)))
46194623
(if val (emit-assignment val v1))
46204624
(if (and (not tail) (or (length> e 3) val))
4621-
(emit end-jump))
4625+
(begin (emit `(line #f))
4626+
(emit end-jump)))
46224627
(let ((elselabel (make&mark-label)))
46234628
(for-each (lambda (test)
46244629
(set-car! (cddr test) elselabel))
@@ -4630,7 +4635,7 @@ f(x) = yt(x)
46304635
(if (not tail)
46314636
(set-car! (cdr end-jump) (make&mark-label))
46324637
(if (length= e 3)
4633-
(emit-return v2)))
4638+
(emit-return tail v2)))
46344639
val))))
46354640
((_while)
46364641
(let* ((endl (make-label))
@@ -4672,7 +4677,7 @@ f(x) = yt(x)
46724677
(emit `(label ,m))
46734678
(put! label-map (cadr e) (make&mark-label)))
46744679
(if tail
4675-
(emit-return '(null))
4680+
(emit-return tail '(null))
46764681
(if value (error "misplaced label")))))
46774682
((symbolicgoto)
46784683
(let* ((m (get label-map (cadr e) #f))
@@ -4712,7 +4717,7 @@ f(x) = yt(x)
47124717
(begin (if els
47134718
(begin (if (and (not val) v1) (emit v1))
47144719
(emit '(leave 1)))
4715-
(if v1 (emit-return v1)))
4720+
(if v1 (emit-return tail v1)))
47164721
(if (not finally) (set! endl #f)))
47174722
(begin (emit '(leave 1))
47184723
(emit `(goto ,(or els endl)))))
@@ -4744,7 +4749,7 @@ f(x) = yt(x)
47444749
(emit `(= ,tmp (call (core ===) ,finally ,(caar actions))))
47454750
(emit `(gotoifnot ,tmp ,skip))))
47464751
(let ((ac (cdar actions)))
4747-
(cond ((eq? (car ac) 'return) (emit-return (cadr ac)))
4752+
(cond ((eq? (car ac) 'return) (emit-return tail (cadr ac)))
47484753
((eq? (car ac) 'break) (emit-break (cadr ac)))
47494754
(else ;; assumed to be a rethrow
47504755
(emit ac))))
@@ -4783,8 +4788,8 @@ f(x) = yt(x)
47834788
(set! global-const-error current-loc))
47844789
(emit e))))
47854790
((atomic) (error "misplaced atomic declaration"))
4786-
((isdefined) (if tail (emit-return e) e))
4787-
((boundscheck) (if tail (emit-return e) e))
4791+
((isdefined) (if tail (emit-return tail e) e))
4792+
((boundscheck) (if tail (emit-return tail e) e))
47884793

47894794
((method)
47904795
(if (not (null? (cadr lam)))
@@ -4805,20 +4810,20 @@ f(x) = yt(x)
48054810
l))))
48064811
(emit `(method ,(or (cadr e) '(false)) ,sig ,lam))
48074812
(if value (compile '(null) break-labels value tail)))
4808-
(cond (tail (emit-return e))
4813+
(cond (tail (emit-return tail e))
48094814
(value e)
48104815
(else (emit e)))))
48114816
((lambda)
48124817
(let ((temp (linearize e)))
4813-
(cond (tail (emit-return temp))
4818+
(cond (tail (emit-return tail temp))
48144819
(value temp)
48154820
(else (emit temp)))))
48164821

48174822
;; top level expressions
48184823
((thunk module)
48194824
(check-top-level e)
48204825
(emit e)
4821-
(if tail (emit-return '(null)))
4826+
(if tail (emit-return tail '(null)))
48224827
'(null))
48234828
((toplevel-only)
48244829
(check-top-level (cdr e))
@@ -4828,7 +4833,7 @@ f(x) = yt(x)
48284833
(check-top-level e)
48294834
(let ((val (make-ssavalue)))
48304835
(emit `(= ,val ,e))
4831-
(if tail (emit-return val))
4836+
(if tail (emit-return tail val))
48324837
val))
48334838

48344839
;; other top level expressions
@@ -4837,7 +4842,7 @@ f(x) = yt(x)
48374842
(emit e)
48384843
(let ((have-ret? (and (pair? code) (pair? (car code)) (eq? (caar code) 'return))))
48394844
(if (and tail (not have-ret?))
4840-
(emit-return '(null))))
4845+
(emit-return tail '(null))))
48414846
'(null))
48424847

48434848
((gc_preserve_begin)
@@ -4861,7 +4866,7 @@ f(x) = yt(x)
48614866
(else
48624867
(emit e)))
48634868
(if (and tail (not have-ret?))
4864-
(emit-return '(null)))
4869+
(emit-return tail '(null)))
48654870
'(null)))
48664871

48674872
;; unsupported assignment operators
@@ -4979,6 +4984,7 @@ f(x) = yt(x)
49794984
(labltable (table))
49804985
(ssavtable (table))
49814986
(current-loc 0)
4987+
(nowhere #f)
49824988
(current-file file)
49834989
(current-line line)
49844990
(locstack '())
@@ -4991,25 +4997,32 @@ f(x) = yt(x)
49914997
(set! current-loc 1)))
49924998
(set! code (cons e code))
49934999
(set! i (+ i 1))
4994-
(set! locs (cons current-loc locs)))
5000+
(set! locs (cons (if nowhere 0 current-loc) locs))
5001+
(set! nowhere #f))
49955002
(let loop ((stmts (cdr body)))
49965003
(if (pair? stmts)
49975004
(let ((e (car stmts)))
49985005
(cond ((atom? e) (emit e))
49995006
((eq? (car e) 'line)
5000-
(if (and (= current-line 0) (length= e 2) (pair? linetable))
5001-
;; (line n) after push_loc just updates the line for the new file
5002-
(begin (set-lineno! (car linetable) (cadr e))
5003-
(set! current-line (cadr e)))
5004-
(begin
5005-
(set! current-line (cadr e))
5006-
(if (pair? (cddr e))
5007-
(set! current-file (caddr e)))
5008-
(set! linetable (cons (if (null? locstack)
5009-
(make-lineinfo name current-file current-line)
5010-
(make-lineinfo name current-file current-line (caar locstack)))
5011-
linetable))
5012-
(set! current-loc (- (length linetable) 1)))))
5007+
(cond ((and (length= e 2) (not (cadr e)))
5008+
;; (line #f) marks that we are entering a generated statement
5009+
;; that should not be counted as belonging to the previous marked location,
5010+
;; for example `return` after a not-executed `if` arm in tail position.
5011+
(set! nowhere #t))
5012+
((and (= current-line 0) (length= e 2) (pair? linetable))
5013+
;; (line n) after push_loc just updates the line for the new file
5014+
(begin (set-lineno! (car linetable) (cadr e))
5015+
(set! current-line (cadr e))))
5016+
(else
5017+
(begin
5018+
(set! current-line (cadr e))
5019+
(if (pair? (cddr e))
5020+
(set! current-file (caddr e)))
5021+
(set! linetable (cons (if (null? locstack)
5022+
(make-lineinfo name current-file current-line)
5023+
(make-lineinfo name current-file current-line (caar locstack)))
5024+
linetable))
5025+
(set! current-loc (- (length linetable) 1))))))
50135026
((and (length> e 2) (eq? (car e) 'meta) (eq? (cadr e) 'push_loc))
50145027
(set! locstack (cons (list current-loc current-line current-file) locstack))
50155028
(set! current-file (caddr e))

Diff for: src/julia_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ jl_tupletype_t *jl_lookup_arg_tuple_type(jl_value_t *arg1 JL_PROPAGATES_ROOT, jl
696696
JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method, jl_tupletype_t *simpletype);
697697
jl_datatype_t *jl_mk_builtin_func(jl_datatype_t *dt, const char *name, jl_fptr_args_t fptr) JL_GC_DISABLED;
698698
int jl_obviously_unequal(jl_value_t *a, jl_value_t *b);
699+
int jl_has_bound_typevars(jl_value_t *v, jl_typeenv_t *env) JL_NOTSAFEPOINT;
699700
JL_DLLEXPORT jl_array_t *jl_find_free_typevars(jl_value_t *v);
700701
int jl_has_fixed_layout(jl_datatype_t *t);
701702
JL_DLLEXPORT int jl_struct_try_layout(jl_datatype_t *dt);

0 commit comments

Comments
 (0)