Skip to content

Commit

Permalink
Merge pull request #13485 from JuliaLang/jn/runtime_intrinsics
Browse files Browse the repository at this point in the history
runtime versions of Intrinsics.reinterpret
  • Loading branch information
vtjnash committed Oct 17, 2015
2 parents c13128a + cda8b06 commit 7a4d817
Show file tree
Hide file tree
Showing 22 changed files with 2,473 additions and 495 deletions.
1 change: 1 addition & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ EXE :=
endif

JULIAGC := MARKSWEEP
JULIACODEGEN := LLVM
USE_COPY_STACKS := 1

# flag for disabling assertions
Expand Down
10 changes: 5 additions & 5 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# definitions related to C interface

import Core.Intrinsics: cglobal, box, unbox
import Core.Intrinsics: cglobal, box

const OS_NAME = ccall(:jl_get_OS_NAME, Any, ())

Expand Down Expand Up @@ -58,10 +58,10 @@ else
bitstype 32 Cwstring
end

convert{T<:Union{Int8,UInt8}}(::Type{Cstring}, p::Ptr{T}) = box(Cstring, unbox(Ptr{T}, p))
convert(::Type{Cwstring}, p::Ptr{Cwchar_t}) = box(Cwstring, unbox(Ptr{Cwchar_t}, p))
convert{T<:Union{Int8,UInt8}}(::Type{Ptr{T}}, p::Cstring) = box(Ptr{T}, unbox(Cstring, p))
convert(::Type{Ptr{Cwchar_t}}, p::Cwstring) = box(Ptr{Cwchar_t}, unbox(Cwstring, p))
convert{T<:Union{Int8,UInt8}}(::Type{Cstring}, p::Ptr{T}) = box(Cstring, p)
convert(::Type{Cwstring}, p::Ptr{Cwchar_t}) = box(Cwstring, p)
convert{T<:Union{Int8,UInt8}}(::Type{Ptr{T}}, p::Cstring) = box(Ptr{T}, p)
convert(::Type{Ptr{Cwchar_t}}, p::Cwstring) = box(Ptr{Cwchar_t}, p)

# here, not in pointer.jl, to avoid bootstrapping problems in coreimg.jl
pointer_to_string(p::Cstring, own::Bool=false) = pointer_to_string(convert(Ptr{UInt8}, p), own)
Expand Down
22 changes: 16 additions & 6 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ function abstract_call(f, fargs, argtypes::Vector{Any}, vtypes, sv::StaticVarInf
end
end
rt = builtin_tfunction(f, fargs, Tuple{argtypes...}, vtypes, sv)
if isa(rt, TypeVar)
rt = rt.ub
end
#print("=> ", rt, "\n")
return rt
end
Expand Down Expand Up @@ -1421,14 +1424,14 @@ function typeinf(linfo::LambdaStaticData,atypes::ANY,sparams::SimpleVector, def,
break
end
if isa(code,Type)
curtype = code
curtype = code::Type
# sometimes just a return type is stored here. if a full AST
# is not needed, we can return it.
if !needtree
return (nothing, code)
end
else
curtype = ccall(:jl_ast_rettype, Any, (Any,Any), def, code)
curtype = ccall(:jl_ast_rettype, Any, (Any,Any), def, code)::Type
return (code, curtype)
end
end
Expand All @@ -1441,7 +1444,7 @@ function typeinf(linfo::LambdaStaticData,atypes::ANY,sparams::SimpleVector, def,

(fulltree, result, rec) = typeinf_uncached(linfo, atypes, sparams, def, curtype, cop, true)
if fulltree === ()
return (fulltree,result)
return (fulltree, result::Type)
end

if !redo
Expand Down Expand Up @@ -1470,7 +1473,7 @@ function typeinf(linfo::LambdaStaticData,atypes::ANY,sparams::SimpleVector, def,
def.tfunc[tfunc_idx+1] = rec
end

return (fulltree, result)
return (fulltree, result::Type)
end

typeinf_uncached(linfo, atypes::ANY, sparams::ANY; optimize=true) =
Expand Down Expand Up @@ -1584,14 +1587,21 @@ function typeinf_uncached(linfo::LambdaStaticData, atypes::ANY, sparams::SimpleV
lastatype = lastatype.parameters[1]
laty -= 1
end
if isa(lastatype, TypeVar)
lastatype = lastatype.ub
end
if laty > la
laty = la
end
for i=1:laty
s[1][args[i]] = VarState(atypes.parameters[i],false)
atyp = atypes.parameters[i]
if isa(atyp, TypeVar)
atyp = atyp.ub
end
s[1][args[i]] = VarState(atyp, false)
end
for i=laty+1:la
s[1][args[i]] = VarState(lastatype,false)
s[1][args[i]] = VarState(lastatype, false)
end
elseif la != 0
return ((), Bottom, false) # wrong number of arguments
Expand Down
4 changes: 2 additions & 2 deletions base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const C_NULL = box(Ptr{Void}, 0)

# pointer to integer
convert{T<:Union{Int,UInt}}(::Type{T}, x::Ptr) = box(T, unbox(Ptr,x))
convert{T<:Union{Int,UInt}}(::Type{T}, x::Ptr) = box(T, unbox(Ptr{Void},x))
convert{T<:Integer}(::Type{T}, x::Ptr) = convert(T,convert(UInt, x))

# integer to pointer
Expand All @@ -14,7 +14,7 @@ convert{T}(::Type{Ptr{T}}, x::Int) = box(Ptr{T},unbox(Int,Int(x)))

# pointer to pointer
convert{T}(::Type{Ptr{T}}, p::Ptr{T}) = p
convert{T}(::Type{Ptr{T}}, p::Ptr) = box(Ptr{T}, unbox(Ptr,p))
convert{T}(::Type{Ptr{T}}, p::Ptr) = box(Ptr{T}, unbox(Ptr{Void},p))

# object to pointer (when used with ccall)
unsafe_convert(::Type{Ptr{UInt8}}, x::Symbol) = ccall(:jl_symbol_name, Ptr{UInt8}, (Any,), x)
Expand Down
Loading

0 comments on commit 7a4d817

Please sign in to comment.