From ed4f968a241586d9d7a60a9c40c07268e353f94d Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 18 Sep 2020 09:41:11 -0400 Subject: [PATCH] fix fields description of Module type The fields are not accessible, so it is awkward to report they exist. Fixes #37630 Caused issues starting with #34804 --- base/boot.jl | 19 +++++++++++++++++-- base/compiler/tfuncs.jl | 6 +++--- src/datatype.c | 2 +- src/jltypes.c | 5 +++-- test/misc.jl | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/base/boot.jl b/base/boot.jl index e653a82399ba5..7c8d05cc132c4 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -8,7 +8,7 @@ #abstract type Vararg{T} end #mutable struct Symbol -# #opaque +## opaque #end #mutable struct TypeName @@ -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 diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index cbf8e4f0f591d..a938d86f953ae 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -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 diff --git a/src/datatype.c b/src/datatype.c index 269076ef2819b..2fa35f1b5f5f0 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -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; diff --git a/src/jltypes.c b/src/jltypes.c index dd36776f1bac1..27ef5a814411c 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -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 = diff --git a/test/misc.jl b/test/misc.jl index e5fc2f461643c..920a03abdb520 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -840,7 +840,7 @@ end end @testset "fieldtypes Module" begin - @test fieldtypes(Module) isa Tuple + @test fieldtypes(Module) === () end