Skip to content

Commit 0bc84ef

Browse files
authored
Merge branch 'master' into LilithHafner-patch-1
2 parents cb311fa + 2e2fac5 commit 0bc84ef

File tree

30 files changed

+184
-98
lines changed

30 files changed

+184
-98
lines changed

Compiler/src/Compiler.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospeciali
6565
structdiff, tls_world_age, unconstrain_vararg_length, unionlen, uniontype_layout,
6666
uniontypes, unsafe_convert, unwrap_unionall, unwrapva, vect, widen_diagonal,
6767
_uncompressed_ir, maybe_add_binding_backedge!, datatype_min_ninitialized,
68-
partialstruct_init_undefs, fieldcount_noerror, _eval_import, _eval_using
68+
partialstruct_init_undefs, fieldcount_noerror, _eval_import, _eval_using,
69+
get_ci_mi
70+
6971
using Base.Order
7072

7173
import Base: ==, _topmod, append!, convert, copy, copy!, findall, first, get, get!,

Compiler/src/abstractinterpretation.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,18 +2215,12 @@ function abstract_call_unionall(interp::AbstractInterpreter, argtypes::Vector{An
22152215
return CallMeta(ret, Any, Effects(EFFECTS_TOTAL; nothrow), call.info)
22162216
end
22172217

2218-
function ci_abi(ci::CodeInstance)
2218+
function get_ci_abi(ci::CodeInstance)
22192219
def = ci.def
22202220
isa(def, ABIOverride) && return def.abi
22212221
(def::MethodInstance).specTypes
22222222
end
22232223

2224-
function get_ci_mi(ci::CodeInstance)
2225-
def = ci.def
2226-
isa(def, ABIOverride) && return def.def
2227-
return def::MethodInstance
2228-
end
2229-
22302224
function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::StmtInfo, sv::AbsIntState)
22312225
argtypes = arginfo.argtypes
22322226
ft′ = argtype_by_index(argtypes, 2)
@@ -2238,7 +2232,7 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
22382232
if isa(method_or_ci, CodeInstance)
22392233
our_world = sv.world.this
22402234
argtype = argtypes_to_type(pushfirst!(argtype_tail(argtypes, 4), ft))
2241-
specsig = ci_abi(method_or_ci)
2235+
specsig = get_ci_abi(method_or_ci)
22422236
defdef = get_ci_mi(method_or_ci).def
22432237
exct = method_or_ci.exctype
22442238
if !hasintersect(argtype, specsig)

Compiler/src/ssair/ir.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ end
810810
types(ir::Union{IRCode, IncrementalCompact}) = TypesView(ir)
811811

812812
function getindex(compact::IncrementalCompact, ssa::SSAValue)
813-
(1 ssa.id compact.result_idx) || throw(InvalidIRError())
813+
(1 ssa.id < compact.result_idx) || throw(InvalidIRError())
814814
return compact.result[ssa.id]
815815
end
816816

Compiler/src/ssair/show.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ using .Compiler: ALWAYS_FALSE, ALWAYS_TRUE, argextype, BasicBlock, block_for_ins
1212
CachedMethodTable, CFG, compute_basic_blocks, DebugInfoStream, Effects,
1313
EMPTY_SPTYPES, getdebugidx, IncrementalCompact, InferenceResult, InferenceState,
1414
InvalidIRError, IRCode, LimitedAccuracy, NativeInterpreter, scan_ssa_use!,
15-
singleton_type, sptypes_from_meth_instance, StmtRange, Timings, VarState, widenconst
15+
singleton_type, sptypes_from_meth_instance, StmtRange, Timings, VarState, widenconst,
16+
get_ci_mi, get_ci_abi
1617

1718
@nospecialize
1819

@@ -95,16 +96,14 @@ function print_stmt(io::IO, idx::Int, @nospecialize(stmt), code::Union{IRCode,Co
9596
elseif isexpr(stmt, :invoke) && length(stmt.args) >= 2 && isa(stmt.args[1], Union{MethodInstance,CodeInstance})
9697
stmt = stmt::Expr
9798
# TODO: why is this here, and not in Base.show_unquoted
98-
printstyled(io, " invoke "; color = :light_black)
99-
mi = stmt.args[1]
100-
if !(mi isa Core.MethodInstance)
101-
mi = (mi::Core.CodeInstance).def
102-
end
103-
if isa(mi, Core.ABIOverride)
104-
abi = mi.abi
105-
mi = mi.def
99+
ci = stmt.args[1]
100+
if ci isa Core.CodeInstance
101+
printstyled(io, " invoke "; color = :light_black)
102+
mi = get_ci_mi(ci)
103+
abi = get_ci_abi(ci)
106104
else
107-
abi = mi.specTypes
105+
printstyled(io, "dynamic invoke "; color = :yellow)
106+
abi = (ci::Core.MethodInstance).specTypes
108107
end
109108
show_unquoted(io, stmt.args[2], indent)
110109
print(io, "(")

Compiler/src/ssair/verify.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int,
3232
if isa(op, SSAValue)
3333
op.id > 0 || @verify_error "Def ($(op.id)) is invalid in final IR"
3434
if op.id > length(ir.stmts)
35+
if op.id - length(ir.stmts) > length(ir.new_nodes.info)
36+
@verify_error "Def ($(op.id)) points to non-existent new node"
37+
raise_error()
38+
end
3539
def_bb = block_for_inst(ir.cfg, ir.new_nodes.info[op.id - length(ir.stmts)].pos)
3640
else
3741
def_bb = block_for_inst(ir.cfg, op.id)

Compiler/src/validation.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ const VALID_EXPR_HEADS = IdDict{Symbol,UnitRange{Int}}(
3535
:aliasscope => 0:0,
3636
:popaliasscope => 0:0,
3737
:new_opaque_closure => 5:typemax(Int),
38-
:import => 1:typemax(Int),
39-
:using => 1:typemax(Int),
4038
:export => 1:typemax(Int),
4139
:public => 1:typemax(Int),
4240
:latestworld => 0:0,
@@ -72,11 +70,13 @@ function maybe_validate_code(mi::MethodInstance, src::CodeInfo, kind::String)
7270
if !isempty(errors)
7371
for e in errors
7472
if mi.def isa Method
75-
println(stderr, "WARNING: Encountered invalid ", kind, " code for method ",
76-
mi.def, ": ", e)
73+
println(Core.stderr,
74+
"WARNING: Encountered invalid ", kind,
75+
" code for method ", mi.def, ": ", e)
7776
else
78-
println(stderr, "WARNING: Encountered invalid ", kind, " code for top level expression in ",
79-
mi.def, ": ", e)
77+
println(Core.stderr,
78+
"WARNING: Encountered invalid ", kind,
79+
" code for top level expression in ", mi.def, ": ", e)
8080
end
8181
end
8282
error("")

Compiler/test/codegen.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,16 @@ for (T, StructName) in ((Int128, :Issue55558), (UInt128, :UIssue55558))
951951
end
952952
end
953953

954+
# Issue #42326
955+
primitive type PadAfter64_42326 448 end
956+
mutable struct CheckPadAfter64_42326
957+
a::UInt64
958+
pad::PadAfter64_42326
959+
b::UInt64
960+
end
961+
@test fieldoffset(CheckPadAfter64_42326, 3) == 80
962+
@test sizeof(CheckPadAfter64_42326) == 96
963+
954964
@noinline Base.@nospecializeinfer f55768(@nospecialize z::UnionAll) = z === Vector
955965
@test f55768(Vector)
956966
@test f55768(Vector{T} where T)

base/invalidation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ invalidate_code_for_globalref!(gr::GlobalRef, invalidated_bpart::Core.BindingPar
188188
invalidate_code_for_globalref!(convert(Core.Binding, gr), invalidated_bpart, new_bpart, new_max_world)
189189

190190
function maybe_add_binding_backedge!(b::Core.Binding, edge::Union{Method, CodeInstance})
191-
meth = isa(edge, Method) ? edge : Compiler.get_ci_mi(edge).def
191+
meth = isa(edge, Method) ? edge : get_ci_mi(edge).def
192192
ccall(:jl_maybe_add_binding_backedge, Cint, (Any, Any, Any), b, edge, meth)
193193
return nothing
194194
end

base/runtime_internals.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,15 @@ end
14781478
_uncompressed_ir(codeinst::CodeInstance, s::String) =
14791479
ccall(:jl_uncompress_ir, Ref{CodeInfo}, (Any, Any, Any), codeinst.def.def::Method, codeinst, s)
14801480

1481+
function get_ci_mi(codeinst::CodeInstance)
1482+
def = codeinst.def
1483+
if def isa Core.ABIOverride
1484+
return def.def
1485+
else
1486+
return def::MethodInstance
1487+
end
1488+
end
1489+
14811490
"""
14821491
Base.generating_output([incremental::Bool])::Bool
14831492

base/stacktraces.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,12 @@ function show_spec_linfo(io::IO, frame::StackFrame)
273273
if linfo isa Union{MethodInstance, CodeInstance}
274274
def = frame_method_or_module(frame)
275275
if def isa Module
276-
Base.show_mi(io, linfo, #=from_stackframe=#true)
276+
Base.show_mi(io, linfo::MethodInstance, #=from_stackframe=#true)
277+
elseif linfo isa CodeInstance && linfo.owner !== nothing
278+
show_custom_spec_sig(io, linfo.owner, linfo, frame)
277279
else
280+
# Equivalent to the default implementation of `show_custom_spec_sig`
281+
# for `linfo isa CodeInstance`, but saves an extra dynamic dispatch.
278282
show_spec_sig(io, def, frame_mi(frame).specTypes)
279283
end
280284
else
@@ -284,6 +288,12 @@ function show_spec_linfo(io::IO, frame::StackFrame)
284288
end
285289
end
286290

291+
# Can be extended by compiler packages to customize backtrace display of custom code instance frames
292+
function show_custom_spec_sig(io::IO, @nospecialize(owner), linfo::CodeInstance, frame::StackFrame)
293+
mi = get_ci_mi(linfo)
294+
return show_spec_sig(io, mi.def, mi.specTypes)
295+
end
296+
287297
function show_spec_sig(io::IO, m::Method, @nospecialize(sig::Type))
288298
if get(io, :limit, :false)::Bool
289299
if !haskey(io, :displaysize)

base/staticdata.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@
33
module StaticData
44

55
using .Core: CodeInstance, MethodInstance
6-
using .Base: JLOptions, Compiler, get_world_counter, _methods_by_ftype, get_methodtable
6+
using .Base: JLOptions, Compiler, get_world_counter, _methods_by_ftype, get_methodtable, get_ci_mi
77

88
const WORLD_AGE_REVALIDATION_SENTINEL::UInt = 1
99
const _jl_debug_method_invalidation = Ref{Union{Nothing,Vector{Any}}}(nothing)
1010
debug_method_invalidation(onoff::Bool) =
1111
_jl_debug_method_invalidation[] = onoff ? Any[] : nothing
1212

13-
function get_ci_mi(codeinst::CodeInstance)
14-
def = codeinst.def
15-
if def isa Core.ABIOverride
16-
return def.def
17-
else
18-
return def::MethodInstance
19-
end
20-
end
21-
2213
# Restore backedges to external targets
2314
# `edges` = [caller1, ...], the list of worklist-owned code instances internally
2415
# `ext_ci_list` = [caller1, ...], the list of worklist-owned code instances externally

base/strings/string.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ function String(v::Vector{UInt8})
7878
return str
7979
end
8080

81-
"Create a string re-using the memory, if possible.
82-
Mutating or reading the memory after calling this function is undefined behaviour."
81+
"""
82+
unsafe_takestring(m::Memory{UInt8})::String
83+
84+
Create a `String` from `m`, changing the interpretation of the contents of `m`.
85+
This is done without copying, if possible. Thus, any access to `m` after
86+
calling this function, either to read or to write, is undefined behaviour.
87+
"""
8388
function unsafe_takestring(m::Memory{UInt8})
8489
isempty(m) ? "" : ccall(:jl_genericmemory_to_string, Ref{String}, (Any, Int), m, length(m))
8590
end

contrib/generate_precompile.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ precompile(Base.CoreLogging.current_logger_for_env, (Base.CoreLogging.LogLevel,
103103
precompile(Base.CoreLogging.env_override_minlevel, (Symbol, Module))
104104
precompile(Base.StackTraces.lookup, (Ptr{Nothing},))
105105
precompile(Tuple{typeof(Base.run_module_init), Module, Int})
106+
precompile(Tuple{Type{Base.VersionNumber}, Int32, Int32, Int32})
106107
107108
# Presence tested in the tests
108109
precompile(Tuple{typeof(Base.print), Base.IOStream, String})
@@ -140,6 +141,9 @@ for match = Base._methods(+, (Int, Int), -1, Base.get_world_counter())
140141
end
141142
empty!(Set())
142143
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
144+
get!(ENV, "___DUMMY", "")
145+
ENV["___DUMMY"]
146+
delete!(ENV, "___DUMMY")
143147
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
144148
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
145149
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
@@ -209,6 +213,9 @@ if Artifacts !== nothing
209213
end
210214
dlopen("libjulia$(Base.isdebugbuild() ? "-debug" : "")", RTLD_LAZY | RTLD_DEEPBIND)
211215
"""
216+
hardcoded_precompile_statements *= """
217+
precompile(Tuple{typeof(Artifacts._artifact_str), Module, String, Base.SubString{String}, String, Base.Dict{String, Any}, Base.SHA1, Base.BinaryPlatforms.Platform, Base.Val{Artifacts}})
218+
"""
212219
end
213220

214221
FileWatching = get(Base.loaded_modules,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ec80bedb86483002a78de7859f524621
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
563e706de71b7147f44fa28ec1a729e08172bdf27bdf741f0702a451717f561562b2211d74ca2d01218fd9da05268436dc795fe7aeef7d34b46bbd966c23f71e

deps/checksums/SparseArrays-f3610c07fe0403792743d9c9802a25642a5f2d18.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/SparseArrays-f3610c07fe0403792743d9c9802a25642a5f2d18.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ deploy: deps
5757
@echo "Deploying HTML documentation."
5858
$(JULIA_EXECUTABLE) --color=yes $(call cygpath_w,$(SRCDIR)/make.jl) -- deploy $(DOCUMENTER_OPTIONS)
5959
@echo "Build & deploy of docs finished."
60+
61+
update-documenter:
62+
@echo "Updating Documenter."
63+
JULIA_PKG_PRECOMPILE_AUTO=0 $(JULIA_EXECUTABLE) --project --color=yes -e 'using Pkg; Pkg.update("Documenter")'

doc/Manifest.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ version = "0.9.4"
4444

4545
[[deps.Documenter]]
4646
deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "CodecZlib", "Dates", "DocStringExtensions", "Downloads", "Git", "IOCapture", "InteractiveUtils", "JSON", "Logging", "Markdown", "MarkdownAST", "Pkg", "PrecompileTools", "REPL", "RegistryInstances", "SHA", "TOML", "Test", "Unicode"]
47-
git-tree-sha1 = "6f8730fd1bdf974009ef296bd81afb2728854fc0"
47+
git-tree-sha1 = "6c182d0bd94142d7cbc3ae8a1e74668f15d0dd65"
4848
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
49-
version = "1.11.3"
49+
version = "1.11.4"
5050

5151
[[deps.Downloads]]
5252
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]

src/ast.scm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@
493493
(define (vinfo:never-undef v) (< 0 (logand (caddr v) 4)))
494494
(define (vinfo:read v) (< 0 (logand (caddr v) 8)))
495495
(define (vinfo:sa v) (< 0 (logand (caddr v) 16)))
496+
(define (vinfo:nospecialize v) (< 0 (logand (caddr v) 128)))
496497
(define (set-bit x b val) (if val (logior x b) (logand x (lognot b))))
497498
;; record whether var is captured
498499
(define (vinfo:set-capt! v c) (set-car! (cddr v) (set-bit (caddr v) 1 c)))
@@ -507,6 +508,7 @@
507508
;; occurs undef: mask 32
508509
;; whether var is called (occurs in function call head position)
509510
(define (vinfo:set-called! v a) (set-car! (cddr v) (set-bit (caddr v) 64 a)))
511+
(define (vinfo:set-nospecialize! v c) (set-car! (cddr v) (set-bit (caddr v) 128 c)))
510512

511513
(define var-info-for assq)
512514

src/codegen.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4990,8 +4990,10 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, bool is_opaque_clos
49904990
}
49914991
jl_value_t *jt = jl_nth_slot_type(specTypes, i);
49924992
jl_cgval_t arg = update_julia_type(ctx, argv[i], jt);
4993-
if (arg.typ == jl_bottom_type)
4993+
if (arg.typ == jl_bottom_type) {
4994+
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Argument type mismatch in Expr(:invoke)");
49944995
return jl_cgval_t();
4996+
}
49954997
if (is_uniquerep_Type(jt)) {
49964998
continue;
49974999
}
@@ -5028,7 +5030,7 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, bool is_opaque_clos
50285030
Value *val = emit_unbox(ctx, et, arg, jt);
50295031
if (!val) {
50305032
// There was a type mismatch of some sort - exit early
5031-
CreateTrap(ctx.builder);
5033+
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Argument type mismatch in Expr(:invoke)");
50325034
return jl_cgval_t();
50335035
}
50345036
argvals[idx] = val;
@@ -5295,7 +5297,7 @@ static jl_cgval_t emit_invoke(jl_codectx_t &ctx, const jl_cgval_t &lival, ArrayR
52955297
}
52965298
if (result.typ == jl_bottom_type) {
52975299
#ifndef JL_NDEBUG
5298-
emit_error(ctx, "(Internal Error - IR Validity): Returned from function we expected not to.");
5300+
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Returned from function we expected not to.");
52995301
#endif
53005302
CreateTrap(ctx.builder);
53015303
}
@@ -5647,7 +5649,7 @@ static jl_cgval_t emit_local(jl_codectx_t &ctx, jl_value_t *slotload)
56475649
if (sym == jl_unused_sym) {
56485650
// This shouldn't happen in well-formed input, but let's be robust,
56495651
// since we otherwise cause undefined behavior here.
5650-
emit_error(ctx, "(INTERNAL ERROR): Tried to use `#undef#` argument.");
5652+
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Tried to use `#undef#` argument.");
56515653
return jl_cgval_t();
56525654
}
56535655
return emit_varinfo(ctx, vi, sym);
@@ -6494,7 +6496,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_
64946496
if (source.constant == NULL) {
64956497
// For now, we require non-constant source to be handled by using
64966498
// eval. This should probably be a verifier error and an abort here.
6497-
emit_error(ctx, "(internal error) invalid IR: opaque closure source must be constant");
6499+
emit_error(ctx, "(INTERNAL ERROR - IR Validity): opaque closure source must be constant");
64986500
return jl_cgval_t();
64996501
}
65006502
bool can_optimize = argt.constant != NULL && lb.constant != NULL && ub.constant != NULL &&
@@ -9380,7 +9382,7 @@ static jl_llvm_functions_t
93809382
// Probably dead code, but let's be loud about it in case it isn't, so we fail
93819383
// at the point of the miscompile, rather than later when something attempts to
93829384
// read the scope.
9383-
emit_error(ctx, "(INTERNAL ERROR): Attempted to execute EnterNode with bad scope");
9385+
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Attempted to execute EnterNode with bad scope");
93849386
find_next_stmt(-1);
93859387
continue;
93869388
}

src/datatype.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,19 @@ void jl_compute_field_offsets(jl_datatype_t *st)
702702
// Should never happen
703703
throw_ovf(should_malloc, desc, st, fsz);
704704
desc[i].isptr = 0;
705+
705706
if (jl_is_uniontype(fld)) {
706707
fsz += 1; // selector byte
707708
zeroinit = 1;
708709
// TODO: Some unions could be bits comparable.
709710
isbitsegal = 0;
710711
}
711712
else {
713+
if (fsz > jl_datatype_size(fld)) {
714+
// We have to pad the size to integer size class, but it means this has some padding
715+
isbitsegal = 0;
716+
haspadding = 1;
717+
}
712718
uint32_t fld_npointers = ((jl_datatype_t*)fld)->layout->npointers;
713719
if (((jl_datatype_t*)fld)->layout->flags.haspadding)
714720
haspadding = 1;

0 commit comments

Comments
 (0)