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

ensure revising structs is safe #51303

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,8 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!

for (j = 0; j < jl_array_len(partial); j++) {
jl_datatype_t *ndt = (jl_datatype_t*)jl_array_ptr_ref(partial, j);
if (ndt == NULL)
continue;
assert(jl_unwrap_unionall(ndt->name->wrapper) == (jl_value_t*)t);
for (i = 0; i < n; i++)
env[i].val = jl_svecref(ndt->parameters, i);
Expand All @@ -2506,6 +2508,8 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
if (t->types != jl_emptysvec) {
for (j = 0; j < jl_array_len(partial); j++) {
jl_datatype_t *ndt = (jl_datatype_t*)jl_array_ptr_ref(partial, j);
if (ndt == NULL)
continue;
for (i = 0; i < n; i++)
env[i].val = jl_svecref(ndt->parameters, i);
assert(ndt->types == NULL);
Expand All @@ -2514,7 +2518,9 @@ void jl_reinstantiate_inner_types(jl_datatype_t *t) // can throw!
if (ndt->isconcretetype) { // cacheable
jl_compute_field_offsets(ndt);
}
jl_array_ptr_set(partial, j, NULL);
}
t->name->partial = NULL;
}
else {
assert(jl_field_names(t) == jl_emptysvec);
Expand Down
13 changes: 13 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7593,6 +7593,19 @@ end
struct T36104 # check that redefining it works, issue #21816
v::Vector{T36104}
end
struct S36104{K,V}
v::S36104{K,V}
S36104{K,V}() where {K,V} = new()
S36104{K,V}(x::S36104) where {K,V} = new(x)
end
@test !isdefined(Base.unwrap_unionall(Base.ImmutableDict).name, :partial)
@test !isdefined(S36104.body.body.name, :partial)
@test hasfield(typeof(S36104.body.body.name), :partial)
struct S36104{K,V} # check that redefining it works
v::S36104{K,V}
S36104{K,V}() where {K,V} = new()
S36104{K,V}(x::S36104) where {K,V} = new(x)
end
# with a gensymmed unionall
struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
data::S
Expand Down