Skip to content

Commit

Permalink
disallow global const in non-toplevel code. fixes #12010 (#25586)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored Jan 17, 2018
1 parent b9cb073 commit d6f079a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Language changes
For example, `f() = (global sin = "gluttony"; nothing)` will now resolve which module
contains `sin` eagerly, rather than delaying that decision until `f` is run. ([#22984]).

* `global const` declarations may no longer appear inside functions ([#12010]).

* Uninitialized `BitArray` constructors of the form `BitArray[{N}](shape...)` have been
deprecated in favor of equivalents accepting `uninitialized` (an alias for
`Uninitialized()`) as their first argument, as in
Expand Down
13 changes: 12 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3435,6 +3435,7 @@ f(x) = yt(x)
(current-loc #f)
(rett #f)
(deprecated-loop-vars (table))
(deprecated-global-const-locs '())
(arg-map #f) ;; map arguments to new names if they are assigned
(label-counter 0) ;; counter for generating label addresses
(label-map (table)) ;; maps label names to generated addresses
Expand Down Expand Up @@ -3833,7 +3834,11 @@ f(x) = yt(x)
(begin
(syntax-deprecation "`const` declaration on local variable" "" current-loc)
'(null))
(emit e)))
(if (pair? (cadr lam))
;; delay these deprecation warnings to allow "misplaced struct" errors to happen first
(set! deprecated-global-const-locs
(cons current-loc deprecated-global-const-locs))
(emit e))))
((isdefined) (if tail (emit-return e) e))
((warn-loop-var)
(if (or *warn-all-loop-vars*
Expand Down Expand Up @@ -3964,6 +3969,12 @@ f(x) = yt(x)
(else
(set-car! (cdr point) `(leave ,(- hl target-level))))))))
handler-goto-fixups)
(for-each (lambda (loc)
(deprecation-message
(string "`global const` declarations may no longer appear inside functions." #\newline
"Instead, use a non-constant global, or a global `const var = Ref{T}()`.")
loc))
(reverse! deprecated-global-const-locs))
(let* ((stmts (reverse! code))
(di (definitely-initialized-vars stmts vi))
(body (cons 'body (filter (lambda (e)
Expand Down

2 comments on commit d6f079a

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.