Skip to content

Commit 60b0813

Browse files
committed
inform compiler about local variable definedness
JET's new analysis pass now detects local variables that may be undefined, which has revealed such issues in several functions within Base (#58762). This commit addresses local variables whose definedness the compiler cannot properly determine, primarily in functions reachable from JET's test suite. No functional changes are made.
1 parent 4962d2d commit 60b0813

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

base/logging/logging.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,13 @@ function logmsg_code(_module, file, line, level, message, exs...)
411411
end
412412
line = $(log_data._line)
413413
local msg, kwargs
414-
$(logrecord) && $handle_message_nothrow(
415-
logger, level, msg, _module, group, id, file, line;
416-
kwargs...)
414+
if $(logrecord)
415+
@assert @isdefined(msg) "Assertion to tell the compiler about the definedness of this variable"
416+
@assert @isdefined(kwargs) "Assertion to tell the compiler about the definedness of this variable"
417+
$handle_message_nothrow(
418+
logger, level, msg, _module, group, id, file, line;
419+
kwargs...)
420+
end
417421
end
418422
end
419423
end

base/partr.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ function multiq_sift_down(heap::taskheap, idx::Int32)
107107
end
108108
end
109109

110-
111110
function multiq_size(tpid::Int8)
112111
nt = UInt32(Threads._nthreads_in_pool(tpid))
113112
tp = tpid + 1
@@ -138,7 +137,6 @@ function multiq_size(tpid::Int8)
138137
return heap_p
139138
end
140139

141-
142140
function multiq_insert(task::Task, priority::UInt16)
143141
tpid = ccall(:jl_get_task_threadpoolid, Int8, (Any,), task)
144142
@assert tpid > -1
@@ -171,10 +169,8 @@ function multiq_insert(task::Task, priority::UInt16)
171169
return true
172170
end
173171

174-
175172
function multiq_deletemin()
176-
local rn1, rn2
177-
local prio1, prio2
173+
local rn1::UInt32
178174

179175
tid = Threads.threadid()
180176
tp = ccall(:jl_threadpoolid, Int8, (Int16,), tid-1) + 1
@@ -208,6 +204,8 @@ function multiq_deletemin()
208204
end
209205
end
210206

207+
@assert @isdefined(rn1) "Assertion to tell the compiler about the definedness of this variable"
208+
211209
heap = tpheaps[rn1]
212210
task = heap.tasks[1]
213211
if ccall(:jl_set_task_tid, Cint, (Any, Cint), task, tid-1) == 0

base/ryu/shortest.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ integer. If a `maxsignif` argument is provided, then `b < maxsignif`.
196196
e10 = 0
197197

198198
if maxsignif !== nothing && b > maxsignif
199+
roundup = false
199200
b_allzero = true
200201
# reduce to max significant digits
201202
while true

0 commit comments

Comments
 (0)