@@ -158,23 +158,27 @@ function static_convert(to::ANY, from::ANY)
158158 end
159159 # tuple conversion calls convert recursively
160160 if isseqtype(ce)
161- R = abstract_call_gf(convert, (), (Type{pe}, ce .parameters [1 ]), ())
161+ #R = abstract_call_gf(convert, (), (Type{pe}, ce .parameters [1 ]), ())
162+ R = static_convert (pe, ce .parameters [1 ])
162163 isType (R ) && (R = R .parameters [1 ])
163164 result[i] = ... {R }
164165 else
165- R = abstract_call_gf (convert, (), (Type{pe}, ce), ())
166+ #R = abstract_call_gf (convert, (), (Type{pe}, ce), ())
167+ R = static_convert (pe, ce)
166168 isType (R ) && (R = R .parameters [1 ])
167169 result[i] = R
168170 end
169171 end
170172 a2t (result)
171173end
172- t_func[: convert] =
173- (2 , 2 , (t,x)- > (if isa (t,Tuple) && allp (isType,t)
174- t = Type{map (t- > t .parameters [1 ],t)}
175- end;
176- isType (t) ? static_convert (t .parameters [1 ],x) :
177- Any))
174+ t_func[convert_default] =
175+ (3 , 3 , (t,x,f)- > (isType (t) ? static_convert (t .parameters [1 ],x) : Any))
176+ t_func[convert_tuple] =
177+ (3 , 3 , (t,x,f)- > (if isa (t,Tuple) && allp (isType,t)
178+ t = Type{map (t- > t .parameters [1 ],t)}
179+ end;
180+ isType (t) ? static_convert (t .parameters [1 ],x) :
181+ Any))
178182typeof_tfunc = function (t )
179183 if isType(t)
180184 t = t.parameters[1]
@@ -486,6 +490,9 @@ function abstract_call(f, fargs, argtypes, vtypes, sv::StaticVarInfo, e)
486490 end
487491 end
488492 end
493+ if !is(f,apply) && isa(e,Expr) && isa(f,Function)
494+ e.head = :call1
495+ end
489496 rt = builtin_tfunction(f, fargs, argtypes)
490497 #print("=> ", rt, "\n")
491498 return rt
@@ -497,8 +504,8 @@ function abstract_call(f, fargs, argtypes, vtypes, sv::StaticVarInfo, e)
497504 end
498505end
499506
500- ft_tfunc(ft, argtypes) = ccall(:jl_func_type_tfunc, Any,
501- (Any, Any), ft, argtypes)
507+ ft_tfunc(ft, argtypes) = ccall(:jl_func_type_tfunc, Any, (Any, Any),
508+ ft, argtypes)
502509
503510function abstract_eval_call(e, vtypes, sv::StaticVarInfo)
504511 fargs = a2t_butfirst(e.args)
828835typeinf(linfo,atypes,sparams) = typeinf(linfo,atypes,sparams,linfo,true)
829836typeinf(linfo,atypes,sparams,linfo) = typeinf(linfo,atypes,sparams,linfo,true)
830837
831- abstract RecPending{T }
832-
833- isRecPending (t) = isa (t, AbstractKind) && is (t .name , RecPending .name )
834-
835838ast_rettype(ast) = ast.args[3].typ
836839
837840# def is the original unspecialized version of a method. we aggregate all
@@ -840,8 +843,6 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
840843 #dbg =
841844 #dotrace = true#is(linfo,sizestr)
842845 local ast::Expr
843- redo = false
844- curtype = None
845846 # check cached t-functions
846847 tf = def.tfunc
847848 while !is(tf,())
@@ -853,15 +854,9 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
853854 # if the frame above this one recurred, rerun type inf
854855 # here instead of returning, and update the cache, until the new
855856 # inferred type equals the cached type (fixed point)
856- rt = ast_rettype(tf[2])
857- if isRecPending(rt)
858- curtype = rt.parameters[1]
859- redo = true
860- ast = tf[2]
861- break
862- else
863- return (tf[2], rt)
864- end
857+ ast = tf[2]
858+ rt = ast_rettype(ast)
859+ return (ast, rt)
865860 end
866861 tf = tf[3]
867862 end
@@ -893,12 +888,9 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
893888 f = f.prev
894889 end
895890
896- rec = false
897-
898891 #print("typeinf ", linfo.name, " ", atypes, "\n")
899892
900- if redo
901- elseif cop
893+ if cop
902894 sparams = append(sparams, linfo.sparams)
903895 ast = ccall(:jl_prepare_ast, Any, (Any,Any), linfo, sparams)::Expr
904896 else
@@ -910,8 +902,20 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
910902 locals = (ast.args[2].args[1].args)::Array{Any,1 }
911903 vars = append (args, locals)
912904 body = (ast .args [3 ].args ):: Array {Any,1 }
913-
914905 n = length (body)
906+
907+ # our stack frame
908+ frame = CallStack (ast0, linfo .module , atypes, inference_stack)
909+ inference_stack = frame
910+ curtype = None
911+ frame .result = curtype
912+
913+ local s, sv
914+
915+ while true
916+
917+ rec = false
918+
915919 s = { () | i= 1 : n }
916920 recpts = IntSet (n+ 1 ) # statements that depend recursively on our value
917921 W = IntSet (n+ 1 )
@@ -958,11 +962,6 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
958962 end
959963 sv = StaticVarInfo (sparams, cenv)
960964
961- # our stack frame
962- frame = CallStack (ast0, linfo .module , atypes, inference_stack)
963- frame .result = curtype
964- inference_stack = frame
965-
966965 # exception handlers
967966 cur_hand = ()
968967 handler_at = { () | i= 1 : n }
@@ -1069,23 +1068,23 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
10691068 end
10701069 #print (" \n " ,ast," \n " )
10711070 #print (" ==> " , frame .result ," \n " )
1072- if redo && typeseq (curtype, frame .result )
1073- rec = false
1074- end
1075- fulltree = type_annotate (ast, s, sv,
1076- rec ? RecPending{ frame . result } : frame . result ,
1077- vars)
1078- if ! rec
1079- fulltree . args [ 3 ] = inlining_pass ( fulltree . args [ 3 ], s[ 1 ])
1080- tuple_elim_pass (fulltree)
1081- linfo . inferred = true
1082- end
1083- if ! redo
1084- compressed = ccall (: jl_compress_ast, Any, (Any,), fulltree)
1085- fulltree = compressed
1086- #compressed = fulltree
1087- def .tfunc = (atypes, compressed, def .tfunc )
1088- end
1071+ if ! rec || typeseq (curtype, frame .result )
1072+ break
1073+ end
1074+ curtype = frame . result
1075+ end # while
1076+
1077+ fulltree = type_annotate (ast, s, sv, frame . result , vars)
1078+
1079+ fulltree . args [ 3 ] = inlining_pass (fulltree . args [ 3 ], s[ 1 ] )
1080+ tuple_elim_pass (fulltree)
1081+ linfo . inferred = true
1082+
1083+ compressed = ccall (: jl_compress_ast, Any, (Any,), fulltree)
1084+ fulltree = compressed
1085+ #compressed = fulltree
1086+ def .tfunc = (atypes, compressed, def .tfunc )
1087+
10891088 inference_stack = (inference_stack:: CallStack).prev
10901089 return (fulltree, frame .result )
10911090end
@@ -1173,11 +1172,6 @@ function type_annotate(ast::Expr, states::Array{Any,1},
11731172 end
11741173 end
11751174
1176- # do inference on inner functions
1177- if isRecPending (rettype)
1178- return ast
1179- end
1180-
11811175 for li in closures
11821176 if ! li .inferred
11831177 a = li .ast
@@ -1286,6 +1280,15 @@ end
12861280function inlineable(f, e::Expr, vars)
12871281 argexprs = a2t_butfirst(e.args)
12881282 atypes = map(exprtype, argexprs)
1283+
1284+ if is(f, convert_default) && length(atypes)==3
1285+ # builtin case of convert. convert(T,x::S) => x, when S<:T
1286+ if isType(atypes[1]) && subtype(atypes[2],atypes[1].parameters[1])
1287+ # todo: if T expression has side effects??!
1288+ return e.args[3]
1289+ end
1290+ end
1291+
12891292 meth = getmethods(f, atypes)
12901293 if length(meth) != 1
12911294 return NF
@@ -1297,13 +1300,6 @@ function inlineable(f, e::Expr, vars)
12971300 if !subtype(atypes, meth[1])
12981301 return NF
12991302 end
1300- if is(meth[3],:convert) && length(atypes)==2
1301- # builtin case of convert. convert(T,x::S) => x, when S<:T
1302- if isType(atypes[1]) && subtype(atypes[2],atypes[1].parameters[1])
1303- # todo: if T expression has side effects??!
1304- return e.args[3]
1305- end
1306- end
13071303 if !isa(meth[3],LambdaStaticData) || !is(meth[4],())
13081304 return NF
13091305 end
0 commit comments