瀏覽代碼

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

RoBBoR 2 年之前
父節點
當前提交
5a86d0dc57
共有 3 個文件被更改,包括 13 次插入1 次删除
  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.",
 		"platforms": ["cs", "java"]
 	},
+	{
+		"name": "RetainUntypedMeta",
+		"define": "retain-untyped-meta",
+		"doc": "Prevents arbitrary expression metadata from being discarded upon typing."
+	},
 	{
 		"name": "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 debug_delayed : (typer_pass * ((unit -> unit) * string * typer) list) list;
 	doinline : bool;
+	retain_meta : bool;
 	mutable core_api : typer option;
 	mutable macros : ((unit -> unit) * typer) option;
 	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) ->
 			display_error ctx.com (Printf.sprintf "Reification $%s is not allowed outside of `macro` expression" s) p;
 			e()
-		| _ -> e()
+		| _ ->
+			if ctx.g.retain_meta then
+				let e = e() in
+				{e with eexpr = TMeta(m,e)}
+			else
+				e()
 	in
 	ctx.meta <- old;
 	e
@@ -2056,6 +2061,7 @@ let rec create com =
 			delayed = [];
 			debug_delayed = [];
 			doinline = com.display.dms_inline && not (Common.defined com Define.NoInline);
+			retain_meta = Common.defined com Define.RetainUntypedMeta;
 			std = null_module;
 			global_using = [];
 			complete = false;