Explorar o código

Added `-D retain-untyped-meta` (#10973)

RoBBoR %!s(int64=2) %!d(string=hai) anos
pai
achega
5a86d0dc57
Modificáronse 3 ficheiros con 13 adicións e 1 borrados
  1. 5 0
      src-json/define.json
  2. 1 0
      src/context/typecore.ml
  3. 7 1
      src/typing/typer.ml

+ 5 - 0
src-json/define.json

@@ -579,6 +579,11 @@
 		"doc": "GenCommon internal.",
 		"doc": "GenCommon internal.",
 		"platforms": ["cs", "java"]
 		"platforms": ["cs", "java"]
 	},
 	},
+	{
+		"name": "RetainUntypedMeta",
+		"define": "retain-untyped-meta",
+		"doc": "Prevents arbitrary expression metadata from being discarded upon typing."
+	},
 	{
 	{
 		"name": "Scriptable",
 		"name": "Scriptable",
 		"define": "scriptable",
 		"define": "scriptable",

+ 1 - 0
src/context/typecore.ml

@@ -71,6 +71,7 @@ type typer_globals = {
 	mutable delayed : (typer_pass * (unit -> unit) list) list;
 	mutable delayed : (typer_pass * (unit -> unit) list) list;
 	mutable debug_delayed : (typer_pass * ((unit -> unit) * string * typer) list) list;
 	mutable debug_delayed : (typer_pass * ((unit -> unit) * string * typer) list) list;
 	doinline : bool;
 	doinline : bool;
+	retain_meta : bool;
 	mutable core_api : typer option;
 	mutable core_api : typer option;
 	mutable macros : ((unit -> unit) * typer) option;
 	mutable macros : ((unit -> unit) * typer) option;
 	mutable std : module_def;
 	mutable std : module_def;

+ 7 - 1
src/typing/typer.ml

@@ -1685,7 +1685,12 @@ and type_meta ?(mode=MGet) ctx m e1 with_type p =
 		| (Meta.Dollar s,_,p) ->
 		| (Meta.Dollar s,_,p) ->
 			display_error ctx.com (Printf.sprintf "Reification $%s is not allowed outside of `macro` expression" s) p;
 			display_error ctx.com (Printf.sprintf "Reification $%s is not allowed outside of `macro` expression" s) p;
 			e()
 			e()
-		| _ -> e()
+		| _ ->
+			if ctx.g.retain_meta then
+				let e = e() in
+				{e with eexpr = TMeta(m,e)}
+			else
+				e()
 	in
 	in
 	ctx.meta <- old;
 	ctx.meta <- old;
 	e
 	e
@@ -2056,6 +2061,7 @@ let rec create com =
 			delayed = [];
 			delayed = [];
 			debug_delayed = [];
 			debug_delayed = [];
 			doinline = com.display.dms_inline && not (Common.defined com Define.NoInline);
 			doinline = com.display.dms_inline && not (Common.defined com Define.NoInline);
+			retain_meta = Common.defined com Define.RetainUntypedMeta;
 			std = null_module;
 			std = null_module;
 			global_using = [];
 			global_using = [];
 			complete = false;
 			complete = false;