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

[macro] Remove CompilationServer.setModuleCheckPolicy options #11615

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/compiler/compilationCache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,3 @@ class cache = object(self)
end

type t = cache

type context_options =
| NormalContext
| MacroContext
| NormalAndMacroContext
8 changes: 4 additions & 4 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ let check_module sctx com m_path m_extra p =
end
in
let has_policy policy = List.mem policy m_extra.m_check_policy || match policy with
| NoCheckShadowing | NoCheckFileTimeModification when !ServerConfig.do_not_check_modules && !Parser.display_mode <> DMNone -> true
| NoFileSystemCheck when !ServerConfig.do_not_check_modules && !Parser.display_mode <> DMNone -> true
| _ -> false
in
let check_file () =
Expand Down Expand Up @@ -325,9 +325,9 @@ let check_module sctx com m_path m_extra p =
in
let check () =
try
if not (has_policy NoCheckShadowing) then check_module_path();
if not (has_policy NoCheckFileTimeModification) || Path.file_extension (Path.UniqueKey.lazy_path m_extra.m_file) <> "hx" then check_file();
if not (has_policy NoCheckDependencies) then check_dependencies();
check_module_path();
if not (has_policy NoFileSystemCheck) || Path.file_extension (Path.UniqueKey.lazy_path m_extra.m_file) <> "hx" then check_file();
check_dependencies();
None
with
| Dirty reason ->
Expand Down
5 changes: 2 additions & 3 deletions src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ and method_kind =
| MethMacro

type module_check_policy =
| NoCheckFileTimeModification
| NoFileSystemCheck
| CheckFileModificationTime
| CheckFileContentModification
| NoCheckDependencies
| NoCheckShadowing

type module_tainting_reason =
| CheckDisplayFile
Expand Down
6 changes: 3 additions & 3 deletions src/macro/macroApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type 'value compiler_api = {
add_global_metadata : string -> string -> (bool * bool * bool) -> pos -> unit;
register_define : string -> Define.user_define -> unit;
register_metadata : string -> Meta.user_meta -> unit;
add_module_check_policy : string list -> int list -> bool -> int -> unit;
add_module_check_policy : string list -> int list -> bool -> unit;
decode_expr : 'value -> Ast.expr;
encode_expr : Ast.expr -> 'value;
encode_ctype : Ast.type_hint -> 'value;
Expand Down Expand Up @@ -2292,10 +2292,10 @@ let macro_api ccom get_api =
vnull
);
(* Compilation server *)
"server_add_module_check_policy", vfun4 (fun filter policy recursive context_options ->
"server_add_module_check_policy", vfun3 (fun filter policy recursive ->
let filter = List.map decode_string (decode_array filter) in
let policy = List.map decode_int (decode_array policy) in
(get_api()).add_module_check_policy filter policy (decode_bool recursive) (decode_int context_options);
(get_api()).add_module_check_policy filter policy (decode_bool recursive);
vnull
);
"server_invalidate_files", vfun1 (fun a ->
Expand Down
15 changes: 5 additions & 10 deletions src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ let make_macro_com_api com mcom p =
com.global_metadata <- (ExtString.String.nsplit s1 ".",m,config) :: com.global_metadata;
) meta;
);
add_module_check_policy = (fun sl il b i ->
add_module_check_policy = (fun sl il b ->
Interp.exc_string "unsupported"
);
register_define = (fun s data -> Define.register_user_define com.user_defines s data);
Expand Down Expand Up @@ -526,20 +526,15 @@ let make_macro_api ctx mctx p =
ctx.com.global_metadata <- (ExtString.String.nsplit s1 ".",m,config) :: ctx.com.global_metadata;
) meta;
);
MacroApi.add_module_check_policy = (fun sl il b i ->
MacroApi.add_module_check_policy = (fun sl il b ->
let add ctx =
ctx.g.module_check_policies <- (List.fold_left (fun acc s -> (ExtString.String.nsplit s ".",List.map Obj.magic il,b) :: acc) ctx.g.module_check_policies sl);
ctx.com.module_lut#iter (fun _ m -> m.m_extra.m_check_policy <- TypeloadModule.get_policy ctx.g m.m_path);
in
let add_macro ctx = match ctx.g.macros with
add ctx;
match ctx.g.macros with
| None -> ()
| Some(_,mctx) -> add mctx;
in
let open CompilationCache in
match Obj.magic i with
| NormalContext -> add ctx
| MacroContext -> add_macro ctx
| NormalAndMacroContext -> add ctx; add_macro ctx;
| Some(_,mctx) -> add mctx
);
MacroApi.with_imports = (fun imports usings f ->
let restore_resolution = ctx.m.import_resolution#save in
Expand Down
51 changes: 9 additions & 42 deletions std/haxe/macro/CompilationServer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,55 +28,26 @@ enum abstract ModuleCheckPolicy(Int) {
/**
Disables file modification checks, avoiding some filesystem operations.
**/
var NoCheckFileTimeModification = 0;
var NoFileSystemCheck = 0;

/**
If a file is modified, also checks if its content changed. This check
is not free, but useful when .hx files are auto-generated.
**/
var CheckFileContentModification = 1;

/**
Disables dependency checks of the module.

This should only be used for modules that don't depend on any module that
might change. It is effectively a promise to the compiler that the module
is unaffected by changes made to other modules. If that promise is broken,
the compiler is sad and things probably stop working.
Default behavior: check last modification time.
**/
var NoCheckDependencies = 2;

/**
Disables file shadowing checks. Shadowing can occur when a new file
is added to a class-path that has higher priority than the class-path
of the current module file.
**/
var NoCheckShadowing = 3;
}
var CheckFileModificationTime = 1;

enum abstract ContextOptions(Int) {
/**
Affects only the normal context.
**/
var NormalContext = 0;

/**
Affects only the macro context.
**/
var MacroContext = 1;

/**
Affects the normal and macro contexts.
If a file is modified, also checks if its content changed. This check
is not free, but useful when .hx files are auto-generated.
**/
var NormalAndMacroContext = 2;
var CheckFileContentModification = 2;
}

/**
This class provides some methods which can be invoked from command line using
`--macro server.field(args)`.
**/
class CompilationServer {
#if (macro || display)
#if macro
/**
Sets the `ModuleCheckPolicy` of all files whose dot-path matches an
element of `pathFilters`.
Expand All @@ -89,16 +60,12 @@ class CompilationServer {
everything (if `recursive = true`) or only top-level types (if
`recursive = false`).

The argument `contextOptions` determines which context (normal, macro
or both) this affects.

If a call to this function is added to the compilation parameters, the
compilation server should be restarted to ensure it takes effect.
**/
static public function setModuleCheckPolicy(pathFilters:Array<String>, policy:Array<ModuleCheckPolicy>, ?recursive = true,
?contextOptions:ContextOptions = NormalContext) {
static public function setModuleCheckPolicy(pathFilters:Array<String>, policy:Array<ModuleCheckPolicy>, ?recursive = true) {
Context.onAfterInitMacros(() -> {
@:privateAccess Compiler.load("server_add_module_check_policy", 4)(pathFilters, policy, recursive, contextOptions);
@:privateAccess Compiler.load("server_add_module_check_policy", 4)(pathFilters, policy, recursive);
});
}

Expand Down
2 changes: 1 addition & 1 deletion std/haxe/macro/ExampleJSGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class ExampleJSGenerator {
sys.io.File.saveContent(api.outputFile, buf.toString());
}

#if (macro || display)
#if macro
public static function use() {
Compiler.setCustomJSGenerator(function(api) new ExampleJSGenerator(api).generate());
}
Expand Down
2 changes: 1 addition & 1 deletion std/haxe/macro/Format.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import haxe.macro.Context;
The actual macro implemented for Std.format
**/
class Format {
#if (macro || display)
#if macro
public static function format(estr:Expr) {
var str = switch (estr.expr) {
case EConst(c): switch (c) {
Expand Down