Skip to content

Commit

Permalink
Merge branch 'development' into server/resetCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jan 24, 2024
2 parents d5afa9b + e5983c2 commit ef3dbf8
Show file tree
Hide file tree
Showing 56 changed files with 266 additions and 176 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -616,23 +616,16 @@ jobs:
- name: Install dependencies
env:
# For compatibility with macOS 10.13
ZLIB_VERSION: 1.3
ZLIB_VERSION: 1.3.1
MBEDTLS_VERSION: 2.28.5
PCRE2_VERSION: 10.42
run: |
set -ex
brew uninstall openssl@1.0.2t || echo
brew uninstall python@2.7.17 || echo
brew untap local/openssl || echo
brew untap local/python2 || echo
brew update
# brew unlink python@2
brew bundle --file=tests/Brewfile --no-upgrade || brew link --overwrite awscli
brew install libunistring
brew install cpanminus
brew bundle --file=tests/Brewfile --no-upgrade
cpanm IPC::System::Simple
cpanm String::ShellQuote
curl -L https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xz
curl -L https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz | tar xz
cd zlib-$ZLIB_VERSION
./configure
make && make install
Expand Down
13 changes: 3 additions & 10 deletions extra/github-actions/build-mac.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
- name: Install dependencies
env:
# For compatibility with macOS 10.13
ZLIB_VERSION: 1.3
ZLIB_VERSION: 1.3.1
MBEDTLS_VERSION: 2.28.5
PCRE2_VERSION: 10.42
run: |
set -ex
brew uninstall openssl@1.0.2t || echo
brew uninstall python@2.7.17 || echo
brew untap local/openssl || echo
brew untap local/python2 || echo
brew update
# brew unlink python@2
brew bundle --file=tests/Brewfile --no-upgrade || brew link --overwrite awscli
brew install libunistring
brew install cpanminus
brew bundle --file=tests/Brewfile --no-upgrade
cpanm IPC::System::Simple
cpanm String::ShellQuote
curl -L https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xz
curl -L https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz | tar xz
cd zlib-$ZLIB_VERSION
./configure
make && make install
Expand Down
13 changes: 4 additions & 9 deletions src/codegen/codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ module Dump = struct
| Some f -> print_field false f);
List.iter (print_field false) c.cl_ordered_fields;
List.iter (print_field true) c.cl_ordered_statics;
(match c.cl_init with
(match TClass.get_cl_init c with
| None -> ()
| Some e ->
print "\n\tstatic function __init__() ";
Expand Down Expand Up @@ -388,8 +388,8 @@ module Dump = struct
let dep = Hashtbl.create 0 in
List.iter (fun m ->
print "%s:\n" (Path.UniqueKey.lazy_path m.m_extra.m_file);
PMap.iter (fun _ (sign,mpath) ->
let m2 = com.module_lut#find mpath in
PMap.iter (fun _ mdep ->
let m2 = com.module_lut#find mdep.md_path in
let file = Path.UniqueKey.lazy_path m2.m_extra.m_file in
print "\t%s\n" file;
let l = try Hashtbl.find dep file with Not_found -> [] in
Expand Down Expand Up @@ -490,14 +490,9 @@ let map_source_header com f =

(* Static extensions for classes *)
module ExtClass = struct

let add_cl_init c e = match c.cl_init with
| None -> c.cl_init <- Some e
| Some e' -> c.cl_init <- Some (concat e' e)

let add_static_init c cf e p =
let ethis = Texpr.Builder.make_static_this c p in
let ef1 = mk (TField(ethis,FStatic(c,cf))) cf.cf_type p in
let e_assign = mk (TBinop(OpAssign,ef1,e)) e.etype p in
add_cl_init c e_assign
TClass.add_cl_init c e_assign
end
4 changes: 2 additions & 2 deletions src/codegen/gencommon/gencommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ let run_filters_from gen t filters =
gen.gcurrent_classfield <- None;
(match c.cl_init with
| None -> ()
| Some e ->
c.cl_init <- Some (List.fold_left (fun e f -> f e) e filters));
| Some f ->
process_field f);
| TClassDecl _ | TEnumDecl _ | TTypeDecl _ | TAbstractDecl _ ->
()

Expand Down
4 changes: 2 additions & 2 deletions src/codegen/gencommon/initFunction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let handle_override_dynfun acc e this field =

let handle_class gen cl =
let com = gen.gcon in
let init = match cl.cl_init with
let init = match TClass.get_cl_init cl with
| None -> []
| Some i -> [i]
in
Expand Down Expand Up @@ -109,7 +109,7 @@ let handle_class gen cl =
let init = List.rev init in
(match init with
| [] -> cl.cl_init <- None
| _ -> cl.cl_init <- Some (mk (TBlock init) com.basic.tvoid cl.cl_pos));
| _ -> TClass.set_cl_init cl (mk (TBlock init) com.basic.tvoid cl.cl_pos));

(* FIXME: find a way to tell OverloadingConstructor to execute this code even with empty constructors *)
let vars, funs = List.fold_left (fun (acc_vars,acc_funs) cf ->
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,10 @@ let compile ctx actx callbacks =
filter ctx tctx (fun () -> ());
end;
if ctx.has_error then raise Abort;
Generate.check_auxiliary_output com actx;
if is_compilation com then Generate.check_auxiliary_output com actx;
enter_stage com CGenerationStart;
ServerMessage.compiler_stage com;
Generate.maybe_generate_dump ctx tctx;
if not actx.no_output then Generate.generate ctx tctx ext actx;
enter_stage com CGenerationDone;
ServerMessage.compiler_stage com;
Expand Down
15 changes: 9 additions & 6 deletions src/compiler/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ let parse_swf_header ctx h = match ExtString.String.nsplit h ":" with

let delete_file f = try Sys.remove f with _ -> ()

let generate ctx tctx ext actx =
let maybe_generate_dump ctx tctx =
let com = tctx.Typecore.com in
(* check file extension. In case of wrong commandline, we don't want
to accidentaly delete a source file. *)
if Path.file_extension com.file = ext then delete_file com.file;
if com.platform = Flash || com.platform = Cpp || com.platform = Hl then List.iter (Codegen.fix_overrides com) com.types;
if Common.defined com Define.Dump then begin
Codegen.Dump.dump_types com;
Option.may Codegen.Dump.dump_types (com.get_macros())
Expand All @@ -47,7 +43,14 @@ let generate ctx tctx ext actx =
if not com.is_macro_context then match tctx.Typecore.g.Typecore.macros with
| None -> ()
| Some(_,ctx) -> Codegen.Dump.dump_dependencies ~target_override:(Some "macro") ctx.Typecore.com
end;
end

let generate ctx tctx ext actx =
let com = tctx.Typecore.com in
(* check file extension. In case of wrong commandline, we don't want
to accidentaly delete a source file. *)
if Path.file_extension com.file = ext then delete_file com.file;
if com.platform = Flash || com.platform = Cpp || com.platform = Hl then List.iter (Codegen.fix_overrides com) com.types;
begin match com.platform with
| Neko | Hl | Eval when actx.interp -> ()
| Cpp when Common.defined com Define.Cppia -> ()
Expand Down
12 changes: 11 additions & 1 deletion src/compiler/messageReporting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@ let compiler_pretty_message_string com ectx cm =
(* Error source *)
if display_source then out := List.fold_left (fun out (l, line) ->
let nb_len = String.length (string_of_int l) in
let gutter = gutter_len - nb_len - 1 in

(* Replace tabs with 1 space to avoid column misalignments *)
let line = String.concat " " (ExtString.String.nsplit line "\t") in
let len = String.length line in

out ^ Printf.sprintf "%s%s | %s\n"
(* left-padded line number *)
(String.make (gutter_len-nb_len-1) ' ')
(if gutter < 1 then "" else String.make gutter ' ')
(if l = 0 then "-" else Printf.sprintf "%d" l)
(* Source code at that line *)
(
Expand Down Expand Up @@ -308,6 +309,15 @@ let get_max_line max_lines messages =
else max_lines
) max_lines messages

let display_source_at com p =
let absolute_positions = Define.defined com.defines Define.MessageAbsolutePositions in
let ectx = create_error_context absolute_positions in
let msg = make_compiler_message "" p 0 MessageKind.DKCompilerMessage MessageSeverity.Information in
ectx.max_lines <- get_max_line ectx.max_lines [msg];
match compiler_pretty_message_string com ectx msg with
| None -> ()
| Some s -> prerr_endline s

exception ConfigError of string

let get_formatter com def default =
Expand Down
10 changes: 6 additions & 4 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let parse_file cs com (rfile : ClassPaths.resolved_file) p =
let ident = Hashtbl.find Parser.special_identifier_files fkey in
Printf.sprintf "not cached, using \"%s\" define" ident,true
with Not_found ->
cc#cache_file fkey rfile ftime data pdi;
cc#cache_file fkey (ClassPaths.create_resolved_file ffile rfile.class_path) ftime data pdi;
"cached",false
end
in
Expand Down Expand Up @@ -316,7 +316,9 @@ let check_module sctx ctx m_path m_extra p =
((com.cs#get_context sign)#find_module mpath).m_extra
in
let check_dependencies () =
PMap.iter (fun _ (sign,mpath) ->
PMap.iter (fun _ mdep ->
let sign = mdep.md_sign in
let mpath = mdep.md_path in
let m2_extra = try
find_module_extra sign mpath
with Not_found ->
Expand Down Expand Up @@ -418,8 +420,8 @@ let add_modules sctx ctx m p =
) m.m_types;
TypeloadModule.ModuleLevel.add_module ctx m p;
handle_cache_bound_objects com m.m_extra.m_cache_bound_objects;
PMap.iter (fun _ (sign,mpath) ->
let m2 = (com.cs#get_context sign)#find_module mpath in
PMap.iter (fun _ mdep ->
let m2 = (com.cs#get_context mdep.md_sign)#find_module mdep.md_path in
add_modules (tabs ^ " ") m0 m2
) m.m_extra.m_deps
)
Expand Down
2 changes: 2 additions & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ let is_diagnostics com = match com.report_mode with
| RMLegacyDiagnostics _ | RMDiagnostics _ -> true
| _ -> false

let is_compilation com = com.display.dms_kind = DMNone && not (is_diagnostics com)

let disable_report_mode com =
let old = com.report_mode in
com.report_mode <- RMNone;
Expand Down
2 changes: 1 addition & 1 deletion src/context/display/deprecationCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let run com =
| TClassDecl c when not (Meta.has Meta.Deprecated c.cl_meta) ->
let dctx = {dctx with class_meta = c.cl_meta; curmod = c.cl_module} in
(match c.cl_constructor with None -> () | Some cf -> run_on_field dctx cf);
(match c.cl_init with None -> () | Some e -> run_on_expr dctx e);
(match TClass.get_cl_init c with None -> () | Some e -> run_on_expr dctx e);
List.iter (run_on_field dctx) c.cl_ordered_statics;
List.iter (run_on_field dctx) c.cl_ordered_fields;
| _ ->
Expand Down
6 changes: 5 additions & 1 deletion src/context/display/displayFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ let collect ctx e_ast e dk with_type p =
| _ -> items
in
(* Anon own fields *)
let fields = match !(an.a_status) with
| ClassStatics c -> c.cl_statics
| _ -> an.a_fields
in
PMap.foldi (fun name cf acc ->
if is_new_item acc name then begin
let allow_static_abstract_access c cf =
Expand Down Expand Up @@ -293,7 +297,7 @@ let collect ctx e_ast e dk with_type p =
add origin make_ci_class_field;
end else
acc
) an.a_fields items
) fields items
| TFun (args,ret) ->
(* A function has no field except the magic .bind one. *)
if is_new_item items "bind" then begin
Expand Down
25 changes: 23 additions & 2 deletions src/context/display/displayToplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ let is_pack_visible pack =
not (List.exists (fun s -> String.length s > 0 && s.[0] = '_') pack)

let collect ctx tk with_type sort =
let t = Timer.timer ["display";"toplevel"] in
let t = Timer.timer ["display";"toplevel collect"] in
let cctx = CollectionContext.create ctx in
let curpack = fst ctx.curclass.cl_path in
(* Note: This checks for the explicit `ServerConfig.legacy_completion` setting instead of using
Expand Down Expand Up @@ -298,10 +298,12 @@ let collect ctx tk with_type sort =
| TKType | TKOverride -> ()
| TKExpr p | TKPattern p | TKField p ->
(* locals *)
let t = Timer.timer ["display";"toplevel collect";"locals"] in
PMap.iter (fun _ v ->
if not (is_gen_local v) then
add (make_ci_local v (tpair ~values:(get_value_meta v.v_meta) v.v_type)) (Some v.v_name)
) ctx.locals;
t();

let add_field scope origin cf =
let origin,cf = match origin with
Expand All @@ -326,6 +328,8 @@ let collect ctx tk with_type sort =
let maybe_add_field scope origin cf =
if not (Meta.has Meta.NoCompletion cf.cf_meta) then add_field scope origin cf
in

let t = Timer.timer ["display";"toplevel collect";"fields"] in
(* member fields *)
if ctx.curfun <> FunStatic then begin
let all_fields = Type.TClass.get_all_fields ctx.curclass (extract_param_types ctx.curclass.cl_params) in
Expand Down Expand Up @@ -353,7 +357,9 @@ let collect ctx tk with_type sort =
| _ ->
List.iter (maybe_add_field CFSStatic (Self (TClassDecl ctx.curclass))) ctx.curclass.cl_ordered_statics
end;
t();

let t = Timer.timer ["display";"toplevel collect";"enum ctors"] in
(* enum constructors *)
let rec enum_ctors t =
match t with
Expand Down Expand Up @@ -388,7 +394,9 @@ let collect ctx tk with_type sort =
(try enum_ctors (module_type_of_type (follow t)) with Exit -> ())
| _ -> ()
end;
t();

let t = Timer.timer ["display";"toplevel collect";"globals"] in
(* imported globals *)
PMap.iter (fun name (mt,s,_) ->
try
Expand Down Expand Up @@ -418,7 +426,9 @@ let collect ctx tk with_type sort =
with Not_found ->
()
) ctx.m.import_resolution#extract_field_imports;
t();

let t = Timer.timer ["display";"toplevel collect";"rest"] in
(* literals *)
add (make_ci_literal "null" (tpair t_dynamic)) (Some "null");
add (make_ci_literal "true" (tpair ctx.com.basic.tbool)) (Some "true");
Expand Down Expand Up @@ -448,7 +458,8 @@ let collect ctx tk with_type sort =

(* builtins *)
add (make_ci_literal "trace" (tpair (TFun(["value",false,t_dynamic],ctx.com.basic.tvoid)))) (Some "trace")
end
end;
t()
end;

(* type params *)
Expand All @@ -462,6 +473,7 @@ let collect ctx tk with_type sort =
(* module imports *)
List.iter add_type (List.rev_map fst ctx.m.import_resolution#extract_type_imports); (* reverse! *)

let t_syntax = Timer.timer ["display";"toplevel collect";"syntax"] in
(* types from files *)
let cs = ctx.com.cs in
(* online: iter context files *)
Expand Down Expand Up @@ -494,6 +506,9 @@ let collect ctx tk with_type sort =
if process_decls cfile.c_package module_name cfile.c_decls then check_package cfile.c_package;
end
) files;
t_syntax();

let t_native_lib = Timer.timer ["display";"toplevel collect";"native lib"] in
List.iter (fun file ->
match cs#get_native_lib file with
| Some lib ->
Expand All @@ -503,13 +518,19 @@ let collect ctx tk with_type sort =
| None ->
()
) ctx.com.native_libs.all_libs;
t_native_lib();

let t_packages = Timer.timer ["display";"toplevel collect";"packages"] in
(* packages *)
Hashtbl.iter (fun path _ ->
let full_pack = fst path @ [snd path] in
if is_pack_visible full_pack then add (make_ci_package path []) (Some (snd path))
) packages;
t_packages();

t();

let t = Timer.timer ["display";"toplevel sorting"] in
(* sorting *)
let l = DynArray.to_list cctx.items in
let l = if is_legacy_completion then
Expand Down
13 changes: 7 additions & 6 deletions src/context/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ let rec scan_module_deps cs m h =
()
else begin
Hashtbl.add h m.m_id m;
PMap.iter (fun _ (sign,mpath) ->
let m = (cs#get_context sign)#find_module mpath in
scan_module_deps cs m h) m.m_extra.m_deps
PMap.iter (fun _ mdep ->
let m = (cs#get_context mdep.md_sign)#find_module mdep.md_path in
scan_module_deps cs m h
) m.m_extra.m_deps
end

let module_sign key md =
Expand Down Expand Up @@ -274,9 +275,9 @@ let display_memory com =
());
if verbose then begin
print (Printf.sprintf " %d total deps" (List.length deps));
PMap.iter (fun _ (sign,mpath) ->
let md = (com.cs#get_context sign)#find_module mpath in
print (Printf.sprintf " dep %s%s" (s_type_path mpath) (module_sign key md));
PMap.iter (fun _ mdep ->
let md = (com.cs#get_context mdep.md_sign)#find_module mdep.md_path in
print (Printf.sprintf " dep %s%s" (s_type_path mdep.md_path) (module_sign key md));
) m.m_extra.m_deps;
end;
flush stdout
Expand Down
Loading

0 comments on commit ef3dbf8

Please sign in to comment.