瀏覽代碼

store type parameters in FClosure too

Simon Krajewski 10 年之前
父節點
當前提交
f996b26c63
共有 8 個文件被更改,包括 14 次插入14 次删除
  1. 1 1
      codegen.ml
  2. 3 3
      gencommon.ml
  3. 1 1
      genjs.ml
  4. 1 1
      genpy.ml
  5. 1 1
      interp.ml
  6. 1 1
      optimizer.ml
  7. 3 3
      type.ml
  8. 3 3
      typer.ml

+ 1 - 1
codegen.ml

@@ -1763,7 +1763,7 @@ module DeprecationCheck = struct
 					| FAnon cf ->
 					| FAnon cf ->
 						check_cf com cf e.epos
 						check_cf com cf e.epos
 					| FClosure(co,cf) ->
 					| FClosure(co,cf) ->
-						(match co with None -> () | Some c -> check_class com c e.epos);
+						(match co with None -> () | Some (c,_) -> check_class com c e.epos);
 						check_cf com cf e.epos
 						check_cf com cf e.epos
 					| FEnum(en,ef) ->
 					| FEnum(en,ef) ->
 						check_enum com en e.epos;
 						check_enum com en e.epos;

+ 3 - 3
gencommon.ml

@@ -3374,7 +3374,7 @@ struct
 				expr,clscapt
 				expr,clscapt
 			| Some _ ->
 			| Some _ ->
 				{
 				{
-					eexpr = TField(expr, FClosure(Some cls,invokecf));
+					eexpr = TField(expr, FClosure(Some (cls,[]),invokecf)); (* TODO: FClosure change *)
 					etype = invokecf.cf_type;
 					etype = invokecf.cf_type;
 					epos = cls.cl_pos
 					epos = cls.cl_pos
 				}, clscapt
 				}, clscapt
@@ -6226,7 +6226,7 @@ struct
 							cf,t,false
 							cf,t,false
 					| true ->
 					| true ->
 					let (cf, actual_t, error), is_static = match f with
 					let (cf, actual_t, error), is_static = match f with
-						| FInstance(c,_,cf) | FClosure(Some c,cf) ->
+						| FInstance(c,_,cf) | FClosure(Some (c,_),cf) ->
 							(* get from overloads *)
 							(* get from overloads *)
 							(* FIXME: this is a workaround for issue #1743 . Uncomment this code after it was solved *)
 							(* FIXME: this is a workaround for issue #1743 . Uncomment this code after it was solved *)
 							(* let t, cf = List.find (fun (t,cf2) -> cf == cf2) (Typeload.get_overloads cl (field_name f)) in *)
 							(* let t, cf = List.find (fun (t,cf2) -> cf == cf2) (Typeload.get_overloads cl (field_name f)) in *)
@@ -7785,7 +7785,7 @@ struct
 						| Var _
 						| Var _
 						| Method MethDynamic -> { eexpr = TField (ethis, FInstance(cl,List.map snd cl.cl_params,cf)); etype = cf_type; epos = pos }
 						| Method MethDynamic -> { eexpr = TField (ethis, FInstance(cl,List.map snd cl.cl_params,cf)); etype = cf_type; epos = pos }
 						| _ ->
 						| _ ->
-								{ eexpr = TField (this, FClosure(Some cl, cf)); etype = cf_type; epos = pos }
+								{ eexpr = TField (this, FClosure(Some (cl,[]), cf)); etype = cf_type; epos = pos } (* TODO: FClosure change *)
 				in
 				in
 
 
 				let do_field cf cf_type static =
 				let do_field cf cf_type static =

+ 1 - 1
genjs.ml

@@ -494,7 +494,7 @@ and gen_expr ctx e =
 		print ctx "$iterator(";
 		print ctx "$iterator(";
 		gen_value ctx x;
 		gen_value ctx x;
 		print ctx ")";
 		print ctx ")";
-	| TField (x,FClosure (Some {cl_path=[],"Array"}, {cf_name="push"})) ->
+	| TField (x,FClosure (Some ({cl_path=[],"Array"},_), {cf_name="push"})) ->
 		(* see https://github.com/HaxeFoundation/haxe/issues/1997 *)
 		(* see https://github.com/HaxeFoundation/haxe/issues/1997 *)
 		add_feature ctx "use.$arrayPushClosure";
 		add_feature ctx "use.$arrayPushClosure";
 		print ctx "$arrayPushClosure(";
 		print ctx "$arrayPushClosure(";

+ 1 - 1
genpy.ml

@@ -817,7 +817,7 @@ module Transformer = struct
 		| (is_value, TBinop(OpAssignOp op,{eexpr = TField(e1,FDynamic s)},e2)) ->
 		| (is_value, TBinop(OpAssignOp op,{eexpr = TField(e1,FDynamic s)},e2)) ->
 			let e = dynamic_field_read_write ae.a_next_id e1 s op e2 in
 			let e = dynamic_field_read_write ae.a_next_id e1 s op e2 in
 			transform_expr ~is_value:is_value e
 			transform_expr ~is_value:is_value e
-		| (is_value, TField(e1, FClosure(Some {cl_path = [],("String" | "list")},cf))) ->
+		| (is_value, TField(e1, FClosure(Some ({cl_path = [],("String" | "list")},_),cf))) ->
 			let e = dynamic_field_read e1 cf.cf_name in
 			let e = dynamic_field_read e1 cf.cf_name in
 			transform_expr ~is_value:is_value e
 			transform_expr ~is_value:is_value e
 		| (is_value, TBinop(OpAssign, left, right))->
 		| (is_value, TBinop(OpAssign, left, right))->

+ 1 - 1
interp.ml

@@ -4564,7 +4564,7 @@ and encode_field_access fa =
 		| FStatic(c,cf) -> 1,[encode_clref c;encode_cfref cf]
 		| FStatic(c,cf) -> 1,[encode_clref c;encode_cfref cf]
 		| FAnon(cf) -> 2,[encode_cfref cf]
 		| FAnon(cf) -> 2,[encode_cfref cf]
 		| FDynamic(s) -> 3,[enc_string s]
 		| FDynamic(s) -> 3,[enc_string s]
-		| FClosure(co,cf) -> 4,[vopt encode_clref co;encode_cfref cf]
+		| FClosure(co,cf) -> 4,[(match co with Some (c,_) -> encode_clref c | None -> VNull);encode_cfref cf] (* TODO: breaking change, kind of, too *)
 		| FEnum(en,ef) -> 5,[encode_enref en;encode_efield ef]
 		| FEnum(en,ef) -> 5,[encode_enref en;encode_efield ef]
 	in
 	in
 	enc_enum IFieldAccess tag pl
 	enc_enum IFieldAccess tag pl

+ 1 - 1
optimizer.ml

@@ -1085,7 +1085,7 @@ let rec reduce_loop ctx e =
 		| None -> reduce_expr ctx e
 		| None -> reduce_expr ctx e
 		| Some e -> reduce_loop ctx e)
 		| Some e -> reduce_loop ctx e)
 	| TCall ({ eexpr = TField (o,FClosure (c,cf)) } as f,el) ->
 	| TCall ({ eexpr = TField (o,FClosure (c,cf)) } as f,el) ->
-		let fmode = (match c with None -> FAnon cf | Some c -> FInstance (c,[],cf)) in (* TODO *)
+		let fmode = (match c with None -> FAnon cf | Some (c,tl) -> FInstance (c,tl,cf)) in
 		{ e with eexpr = TCall ({ f with eexpr = TField (o,fmode) },el) }
 		{ e with eexpr = TCall ({ f with eexpr = TField (o,fmode) },el) }
 	| TSwitch (e1,[[{eexpr = TConst (TBool true)}],{eexpr = TConst (TBool true)}],Some ({eexpr = TConst (TBool false)})) ->
 	| TSwitch (e1,[[{eexpr = TConst (TBool true)}],{eexpr = TConst (TBool true)}],Some ({eexpr = TConst (TBool false)})) ->
 		(* introduced by extractors in some cases *)
 		(* introduced by extractors in some cases *)

+ 3 - 3
type.ml

@@ -135,7 +135,7 @@ and tfield_access =
 	| FStatic of tclass * tclass_field
 	| FStatic of tclass * tclass_field
 	| FAnon of tclass_field
 	| FAnon of tclass_field
 	| FDynamic of string
 	| FDynamic of string
-	| FClosure of tclass option * tclass_field (* None class = TAnon *)
+	| FClosure of (tclass * tparams) option * tclass_field (* None class = TAnon *)
 	| FEnum of tenum * tenum_field
 	| FEnum of tenum * tenum_field
 
 
 and texpr = {
 and texpr = {
@@ -907,7 +907,7 @@ let rec s_expr s_type e =
 		let fstr = (match f with
 		let fstr = (match f with
 			| FStatic (c,f) -> "static(" ^ s_type_path c.cl_path ^ "." ^ f.cf_name ^ ")"
 			| FStatic (c,f) -> "static(" ^ s_type_path c.cl_path ^ "." ^ f.cf_name ^ ")"
 			| FInstance (c,_,f) -> "inst(" ^ s_type_path c.cl_path ^ "." ^ f.cf_name ^ " : " ^ s_type f.cf_type ^ ")"
 			| FInstance (c,_,f) -> "inst(" ^ s_type_path c.cl_path ^ "." ^ f.cf_name ^ " : " ^ s_type f.cf_type ^ ")"
-			| FClosure (c,f) -> "closure(" ^ (match c with None -> f.cf_name | Some c -> s_type_path c.cl_path ^ "." ^ f.cf_name)  ^ ")"
+			| FClosure (c,f) -> "closure(" ^ (match c with None -> f.cf_name | Some (c,_) -> s_type_path c.cl_path ^ "." ^ f.cf_name)  ^ ")"
 			| FAnon f -> "anon(" ^ f.cf_name ^ ")"
 			| FAnon f -> "anon(" ^ f.cf_name ^ ")"
 			| FEnum (en,f) -> "enum(" ^ s_type_path en.e_path ^ "." ^ f.ef_name ^ ")"
 			| FEnum (en,f) -> "enum(" ^ s_type_path en.e_path ^ "." ^ f.ef_name ^ ")"
 			| FDynamic f -> "dynamic(" ^ f ^ ")"
 			| FDynamic f -> "dynamic(" ^ f ^ ")"
@@ -1076,7 +1076,7 @@ let rec s_expr_ast print_var_ids tabs s_type e =
 		let sfa = match fa with
 		let sfa = match fa with
 			| FInstance(c,tl,cf) -> tag "FInstance" ~extra_tabs:"\t" [s_type (TInst(c,tl)); cf.cf_name]
 			| FInstance(c,tl,cf) -> tag "FInstance" ~extra_tabs:"\t" [s_type (TInst(c,tl)); cf.cf_name]
 			| FStatic(c,cf) -> tag "FStatic" ~extra_tabs:"\t" [s_type_path c.cl_path; cf.cf_name]
 			| FStatic(c,cf) -> tag "FStatic" ~extra_tabs:"\t" [s_type_path c.cl_path; cf.cf_name]
-			| FClosure(co,cf) -> tag "FClosure" ~extra_tabs:"\t" [(match co with None -> "None" | Some c -> s_type_path c.cl_path); cf.cf_name]
+			| FClosure(co,cf) -> tag "FClosure" ~extra_tabs:"\t" [(match co with None -> "None" | Some (c,_) -> s_type_path c.cl_path); cf.cf_name]
 			| FAnon cf -> tag "FAnon" ~extra_tabs:"\t" [cf.cf_name]
 			| FAnon cf -> tag "FAnon" ~extra_tabs:"\t" [cf.cf_name]
 			| FDynamic s -> tag "FDynamic" ~extra_tabs:"\t" [s]
 			| FDynamic s -> tag "FDynamic" ~extra_tabs:"\t" [s]
 			| FEnum(en,ef) -> tag "FEnum" ~extra_tabs:"\t" [s_type_path en.e_path; ef.ef_name]
 			| FEnum(en,ef) -> tag "FEnum" ~extra_tabs:"\t" [s_type_path en.e_path; ef.ef_name]

+ 3 - 3
typer.ml

@@ -1001,7 +1001,7 @@ let rec acc_get ctx g p =
 		| _ -> assert false)
 		| _ -> assert false)
 	| AKInline (e,f,fmode,t) ->
 	| AKInline (e,f,fmode,t) ->
 		(* do not create a closure for static calls *)
 		(* do not create a closure for static calls *)
-		let cmode = (match fmode with FStatic _ -> fmode | FInstance (c,_,f) -> FClosure (Some c,f) | _ -> assert false) in
+		let cmode = (match fmode with FStatic _ -> fmode | FInstance (c,tl,f) -> FClosure (Some (c,tl),f) | _ -> assert false) in
 		ignore(follow f.cf_type); (* force computing *)
 		ignore(follow f.cf_type); (* force computing *)
 		(match f.cf_expr with
 		(match f.cf_expr with
 		| None ->
 		| None ->
@@ -1126,7 +1126,7 @@ let field_access ctx mode f fmode t e p =
 			| _ , MGet ->
 			| _ , MGet ->
 				let cmode = (match fmode with
 				let cmode = (match fmode with
 					| FInstance(_, _, cf) | FStatic(_, cf) when Meta.has Meta.Generic cf.cf_meta -> display_error ctx "Cannot create closure on generic function" p; fmode
 					| FInstance(_, _, cf) | FStatic(_, cf) when Meta.has Meta.Generic cf.cf_meta -> display_error ctx "Cannot create closure on generic function" p; fmode
-					| FInstance (c,_,cf) -> FClosure (Some c,cf)
+					| FInstance (c,tl,cf) -> FClosure (Some (c,tl),cf)
 					| FStatic _ | FEnum _ -> fmode
 					| FStatic _ | FEnum _ -> fmode
 					| FAnon f -> FClosure (None, f)
 					| FAnon f -> FClosure (None, f)
 					| FDynamic _ | FClosure _ -> assert false
 					| FDynamic _ | FClosure _ -> assert false
@@ -2012,7 +2012,7 @@ and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 				let std = type_type ctx ([],"Std") e.epos in
 				let std = type_type ctx ([],"Std") e.epos in
 				let acc = acc_get ctx (type_field ctx std "string" e.epos MCall) e.epos in
 				let acc = acc_get ctx (type_field ctx std "string" e.epos MCall) e.epos in
 				ignore(follow acc.etype);
 				ignore(follow acc.etype);
-				let acc = (match acc.eexpr with TField (e,FClosure (Some c,f)) -> { acc with eexpr = TField (e,FInstance (c,[],f)) } | _ -> acc) in
+				let acc = (match acc.eexpr with TField (e,FClosure (Some (c,tl),f)) -> { acc with eexpr = TField (e,FInstance (c,tl,f)) } | _ -> acc) in
 				make_call ctx acc [e] ctx.t.tstring e.epos
 				make_call ctx acc [e] ctx.t.tstring e.epos
 			| KAbstract (a,tl) ->
 			| KAbstract (a,tl) ->
 				loop (Abstract.get_underlying_type a tl)
 				loop (Abstract.get_underlying_type a tl)