Skip to content

Commit 9a0073d

Browse files
committed
more predictable global binding resolution
fix #18933 fix #17387 (for the syntactic case)
1 parent 04d76f3 commit 9a0073d

10 files changed

+176
-236
lines changed

NEWS.md

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ Language changes
2222
* The parsing of `1<<2*3` as `1<<(2*3)` is deprecated, and will change to
2323
`(1<<2)*3` in a future version ([#13079]).
2424

25+
* The `global` keyword now always introduces a new binding when appearing in toplevel (global) scope.
26+
Whereas, previously, embedding it in a block (such as `begin; global sin; nothing; end`) would change its meaning.
27+
Additionally, the new bindings are now created before the statement is executed.
28+
For example, `f() = (global sin = rand(); nothing)` will now reliably shadow the `Base.sin` function,
29+
with a new, undefined `sin` variable. ([#22984]).
30+
31+
2532
Breaking changes
2633
----------------
2734

base/poll.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ mutable struct _FDWatcher
145145
end
146146
end
147147

148-
global uvfinalize
149-
function uvfinalize(t::_FDWatcher)
148+
function Base.uvfinalize(t::_FDWatcher)
150149
if t.handle != C_NULL
151150
disassociate_julia_struct(t)
152151
ccall(:jl_close_uv, Void, (Ptr{Void},), t.handle)

doc/make.jl

-152
Original file line numberDiff line numberDiff line change
@@ -1,152 +0,0 @@
1-
# Install dependencies needed to build the documentation.
2-
ENV["JULIA_PKGDIR"] = joinpath(@__DIR__, "deps")
3-
Pkg.init()
4-
cp(joinpath(@__DIR__, "REQUIRE"), Pkg.dir("REQUIRE"); remove_destination = true)
5-
Pkg.update()
6-
Pkg.resolve()
7-
8-
using Documenter
9-
10-
# Include the `build_sysimg` file.
11-
12-
baremodule GenStdLib end
13-
isdefined(:build_sysimg) || @eval module BuildSysImg
14-
include(joinpath(@__DIR__, "..", "contrib", "build_sysimg.jl"))
15-
end
16-
17-
# Documenter Setup.
18-
19-
const PAGES = [
20-
"Home" => "index.md",
21-
"Manual" => [
22-
"manual/introduction.md",
23-
"manual/getting-started.md",
24-
"manual/variables.md",
25-
"manual/integers-and-floating-point-numbers.md",
26-
"manual/mathematical-operations.md",
27-
"manual/complex-and-rational-numbers.md",
28-
"manual/strings.md",
29-
"manual/functions.md",
30-
"manual/control-flow.md",
31-
"manual/variables-and-scoping.md",
32-
"manual/types.md",
33-
"manual/methods.md",
34-
"manual/constructors.md",
35-
"manual/conversion-and-promotion.md",
36-
"manual/interfaces.md",
37-
"manual/modules.md",
38-
"manual/documentation.md",
39-
"manual/metaprogramming.md",
40-
"manual/arrays.md",
41-
"manual/linear-algebra.md",
42-
"manual/networking-and-streams.md",
43-
"manual/parallel-computing.md",
44-
"manual/dates.md",
45-
"manual/interacting-with-julia.md",
46-
"manual/running-external-programs.md",
47-
"manual/calling-c-and-fortran-code.md",
48-
"manual/handling-operating-system-variation.md",
49-
"manual/environment-variables.md",
50-
"manual/embedding.md",
51-
"manual/packages.md",
52-
"manual/profile.md",
53-
"manual/stacktraces.md",
54-
"manual/performance-tips.md",
55-
"manual/workflow-tips.md",
56-
"manual/style-guide.md",
57-
"manual/faq.md",
58-
"manual/noteworthy-differences.md",
59-
"manual/unicode-input.md",
60-
],
61-
"Standard Library" => [
62-
"stdlib/base.md",
63-
"stdlib/collections.md",
64-
"stdlib/math.md",
65-
"stdlib/numbers.md",
66-
"stdlib/strings.md",
67-
"stdlib/arrays.md",
68-
"stdlib/parallel.md",
69-
"stdlib/linalg.md",
70-
"stdlib/constants.md",
71-
"stdlib/file.md",
72-
"stdlib/io-network.md",
73-
"stdlib/punctuation.md",
74-
"stdlib/sort.md",
75-
"stdlib/pkg.md",
76-
"stdlib/dates.md",
77-
"stdlib/iterators.md",
78-
"stdlib/test.md",
79-
"stdlib/c.md",
80-
"stdlib/libc.md",
81-
"stdlib/libdl.md",
82-
"stdlib/profile.md",
83-
"stdlib/stacktraces.md",
84-
"stdlib/simd-types.md",
85-
],
86-
"Developer Documentation" => [
87-
"devdocs/reflection.md",
88-
"Documentation of Julia's Internals" => [
89-
"devdocs/init.md",
90-
"devdocs/ast.md",
91-
"devdocs/types.md",
92-
"devdocs/object.md",
93-
"devdocs/eval.md",
94-
"devdocs/callconv.md",
95-
"devdocs/compiler.md",
96-
"devdocs/functions.md",
97-
"devdocs/cartesian.md",
98-
"devdocs/meta.md",
99-
"devdocs/subarrays.md",
100-
"devdocs/sysimg.md",
101-
"devdocs/llvm.md",
102-
"devdocs/stdio.md",
103-
"devdocs/boundscheck.md",
104-
"devdocs/locks.md",
105-
"devdocs/offset-arrays.md",
106-
"devdocs/libgit2.md",
107-
"devdocs/require.md",
108-
"devdocs/inference.md",
109-
],
110-
"Developing/debugging Julia's C code" => [
111-
"devdocs/backtraces.md",
112-
"devdocs/debuggingtips.md",
113-
"devdocs/valgrind.md",
114-
"devdocs/sanitizers.md",
115-
]
116-
],
117-
]
118-
119-
makedocs(
120-
build = joinpath(pwd(), "_build/html/en"),
121-
modules = [Base, Core, BuildSysImg],
122-
clean = false,
123-
doctest = "doctest" in ARGS,
124-
linkcheck = "linkcheck" in ARGS,
125-
linkcheck_ignore = ["https://bugs.kde.org/show_bug.cgi?id=136779"], # fails to load from nanosoldier?
126-
strict = true,
127-
checkdocs = :none,
128-
format = "pdf" in ARGS ? :latex : :html,
129-
sitename = "The Julia Language",
130-
authors = "The Julia Project",
131-
analytics = "UA-28835595-6",
132-
pages = PAGES,
133-
html_prettyurls = ("deploy" in ARGS),
134-
)
135-
136-
if "deploy" in ARGS
137-
# Only deploy docs from 64bit Linux to avoid committing multiple versions of the same
138-
# docs from different workers.
139-
(Sys.ARCH === :x86_64 && Sys.KERNEL === :Linux) || return
140-
141-
# Since the `.travis.yml` config specifies `language: cpp` and not `language: julia` we
142-
# need to manually set the version of Julia that we are deploying the docs from.
143-
ENV["TRAVIS_JULIA_VERSION"] = "nightly"
144-
145-
deploydocs(
146-
repo = "github.com/JuliaLang/julia.git",
147-
target = "_build/html/en",
148-
dirname = "en",
149-
deps = nothing,
150-
make = nothing,
151-
)
152-
end

src/interpreter.c

-16
Original file line numberDiff line numberDiff line change
@@ -319,22 +319,6 @@ static jl_value_t *eval(jl_value_t *e, interpreter_state *s)
319319
jl_declare_constant(b);
320320
return (jl_value_t*)jl_nothing;
321321
}
322-
else if (ex->head == global_sym) {
323-
// create uninitialized mutable binding for "global x" decl
324-
// TODO: handle type decls
325-
size_t i, l = jl_array_len(ex->args);
326-
for (i = 0; i < l; i++) {
327-
jl_sym_t *gsym = (jl_sym_t*)args[i];
328-
jl_module_t *gmodu = modu;
329-
if (jl_is_globalref(gsym)) {
330-
gmodu = jl_globalref_mod(gsym);
331-
gsym = jl_globalref_name(gsym);
332-
}
333-
assert(jl_is_symbol(gsym));
334-
jl_get_binding_wr(gmodu, gsym);
335-
}
336-
return (jl_value_t*)jl_nothing;
337-
}
338322
else if (ex->head == abstracttype_sym) {
339323
if (inside_typedef)
340324
jl_error("cannot eval a new abstract type definition while defining another type");

0 commit comments

Comments
 (0)