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

runtime versions of Intrinsics.reinterpret #13485

Merged
merged 11 commits into from
Oct 17, 2015
Merged
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 @@ -903,6 +903,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 @@ -1324,14 +1327,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 @@ -1344,7 +1347,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 @@ -1373,7 +1376,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 @@ -1487,14 +1490,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