Skip to content

Commit

Permalink
fix fields description of Module type
Browse files Browse the repository at this point in the history
The fields are not accessible, so it is awkward to report they exist.

Fixes #37630
Caused issues starting with #34804
  • Loading branch information
vtjnash committed Sep 18, 2020
1 parent b884dca commit ed4f968
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
19 changes: 17 additions & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#abstract type Vararg{T} end

#mutable struct Symbol
# #opaque
## opaque
#end

#mutable struct TypeName
Expand Down Expand Up @@ -53,28 +53,43 @@
#abstract type DenseArray{T,N} <: AbstractArray{T,N} end

#mutable struct Array{T,N} <: DenseArray{T,N}
## opaque
#end

#mutable struct Module
# name::Symbol
## opaque
#end

#mutable struct SimpleVector
## opaque
#end

#mutable struct String
## opaque
#end

#mutable struct Method
#...
#end

#mutable struct MethodInstance
#...
#end

#mutable struct CodeInstance
#...
#end

#mutable struct CodeInfo
#...
#end

#mutable struct TypeMapLevel
#...
#end

#mutable struct TypeMapEntry
#...
#end

#abstract type Ref{T} end
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -951,11 +951,11 @@ function fieldtype_tfunc(@nospecialize(s0), @nospecialize(name))
if s0 === Any || s0 === Type || DataType s0 || UnionAll s0
return Type
end
# fieldtype only accepts Types, errors on `Module`
if isa(s0, Const) && (!(isa(s0.val, DataType) || isa(s0.val, UnionAll) || isa(s0.val, Union)) || s0.val === Module)
# fieldtype only accepts Types
if isa(s0, Const) && !(isa(s0.val, DataType) || isa(s0.val, UnionAll) || isa(s0.val, Union))
return Bottom
end
if (s0 isa Type && (s0 == Type{Module} || s0 == Type{Union{}})) || isa(s0, Conditional)
if (s0 isa Type && s0 == Type{Union{}}) || isa(s0, Conditional)
return Bottom
end

Expand Down
2 changes: 1 addition & 1 deletion src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void jl_compute_field_offsets(jl_datatype_t *st)
st->layout = &opaque_byte_layout;
return;
}
else if (st == jl_simplevector_type || st->name == jl_array_typename) {
else if (st == jl_simplevector_type || st == jl_module_type || st->name == jl_array_typename) {
static const jl_datatype_layout_t opaque_ptr_layout = {0, 1, -1, sizeof(void*), 0, 0};
st->layout = &opaque_ptr_layout;
return;
Expand Down
5 changes: 3 additions & 2 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2170,8 +2170,9 @@ void jl_init_types(void) JL_GC_DISABLED

jl_module_type =
jl_new_datatype(jl_symbol("Module"), core, jl_any_type, jl_emptysvec,
jl_perm_symsvec(2, "name", "parent"),
jl_svec(2, jl_symbol_type, jl_any_type), 0, 1, 2);
jl_emptysvec, jl_emptysvec, 0, 1, 0);
jl_module_type->instance = NULL;
jl_compute_field_offsets(jl_module_type);

jl_value_t *symornothing[2] = { (jl_value_t*)jl_symbol_type, (jl_value_t*)jl_void_type };
jl_linenumbernode_type =
Expand Down
2 changes: 1 addition & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ end
end

@testset "fieldtypes Module" begin
@test fieldtypes(Module) isa Tuple
@test fieldtypes(Module) === ()
end


Expand Down

0 comments on commit ed4f968

Please sign in to comment.