Skip to content

Commit

Permalink
some test findings
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Sep 18, 2023
1 parent 778a65e commit 822bc73
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft)
return AbstractIterationResult(Any[Vararg{Any}], nothing)
elseif tti0 === Any
return AbstractIterationResult(Any[Vararg{Any}], nothing, Effects())
elseif tti0 <: Array
elseif tti0 <: Array || tti0 <: GenericMemory
if eltype(tti0) === Union{}
return AbstractIterationResult(Any[], nothing)
end
Expand Down
4 changes: 2 additions & 2 deletions base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ end
names = merge_names(an, bn)
types = merge_types(names, typeof(a), typeof(b))
n = length(names)
A = Vector{Any}(undef, n)
A = Memory{Any}(undef, n)
for i=1:n
n = names[i]
A[i] = getfield(sym_in(n, bn) ? b : a, n)
Expand Down Expand Up @@ -403,7 +403,7 @@ end
isempty(names) && return (;)
types = diff_types(a, names)
n = length(names)
A = Vector{Any}(undef, n)
A = Memory{Any}(undef, n)
for i=1:n
n = names[i]
A[i] = getfield(a, n)
Expand Down
49 changes: 41 additions & 8 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,6 @@ JL_CALLABLE(jl_f_sizeof)
}
if (x == jl_bottom_type)
jl_error("The empty type does not have a definite size since it does not have instances.");
#if 0 // TODO(jwn): is this breaking?
if (jl_is_array(x)) {
return jl_box_long(jl_array_len(x) * jl_datatype_size((jl_datatype_t*)jl_typeof(((jl_array_t*)x)->ref.mem)));

}
#endif
if (jl_is_string(x))
return jl_box_long(jl_string_len(x));
if (jl_is_symbol(x))
Expand Down Expand Up @@ -627,6 +621,17 @@ static jl_value_t *do_apply(jl_value_t **args, uint32_t nargs, jl_value_t *itera
if (f == jl_builtin_svec) {
if (jl_is_svec(args[1]))
return args[1];
if (jl_is_genericmemory(args[1])) {
jl_genericmemory_t *mem = (jl_genericmemory_t*)args[1];
size_t n = mem->length;
jl_svec_t *t = jl_alloc_svec(n);
JL_GC_PUSH1(&t);
for (size_t i = 0; i < n; i++) {
jl_svecset(t, i, jl_genericmemoryref(mem, i));
}
JL_GC_POP();
return (jl_value_t*)t;
}
if (jl_is_array(args[1])) {
size_t n = jl_array_len(args[1]);
jl_svec_t *t = jl_alloc_svec(n);
Expand All @@ -653,6 +658,9 @@ static jl_value_t *do_apply(jl_value_t **args, uint32_t nargs, jl_value_t *itera
else if (jl_is_tuple(args[i]) || jl_is_namedtuple(args[i])) {
precount += jl_nfields(args[i]);
}
else if (jl_is_genericmemory(args[i])) {
precount += ((jl_genericmemory_t*)args[i])->length;
}
else if (jl_is_array(args[i])) {
precount += jl_array_len(args[i]);
}
Expand Down Expand Up @@ -721,15 +729,40 @@ static jl_value_t *do_apply(jl_value_t **args, uint32_t nargs, jl_value_t *itera
jl_gc_wb(arg_heap, newargs[n - 1]);
}
}
else if (jl_is_genericmemory(ai)) {
jl_genericmemory_t *mem = (jl_genericmemory_t*)ai;
size_t j, al = mem->length;
precount = (precount > al) ? precount - al : 0;
_grow_to(&roots[0], &newargs, &arg_heap, &n_alloc, n + precount + al, extra);
assert(newargs != NULL); // inform GCChecker that we didn't write a NULL here
const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(mem))->layout;
if (layout->arrayelem_isboxed) {
for (j = 0; j < al; j++) {
jl_value_t *arg = jl_genericmemory_ptr_ref(mem, j);
// apply with array splatting may have embedded NULL value (#11772)
if (__unlikely(arg == NULL))
jl_throw(jl_undefref_exception);
newargs[n++] = arg;
if (arg_heap)
jl_gc_wb(arg_heap, arg);
}
}
else {
for (j = 0; j < al; j++) {
newargs[n++] = jl_genericmemoryref(mem, j);
if (arg_heap)
jl_gc_wb(arg_heap, newargs[n - 1]);
}
}
}
else if (jl_is_array(ai)) {
jl_array_t *aai = (jl_array_t*)ai;
size_t j, al = jl_array_len(aai);
precount = (precount > al) ? precount - al : 0;
_grow_to(&roots[0], &newargs, &arg_heap, &n_alloc, n + precount + al, extra);
assert(newargs != NULL); // inform GCChecker that we didn't write a NULL here
const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(aai->ref.mem))->layout;
if (layout->arrayelem_isboxed)
{
if (layout->arrayelem_isboxed) {
for (j = 0; j < al; j++) {
jl_value_t *arg = jl_array_ptr_ref(aai, j);
// apply with array splatting may have embedded NULL value (#11772)
Expand Down
3 changes: 2 additions & 1 deletion stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ CC.haskey(wvc::CC.WorldView{REPLInterpreterCache}, mi::MethodInstance) = haskey(
CC.setindex!(wvc::CC.WorldView{REPLInterpreterCache}, ci::CodeInstance, mi::MethodInstance) = setindex!(wvc.cache.dict, ci, mi)

# REPLInterpreter is only used for type analysis, so it should disable optimization entirely
CC.may_optimize(::REPLInterpreter) = false
# however, since effects are not computed until after optimization, the optimizations cannot be disabled
CC.may_optimize(::REPLInterpreter) = true

# REPLInterpreter analyzes a top-level frame, so better to not bail out from it
CC.bail_out_toplevel_call(::REPLInterpreter, ::CC.InferenceLoopState, ::CC.InferenceState) = false
Expand Down
4 changes: 2 additions & 2 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ end
let s = "CompletionFoo.test3([1, 2] .+ CompletionFoo.varfloat,"
c, r, res = test_complete(s)
@test !res
@test_broken only(c) == first(test_methods_list(Main.CompletionFoo.test3, Tuple{Array{Float64, 1}, Float64, Vararg}))
@test only(c) == first(test_methods_list(Main.CompletionFoo.test3, Tuple{Array{Float64, 1}, Float64, Vararg}))
end

let s = "CompletionFoo.test3([1.,2.], 1.,"
Expand Down Expand Up @@ -566,7 +566,7 @@ end
let s = "CompletionFoo.test3(@time([1, 2] .+ CompletionFoo.varfloat),"
c, r, res = test_complete(s)
@test !res
@test length(c) == 2
@test length(c) == 1
end

# method completions with kwargs
Expand Down
8 changes: 4 additions & 4 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,15 @@ end
B = OffsetArray(reshape(1:24, 4, 3, 2), -5, 6, -7)
for R in (fill(0, -4:-1), fill(0, -4:-1, 7:7), fill(0, -4:-1, 7:7, -6:-6))
@test @inferred(maximum!(R, B)) == reshape(maximum(B, dims=(2,3)), axes(R)) == reshape(21:24, axes(R))
@test @allocated(maximum!(R, B)) <= 300
@test @allocated(maximum!(R, B)) <= 400
@test @inferred(minimum!(R, B)) == reshape(minimum(B, dims=(2,3)), axes(R)) == reshape(1:4, axes(R))
@test @allocated(minimum!(R, B)) <= 300
@test @allocated(minimum!(R, B)) <= 400
end
for R in (fill(0, -4:-4, 7:9), fill(0, -4:-4, 7:9, -6:-6))
@test @inferred(maximum!(R, B)) == reshape(maximum(B, dims=(1,3)), axes(R)) == reshape(16:4:24, axes(R))
@test @allocated(maximum!(R, B)) <= 300
@test @allocated(maximum!(R, B)) <= 400
@test @inferred(minimum!(R, B)) == reshape(minimum(B, dims=(1,3)), axes(R)) == reshape(1:4:9, axes(R))
@test @allocated(minimum!(R, B)) <= 300
@test @allocated(minimum!(R, B)) <= 400
end
@test_throws DimensionMismatch maximum!(fill(0, -4:-1, 7:7, -6:-6, 1:1), B)
@test_throws DimensionMismatch minimum!(fill(0, -4:-1, 7:7, -6:-6, 1:1), B)
Expand Down
3 changes: 2 additions & 1 deletion test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ end
sizeof(Real))
@test sizeof(Union{ComplexF32,ComplexF64}) == 16
@test sizeof(Union{Int8,UInt8}) == 1
@test sizeof(MemoryRef{false,Int}) == 2 * sizeof(Int)
@test sizeof(MemoryRef{:not_atomic,Int}) == 2 * sizeof(Int)
@test sizeof(MemoryRef{:atomic,Int}) == 2 * sizeof(Int)
@test sizeof(Array{Int,0}) == 2 * sizeof(Int)
@test sizeof(Array{Int,1}) == 3 * sizeof(Int)
@test sizeof(Array{Int,2}) == 4 * sizeof(Int)
Expand Down

0 comments on commit 822bc73

Please sign in to comment.