Skip to content

Commit 1e70913

Browse files
LilithHafnerc42f
authored andcommitted
Add public keyword (#50105)
Co-authored-by: Claire Foster <[email protected]>
1 parent 1175944 commit 1e70913

File tree

30 files changed

+432
-90
lines changed

30 files changed

+432
-90
lines changed

base/docs/basedocs.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,23 @@ kw"import"
5252
"""
5353
export
5454
55-
`export` is used within modules to tell Julia which functions should be
55+
`export` is used within modules to tell Julia which names should be
5656
made available to the user. For example: `export foo` makes the name
5757
`foo` available when [`using`](@ref) the module.
5858
See the [manual section about modules](@ref modules) for details.
5959
"""
6060
kw"export"
6161

62+
"""
63+
public
64+
65+
`public` is used within modules to tell Julia which names are part of the
66+
public API of the module . For example: `public foo` indicates that the name
67+
`foo` is public, without making it available available when [`using`](@ref)
68+
the module. See the [manual section about modules](@ref modules) for details.
69+
"""
70+
kw"public"
71+
6272
"""
6373
as
6474

base/exports.jl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,3 +1063,84 @@ export
10631063
@view,
10641064
@views,
10651065
@static
1066+
1067+
# TODO: use normal syntax once JuliaSyntax.jl becomes available at this point in bootstrapping
1068+
eval(Expr(:public,
1069+
# Modules
1070+
:Checked,
1071+
:Filesystem,
1072+
:Order,
1073+
:Sort,
1074+
1075+
# Types
1076+
:AbstractLock,
1077+
:AsyncCondition,
1078+
:CodeUnits,
1079+
:Event,
1080+
:Fix1,
1081+
:Fix2,
1082+
:Generator,
1083+
:ImmutableDict,
1084+
:OneTo,
1085+
:UUID,
1086+
1087+
# Semaphores
1088+
:Semaphore,
1089+
:acquire,
1090+
:release,
1091+
1092+
# collections
1093+
:IteratorEltype,
1094+
:IteratorSize,
1095+
:to_index,
1096+
:vect,
1097+
:isdone,
1098+
:front,
1099+
:rest,
1100+
:split_rest,
1101+
:tail,
1102+
:checked_length,
1103+
1104+
# Loading
1105+
:DL_LOAD_PATH,
1106+
:load_path,
1107+
:active_project,
1108+
1109+
# Reflection and introspection
1110+
:isambiguous,
1111+
:isexpr,
1112+
:isidentifier,
1113+
:issingletontype,
1114+
:identify_package,
1115+
:locate_package,
1116+
:moduleroot,
1117+
:jit_total_bytes,
1118+
:summarysize,
1119+
:isexported,
1120+
:ispublic,
1121+
1122+
# Opperators
1123+
:operator_associativity,
1124+
:operator_precedence,
1125+
:isbinaryoperator,
1126+
:isoperator,
1127+
:isunaryoperator,
1128+
1129+
# C interface
1130+
:cconvert,
1131+
:unsafe_convert,
1132+
1133+
# Error handling
1134+
:exit_on_sigint,
1135+
:windowserror,
1136+
1137+
# Macros
1138+
Symbol("@assume_effects"),
1139+
Symbol("@constprop"),
1140+
Symbol("@locals"),
1141+
Symbol("@propagate_inbounds"),
1142+
1143+
# misc
1144+
:notnothing,
1145+
:runtests,
1146+
:text_colors))

base/reflection.jl

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,100 @@ end
7575
"""
7676
names(x::Module; all::Bool = false, imported::Bool = false)
7777
78-
Get an array of the names exported by a `Module`, excluding deprecated names.
79-
If `all` is true, then the list also includes non-exported names defined in the module,
78+
Get an array of the public names of a `Module`, excluding deprecated names.
79+
If `all` is true, then the list also includes non-public names defined in the module,
8080
deprecated names, and compiler-generated names.
8181
If `imported` is true, then names explicitly imported from other modules
8282
are also included.
8383
84-
As a special case, all names defined in `Main` are considered \"exported\",
85-
since it is not idiomatic to explicitly export names from `Main`.
84+
As a special case, all names defined in `Main` are considered \"public\",
85+
since it is not idiomatic to explicitly mark names from `Main` as public.
8686
87-
See also: [`@locals`](@ref Base.@locals), [`@__MODULE__`](@ref).
87+
See also: [`isexported`](@ref), [`ispublic`](@ref), [`@locals`](@ref Base.@locals), [`@__MODULE__`](@ref).
8888
"""
8989
names(m::Module; all::Bool = false, imported::Bool = false) =
9090
sort!(unsorted_names(m; all, imported))
9191
unsorted_names(m::Module; all::Bool = false, imported::Bool = false) =
9292
ccall(:jl_module_names, Array{Symbol,1}, (Any, Cint, Cint), m, all, imported)
9393

94+
"""
95+
isexported(m::Module, s::Symbol) -> Bool
96+
97+
Returns whether a symbol is exported from a module.
98+
99+
See also: [`ispublic`](@ref), [`names`](@ref)
100+
101+
```jldoctest
102+
julia> module Mod
103+
export foo
104+
public bar
105+
end
106+
Mod
107+
108+
julia> Base.isexported(Mod, :foo)
109+
true
110+
111+
julia> Base.isexported(Mod, :bar)
112+
false
113+
114+
julia> Base.isexported(Mod, :baz)
115+
false
116+
```
117+
"""
94118
isexported(m::Module, s::Symbol) = ccall(:jl_module_exports_p, Cint, (Any, Any), m, s) != 0
119+
120+
"""
121+
ispublic(m::Module, s::Symbol) -> Bool
122+
123+
Returns whether a symbol is marked as public in a module.
124+
125+
Exported symbols are considered public.
126+
127+
See also: [`isexported`](@ref), [`names`](@ref)
128+
129+
```jldoctest
130+
julia> module Mod
131+
export foo
132+
public bar
133+
end
134+
Mod
135+
136+
julia> Base.ispublic(Mod, :foo)
137+
true
138+
139+
julia> Base.ispublic(Mod, :bar)
140+
true
141+
142+
julia> Base.ispublic(Mod, :baz)
143+
false
144+
```
145+
"""
146+
ispublic(m::Module, s::Symbol) = ccall(:jl_module_public_p, Cint, (Any, Any), m, s) != 0
147+
148+
# TODO: this is vaguely broken because it only works for explicit calls to
149+
# `Base.deprecate`, not the @deprecated macro:
95150
isdeprecated(m::Module, s::Symbol) = ccall(:jl_is_binding_deprecated, Cint, (Any, Any), m, s) != 0
151+
152+
"""
153+
isbindingresolved(m::Module, s::Symbol) -> Bool
154+
155+
Returns whether the binding of a symbol in a module is resolved.
156+
157+
See also: [`isexported`](@ref), [`ispublic`](@ref), [`isdeprecated`](@ref)
158+
159+
```jldoctest
160+
julia> module Mod
161+
foo() = 17
162+
end
163+
Mod
164+
165+
julia> Base.isbindingresolved(Mod, :foo)
166+
true
167+
168+
julia> Base.isbindingresolved(Mod, :bar)
169+
false
170+
```
171+
"""
96172
isbindingresolved(m::Module, var::Symbol) = ccall(:jl_binding_resolved_p, Cint, (Any, Any), m, var) != 0
97173

98174
function binding_module(m::Module, s::Symbol)

base/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In
22262226
print(io, head, ' ')
22272227
show_list(io, args, ", ", indent, 0, quote_level)
22282228

2229-
elseif head === :export
2229+
elseif head in (:export, :public)
22302230
print(io, head, ' ')
22312231
show_list(io, mapany(allow_macroname, args), ", ", indent)
22322232

deps/JuliaSyntax.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
JULIASYNTAX_BRANCH = main
2-
JULIASYNTAX_SHA1 = 045d156c44dbb87769c7416d049a7c08908539d4
2+
JULIASYNTAX_SHA1 = a9110fa8ecbe79943bb9525b4ccd99a3976cfcb7
33
JULIASYNTAX_GIT_URL := https://github.com/JuliaLang/JuliaSyntax.jl.git
44
JULIASYNTAX_TAR_URL = https://api.github.com/repos/JuliaLang/JuliaSyntax.jl/tarball/$1

deps/checksums/JuliaSyntax-045d156c44dbb87769c7416d049a7c08908539d4.tar.gz/md5

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

deps/checksums/JuliaSyntax-045d156c44dbb87769c7416d049a7c08908539d4.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a42bbb42babbbd727556f6bc01455826
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
d542766e72b57418b9b4e17743f89d8535c1f36497346b57538bd0cb451e64af9493015692179f80ec4ee8cf18349c1e0888f5710db895e19f9bb0322f0f7464

doc/src/base/base.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ However, you can create variables with names:
6060
Finally:
6161
`where` is parsed as an infix operator for writing parametric method and type definitions;
6262
`in` and `isa` are parsed as infix operators;
63+
`public` is parsed as a keyword when beginning a toplevel statement;
6364
`outer` is parsed as a keyword when used to modify the scope of a variable in an iteration specification of a `for` loop;
6465
and `as` is used as a keyword to rename an identifier brought into scope by `import` or `using`.
6566
Creation of variables named `where`, `in`, `isa`, `outer` and `as` is allowed, though.
6667

6768
```@docs
6869
module
6970
export
71+
public
7072
import
7173
using
7274
as
@@ -451,6 +453,8 @@ Base.@__DIR__
451453
Base.@__LINE__
452454
Base.fullname
453455
Base.names
456+
Base.isexported
457+
Base.ispublic
454458
Base.nameof(::Function)
455459
Base.functionloc(::Any, ::Any)
456460
Base.functionloc(::Method)

0 commit comments

Comments
 (0)