Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeassert syntax deprecations #17445

Merged
merged 3 commits into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ if is_windows()
start(hash::EnvHash) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
function done(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
if unsafe_load(block[1]) == 0
ccall(:FreeEnvironmentStringsW,stdcall,Int32,(Ptr{UInt16},),block[2])
ccall(:FreeEnvironmentStringsW, stdcall, Int32, (Ptr{UInt16},), block[2])
return true
end
false
return false
end
function next(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
pos = block[1]
Expand All @@ -102,7 +102,7 @@ function next(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
if m === nothing
error("malformed environment entry: $env")
end
(Pair{String,String}(m.captures[1], m.captures[2]), (pos+len*2, blk))
return (Pair{String,String}(m.captures[1], m.captures[2]), (pos+len*2, blk))
end

else # !windows
Expand All @@ -114,12 +114,12 @@ function next(::EnvHash, i)
if env === nothing
throw(BoundsError())
end
env::String
env = env::String
m = match(r"^(.*?)=(.*)$"s, env)
if m === nothing
error("malformed environment entry: $env")
end
(Pair{String,String}(m.captures[1], m.captures[2]), i+1)
return (Pair{String,String}(m.captures[1], m.captures[2]), i+1)
end

end # os-test
Expand Down
10 changes: 5 additions & 5 deletions base/float16.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

function convert(::Type{Float32}, val::Float16)
ival::UInt32 = reinterpret(UInt16, val)
sign::UInt32 = (ival & 0x8000) >> 15
exp::UInt32 = (ival & 0x7c00) >> 10
sig::UInt32 = (ival & 0x3ff) >> 0
ret::UInt32
local ival::UInt32 = reinterpret(UInt16, val),
Copy link
Contributor

Choose a reason for hiding this comment

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

does this also deprecate this form, or did you just add local because you're deprecating the no-assignment form used for ret ?

Copy link
Member Author

Choose a reason for hiding this comment

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

the code just looked silly with only local on the ret declation. I didn't deprecate this form, since it's not clear to me that is decided.

sign::UInt32 = (ival & 0x8000) >> 15,
exp::UInt32 = (ival & 0x7c00) >> 10,
sig::UInt32 = (ival & 0x3ff) >> 0,
ret::UInt32

if exp == 0
if sig == 0
Expand Down
2 changes: 1 addition & 1 deletion base/libuv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ show(io::IO, e::UVError) = print(io, e.prefix*": "*struverror(e)*" ("*uverrornam

## event loop ##

eventloop() = global uv_eventloop::Ptr{Void}
eventloop() = uv_eventloop::Ptr{Void}
#mkNewEventLoop() = ccall(:jl_new_event_loop,Ptr{Void},()) # this would probably be fine, but is nowhere supported

function run_event_loop()
Expand Down
3 changes: 1 addition & 2 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,7 @@ end
### BLAS-2 / sparse A * sparse x -> dense y

function densemv(A::SparseMatrixCSC, x::AbstractSparseVector; trans::Char='N')
xlen::Int
ylen::Int
local xlen::Int, ylen::Int
m, n = size(A)
if trans == 'N' || trans == 'n'
xlen = n; ylen = m
Expand Down
29 changes: 17 additions & 12 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1321,16 +1321,11 @@
(define (remove-argument-side-effects e)
(let ((a '()))
(cond
((and (decl? e) (symbol? (cadr e)))
(cons (cadr e) (list e)))
((not (pair? e))
(cons e '()))
(else
(cons (map (lambda (x)
(cond
((and (decl? x) (symbol? (cadr x)))
(set! a (cons x a))
(cadr x))
((not (effect-free? x))
(let ((g (make-ssavalue)))
(if (or (eq? (car x) '...) (eq? (car x) '&))
Expand Down Expand Up @@ -1689,8 +1684,8 @@
(else
`(block
,.(map (lambda (x)
(if (decl? x)
`(decl ,@(map expand-forms (cdr x)))
(if (and (decl? x) (length= (cdr x) 2) (symbol? (cadr x)))
`(impl-decl ,@(map expand-forms (cdr x)))
(expand-forms x)))
(butlast (cdr e)))
,(expand-forms (last (cdr e)))))))
Expand Down Expand Up @@ -1943,9 +1938,9 @@

'|::|
(lambda (e)
(if (length= e 2)
(if (not (length= e 3))
(error "invalid \"::\" syntax"))
(if (and (length= e 3) (not (symbol-like? (cadr e))))
(if (not (symbol-like? (cadr e)))
`(call (core typeassert)
,(expand-forms (cadr e)) ,(expand-forms (caddr e)))
(map expand-forms e)))
Expand Down Expand Up @@ -2426,7 +2421,7 @@
(vinfo:set-called! vi #t))
(for-each (lambda (x) (analyze-vars x env captvars sp))
(cdr e))))
((decl)
((decl impl-decl)
;; handle var::T declaration by storing the type in the var-info
;; record. for non-symbols or globals, emit a type assertion.
(let ((vi (var-info-for (cadr e) env)))
Expand Down Expand Up @@ -2914,11 +2909,21 @@ f(x) = yt(x)
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))
;; remaining `decl` expressions are only type assertions if the
;; argument is global or a non-symbol.
((decl)
((impl-decl)
(if (or (assq (cadr e) (car (lam:vinfo lam)))
(assq (cadr e) (cadr (lam:vinfo lam))))
'(null)
(let ((str-e (deparse `(|::| ,@(cdr e)))))
(syntax-deprecation #f str-e (string "local " str-e))
'(null))
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp)))
((decl)
(cond ((not (symbol? (cadr e)))
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))
((or (assq (cadr e) (car (lam:vinfo lam)))
(assq (cadr e) (cadr (lam:vinfo lam))))
'(null))
(else (syntax-deprecation #f (string "global " (deparse `(|::| ,@(cdr e)))) "typeassert")
(cl-convert `(call (core typeassert) ,@(cdr e)) fname lam namemap toplevel interp))))
;; `with-static-parameters` expressions can be removed now; used only by analyze-vars
((with-static-parameters)
(cl-convert (cadr e) fname lam namemap toplevel interp))
Expand Down
5 changes: 3 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3134,8 +3134,9 @@ immutable Foo11874
end

function bar11874(x)
y::Foo11874
y=x
local y::Foo11874
y = x
nothing
end

Base.convert(::Type{Foo11874},x::Int) = float(x)
Expand Down