From 87ada5e2afa288c136fc1963c5d2c126dcd7241d Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 14 Sep 2023 20:37:45 +0200 Subject: [PATCH 01/26] OCaml 5 compatibility (#11272) --- .github/workflows/main.yml | 15 ++++-- Earthfile | 3 ++ extra/github-actions/cache-opam-windows.yml | 6 --- extra/github-actions/cache-opam.yml | 6 --- extra/github-actions/workflows/main.yml | 27 +++++++++-- haxe.opam | 5 +- libs/extc/extc_stubs.c | 42 ++++++++--------- libs/extc/process_stubs.c | 4 +- libs/extlib-leftovers/uTF8.ml | 2 +- libs/ilib/peReader.ml | 4 +- libs/objsize/c_objsize.c | 31 ++++++++++-- libs/swflib/swfParser.ml | 2 +- libs/swflib/swfPic.ml | 2 +- libs/ttflib/tTFParser.ml | 2 +- libs/ziplib/zip.ml | 16 +++---- src/codegen/dotnet.ml | 4 +- src/codegen/java.ml | 2 +- src/codegen/javaModern.ml | 2 +- src/codegen/swfLoader.ml | 2 +- src/compiler/displayProcessing.ml | 2 +- src/context/display/displayException.ml | 16 +++---- src/context/display/documentSymbols.ml | 2 +- src/context/typecore.ml | 8 ++-- src/core/path.ml | 4 +- src/dune | 2 +- src/generators/gencpp.ml | 4 +- src/generators/genhl.ml | 4 +- src/generators/genphp7.ml | 52 ++++++++++----------- src/generators/genswf9.ml | 2 +- src/generators/hl2c.ml | 2 +- src/generators/hlinterp.ml | 12 ++--- src/macro/eval/evalJit.ml | 2 +- src/macro/eval/evalStdLib.ml | 28 +++++------ src/optimization/inlineConstructors.ml | 4 +- src/typing/matcher.ml | 2 +- src/typing/typeloadCheck.ml | 2 +- src/typing/typeloadParse.ml | 2 +- 37 files changed, 185 insertions(+), 142 deletions(-) delete mode 100644 extra/github-actions/cache-opam-windows.yml delete mode 100644 extra/github-actions/cache-opam.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5c13a228fd7..f9378961b1e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -259,6 +259,10 @@ jobs: env: PLATFORM: linux64 OPAMYES: 1 + strategy: + fail-fast: false + matrix: + ocaml: ["4.08.1", "5.0.0"] steps: - uses: actions/checkout@main with: @@ -269,7 +273,7 @@ jobs: uses: actions/cache@v3.0.11 with: path: ~/.opam/ - key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}-2 + key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }} - name: Install Neko from S3 run: | @@ -303,6 +307,7 @@ jobs: set -ex opam init # --disable-sandboxing opam update + opam switch create ${{ matrix.ocaml }} opam pin add haxe . --no-action opam install haxe --deps-only --assume-depexts opam list @@ -343,11 +348,12 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: linuxBinaries + name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: out - name: Upload xmldoc artifact uses: actions/upload-artifact@v3 + if: matrix.ocaml == '4.08.1' with: name: xmldoc path: extra/doc @@ -363,6 +369,7 @@ jobs: strategy: fail-fast: false matrix: + ocaml: ["4.08.1", "5.0.0"] target: [macro, js, hl, cpp, 'java,jvm', cs, php, python, lua, flash, neko] include: - target: hl @@ -379,7 +386,7 @@ jobs: submodules: recursive - uses: actions/download-artifact@v3 with: - name: linuxBinaries + name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: linuxBinaries - name: Install Neko from S3 @@ -586,7 +593,7 @@ jobs: uses: actions/cache@v3.0.11 with: path: ~/.opam/ - key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}-2 + key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }} - name: Install Neko from S3 run: | diff --git a/Earthfile b/Earthfile index 8f399bb103a..dda473f6c60 100644 --- a/Earthfile +++ b/Earthfile @@ -93,6 +93,9 @@ devcontainer: # Install OCaml libraries COPY haxe.opam . RUN opam init --disable-sandboxing + RUN opam switch create 4.08.1 + RUN eval $(opam env) + RUN opam env RUN opam install . --yes --deps-only --no-depexts RUN opam list RUN ocamlopt -v diff --git a/extra/github-actions/cache-opam-windows.yml b/extra/github-actions/cache-opam-windows.yml deleted file mode 100644 index 5270fbf1fed..00000000000 --- a/extra/github-actions/cache-opam-windows.yml +++ /dev/null @@ -1,6 +0,0 @@ -- name: Cache opam - id: cache-opam - uses: actions/cache@v3.0.11 - with: - path: D:\.opam - key: ${{ runner.os }}${{ env.ARCH }}-${{ hashFiles('./haxe.opam', './libs/') }} diff --git a/extra/github-actions/cache-opam.yml b/extra/github-actions/cache-opam.yml deleted file mode 100644 index faaee00b723..00000000000 --- a/extra/github-actions/cache-opam.yml +++ /dev/null @@ -1,6 +0,0 @@ -- name: Cache opam - id: cache-opam - uses: actions/cache@v3.0.11 - with: - path: ~/.opam/ - key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}-2 diff --git a/extra/github-actions/workflows/main.yml b/extra/github-actions/workflows/main.yml index 629d1bd640c..5dbff676142 100644 --- a/extra/github-actions/workflows/main.yml +++ b/extra/github-actions/workflows/main.yml @@ -57,12 +57,22 @@ jobs: env: PLATFORM: linux64 OPAMYES: 1 + strategy: + fail-fast: false + matrix: + ocaml: ["4.08.1", "5.0.0"] steps: - uses: actions/checkout@main with: submodules: recursive - @import cache-opam.yml + - name: Cache opam + id: cache-opam + uses: actions/cache@v3.0.11 + with: + path: ~/.opam/ + key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }} + @import install-neko-unix.yml - name: Install dependencies @@ -79,6 +89,7 @@ jobs: set -ex opam init # --disable-sandboxing opam update + opam switch create ${{ matrix.ocaml }} opam pin add haxe . --no-action opam install haxe --deps-only --assume-depexts opam list @@ -119,11 +130,12 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: linuxBinaries + name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: out - name: Upload xmldoc artifact uses: actions/upload-artifact@v3 + if: matrix.ocaml == '4.08.1' with: name: xmldoc path: extra/doc @@ -139,6 +151,7 @@ jobs: strategy: fail-fast: false matrix: + ocaml: ["4.08.1", "5.0.0"] target: [macro, js, hl, cpp, 'java,jvm', cs, php, python, lua, flash, neko] include: - target: hl @@ -155,7 +168,7 @@ jobs: submodules: recursive - uses: actions/download-artifact@v3 with: - name: linuxBinaries + name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: linuxBinaries @import install-neko-unix.yml @@ -325,7 +338,13 @@ jobs: with: submodules: recursive - @import cache-opam.yml + - name: Cache opam + id: cache-opam + uses: actions/cache@v3.0.11 + with: + path: ~/.opam/ + key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }} + @import install-neko-unix.yml @import build-mac.yml diff --git a/haxe.opam b/haxe.opam index 60e1671fe72..6da637e9549 100644 --- a/haxe.opam +++ b/haxe.opam @@ -19,15 +19,16 @@ build: [ install: [make "install" "INSTALL_DIR=%{prefix}%"] remove: [make "uninstall" "INSTALL_DIR=%{prefix}%"] depends: [ - "ocaml" {>= "4.08"} + ("ocaml" {>= "5.0"} & ("camlp5" {build})) + | ("ocaml" {>= "4.08" & < "5.0"} & ("camlp5" {build & = "8.00"})) "ocamlfind" {build} "dune" {>= "1.11"} - "camlp5" {build & = "8.00"} "sedlex" {>= "2.0"} "xml-light" "extlib" {>= "1.7.8"} "ptmap" {>= "2.0.0"} "sha" + "camlp-streams" "conf-libpcre2-8" "conf-zlib" "conf-neko" diff --git a/libs/extc/extc_stubs.c b/libs/extc/extc_stubs.c index 30dc986d5c4..92faa58aa2a 100644 --- a/libs/extc/extc_stubs.c +++ b/libs/extc/extc_stubs.c @@ -92,7 +92,7 @@ int Zflush_val(value zflush_val) { case 4: return Z_FINISH; // TODO: support Z_BLOCK and Z_TREE // TODO: append the received value - default: failwith("Error in `Zflush_val` (extc_stubs.c): Unknown zflush value"); + default: caml_failwith("Error in `Zflush_val` (extc_stubs.c): Unknown zflush value"); } assert(0); } @@ -222,14 +222,14 @@ CAMLprim value zlib_deflate_init2(value level_val, value window_bits_val) { break; case Z_STREAM_ERROR: // TODO: use stream->msg to get _zlib_'s text message - failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_STREAM_ERROR"); + caml_failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_STREAM_ERROR"); break; case Z_VERSION_ERROR: // TODO: use stream->msg to get _zlib_'s text message - failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_VERSION_ERROR"); + caml_failwith("Error in `zlib_deflate_init2` (extc_stubs.c): call to `deflateInit2` failed: Z_VERSION_ERROR"); break; default: - failwith("Error in `zlib_deflate_init2` (extc_stubs.c): unknown return code from `deflateInit2`"); + caml_failwith("Error in `zlib_deflate_init2` (extc_stubs.c): unknown return code from `deflateInit2`"); } assert(0); } @@ -275,7 +275,7 @@ CAMLprim value zlib_deflate(value stream_val, value src, value spos, value slen, if (deflate_result == Z_OK || deflate_result == Z_STREAM_END) { stream->next_in = NULL; stream->next_out = NULL; - value zresult = alloc_small(3, 0); + value zresult = caml_alloc_small(3, 0); // z_finish Field(zresult, 0) = Val_bool(deflate_result == Z_STREAM_END); // z_read @@ -291,14 +291,14 @@ CAMLprim value zlib_deflate(value stream_val, value src, value spos, value slen, break; case Z_STREAM_ERROR: // TODO: use stream->msg to get _zlib_'s text message - failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_STREAM_ERROR"); + caml_failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_STREAM_ERROR"); break; case Z_BUF_ERROR: // TODO: use stream->msg to get _zlib_'s text message - failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_BUF_ERROR"); + caml_failwith("Error in `zlib_deflate` (extc_stubs.c): call to `deflate` failed: Z_BUF_ERROR"); break; default: - failwith("Error in `zlib_deflate` (extc_stubs.c): unknown return code from `deflate`"); + caml_failwith("Error in `zlib_deflate` (extc_stubs.c): unknown return code from `deflate`"); } assert(0); } @@ -309,14 +309,14 @@ CAMLprim value zlib_deflate_bytecode(value *arg, int nargs) { CAMLprim value zlib_deflate_end(value zv) { if( deflateEnd(ZStreamP_val(zv)) != 0 ) - failwith("zlib_deflate_end"); + caml_failwith("zlib_deflate_end"); return Val_unit; } CAMLprim value zlib_inflate_init(value wbits) { value z = zlib_new_stream(); if( inflateInit2(ZStreamP_val(z),Int_val(wbits)) != Z_OK ) - failwith("zlib_inflate_init"); + caml_failwith("zlib_inflate_init"); return z; } @@ -330,12 +330,12 @@ CAMLprim value zlib_inflate( value zv, value src, value spos, value slen, value z->avail_in = Int_val(slen); z->avail_out = Int_val(dlen); if( (r = inflate(z,Int_val(flush))) < 0 ) - failwith("zlib_inflate"); + caml_failwith("zlib_inflate"); z->next_in = NULL; z->next_out = NULL; - res = alloc_small(3, 0); + res = caml_alloc_small(3, 0); Field(res, 0) = Val_bool(r == Z_STREAM_END); Field(res, 1) = Val_int(Int_val(slen) - z->avail_in); Field(res, 2) = Val_int(Int_val(dlen) - z->avail_out); @@ -348,7 +348,7 @@ CAMLprim value zlib_inflate_bytecode(value * arg, int nargs) { CAMLprim value zlib_inflate_end(value zv) { if( inflateEnd(ZStreamP_val(zv)) != 0 ) - failwith("zlib_inflate_end"); + caml_failwith("zlib_inflate_end"); return Val_unit; } @@ -368,13 +368,13 @@ CAMLprim value executable_path(value u) { #ifdef _WIN32 char path[MAX_PATH]; if( GetModuleFileName(NULL,path,MAX_PATH) == 0 ) - failwith("executable_path"); + caml_failwith("executable_path"); return caml_copy_string(path); #elif __APPLE__ char path[MAXPATHLEN+1]; uint32_t path_len = MAXPATHLEN; if ( _NSGetExecutablePath(path, &path_len) ) - failwith("executable_path"); + caml_failwith("executable_path"); return caml_copy_string(path); #elif __FreeBSD__ char path[PATH_MAX]; @@ -387,7 +387,7 @@ CAMLprim value executable_path(value u) { len = sizeof(path); error = sysctl(name, 4, path, &len, NULL, 0); if( error < 0 ) - failwith("executable_path"); + caml_failwith("executable_path"); return caml_copy_string(path); #else char path[PATH_MAX]; @@ -397,7 +397,7 @@ CAMLprim value executable_path(value u) { if( p != NULL ) return caml_copy_string(p); else - failwith("executable_path"); + caml_failwith("executable_path"); } path[length] = '\0'; return caml_copy_string(path); @@ -408,12 +408,12 @@ CAMLprim value get_full_path( value f ) { #ifdef _WIN32 char path[MAX_PATH]; if( GetFullPathName(String_val(f),MAX_PATH,path,NULL) == 0 ) - failwith("get_full_path"); + caml_failwith("get_full_path"); return caml_copy_string(path); #else char path[4096]; if( realpath(String_val(f),path) == NULL ) - failwith("get_full_path"); + caml_failwith("get_full_path"); return caml_copy_string(path); #endif } @@ -428,7 +428,7 @@ CAMLprim value get_real_path( value path ) { // this will ensure the full class path with proper casing if( GetFullPathName(String_val(path),MAX_PATH,out,NULL) == 0 ) - failwith("get_real_path"); + caml_failwith("get_real_path"); len = strlen(out); i = 0; @@ -501,7 +501,7 @@ CAMLprim value sys_time() { ULARGE_INTEGER ui; GetSystemTime(&t); if( !SystemTimeToFileTime(&t,&ft) ) - failwith("sys_cpu_time"); + caml_failwith("sys_cpu_time"); ui.LowPart = ft.dwLowDateTime; ui.HighPart = ft.dwHighDateTime; return caml_copy_double( ((double)ui.QuadPart) / 10000000.0 - EPOCH_DIFF ); diff --git a/libs/extc/process_stubs.c b/libs/extc/process_stubs.c index c17c7a4f5bd..1f42c0fd1ad 100644 --- a/libs/extc/process_stubs.c +++ b/libs/extc/process_stubs.c @@ -67,10 +67,10 @@ #define val_null Val_int(0) #define val_some(v) Field(v,0) #define val_int(v) Int_val(v) -#define neko_error() failwith(__FUNCTION__) +#define neko_error() caml_failwith(__FUNCTION__) static value alloc_private( int size ) { - return alloc((size + sizeof(value) - 1) / sizeof(value), Abstract_tag); + return caml_alloc((size + sizeof(value) - 1) / sizeof(value), Abstract_tag); } // --- buffer api diff --git a/libs/extlib-leftovers/uTF8.ml b/libs/extlib-leftovers/uTF8.ml index ef61364deb0..ec25bd7aed9 100644 --- a/libs/extlib-leftovers/uTF8.ml +++ b/libs/extlib-leftovers/uTF8.ml @@ -177,7 +177,7 @@ let rec iter_aux proc s i = let iter proc s = iter_aux proc s 0 -let compare s1 s2 = Pervasives.compare s1 s2 +let compare s1 s2 = Stdlib.compare s1 s2 exception Malformed_code diff --git a/libs/ilib/peReader.ml b/libs/ilib/peReader.ml index fc79151e5b4..4d2e4aadb7a 100644 --- a/libs/ilib/peReader.ml +++ b/libs/ilib/peReader.ml @@ -25,7 +25,7 @@ open ExtList;; exception Error_message of string type reader_ctx = { - ch : Pervasives.in_channel; + ch : Stdlib.in_channel; i : IO.input; verbose : bool; } @@ -42,7 +42,7 @@ let seek r pos = seek_in r.ch pos let pos r = - Pervasives.pos_in r.ch + Stdlib.pos_in r.ch let info r msg = if r.verbose then diff --git a/libs/objsize/c_objsize.c b/libs/objsize/c_objsize.c index 5f222e0727c..4a316753177 100644 --- a/libs/objsize/c_objsize.c +++ b/libs/objsize/c_objsize.c @@ -12,6 +12,11 @@ #include "util.h" #include +#include + +#if OCAML_VERSION_MAJOR >= 5 +#include +#endif // FROM byterun/gc.h #define Caml_white (0 << 8) @@ -38,6 +43,7 @@ #define In_static_data 4 #define In_code_area 8 +#if OCAML_VERSION_MAJOR < 5 #ifdef ARCH_SIXTYFOUR // 64 bits: Represent page table as a sparse hash table @@ -63,6 +69,23 @@ CAMLextern unsigned char * caml_page_table[Pagetable1_size]; #define Is_in_heap_or_young(a) (Classify_addr(a) & (In_heap | In_young)) +void store_explicit(header_t hd, value v, int col) + { + Hd_val(v) = Coloredhd_hd(hd, col); + } + +#else + +void store_explicit(header_t hd, value v, int col) + { + atomic_store_explicit( + Hp_atomic_val(v), + Coloredhd_hd(hd, col), + memory_order_release); + } + +#endif + //-------------------------------------------------------- @@ -352,7 +375,7 @@ void c_rec_objsize(value v, size_t depth) DBG(printf("COL: w %08lx %i\n", v, col)); - Hd_val(v) = Coloredhd_hd(hd, Col_blue); + store_explicit(hd, v, Col_blue); if (Tag_val(v) < No_scan_tag) { @@ -378,7 +401,7 @@ void restore_colors(value v) col = readcolor(); DBG(printf("COL: r %08lx %i\n", v, col)); - Hd_val(v) = Coloredhd_hd(Hd_val(v), col); + store_explicit(Hd_val(v), v, col); if (Tag_val(v) < No_scan_tag) { @@ -417,7 +440,7 @@ int c_objsize(value v, value scan, value reach, size_t* headers, size_t* data, s head = Field(head,1); if( col == Col_blue ) continue; writecolor(col); - Hd_val(v) = Coloredhd_hd(hd, Col_blue); + store_explicit(hd, v, Col_blue); } acc_data = 0; @@ -444,7 +467,7 @@ int c_objsize(value v, value scan, value reach, size_t* headers, size_t* data, s head = Field(head,1); if( Colornum_hd(Hd_val(v)) != Col_blue ) continue; col = readcolor(); - Hd_val(v) = Coloredhd_hd(Hd_val(v), col); + store_explicit(Hd_val(v), v, col); } while( COND_BLOCK(reach) ) { diff --git a/libs/swflib/swfParser.ml b/libs/swflib/swfParser.ml index 2f647453261..8006c81ae52 100644 --- a/libs/swflib/swfParser.ml +++ b/libs/swflib/swfParser.ml @@ -444,7 +444,7 @@ and tag_length t = (* READ PRIMS *) let skip ch n = - seek_in ch ((Pervasives.pos_in ch) + n) + seek_in ch ((Stdlib.pos_in ch) + n) let read_rgba ch = let r = read_byte ch in diff --git a/libs/swflib/swfPic.ml b/libs/swflib/swfPic.ml index 7e69e28eb62..613260d189d 100644 --- a/libs/swflib/swfPic.ml +++ b/libs/swflib/swfPic.ml @@ -59,7 +59,7 @@ let load_picture file id = let len = String.length file in let p = (try String.rindex file '.' with Not_found -> len) in let ext = String.sub file (p + 1) (len - (p + 1)) in - match String.uppercase ext with + match ExtString.String.uppercase ext with | "PNG" -> let png , header, data = (try let p = Png.parse ch in diff --git a/libs/ttflib/tTFParser.ml b/libs/ttflib/tTFParser.ml index 68d1e26329a..9b3468ac7ee 100644 --- a/libs/ttflib/tTFParser.ml +++ b/libs/ttflib/tTFParser.ml @@ -24,7 +24,7 @@ open TTFData open IO type ctx = { - file : Pervasives.in_channel; + file : Stdlib.in_channel; ch : input; mutable entry : entry; } diff --git a/libs/ziplib/zip.ml b/libs/ziplib/zip.ml index 9245f0d00a2..0e5edc1eb52 100644 --- a/libs/ziplib/zip.ml +++ b/libs/ziplib/zip.ml @@ -62,7 +62,7 @@ type entry = type in_file = { if_filename: string; - if_channel: Pervasives.in_channel; + if_channel: Stdlib.in_channel; if_entries: entry list; if_directory: (string, entry) Hashtbl.t; if_comment: string } @@ -72,7 +72,7 @@ let comment ifile = ifile.if_comment type out_file = { of_filename: string; - of_channel: Pervasives.out_channel; + of_channel: Stdlib.out_channel; mutable of_entries: entry list; of_comment: string } @@ -217,7 +217,7 @@ let read_cd filename ic cd_entries cd_offset cd_bound = (* Open a ZIP file for reading *) let open_in filename = - let ic = Pervasives.open_in_bin filename in + let ic = Stdlib.open_in_bin filename in let (cd_entries, cd_size, cd_offset, cd_comment) = read_ecd filename ic in let entries = read_cd filename ic cd_entries cd_offset (Int32.add cd_offset cd_size) in @@ -232,7 +232,7 @@ let open_in filename = (* Close a ZIP file opened for reading *) let close_in ifile = - Pervasives.close_in ifile.if_channel + Stdlib.close_in ifile.if_channel (* Return the info associated with an entry *) @@ -369,7 +369,7 @@ let open_out ?(comment = "") filename = if String.length comment >= 0x10000 then raise(Error(filename, "", "comment too long")); { of_filename = filename; - of_channel = Pervasives.open_out_bin filename; + of_channel = Stdlib.open_out_bin filename; of_entries = []; of_comment = comment } @@ -416,7 +416,7 @@ let close_out ofile = write4_int oc start_cd; (* offset of central dir *) write2 oc (String.length ofile.of_comment); (* length of comment *) writestring oc ofile.of_comment; (* comment *) - Pervasives.close_out oc + Stdlib.close_out oc (* Write a local file header and return the corresponding entry *) @@ -552,9 +552,9 @@ let copy_file_to_entry infilename ofile ?(extra = "") ?(comment = "") with Unix.Unix_error(_,_,_) -> None in try copy_channel_to_entry ic ofile ~extra ~comment ~level ?mtime:mtime' name; - Pervasives.close_in ic + Stdlib.close_in ic with x -> - Pervasives.close_in ic; raise x + Stdlib.close_in ic; raise x (* Add an entry whose content will be produced by the caller *) diff --git a/src/codegen/dotnet.ml b/src/codegen/dotnet.ml index e90cfe95518..90bf25ec6e3 100644 --- a/src/codegen/dotnet.ml +++ b/src/codegen/dotnet.ml @@ -68,7 +68,7 @@ let cs_unops = let netname_to_hx name = let len = String.length name in let chr = String.get name 0 in - String.make 1 (Char.uppercase chr) ^ (String.sub name 1 (len-1)) + String.make 1 (Char.uppercase_ascii chr) ^ (String.sub name 1 (len-1)) (* -net-lib implementation *) @@ -105,7 +105,7 @@ let escape_chars = let netcl_to_hx cl = let cl = if String.length cl > 0 && String.get cl 0 >= 'a' && String.get cl 0 <= 'z' then - Char.escaped (Char.uppercase (String.get cl 0)) ^ (String.sub cl 1 (String.length cl - 1)) + Char.escaped (Char.uppercase_ascii (String.get cl 0)) ^ (String.sub cl 1 (String.length cl - 1)) else cl in diff --git a/src/codegen/java.ml b/src/codegen/java.ml index ba86b4eeae0..20906bbec18 100644 --- a/src/codegen/java.ml +++ b/src/codegen/java.ml @@ -46,7 +46,7 @@ let is_haxe_keyword = function let jname_to_hx name = let name = if name <> "" && (String.get name 0 < 'A' || String.get name 0 > 'Z') then - Char.escaped (Char.uppercase (String.get name 0)) ^ String.sub name 1 (String.length name - 1) + Char.escaped (Char.uppercase_ascii (String.get name 0)) ^ String.sub name 1 (String.length name - 1) else name in diff --git a/src/codegen/javaModern.ml b/src/codegen/javaModern.ml index 5908c19a061..7a298292c3c 100644 --- a/src/codegen/javaModern.ml +++ b/src/codegen/javaModern.ml @@ -555,7 +555,7 @@ module PathConverter = struct let jname_to_hx name = let name = if name <> "" && (String.get name 0 < 'A' || String.get name 0 > 'Z') then - Char.escaped (Char.uppercase (String.get name 0)) ^ String.sub name 1 (String.length name - 1) + Char.escaped (Char.uppercase_ascii (String.get name 0)) ^ String.sub name 1 (String.length name - 1) else name in diff --git a/src/codegen/swfLoader.ml b/src/codegen/swfLoader.ml index 6b7ef3b6784..6588dffde22 100644 --- a/src/codegen/swfLoader.ml +++ b/src/codegen/swfLoader.ml @@ -33,7 +33,7 @@ let lowercase_pack pack = let name = let fchar = String.get name 0 in if fchar >= 'A' && fchar <= 'Z' then - (String.make 1 (Char.lowercase fchar)) ^ String.sub name 1 (String.length name - 1) + (String.make 1 (Char.lowercase_ascii fchar)) ^ String.sub name 1 (String.length name - 1) else name in diff --git a/src/compiler/displayProcessing.ml b/src/compiler/displayProcessing.ml index 7cec1d9d788..e32f7fcacf3 100644 --- a/src/compiler/displayProcessing.ml +++ b/src/compiler/displayProcessing.ml @@ -268,7 +268,7 @@ let maybe_load_display_file_before_typing tctx display_file_dot_path = match dis let handle_display_after_typing ctx tctx display_file_dot_path = let com = ctx.com in - if ctx.com.display.dms_kind = DMNone & ctx.has_error then raise Abort; + if ctx.com.display.dms_kind = DMNone && ctx.has_error then raise Abort; begin match ctx.com.display.dms_kind,!Parser.delayed_syntax_completion with | DMDefault,Some(kind,subj) -> DisplayOutput.handle_syntax_completion com kind subj | _ -> () diff --git a/src/context/display/displayException.ml b/src/context/display/displayException.ml index a731f9a1d98..661bb1bd17b 100644 --- a/src/context/display/displayException.ml +++ b/src/context/display/displayException.ml @@ -23,9 +23,9 @@ let max_completion_items = ref 0 let filter_somehow ctx items kind subj = let subject = match subj.s_name with | None -> "" - | Some name-> String.lowercase name + | Some name-> ExtString.String.lowercase name in - let subject_length = String.length subject in + let subject_length = ExtString.String.length subject in let determine_cost s = let get_initial_cost o = if o = 0 then @@ -33,7 +33,7 @@ let filter_somehow ctx items kind subj = else begin (* Consider `.` as anchors and determine distance from closest one. Penalize starting distance by factor 2. *) try - let last_anchor = String.rindex_from s o '.' in + let last_anchor = ExtString.String.rindex_from s o '.' in (o - (last_anchor + 1)) * 2 with Not_found -> o * 2 @@ -54,12 +54,12 @@ let filter_somehow ctx items kind subj = let o',new_cost = index_from o subject.[i] in loop (i + 1) o' (cost + new_cost) end else - cost + (if o = String.length s - 1 then 0 else 1) (* Slightly penalize for not-exact matches. *) + cost + (if o = ExtString.String.length s - 1 then 0 else 1) (* Slightly penalize for not-exact matches. *) in if subject_length = 0 then 0 else try - let o = String.index s subject.[0] in + let o = ExtString.String.index s subject.[0] in loop 1 o (get_initial_cost o); with Not_found | Invalid_argument _ -> -1 @@ -67,7 +67,7 @@ let filter_somehow ctx items kind subj = let rec loop acc items index = match items with | item :: items -> - let name = String.lowercase (get_filter_name item) in + let name = ExtString.String.lowercase (get_filter_name item) in let cost = determine_cost name in let acc = if cost >= 0 then (item,index,cost) :: acc @@ -102,8 +102,8 @@ let patch_completion_subject subj = match subj.s_name with | Some name -> let delta = p.pmax - p.pmin in - let name = if delta > 0 && delta < String.length name then - String.sub name 0 delta + let name = if delta > 0 && delta < ExtString.String.length name then + ExtString.String.sub name 0 delta else name in diff --git a/src/context/display/documentSymbols.ml b/src/context/display/documentSymbols.ml index 705c8be1dee..4d61a6ae4ef 100644 --- a/src/context/display/documentSymbols.ml +++ b/src/context/display/documentSymbols.ml @@ -56,7 +56,7 @@ let collect_module_symbols mname with_locals (pack,decls) = | FFun f -> add_field ( if fst cff_name = "new" then Constructor - else if ((parent_kind = EnumAbstract or parent_kind = Abstract) && Meta.has_one_of [Meta.Op; Meta.ArrayAccess; Meta.Resolve] cff_meta) then Operator + else if ((parent_kind = EnumAbstract || parent_kind = Abstract) && Meta.has_one_of [Meta.Op; Meta.ArrayAccess; Meta.Resolve] cff_meta) then Operator else Method ); if with_locals then func field_parent f diff --git a/src/context/typecore.ml b/src/context/typecore.ml index 22ccc8a0052..fc2b33ba64e 100644 --- a/src/context/typecore.ml +++ b/src/context/typecore.ml @@ -602,7 +602,7 @@ let merge_core_doc ctx mt = let field_to_type_path com e = let rec loop e pack name = match e with - | EField(e,f,_),p when Char.lowercase (String.get f 0) <> String.get f 0 -> (match name with + | EField(e,f,_),p when Char.lowercase_ascii (String.get f 0) <> String.get f 0 -> (match name with | [] | _ :: [] -> loop e pack (f :: name) | _ -> (* too many name paths *) @@ -614,7 +614,7 @@ let field_to_type_path com e = let pack, name, sub = match name with | [] -> let fchar = String.get f 0 in - if Char.uppercase fchar = fchar then + if Char.uppercase_ascii fchar = fchar then pack, f, None else begin display_error com "A class name must start with an uppercase letter" (snd e); @@ -664,12 +664,12 @@ let s_field_call_candidate fcc = let relative_path ctx file = let slashes path = String.concat "/" (ExtString.String.nsplit path "\\") in let fpath = slashes (Path.get_full_path file) in - let fpath_lower = String.lowercase fpath in + let fpath_lower = String.lowercase_ascii fpath in let flen = String.length fpath_lower in let rec loop = function | [] -> file | path :: l -> - let spath = String.lowercase (slashes path) in + let spath = String.lowercase_ascii (slashes path) in let slen = String.length spath in if slen > 0 && slen < flen && String.sub fpath_lower 0 slen = spath then String.sub fpath slen (flen - slen) else loop l in diff --git a/src/core/path.ml b/src/core/path.ml index c5bf6d74d08..119908524b8 100644 --- a/src/core/path.ml +++ b/src/core/path.ml @@ -223,7 +223,7 @@ end = struct let create = if Globals.is_windows then - (fun f -> String.lowercase (get_full_path f)) + (fun f -> ExtString.String.lowercase (get_full_path f)) else get_full_path @@ -378,7 +378,7 @@ let full_dot_path pack mname tname = let file_extension file = match List.rev (ExtString.String.nsplit file ".") with - | e :: _ -> String.lowercase e + | e :: _ -> ExtString.String.lowercase e | [] -> "" module FilePath = struct diff --git a/src/dune b/src/dune index 6e21a11d434..f0175d63536 100644 --- a/src/dune +++ b/src/dune @@ -9,7 +9,7 @@ (library (name haxe) (libraries - extc extproc extlib_leftovers ilib javalib mbedtls neko objsize pcre2 swflib ttflib ziplib + extc extproc extlib_leftovers ilib javalib mbedtls neko objsize pcre2 camlp-streams swflib ttflib ziplib json unix str bigarray threads dynlink xml-light extlib ptmap sha diff --git a/src/generators/gencpp.ml b/src/generators/gencpp.ml index a8ff59cf29f..8156bfe837c 100644 --- a/src/generators/gencpp.ml +++ b/src/generators/gencpp.ml @@ -7030,8 +7030,8 @@ let write_build_options common_ctx filename defines = | _ -> write_define name (escape_command value)) defines; let pin,pid = Process_helper.open_process_args_in_pid "haxelib" [|"haxelib"; "path"; "hxcpp"|] in set_binary_mode_in pin false; - write_define "hxcpp" (Pervasives.input_line pin); - Pervasives.ignore (Process_helper.close_process_in_pid (pin,pid)); + write_define "hxcpp" (Stdlib.input_line pin); + Stdlib.ignore (Process_helper.close_process_in_pid (pin,pid)); writer#close;; let create_member_types common_ctx = diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index e8ffa87cdcd..12518a9ad40 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -4059,7 +4059,7 @@ let add_types ctx types = | Method MethNormal when not (List.exists (fun (m,_,_) -> m = Meta.HlNative) f.cf_meta) -> (match f.cf_expr with | Some { eexpr = TFunction { tf_expr = { eexpr = TBlock ([] | [{ eexpr = TReturn (Some { eexpr = TConst _ })}]) } } } | None -> - let name = prefix ^ String.lowercase (Str.global_replace (Str.regexp "[A-Z]+") "_\\0" f.cf_name) in + let name = prefix ^ String.lowercase_ascii (Str.global_replace (Str.regexp "[A-Z]+") "_\\0" f.cf_name) in f.cf_meta <- (Meta.HlNative, [(EConst (String(lib,SDoubleQuotes)),p);(EConst (String(name,SDoubleQuotes)),p)], p) :: f.cf_meta; | _ -> ()) | _ -> () @@ -4149,7 +4149,7 @@ let generate com = in if Path.file_extension com.file = "c" then begin - let gnames = Array.create (Array.length code.globals) "" in + let gnames = Array.make (Array.length code.globals) "" in PMap.iter (fun n i -> gnames.(i) <- n) ctx.cglobals.map; if not (Common.defined com Define.SourceHeader) then begin let version_major = com.version / 1000 in diff --git a/src/generators/genphp7.ml b/src/generators/genphp7.ml index 6d6b5394193..9109993efbd 100644 --- a/src/generators/genphp7.ml +++ b/src/generators/genphp7.ml @@ -15,8 +15,8 @@ open Sourcemaps *) let escape_bin s = let b = Buffer.create 0 in - for i = 0 to String.length s - 1 do - match Char.code (String.unsafe_get s i) with + for i = 0 to ExtString.String.length s - 1 do + match Char.code (ExtString.String.unsafe_get s i) with | c when c = Char.code('\\') || c = Char.code('"') || c = Char.code('$') -> Buffer.add_string b "\\"; Buffer.add_char b (Char.chr c) @@ -46,7 +46,7 @@ let write_resource dir name data = *) let copy_file src dst = let buffer_size = 8192 in - let buffer = String.create buffer_size in + let buffer = ExtString.String.create buffer_size in let fd_in = Unix.openfile src [O_RDONLY] 0 in let fd_out = Unix.openfile dst [O_WRONLY; O_CREAT; O_TRUNC] 0o644 in let rec copy_loop () = @@ -196,7 +196,7 @@ end (** Check if specified string is a reserved word in PHP *) -let is_keyword str = Hashtbl.mem php_keywords_tbl (String.lowercase str) +let is_keyword str = Hashtbl.mem php_keywords_tbl (ExtString.String.lowercase str) (** Check if specified type is php.NativeArray @@ -531,10 +531,10 @@ let get_full_type_name ?(escape=false) ?(omit_first_slash=false) (type_path:path else "" :: get_real_path module_path in - (String.concat "\\" parts) ^ "\\" ^ type_name + (ExtString.String.concat "\\" parts) ^ "\\" ^ type_name in if escape then - String.escaped name + ExtString.String.escaped name else name @@ -618,7 +618,7 @@ let fix_call_args callee_type exprs = Escapes all "$" chars and encloses `str` into double quotes *) let quote_string str = - "\"" ^ (Str.global_replace (Str.regexp "\\$") "\\$" (String.escaped str)) ^ "\"" + "\"" ^ (Str.global_replace (Str.regexp "\\$") "\\$" (ExtString.String.escaped str)) ^ "\"" (** Check if specified field is a var with non-constant expression @@ -1296,21 +1296,21 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name = Decrease indentation by one level *) method indent_less = - indentation <- String.make ((String.length indentation) - 1) '\t'; + indentation <- ExtString.String.make ((ExtString.String.length indentation) - 1) '\t'; (** Set indentation level (starting from zero for no indentation) *) method indent level = - indentation <- String.make level '\t'; + indentation <- ExtString.String.make level '\t'; (** Get indentation level (starting from zero for no indentation) *) - method get_indentation = String.length indentation + method get_indentation = ExtString.String.length indentation (** Set indentation level (starting from zero for no indentation) *) method set_indentation level = - indentation <- String.make level '\t' + indentation <- ExtString.String.make level '\t' (** Specify local var name declared in current scope *) @@ -1326,7 +1326,7 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name = else if get_type_name type_path = "" then match get_module_path type_path with | [] -> "\\" - | module_path -> "\\" ^ (String.concat "\\" (get_real_path module_path)) ^ "\\" + | module_path -> "\\" ^ (ExtString.String.concat "\\" (get_real_path module_path)) ^ "\\" else begin let orig_type_path = type_path in let type_path = match type_path with (pack, name) -> (pack, get_real_name name) in @@ -1942,7 +1942,7 @@ class code_writer (ctx:php_generator_context) hx_type_path php_name = set_sourcemap_pointer sourcemap sm_pointer_before_body; let locals = vars#pop_captured in if List.length locals > 0 then begin - self#write ("unset($" ^ (String.concat ", $" locals) ^ ");\n"); + self#write ("unset($" ^ (ExtString.String.concat ", $" locals) ^ ");\n"); self#write_indentation end; self#write_bypassing_sourcemap body; @@ -2999,7 +2999,7 @@ class virtual type_builder ctx (wrapper:type_wrapper) = Returns generated file contents *) method get_contents = - if (String.length contents) = 0 then begin + if (ExtString.String.length contents) = 0 then begin self#write_declaration; writer#write_line " {"; (** opening bracket for a class *) self#write_body; @@ -3016,7 +3016,7 @@ class virtual type_builder ctx (wrapper:type_wrapper) = writer#write_statement ("require_once __DIR__.'/" ^ polyfills_file ^ "'"); writer#write_statement (boot_class ^ "::__hx__init()") end; - let haxe_class = match wrapper#get_type_path with (path, name) -> String.concat "." (path @ [name]) in + let haxe_class = match wrapper#get_type_path with (path, name) -> ExtString.String.concat "." (path @ [name]) in writer#write_statement (boot_class ^ "::registerClass(" ^ (self#get_name) ^ "::class, '" ^ haxe_class ^ "')"); self#write_rtti_meta; self#write_pre_hx_init; @@ -3051,7 +3051,7 @@ class virtual type_builder ctx (wrapper:type_wrapper) = writer#write "\n"; let namespace = self#get_namespace in if List.length namespace > 0 then - writer#write_line ("namespace " ^ (String.concat "\\" namespace) ^ ";\n"); + writer#write_line ("namespace " ^ (ExtString.String.concat "\\" namespace) ^ ";\n"); writer#write_use (** Generates PHP docblock and attributes to output buffer. @@ -3082,11 +3082,11 @@ class virtual type_builder ctx (wrapper:type_wrapper) = Writes description section of docblocks *) method write_doc_description (doc:string) = - let lines = Str.split (Str.regexp "\n") (String.trim doc) + let lines = Str.split (Str.regexp "\n") (ExtString.String.trim doc) and write_line line = - let trimmed = String.trim line in - if String.length trimmed > 0 then ( - if String.get trimmed 0 = '*' then + let trimmed = ExtString.String.trim line in + if ExtString.String.length trimmed > 0 then ( + if ExtString.String.get trimmed 0 = '*' then writer#write_line (" " ^ trimmed) else writer#write_line (" * " ^ trimmed) @@ -3554,7 +3554,7 @@ class class_builder ctx (cls:tclass) = cls.cl_implements in let interfaces = List.map use_interface unique in - writer#write (String.concat ", " interfaces); + writer#write (ExtString.String.concat ", " interfaces); end; (** Returns either user-defined constructor or creates empty constructor if instance initialization is required. @@ -3667,7 +3667,7 @@ class class_builder ctx (cls:tclass) = List.iter (fun field -> if not !required then - required := (String.lowercase field.cf_name = String.lowercase self#get_name) + required := (ExtString.String.lowercase field.cf_name = ExtString.String.lowercase self#get_name) ) (cls.cl_ordered_statics @ cls.cl_ordered_fields); !required @@ -3676,10 +3676,10 @@ class class_builder ctx (cls:tclass) = Writes `-D php-prefix` value as class constant PHP_PREFIX *) method private write_php_prefix () = - let prefix = String.concat "\\" ctx.pgc_prefix in + let prefix = ExtString.String.concat "\\" ctx.pgc_prefix in let indentation = writer#get_indentation in writer#indent 1; - writer#write_statement ("const PHP_PREFIX = \"" ^ (String.escaped prefix) ^ "\""); + writer#write_statement ("const PHP_PREFIX = \"" ^ (ExtString.String.escaped prefix) ^ "\""); writer#indent indentation (** Writes expressions for `__hx__init` method @@ -3998,8 +3998,8 @@ class generator (ctx:php_generator_context) = if front_dirs <> [] then ignore(create_dir_recursive (root_dir :: front_dirs)); let lib_path = - (String.concat "" (List.fold_left (fun acc s -> if s <> "." then "../" :: acc else acc) [] front_dirs)) - ^ (String.concat "/" self#get_lib_path) + (ExtString.String.concat "" (List.fold_left (fun acc s -> if s <> "." then "../" :: acc else acc) [] front_dirs)) + ^ (ExtString.String.concat "/" self#get_lib_path) in let channel = open_out (root_dir ^ "/" ^ filename) in output_string channel " Array.set cases tag (pos - switch_pos)) !constructs; DynArray.set ctx.code switch_index (HSwitch (1,Array.to_list cases)); branch(); diff --git a/src/generators/hl2c.ml b/src/generators/hl2c.ml index af03a261786..2304debb005 100644 --- a/src/generators/hl2c.ml +++ b/src/generators/hl2c.ml @@ -1134,7 +1134,7 @@ let make_types_idents htypes = try PMap.find vp (!types_descs) with Not_found -> - let arr = Array.create (Array.length vp.vfields) ("",DSimple HVoid) in + let arr = Array.make (Array.length vp.vfields) ("",DSimple HVoid) in let td = DVirtual arr in types_descs := PMap.add vp td (!types_descs); Array.iteri (fun i (f,_,t) -> arr.(i) <- (f,make_desc t)) vp.vfields; diff --git a/src/generators/hlinterp.ml b/src/generators/hlinterp.ml index f6fc7f32fd0..2b5bc247a3c 100644 --- a/src/generators/hlinterp.ml +++ b/src/generators/hlinterp.ml @@ -1111,7 +1111,7 @@ let interp ctx f args = (match rtype r with | HEnum e -> let _, _, fl = e.efields.(f) in - let vl = Array.create (Array.length fl) VUndef in + let vl = Array.make (Array.length fl) VUndef in set r (VEnum (e, f, vl)) | _ -> Globals.die "" __LOC__ ) @@ -1257,7 +1257,7 @@ let load_native ctx lib name t = | _ -> Globals.die "" __LOC__) | "alloc_array" -> (function - | [VType t;VInt i] -> VArray (Array.create (int i) (default t),t) + | [VType t;VInt i] -> VArray (Array.make (int i) (default t),t) | _ -> Globals.die "" __LOC__) | "alloc_obj" -> (function @@ -1347,7 +1347,7 @@ let load_native ctx lib name t = | "math_asin" -> (function [VFloat f] -> VFloat (asin f) | _ -> Globals.die "" __LOC__) | "math_atan" -> (function [VFloat f] -> VFloat (atan f) | _ -> Globals.die "" __LOC__) | "math_atan2" -> (function [VFloat a; VFloat b] -> VFloat (atan2 a b) | _ -> Globals.die "" __LOC__) - | "math_log" -> (function [VFloat f] -> VFloat (Pervasives.log f) | _ -> Globals.die "" __LOC__) + | "math_log" -> (function [VFloat f] -> VFloat (Stdlib.log f) | _ -> Globals.die "" __LOC__) | "math_exp" -> (function [VFloat f] -> VFloat (exp f) | _ -> Globals.die "" __LOC__) | "math_pow" -> (function [VFloat a; VFloat b] -> VFloat (a ** b) | _ -> Globals.die "" __LOC__) | "parse_int" -> @@ -1539,7 +1539,7 @@ let load_native ctx lib name t = | "Darwin" -> "Mac" | n -> n ) in - Pervasives.ignore (Process_helper.close_process_in_pid (ic, pid)); + Stdlib.ignore (Process_helper.close_process_in_pid (ic, pid)); cached_sys_name := Some uname; uname) | "Win32" | "Cygwin" -> "Windows" @@ -2147,7 +2147,7 @@ let add_code ctx code = ctx.t_globals <- globals; (* expand function table *) let nfunctions = Array.length code.functions + Array.length code.natives in - let functions = Array.create nfunctions (FNativeFun ("",(fun _ -> Globals.die "" __LOC__),HDyn)) in + let functions = Array.make nfunctions (FNativeFun ("",(fun _ -> Globals.die "" __LOC__),HDyn)) in Array.blit ctx.t_functions 0 functions 0 (Array.length ctx.t_functions); let rec loop i = if i = Array.length code.natives then () else @@ -2191,7 +2191,7 @@ let add_code ctx code = (* ------------------------------- CHECK ---------------------------------------------- *) let check code macros = - let ftypes = Array.create (Array.length code.natives + Array.length code.functions) HVoid in + let ftypes = Array.make (Array.length code.natives + Array.length code.functions) HVoid in let is_native_fun = Hashtbl.create 0 in let check_fun f = diff --git a/src/macro/eval/evalJit.ml b/src/macro/eval/evalJit.ml index 6218f394f59..d2b5f3c1525 100644 --- a/src/macro/eval/evalJit.ml +++ b/src/macro/eval/evalJit.ml @@ -230,7 +230,7 @@ and jit_expr jit return e = let hasret = jit_closure.has_nonfinal_return in let eci = get_env_creation jit_closure false tf.tf_expr.epos.pfile (EKLocalFunction jit.num_closures) in let captures = Hashtbl.fold (fun vid (i,declared) acc -> (i,vid,declared) :: acc) jit_closure.captures [] in - let captures = List.sort (fun (i1,_,_) (i2,_,_) -> Pervasives.compare i1 i2) captures in + let captures = List.sort (fun (i1,_,_) (i2,_,_) -> Stdlib.compare i1 i2) captures in (* Check if the out-of-scope var is in the outer scope because otherwise we have to promote outwards. *) List.iter (fun var -> ignore(get_capture_slot jit var)) jit_closure.captures_outside_scope; let captures = ExtList.List.filter_map (fun (i,vid,declared) -> diff --git a/src/macro/eval/evalStdLib.ml b/src/macro/eval/evalStdLib.ml index 501387567c4..935733b530f 100644 --- a/src/macro/eval/evalStdLib.ml +++ b/src/macro/eval/evalStdLib.ml @@ -289,7 +289,7 @@ module StdBytes = struct let compare = vifun1 (fun vthis other -> let this = this vthis in let other = decode_bytes other in - vint (Pervasives.compare this other) + vint (Stdlib.compare this other) ) let fastGet = vfun2 (fun b pos -> @@ -1694,13 +1694,13 @@ module StdMath = struct let ceil = vfun1 (fun v -> match v with VInt32 _ -> v | _ -> vint32 (to_int (ceil (num v)))) let cos = vfun1 (fun v -> vfloat (cos (num v))) let exp = vfun1 (fun v -> vfloat (exp (num v))) - let fceil = vfun1 (fun v -> vfloat (Pervasives.ceil (num v))) - let ffloor = vfun1 (fun v -> vfloat (Pervasives.floor (num v))) + let fceil = vfun1 (fun v -> vfloat (Stdlib.ceil (num v))) + let ffloor = vfun1 (fun v -> vfloat (Stdlib.floor (num v))) let floor = vfun1 (fun v -> match v with VInt32 _ -> v | _ -> vint32 (to_int (floor (num v)))) - let fround = vfun1 (fun v -> vfloat (Pervasives.floor (num v +. 0.5))) + let fround = vfun1 (fun v -> vfloat (Stdlib.floor (num v +. 0.5))) let isFinite = vfun1 (fun v -> vbool (match v with VFloat f -> f <> infinity && f <> neg_infinity && f = f | _ -> true)) let isNaN = vfun1 (fun v -> vbool (match v with VFloat f -> f <> f | VInt32 _ -> false | _ -> true)) - let log = vfun1 (fun v -> vfloat (Pervasives.log (num v))) + let log = vfun1 (fun v -> vfloat (Stdlib.log (num v))) let max = vfun2 (fun a b -> let a = num a in @@ -1716,7 +1716,7 @@ module StdMath = struct let pow = vfun2 (fun a b -> vfloat ((num a) ** (num b))) let random = vfun0 (fun () -> vfloat (Random.State.float random 1.)) - let round = vfun1 (fun v -> match v with VInt32 _ -> v | _ -> vint32 (to_int (Pervasives.floor (num v +. 0.5)))) + let round = vfun1 (fun v -> match v with VInt32 _ -> v | _ -> vint32 (to_int (Stdlib.floor (num v +. 0.5)))) let sin = vfun1 (fun v -> vfloat (sin (num v))) let sqrt = vfun1 (fun v -> @@ -2690,7 +2690,7 @@ module StdSys = struct | "Darwin" -> "Mac" | n -> n ) in - Pervasives.ignore (Process_helper.close_process_in_pid (ic, pid)); + Stdlib.ignore (Process_helper.close_process_in_pid (ic, pid)); cached_sys_name := Some uname; uname) | "Win32" | "Cygwin" -> "Windows" @@ -2735,10 +2735,12 @@ module StdThread = struct vnull ) - let kill = vifun0 (fun vthis -> - Thread.kill (this vthis).tthread; - vnull - ) + (* Thread.kill has been marked deprecated (because unstable or even not working at all) for a while, and removed in ocaml 5 *) + (* See also https://github.com/HaxeFoundation/haxe/issues/5800 *) + (* let kill = vifun0 (fun vthis -> *) + (* Thread.kill (this vthis).tthread; *) + (* vnull *) + (* ) *) let self = vfun0 (fun () -> let eval = get_eval (get_ctx()) in @@ -3064,7 +3066,7 @@ module StdUtf8 = struct let compare = vfun2 (fun a b -> let a = decode_string a in let b = decode_string b in - vint (Pervasives.compare a b) + vint (Stdlib.compare a b) ) let decode = vfun1 (fun s -> @@ -3730,7 +3732,7 @@ let init_standard_library builtins = "id",StdThread.id; "get_events",StdThread.get_events; "set_events",StdThread.set_events; - "kill",StdThread.kill; + (* "kill",StdThread.kill; *) "sendMessage",StdThread.sendMessage; ]; init_fields builtins (["sys";"thread"],"Tls") [] [ diff --git a/src/optimization/inlineConstructors.ml b/src/optimization/inlineConstructors.ml index 8df1b5d7916..de9b666cf65 100644 --- a/src/optimization/inlineConstructors.ml +++ b/src/optimization/inlineConstructors.ml @@ -499,7 +499,7 @@ let inline_constructors ctx original_e = | IOFInlineMethod(io,io_var,c,tl,cf,tf) -> let argvs, pl = analyze_call_args call_args in io.io_dependent_vars <- io.io_dependent_vars @ argvs; - io.io_has_untyped <- io.io_has_untyped or (Meta.has Meta.HasUntyped cf.cf_meta); + io.io_has_untyped <- io.io_has_untyped || (Meta.has Meta.HasUntyped cf.cf_meta); begin match Inline.type_inline ctx cf tf (mk (TLocal io_var.iv_var) (TInst (c,tl)) e.epos) pl e.etype None e.epos true with | Some e -> let e = mark_ctors e in @@ -727,4 +727,4 @@ let inline_constructors ctx original_e = end ) !vars; e - end \ No newline at end of file + end diff --git a/src/typing/matcher.ml b/src/typing/matcher.ml index 72f2a5e3a2e..6ca7e9a3535 100644 --- a/src/typing/matcher.ml +++ b/src/typing/matcher.ml @@ -1461,7 +1461,7 @@ module TexprConverter = struct in let s = match unmatched with | [] -> "_" - | _ -> String.concat " | " (List.sort Pervasives.compare sl) + | _ -> String.concat " | " (List.sort Stdlib.compare sl) in typing_error (Printf.sprintf "Unmatched patterns: %s" (s_subject v_lookup s e_subject)) e_subject.epos diff --git a/src/typing/typeloadCheck.ml b/src/typing/typeloadCheck.ml index 616be2ec177..6e649860f86 100644 --- a/src/typing/typeloadCheck.ml +++ b/src/typing/typeloadCheck.ml @@ -318,7 +318,7 @@ let check_module_types ctx m p t = let t = t_infos t in try let path2 = ctx.com.type_to_module#find t.mt_path in - if m.m_path <> path2 && String.lowercase (s_type_path path2) = String.lowercase (s_type_path m.m_path) then typing_error ("Module " ^ s_type_path path2 ^ " is loaded with a different case than " ^ s_type_path m.m_path) p; + if m.m_path <> path2 && String.lowercase_ascii (s_type_path path2) = String.lowercase_ascii (s_type_path m.m_path) then typing_error ("Module " ^ s_type_path path2 ^ " is loaded with a different case than " ^ s_type_path m.m_path) p; let m2 = ctx.com.module_lut#find path2 in let hex1 = Digest.to_hex m.m_extra.m_sign in let hex2 = Digest.to_hex m2.m_extra.m_sign in diff --git a/src/typing/typeloadParse.ml b/src/typing/typeloadParse.ml index fcc19238160..066443ada4e 100644 --- a/src/typing/typeloadParse.ml +++ b/src/typing/typeloadParse.ml @@ -102,7 +102,7 @@ let resolve_module_file com m remap p = with Not_found -> Common.find_file com (compose_path true) in - let file = (match String.lowercase (snd m) with + let file = (match ExtString.String.lowercase (snd m) with | "con" | "aux" | "prn" | "nul" | "com1" | "com2" | "com3" | "lpt1" | "lpt2" | "lpt3" when Sys.os_type = "Win32" -> (* these names are reserved by the OS - old DOS legacy, such files cannot be easily created but are reported as visible *) if (try (Unix.stat file).Unix.st_size with _ -> 0) > 0 then file else raise Not_found From e4a40712a32b6ead68045981a1be14aa7d482059 Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:47:38 +0200 Subject: [PATCH 02/26] Make genhl respect Meta.NoExpr. (#11257) Closes https://github.com/HaxeFoundation/haxe/issues/11196 --- src/generators/genhl.ml | 9 +++++++-- tests/misc/hl/projects/Issue11196/Issue11196.hx | 3 +++ tests/misc/hl/projects/Issue11196/compile.hxml | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/misc/hl/projects/Issue11196/Issue11196.hx create mode 100644 tests/misc/hl/projects/Issue11196/compile.hxml diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index 12518a9ad40..95a082dec67 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -3330,7 +3330,10 @@ let generate_static ctx c f = let gen_content() = op ctx (OThrow (make_string ctx ("Requires compiling with -D hl-ver=" ^ ver ^ ".0 or higher") null_pos)); in - ignore(make_fun ctx ~gen_content (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) (match f.cf_expr with Some { eexpr = TFunction f } -> f | _ -> abort "Missing function body" f.cf_pos) None None) + (match f.cf_expr with + | Some { eexpr = TFunction fn } -> ignore(make_fun ctx ~gen_content (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) fn None None) + | _ -> if not (Meta.has Meta.NoExpr f.cf_meta) then abort "Missing function body" f.cf_pos) + else add_native "std" f.cf_name | (Meta.HlNative,[] ,_ ) :: _ -> @@ -3338,7 +3341,9 @@ let generate_static ctx c f = | (Meta.HlNative,_ ,p) :: _ -> abort "Invalid @:hlNative decl" p | [] -> - ignore(make_fun ctx (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) (match f.cf_expr with Some { eexpr = TFunction f } -> f | _ -> abort "Missing function body" f.cf_pos) None None) + (match f.cf_expr with + | Some { eexpr = TFunction fn } -> ignore(make_fun ctx (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) fn None None) + | _ -> if not (Meta.has Meta.NoExpr f.cf_meta) then abort "Missing function body" f.cf_pos) | _ :: l -> loop l in diff --git a/tests/misc/hl/projects/Issue11196/Issue11196.hx b/tests/misc/hl/projects/Issue11196/Issue11196.hx new file mode 100644 index 00000000000..9126da39de6 --- /dev/null +++ b/tests/misc/hl/projects/Issue11196/Issue11196.hx @@ -0,0 +1,3 @@ +function main() { + var a:hl.I64 = 5; +} \ No newline at end of file diff --git a/tests/misc/hl/projects/Issue11196/compile.hxml b/tests/misc/hl/projects/Issue11196/compile.hxml new file mode 100644 index 00000000000..49a5d4098e6 --- /dev/null +++ b/tests/misc/hl/projects/Issue11196/compile.hxml @@ -0,0 +1,3 @@ +-m Issue11196 +-hl out.hl +-dce no \ No newline at end of file From 49bb2da5dd15d7dfcc1930d709290306fa75a50e Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Mon, 25 Sep 2023 17:03:30 +0200 Subject: [PATCH 03/26] [hl] don't add bindings for non existing methods --- src/generators/genhl.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index 95a082dec67..3754ab1d7bb 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -653,8 +653,8 @@ and class_type ?(tref=None) ctx c pl statics = ) in Some fid ) in - match f.cf_kind, fid with - | Method _, Some fid -> p.pbindings <- (fid, alloc_fun_path ctx c.cl_path f.cf_name) :: p.pbindings + match f.cf_kind, f.cf_expr, fid with + | Method _, Some _, Some fid -> p.pbindings <- (fid, alloc_fun_path ctx c.cl_path f.cf_name) :: p.pbindings | _ -> () ) (if statics then c.cl_ordered_statics else c.cl_ordered_fields); if not statics then begin @@ -3333,7 +3333,7 @@ let generate_static ctx c f = (match f.cf_expr with | Some { eexpr = TFunction fn } -> ignore(make_fun ctx ~gen_content (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) fn None None) | _ -> if not (Meta.has Meta.NoExpr f.cf_meta) then abort "Missing function body" f.cf_pos) - + else add_native "std" f.cf_name | (Meta.HlNative,[] ,_ ) :: _ -> From 643086ac430e4260ed5ab7f017932d0b0f061dd2 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 7 Sep 2023 09:18:08 +0200 Subject: [PATCH 04/26] Forward metadata for static local vars Allow things like @:persistent to work with static locals --- src/filters/filters.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/filters/filters.ml b/src/filters/filters.ml index 03ee1c351c4..d0af8ec9475 100644 --- a/src/filters/filters.ml +++ b/src/filters/filters.ml @@ -75,6 +75,7 @@ module LocalStatic = struct typing_error ~depth:1 "Conflicting field was found here" cf.cf_name_pos; with Not_found -> let cf = mk_field name ~static:true v.v_type v.v_pos v.v_pos in + cf.cf_meta <- v.v_meta; begin match eo with | None -> () From f00c71ad0880db07ca7eff5383774b27ad5f1a1d Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 8 Sep 2023 07:44:39 +0200 Subject: [PATCH 05/26] [server] Better error messages for --connect --- src/compiler/server.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/server.ml b/src/compiler/server.ml index ec815960c33..344640af061 100644 --- a/src/compiler/server.ml +++ b/src/compiler/server.ml @@ -898,7 +898,11 @@ let init_wait_stdio() = (* The connect function to connect to [host] at [port] and send arguments [args]. *) let do_connect host port args = let sock = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in - (try Unix.connect sock (Unix.ADDR_INET (Unix.inet_addr_of_string host,port)) with _ -> failwith ("Couldn't connect on " ^ host ^ ":" ^ string_of_int port)); + (try Unix.connect sock (Unix.ADDR_INET (Unix.inet_addr_of_string host,port)) with + | Unix.Unix_error(code,_,_) -> failwith + ("Couldn't connect on " ^ host ^ ":" ^ string_of_int port ^ " (" ^ (Unix.error_message code) ^ ")"); + | _ -> failwith ("Couldn't connect on " ^ host ^ ":" ^ string_of_int port) + ); let rec display_stdin args = match args with | [] -> "" From d6d0cdc5b3c9a1708fb69e8adf3792ae26bbd4bf Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 8 Sep 2023 14:50:23 +0200 Subject: [PATCH 06/26] [macro] Printer: do not break for TDAbstract without flags --- std/haxe/macro/Printer.hx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/std/haxe/macro/Printer.hx b/std/haxe/macro/Printer.hx index 075f7400354..66bb3268f6e 100644 --- a/std/haxe/macro/Printer.hx +++ b/std/haxe/macro/Printer.hx @@ -387,11 +387,13 @@ class Printer { var to = to == null ? [] : to.copy(); var isEnum = false; - for (flag in tflags) { - switch (flag) { - case AbEnum: isEnum = true; - case AbFrom(ct): from.push(ct); - case AbTo(ct): to.push(ct); + if (tflags != null) { + for (flag in tflags) { + switch (flag) { + case AbEnum: isEnum = true; + case AbFrom(ct): from.push(ct); + case AbTo(ct): to.push(ct); + } } } From f6281c2da042d1b59b0801953a8e4ead2d51d12c Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 8 Aug 2023 07:10:30 +0200 Subject: [PATCH 07/26] [compiler] improve error message when hl_version is missing closes #11086 --- src/compiler/compiler.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/compiler.ml b/src/compiler/compiler.ml index ee34bdd2708..02977cd3f5f 100644 --- a/src/compiler/compiler.ml +++ b/src/compiler/compiler.ml @@ -138,7 +138,14 @@ module Setup = struct "python" | Hl -> add_std "hl"; - if not (Common.defined com Define.HlVer) then Define.define_value com.defines Define.HlVer (try Std.input_file (Common.find_file com "hl/hl_version") with Not_found -> die "" __LOC__); + if not (Common.defined com Define.HlVer) then begin + let hl_ver = try + Std.input_file (Common.find_file com "hl/hl_version") + with Not_found -> + failwith "The file hl_version could not be found. Please make sure HAXE_STD_PATH is set to the standard library corresponding to the used compiler version." + in + Define.define_value com.defines Define.HlVer hl_ver + end; "hl" | Eval -> add_std "eval"; From 98b21e4537fbbf6a450e5a87372b209d822bf771 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 28 Sep 2023 15:44:57 +0200 Subject: [PATCH 08/26] [eval,hl] fix catching value exceptions Closes #11321 --- src/filters/exceptions.ml | 2 +- tests/unit/src/unit/TestExceptions.hx | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/filters/exceptions.ml b/src/filters/exceptions.ml index c3318b4c347..609e108f3a7 100644 --- a/src/filters/exceptions.ml +++ b/src/filters/exceptions.ml @@ -486,7 +486,7 @@ let catch_native ctx catches t p = | [], None -> catches_to_ifs ctx catches t p | [], Some catch -> - catches_to_ifs ctx [catch] t p + catches_to_ifs ctx (catch :: catches) t p | _ -> catches_as_value_exception ctx handle_as_value_exception None t p :: catches_to_ifs ctx catches t p diff --git a/tests/unit/src/unit/TestExceptions.hx b/tests/unit/src/unit/TestExceptions.hx index 6fb5580af80..0d00ca01558 100644 --- a/tests/unit/src/unit/TestExceptions.hx +++ b/tests/unit/src/unit/TestExceptions.hx @@ -162,6 +162,14 @@ class TestExceptions extends Test { } catch(e:String) { eq('string', e); } + + try { + throw new CustomHaxeException('Terrible error'); + } catch(e:haxe.ValueException) { + throw 'should not happen'; + } catch(e) { + Assert.pass(); + } } public function testCustomNativeException() { From b14f8c8dfeaa41be3df779e26c22a6f2cd7fe097 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Mon, 25 Sep 2023 07:50:16 +0200 Subject: [PATCH 09/26] [eval] fix Array.resize retaining values closes #11317 --- src/macro/eval/evalArray.ml | 4 ++-- tests/unit/src/unit/issues/Issue11317.hx | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/unit/src/unit/issues/Issue11317.hx diff --git a/src/macro/eval/evalArray.ml b/src/macro/eval/evalArray.ml index 1790f115dbc..0c73e80941e 100644 --- a/src/macro/eval/evalArray.ml +++ b/src/macro/eval/evalArray.ml @@ -201,6 +201,6 @@ let resize a l = set a (l - 1) vnull; () end else if a.alength > l then begin - ignore(splice a l (a.alength - l) a.alength); - () + Array.fill a.avalues l (a.alength - l) vnull; + a.alength <- l; end else () diff --git a/tests/unit/src/unit/issues/Issue11317.hx b/tests/unit/src/unit/issues/Issue11317.hx new file mode 100644 index 00000000000..73b6974fa09 --- /dev/null +++ b/tests/unit/src/unit/issues/Issue11317.hx @@ -0,0 +1,10 @@ +package unit.issues; + +class Issue11317 extends Test { + function test() { + var array:Array = ["0", "1", "2", "3", "4"]; + array.resize(0); + array.resize(5); + utest.Assert.same([null, null, null, null, null], array); + } +} From fd8412b7a0d0200e46ad4e199c581c938f19ead4 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 15 Sep 2023 10:19:28 +0200 Subject: [PATCH 10/26] [hlc] add bool to reserved keywords Closes #11293 --- src/generators/hl2c.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/hl2c.ml b/src/generators/hl2c.ml index 2304debb005..9921fac1117 100644 --- a/src/generators/hl2c.ml +++ b/src/generators/hl2c.ml @@ -85,7 +85,7 @@ let sprintf = Printf.sprintf let keywords = let c_kwds = [ - "auto";"break";"case";"char";"const";"continue";"default";"do";"double";"else";"enum";"extern";"float";"for";"goto"; + "auto";"bool";"break";"case";"char";"const";"continue";"default";"do";"double";"else";"enum";"extern";"float";"for";"goto"; "if";"int";"long";"register";"return";"short";"signed";"sizeof";"static";"struct";"switch";"typedef";"union";"unsigned"; "void";"volatile";"while"; (* Values *) From c8113b8ee8856d29bab389e3933023ce8edabf53 Mon Sep 17 00:00:00 2001 From: Simon Morris <99881147+simon-peek-poke@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:50:19 +0100 Subject: [PATCH 11/26] DOMElement insertAdjacentElement should not be pure. (#11333) --- std/js/html/DOMElement.hx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/std/js/html/DOMElement.hx b/std/js/html/DOMElement.hx index fee60e98271..844b4519be0 100644 --- a/std/js/html/DOMElement.hx +++ b/std/js/html/DOMElement.hx @@ -391,7 +391,6 @@ extern class DOMElement extends Node { Inserts a given element node at a given position relative to the element it is invoked upon. @throws DOMError **/ - @:pure function insertAdjacentElement( where : String, element : Element ) : Element; /** @@ -550,4 +549,4 @@ extern class DOMElement extends Node { /** @throws DOMError */ @:overload( function( nodes : haxe.extern.Rest) : Void {} ) function append( nodes : haxe.extern.Rest ) : Void; -} \ No newline at end of file +} From d52937e53766c1213aa64a3749f60332eec90ae8 Mon Sep 17 00:00:00 2001 From: RblSb Date: Wed, 18 Oct 2023 22:22:04 +0300 Subject: [PATCH 12/26] Improve extra field error range (#11335) * Improve extra field error range * update range * fail --- src/typing/typer.ml | 9 +++++++-- tests/misc/projects/Issue11334/Main.hx | 19 +++++++++++++++++++ .../projects/Issue11334/compile-fail.hxml | 1 + .../Issue11334/compile-fail.hxml.stderr | 2 ++ .../Issue3192/compile1-fail.hxml.stderr | 2 +- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/misc/projects/Issue11334/Main.hx create mode 100644 tests/misc/projects/Issue11334/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11334/compile-fail.hxml.stderr diff --git a/src/typing/typer.ml b/src/typing/typer.ml index 63a1f1b4c8d..70263b008a6 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -904,7 +904,7 @@ and type_object_decl ctx fl with_type p = (try type_eq EqStrict e.etype t; e with Unify_error _ -> mk (TCast (e,None)) t e.epos) with Not_found -> if is_valid then - extra_fields := n :: !extra_fields; + extra_fields := (n,pn) :: !extra_fields; type_expr ctx e WithType.value in if is_valid then begin @@ -923,7 +923,12 @@ and type_object_decl ctx fl with_type p = | depth -> raise_or_display ctx [Unify_custom ("Object requires fields: " ^ (String.concat ", " depth))] p); (match !extra_fields with | [] -> () - | _ -> raise_or_display ctx (List.map (fun n -> has_extra_field t n) !extra_fields) p); + | _ -> + List.iter (fun (n,pn) -> + let err = has_extra_field t n in + raise_or_display ctx [err] pn + ) !extra_fields + ); end; t, fl in diff --git a/tests/misc/projects/Issue11334/Main.hx b/tests/misc/projects/Issue11334/Main.hx new file mode 100644 index 00000000000..f7aeba8d81d --- /dev/null +++ b/tests/misc/projects/Issue11334/Main.hx @@ -0,0 +1,19 @@ +class Main { + static function main() { + final foo:Foo = { + a: () -> { + trace(123); + }, + b: () -> { + trace(123); + }, + c: 123, + d: 123, + } + } +} + +typedef Foo = { + a:() -> Void, + c:Int, +} diff --git a/tests/misc/projects/Issue11334/compile-fail.hxml b/tests/misc/projects/Issue11334/compile-fail.hxml new file mode 100644 index 00000000000..fab0aeecc3d --- /dev/null +++ b/tests/misc/projects/Issue11334/compile-fail.hxml @@ -0,0 +1 @@ +--main Main \ No newline at end of file diff --git a/tests/misc/projects/Issue11334/compile-fail.hxml.stderr b/tests/misc/projects/Issue11334/compile-fail.hxml.stderr new file mode 100644 index 00000000000..fabbffbf963 --- /dev/null +++ b/tests/misc/projects/Issue11334/compile-fail.hxml.stderr @@ -0,0 +1,2 @@ +Main.hx:11: characters 4-5 : { d : Int, c : Int, b : () -> Void, a : () -> Void } has extra field d +Main.hx:7: characters 4-5 : { d : Int, c : Int, b : () -> Void, a : () -> Void } has extra field b diff --git a/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr b/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr index 722e2d25f74..d6978e36903 100644 --- a/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr +++ b/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr @@ -1 +1 @@ -Main1.hx:3: characters 19-33 : { b : Int, a : Int } has extra field b \ No newline at end of file +Main1.hx:3: characters 27-28 : { b : Int, a : Int } has extra field b From 7b5041f820c011305d8b416789556ec14b2978fd Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Sun, 5 Nov 2023 13:32:27 +0100 Subject: [PATCH 13/26] Fix macOS CI (#11359) Update mbedtls to 2.28.5 --- .github/workflows/main.yml | 2 +- extra/github-actions/build-mac.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f9378961b1e..71c8b10b990 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -616,7 +616,7 @@ jobs: env: # For compatibility with macOS 10.13 ZLIB_VERSION: 1.3 - MBEDTLS_VERSION: 2.25.0 + MBEDTLS_VERSION: 2.28.5 PCRE2_VERSION: 10.42 run: | set -ex diff --git a/extra/github-actions/build-mac.yml b/extra/github-actions/build-mac.yml index f21797c360f..d68882a90de 100644 --- a/extra/github-actions/build-mac.yml +++ b/extra/github-actions/build-mac.yml @@ -2,7 +2,7 @@ env: # For compatibility with macOS 10.13 ZLIB_VERSION: 1.3 - MBEDTLS_VERSION: 2.25.0 + MBEDTLS_VERSION: 2.28.5 PCRE2_VERSION: 10.42 run: | set -ex From 2c671fb866e150c2d40787bc1581134b08db8c5e Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Tue, 14 Nov 2023 15:17:40 +0100 Subject: [PATCH 14/26] [error reporting] handle non existing files for positions --- src/compiler/server.ml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/compiler/server.ml b/src/compiler/server.ml index 344640af061..c29a8433833 100644 --- a/src/compiler/server.ml +++ b/src/compiler/server.ml @@ -176,18 +176,16 @@ module Communication = struct if is_null_pos then begin let epos = if is_unknown_file cm.cm_pos.pfile then "(unknown position)" else cm.cm_pos.pfile in (-1, -1, -1, -1, epos, []) - end else begin + end else try begin let f = resolve_file ctx.com cm.cm_pos.pfile in - let f = - try Common.find_file ctx.com f - with Not_found -> failwith ("File not found '" ^ cm.cm_pos.pfile ^ "'") - in - + let f = Common.find_file ctx.com f in let l1, p1, l2, p2 = Lexer.get_pos_coords cm.cm_pos in let lines = resolve_source f l1 p1 l2 p2 in let epos = Lexer.get_error_pos error_printer cm.cm_pos in (l1, p1, l2, p2, epos, lines) - end in + end with Not_found | Sys_error _ -> + (1, 1, 1, 1, cm.cm_pos.pfile, []) + in (* If 4 lines or less, display all; if more, crop the middle *) let lines = match lines with @@ -224,8 +222,9 @@ module Communication = struct ) in let display_heading = cm.cm_depth = 0 || sev_changed || file_changed in - let display_source = cm.cm_depth = 0 || sev_changed || pos_changed in - let display_pos_marker = (not is_null_pos) && (cm.cm_depth = 0 || sev_changed || pos_changed) in + let has_source = match lines with | [] -> false | _ -> true in + let display_source = has_source && (cm.cm_depth = 0 || sev_changed || pos_changed) in + let display_pos_marker = (not is_null_pos) && has_source && (cm.cm_depth = 0 || sev_changed || pos_changed) in let gutter_len = (try String.length (Printf.sprintf "%d" (IntMap.find cm.cm_depth ectx.max_lines)) with Not_found -> 0) + 2 in From 08bb8c137026fad2b352702d4944174b0896c027 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 27 Oct 2023 16:09:02 +0200 Subject: [PATCH 15/26] [java,cs] fix stack overflow from closures constraints (#11350) * [java,cs] revert some change from 7863 * [tests] add test for stack overflow --- src/codegen/gencommon/closuresToClass.ml | 5 ++--- tests/misc/cs/projects/Issue11350/Main.hx | 10 ++++++++++ tests/misc/cs/projects/Issue11350/compile.hxml | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/misc/cs/projects/Issue11350/Main.hx create mode 100644 tests/misc/cs/projects/Issue11350/compile.hxml diff --git a/src/codegen/gencommon/closuresToClass.ml b/src/codegen/gencommon/closuresToClass.ml index 2d7904deea9..9708fb97ef5 100644 --- a/src/codegen/gencommon/closuresToClass.ml +++ b/src/codegen/gencommon/closuresToClass.ml @@ -278,9 +278,8 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu let rec get_type_params acc t = match t with - | TInst(( { cl_kind = KTypeParameter constraints } as cl), []) -> - let params = List.fold_left get_type_params acc constraints in - List.filter (fun t -> not (List.memq t acc)) (cl :: params) @ acc; + | TInst(( { cl_kind = KTypeParameter _ } as cl), []) -> + if List.memq cl acc then acc else cl :: acc | TFun (params,tret) -> List.fold_left get_type_params acc ( tret :: List.map (fun (_,_,t) -> t) params ) | TDynamic None -> diff --git a/tests/misc/cs/projects/Issue11350/Main.hx b/tests/misc/cs/projects/Issue11350/Main.hx new file mode 100644 index 00000000000..850d4cc3606 --- /dev/null +++ b/tests/misc/cs/projects/Issue11350/Main.hx @@ -0,0 +1,10 @@ +class Main { + public static function main() {} + + public static function forComparable>(): T->T->Void + return (a: T, b: T) -> {} +} + +typedef Comparable = { + public function compareTo(that : T) : Int; +} diff --git a/tests/misc/cs/projects/Issue11350/compile.hxml b/tests/misc/cs/projects/Issue11350/compile.hxml new file mode 100644 index 00000000000..9f9209b7ba8 --- /dev/null +++ b/tests/misc/cs/projects/Issue11350/compile.hxml @@ -0,0 +1,3 @@ +--main Main +-cs bin +-D net-ver=45 From aaf3a97a5954b914fa49e20419aee806af183d6d Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 15 Sep 2023 09:56:54 +0200 Subject: [PATCH 16/26] [hlc] I64 mod support --- src/generators/hl2c.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/hl2c.ml b/src/generators/hl2c.ml index 9921fac1117..c4ee052bcb1 100644 --- a/src/generators/hl2c.ml +++ b/src/generators/hl2c.ml @@ -829,7 +829,7 @@ let generate_function ctx f = sexpr "%s = %s == 0 ? 0 : ((unsigned)%s) / ((unsigned)%s)" (reg r) (reg b) (reg a) (reg b) | OSMod (r,a,b) -> (match rtype r with - | HUI8 | HUI16 | HI32 -> + | HUI8 | HUI16 | HI32 | HI64 -> sexpr "%s = %s == 0 ? 0 : %s %% %s" (reg r) (reg b) (reg a) (reg b) | HF32 -> sexpr "%s = fmodf(%s,%s)" (reg r) (reg a) (reg b) From 29a42ba6b86fff4f4683b26b89682453450f5328 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Mon, 15 May 2023 19:43:41 +0200 Subject: [PATCH 17/26] [display] Config to disable populating cache from display requests (#11224) * Add compilation server config to disable populating cache from display requests * [tests] Add test for 11177 (including a disabled one for now) * [tests] Add test for 11184 (including a disabled one for now) --- src/compiler/displayProcessing.ml | 2 +- src/compiler/serverCompilationContext.ml | 2 +- src/compiler/serverConfig.ml | 3 +- src/context/display/displayJson.ml | 6 ++++ src/core/displayTypes.ml | 4 +++ std/haxe/display/Server.hx | 1 + tests/server/src/cases/issues/Issue11177.hx | 31 +++++++++++++++++++ tests/server/src/cases/issues/Issue11184.hx | 25 +++++++++++++++ .../templates/issues/Issue11177/Buttons.hx | 6 ++++ .../templates/issues/Issue11177/KeyCode.hx | 3 ++ .../test/templates/issues/Issue11177/Main.hx | 5 +++ .../test/templates/issues/Issue11177/Main2.hx | 5 +++ .../test/templates/issues/Issue11184/Main.hx | 7 +++++ 13 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 tests/server/src/cases/issues/Issue11177.hx create mode 100644 tests/server/src/cases/issues/Issue11184.hx create mode 100644 tests/server/test/templates/issues/Issue11177/Buttons.hx create mode 100644 tests/server/test/templates/issues/Issue11177/KeyCode.hx create mode 100644 tests/server/test/templates/issues/Issue11177/Main.hx create mode 100644 tests/server/test/templates/issues/Issue11177/Main2.hx create mode 100644 tests/server/test/templates/issues/Issue11184/Main.hx diff --git a/src/compiler/displayProcessing.ml b/src/compiler/displayProcessing.ml index e32f7fcacf3..d228c4ad6d0 100644 --- a/src/compiler/displayProcessing.ml +++ b/src/compiler/displayProcessing.ml @@ -48,7 +48,7 @@ let handle_display_argument_old com file_pos actx = | "diagnostics" -> com.report_mode <- RMDiagnostics [file_unique]; let dm = create DMNone in - {dm with dms_display_file_policy = DFPAlso; dms_per_file = true} + {dm with dms_display_file_policy = DFPAlso; dms_per_file = true; dms_populate_cache = !ServerConfig.populate_cache_from_display} | "statistics" -> com.report_mode <- RMStatistics; let dm = create DMNone in diff --git a/src/compiler/serverCompilationContext.ml b/src/compiler/serverCompilationContext.ml index 95a567aa901..bec9724e4c3 100644 --- a/src/compiler/serverCompilationContext.ml +++ b/src/compiler/serverCompilationContext.ml @@ -58,7 +58,7 @@ let reset sctx = Helper.start_time := get_time() let maybe_cache_context sctx com = - if com.display.dms_full_typing then begin + if com.display.dms_full_typing && com.display.dms_populate_cache then begin CommonCache.cache_context sctx.cs com; ServerMessage.cached_modules com "" (List.length com.modules); end diff --git a/src/compiler/serverConfig.ml b/src/compiler/serverConfig.ml index ec7ba308e59..173637cb401 100644 --- a/src/compiler/serverConfig.ml +++ b/src/compiler/serverConfig.ml @@ -1,2 +1,3 @@ let do_not_check_modules = ref false -let legacy_completion = ref false \ No newline at end of file +let populate_cache_from_display = ref true +let legacy_completion = ref false diff --git a/src/context/display/displayJson.ml b/src/context/display/displayJson.ml index 3792bf7b8a2..8853ef2b225 100644 --- a/src/context/display/displayJson.ml +++ b/src/context/display/displayJson.ml @@ -297,6 +297,12 @@ let handler = l := jstring ("Legacy completion " ^ (if b then "enabled" else "disabled")) :: !l; () ) (); + hctx.jsonrpc#get_opt_param (fun () -> + let b = hctx.jsonrpc#get_bool_param "populateCacheFromDisplay" in + ServerConfig.populate_cache_from_display := b; + l := jstring ("Compilation cache refill from display " ^ (if b then "enabled" else "disabled")) :: !l; + () + ) (); hctx.send_result (jarray !l) ); "server/memory",(fun hctx -> diff --git a/src/core/displayTypes.ml b/src/core/displayTypes.ml index 40fe07007a2..9e04cbc0195 100644 --- a/src/core/displayTypes.ml +++ b/src/core/displayTypes.ml @@ -198,6 +198,7 @@ module DisplayMode = struct dms_inline : bool; dms_display_file_policy : display_file_policy; dms_exit_during_typing : bool; + dms_populate_cache : bool; dms_per_file : bool; } @@ -210,6 +211,7 @@ module DisplayMode = struct dms_inline = false; dms_display_file_policy = DFPOnly; dms_exit_during_typing = true; + dms_populate_cache = false; dms_per_file = false; } @@ -222,6 +224,7 @@ module DisplayMode = struct dms_inline = true; dms_display_file_policy = DFPNo; dms_exit_during_typing = false; + dms_populate_cache = true; dms_per_file = false; } @@ -232,6 +235,7 @@ module DisplayMode = struct | DMDefault | DMDefinition | DMTypeDefinition | DMPackage | DMHover | DMSignature -> settings | DMUsage _ | DMImplementation -> { settings with dms_full_typing = true; + dms_populate_cache = !ServerConfig.populate_cache_from_display; dms_force_macro_typing = true; dms_display_file_policy = DFPAlso; dms_exit_during_typing = false diff --git a/std/haxe/display/Server.hx b/std/haxe/display/Server.hx index 63895758cec..44ce700587e 100644 --- a/std/haxe/display/Server.hx +++ b/std/haxe/display/Server.hx @@ -73,6 +73,7 @@ typedef ConfigurePrintParams = { typedef ConfigureParams = { final ?noModuleChecks:Bool; + final ?populateCacheFromDisplay:Bool; final ?legacyCompletion:Bool; final ?print:ConfigurePrintParams; } diff --git a/tests/server/src/cases/issues/Issue11177.hx b/tests/server/src/cases/issues/Issue11177.hx new file mode 100644 index 00000000000..42aa7423082 --- /dev/null +++ b/tests/server/src/cases/issues/Issue11177.hx @@ -0,0 +1,31 @@ +package cases.issues; + +class Issue11177 extends TestCase { + // Disabled for now until #11177 is actually fixed, likely by #11220 + // function test(_) { + // vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main.hx")); + // vfs.putContent("Buttons.hx", getTemplate("issues/Issue11177/Buttons.hx")); + // vfs.putContent("KeyCode.hx", getTemplate("issues/Issue11177/KeyCode.hx")); + // var args = ["-main", "Main", "--interp"]; + // runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"])); + // vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main2.hx")); + // runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); + // runHaxe(args); + // runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"])); + // Assert.isTrue(lastResult.stderr.length == 2); + // } + + function testWithoutCacheFromDisplay(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main.hx")); + vfs.putContent("Buttons.hx", getTemplate("issues/Issue11177/Buttons.hx")); + vfs.putContent("KeyCode.hx", getTemplate("issues/Issue11177/KeyCode.hx")); + var args = ["-main", "Main", "--interp"]; + runHaxeJson([], ServerMethods.Configure, {populateCacheFromDisplay: false}); + runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"])); + vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main2.hx")); + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); + runHaxe(args); + runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"])); + Assert.isTrue(lastResult.stderr.length == 2); + } +} diff --git a/tests/server/src/cases/issues/Issue11184.hx b/tests/server/src/cases/issues/Issue11184.hx new file mode 100644 index 00000000000..7f2d326d726 --- /dev/null +++ b/tests/server/src/cases/issues/Issue11184.hx @@ -0,0 +1,25 @@ +package cases.issues; + +class Issue11184 extends TestCase { + // Disabled for now until #11184 is actually fixed, likely by #11220 + // function test(_) { + // vfs.putContent("Main.hx", getTemplate("issues/Issue11184/Main.hx")); + // var args = ["-main", "Main", "-js", "bin/test.js"]; + // runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); + // runHaxe(args); + // Assert.isTrue(hasErrorMessage("Cannot use Void as value")); + // runHaxe(args); + // Assert.isTrue(hasErrorMessage("Cannot use Void as value")); + // } + + function testWithoutCacheFromDisplay(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11184/Main.hx")); + var args = ["-main", "Main", "-js", "bin/test.js"]; + runHaxeJson([], ServerMethods.Configure, {populateCacheFromDisplay: false}); + runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); + runHaxe(args); + Assert.isTrue(hasErrorMessage("Cannot use Void as value")); + runHaxe(args); + Assert.isTrue(hasErrorMessage("Cannot use Void as value")); + } +} diff --git a/tests/server/test/templates/issues/Issue11177/Buttons.hx b/tests/server/test/templates/issues/Issue11177/Buttons.hx new file mode 100644 index 00000000000..981215fa8e2 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11177/Buttons.hx @@ -0,0 +1,6 @@ +class Buttons { + public static function init(main:Main):Void { + // Recursive inline is not supported + trace(KeyCode.Backspace); + } +} diff --git a/tests/server/test/templates/issues/Issue11177/KeyCode.hx b/tests/server/test/templates/issues/Issue11177/KeyCode.hx new file mode 100644 index 00000000000..d9e56743fc8 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11177/KeyCode.hx @@ -0,0 +1,3 @@ +enum abstract KeyCode(Int) { + var Backspace = 8; +} diff --git a/tests/server/test/templates/issues/Issue11177/Main.hx b/tests/server/test/templates/issues/Issue11177/Main.hx new file mode 100644 index 00000000000..50277c19e01 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11177/Main.hx @@ -0,0 +1,5 @@ +class Main { + static function main():Void { + trace("change this line"); + } +} diff --git a/tests/server/test/templates/issues/Issue11177/Main2.hx b/tests/server/test/templates/issues/Issue11177/Main2.hx new file mode 100644 index 00000000000..c3300795a09 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11177/Main2.hx @@ -0,0 +1,5 @@ +class Main { + static function main():Void { + trace("change this trace"); + } +} diff --git a/tests/server/test/templates/issues/Issue11184/Main.hx b/tests/server/test/templates/issues/Issue11184/Main.hx new file mode 100644 index 00000000000..c769638ee40 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11184/Main.hx @@ -0,0 +1,7 @@ +class Main { + static function main() { + function foo():Void {} + final arr = [foo()]; + } +} + From 38c4d0c42a9d061d55b0a0d53e4f5b1a57a23505 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 15 Nov 2023 07:15:44 +0100 Subject: [PATCH 18/26] [macro] Update macro API restriction warnings (when using -D haxe-next) (#11377) * [macro] Update macro API restriction warnings (when using -D haxe-next) * Avoid changes in behavior without -D haxe-next --- extra/ImportAll.hx | 70 ++++++++++--------- std/haxe/macro/CompilationServer.hx | 4 +- std/haxe/macro/Compiler.hx | 18 +++-- std/haxe/macro/Context.hx | 23 ++++-- .../user-defined-define-json-fail.hxml.stderr | 2 +- .../user-defined-meta-json-fail.hxml.stderr | 2 +- ...-defined-meta-json-indent-fail.hxml.stderr | 2 +- ...-defined-meta-json-pretty-fail.hxml.stderr | 4 +- .../recursive-callbacks/compile.hxml.stderr | 1 - 9 files changed, 75 insertions(+), 51 deletions(-) diff --git a/extra/ImportAll.hx b/extra/ImportAll.hx index b6b63a02104..5d4d131d3bf 100644 --- a/extra/ImportAll.hx +++ b/extra/ImportAll.hx @@ -72,42 +72,44 @@ class ImportAll { if (!Context.defined("neko") && !Context.defined("cpp")) return; case "tools", "build-tool", "jar-tool": return; } - for( p in Context.getClassPath() ) { - if( p == "/" || p == "" ) - continue; - // skip if we have a classpath to haxe - if( pack.length == 0 && sys.FileSystem.exists(p+"std") ) - continue; - var p = p + pack.split(".").join("/"); - if( StringTools.endsWith(p,"/") ) - p = p.substr(0,-1); - if( !sys.FileSystem.exists(p) || !sys.FileSystem.isDirectory(p) ) - continue; - for( file in sys.FileSystem.readDirectory(p) ) { - if( file == ".svn" || file == "_std" ) + Context.onAfterInitMacros(() -> { + for( p in Context.getClassPath() ) { + if( p == "/" || p == "" ) continue; - var full = (pack == "") ? file : pack + "." + file; - if( StringTools.endsWith(file, ".hx") && file.substr(0, file.length - 3).indexOf(".") < 0 ) { - var cl = full.substr(0, full.length - 3); - switch( cl ) { - case "ImportAll", "neko.db.MacroManager": continue; - case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ) continue; - case "Sys": if(!isSysTarget()) continue; - case "haxe.web.Request": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("js")) ) continue; - case "haxe.macro.ExampleJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("eval") ) continue; - case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue; - case "haxe.remoting.SyncSocketConnection": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue; - case "neko.vm.Ui" | "sys.db.Sqlite" | "sys.db.Mysql" if ( Context.defined("interp") ): continue; - case "sys.db.Sqlite" | "sys.db.Mysql" | "cs.db.AdoNet" if ( Context.defined("cs") ): continue; - case "haxe.atomic.AtomicBool" if(!Context.defined("target.atomics")): continue; - case "haxe.atomic.AtomicInt" if(!Context.defined("target.atomics")): continue; - case "haxe.atomic.AtomicObject" if(!Context.defined("target.atomics") || Context.defined("js") || Context.defined("cpp")): continue; - } - Context.getModule(cl); - } else if( sys.FileSystem.isDirectory(p + "/" + file) ) - run(full); + // skip if we have a classpath to haxe + if( pack.length == 0 && sys.FileSystem.exists(p+"std") ) + continue; + var p = p + pack.split(".").join("/"); + if( StringTools.endsWith(p,"/") ) + p = p.substr(0,-1); + if( !sys.FileSystem.exists(p) || !sys.FileSystem.isDirectory(p) ) + continue; + for( file in sys.FileSystem.readDirectory(p) ) { + if( file == ".svn" || file == "_std" ) + continue; + var full = (pack == "") ? file : pack + "." + file; + if( StringTools.endsWith(file, ".hx") && file.substr(0, file.length - 3).indexOf(".") < 0 ) { + var cl = full.substr(0, full.length - 3); + switch( cl ) { + case "ImportAll", "neko.db.MacroManager": continue; + case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ) continue; + case "Sys": if(!isSysTarget()) continue; + case "haxe.web.Request": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("js")) ) continue; + case "haxe.macro.ExampleJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("eval") ) continue; + case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue; + case "haxe.remoting.SyncSocketConnection": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue; + case "neko.vm.Ui" | "sys.db.Sqlite" | "sys.db.Mysql" if ( Context.defined("interp") ): continue; + case "sys.db.Sqlite" | "sys.db.Mysql" | "cs.db.AdoNet" if ( Context.defined("cs") ): continue; + case "haxe.atomic.AtomicBool" if(!Context.defined("target.atomics")): continue; + case "haxe.atomic.AtomicInt" if(!Context.defined("target.atomics")): continue; + case "haxe.atomic.AtomicObject" if(!Context.defined("target.atomics") || Context.defined("js") || Context.defined("cpp")): continue; + } + Context.getModule(cl); + } else if( sys.FileSystem.isDirectory(p + "/" + file) ) + run(full); + } } - } + }); } } diff --git a/std/haxe/macro/CompilationServer.hx b/std/haxe/macro/CompilationServer.hx index 6952d89f38b..0cb50731bed 100644 --- a/std/haxe/macro/CompilationServer.hx +++ b/std/haxe/macro/CompilationServer.hx @@ -101,7 +101,9 @@ class CompilationServer { **/ static public function setModuleCheckPolicy(pathFilters:Array, policy:Array, ?recursive = true, ?contextOptions:ContextOptions = NormalContext) { - @:privateAccess Compiler.load("server_add_module_check_policy", 4)(pathFilters, policy, recursive, contextOptions); + Context.onAfterInitMacros(() -> { + @:privateAccess Compiler.load("server_add_module_check_policy", 4)(pathFilters, policy, recursive, contextOptions); + }); } /** diff --git a/std/haxe/macro/Compiler.hx b/std/haxe/macro/Compiler.hx index 24655a8b278..0ef487a7ced 100644 --- a/std/haxe/macro/Compiler.hx +++ b/std/haxe/macro/Compiler.hx @@ -93,7 +93,11 @@ class Compiler { if (!ident.match(field)) throw "Invalid " + field; #if (neko || eval) + #if haxe_next + Context.onAfterInitMacros(() -> load("type_patch", 4)(className, field, isStatic == true, null)); + #else load("type_patch", 4)(className, field, isStatic == true, null); + #end #else typePatch(className, field, isStatic == true, null); #end @@ -109,7 +113,11 @@ class Compiler { if (!ident.match((field.charAt(0) == "$") ? field.substr(1) : field)) throw "Invalid " + field; #if (neko || eval) + #if haxe_next + Context.onAfterInitMacros(() -> load("type_patch", 4)(className, field, isStatic == true, type)); + #else load("type_patch", 4)(className, field, isStatic == true, type); + #end #else typePatch(className, field, isStatic == true, type); #end @@ -125,7 +133,11 @@ class Compiler { if (field != null && !ident.match(field)) throw "Invalid " + field; #if (neko || eval) + #if haxe_next + Context.onAfterInitMacros(() -> load("meta_patch", 4)(meta, className, field, isStatic == true)); + #else load("meta_patch", 4)(meta, className, field, isStatic == true); + #end #else metaPatch(meta, className, field, isStatic == true); #end @@ -284,11 +296,7 @@ class Compiler { Context.error('Package "$pack" was not found in any of class paths', Context.currentPos()); } - if (!Context.initMacrosDone()) { - Context.onAfterInitMacros(() -> include(pack, rec, ignore, classPaths, strict)); - } else { - include(pack, rec, ignore, classPaths, strict); - } + Context.onAfterInitMacros(() -> include(pack, rec, ignore, classPaths, strict)); } /** diff --git a/std/haxe/macro/Context.hx b/std/haxe/macro/Context.hx index 73970fa3dbb..b98b5be1b5f 100644 --- a/std/haxe/macro/Context.hx +++ b/std/haxe/macro/Context.hx @@ -175,6 +175,7 @@ class Context { Returns `null` if the current macro is not a `@:genericBuild` macro. **/ public static function getCallArguments():Null> { + assertInitMacrosDone(false); return load("get_call_arguments", 0)(); } @@ -184,6 +185,7 @@ class Context { If no such class exists, `null` is returned. **/ public static function getLocalClass():Null> { + assertInitMacrosDone(false); var l:Type = load("get_local_type", 0)(); if (l == null) return null; @@ -197,6 +199,7 @@ class Context { Returns the current module path in/on which the macro was called. **/ public static function getLocalModule():String { + assertInitMacrosDone(false); return load("get_local_module", 0)(); } @@ -206,6 +209,7 @@ class Context { If no such type exists, `null` is returned. **/ public static function getLocalType():Null { + assertInitMacrosDone(false); return load("get_local_type", 0)(); } @@ -215,6 +219,7 @@ class Context { If no such method exists, `null` is returned. **/ public static function getLocalMethod():Null { + assertInitMacrosDone(false); return load("get_local_method", 0)(); } @@ -225,6 +230,7 @@ class Context { Modifying the returned array has no effect on the compiler. **/ public static function getLocalUsing():Array> { + assertInitMacrosDone(false); return load("get_local_using", 0)(); } @@ -234,6 +240,7 @@ class Context { Modifying the returned array has no effect on the compiler. **/ public static function getLocalImports():Array { + assertInitMacrosDone(false); return load("get_local_imports", 0)(); } @@ -248,6 +255,7 @@ class Context { **/ @:deprecated("Use Context.getLocalTVars() instead") public static function getLocalVars():Map { + assertInitMacrosDone(false); return load("local_vars", 1)(false); } @@ -256,6 +264,7 @@ class Context { of `Type`. **/ public static function getLocalTVars():Map { + assertInitMacrosDone(false); return load("local_vars", 1)(true); } @@ -459,8 +468,11 @@ class Context { actual typing. **/ public static function onAfterInitMacros(callback:Void->Void):Void { - assertInitMacro(); - load("on_after_init_macros", 1)(callback); + if (Context.initMacrosDone()) { + callback(); + } else { + load("on_after_init_macros", 1)(callback); + } } /** @@ -619,6 +631,7 @@ class Context { This is only defined for `@:build/@:autoBuild` macros. **/ public static function getBuildFields():Array { + assertInitMacrosDone(false); return load("get_build_fields", 0)(); } @@ -760,8 +773,7 @@ class Context { run your code once typer is ready to be used. **/ public static function registerModuleDependency(modulePath:String, externFile:String) { - assertInitMacrosDone(); - load("register_module_dependency", 2)(modulePath, externFile); + onAfterInitMacros(() -> load("register_module_dependency", 2)(modulePath, externFile)); } /** @@ -848,7 +860,7 @@ class Context { } private static function sExpr(e:TypedExpr, pretty:Bool):String { - return haxe.macro.Context.load("s_expr", 2)(e, pretty); + return load("s_expr", 2)(e, pretty); } @:allow(haxe.macro.Compiler) @@ -863,6 +875,7 @@ class Context { } } + @:allow(haxe.macro.Compiler) private static function assertInitMacrosDone(includeSuggestion = true):Void { #if haxe_next if (!initMacrosDone()) { diff --git a/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr index ece15c4ea26..6ad908d579b 100644 --- a/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr @@ -1,3 +1,3 @@ (unknown) : Uncaught exception Could not read file define.jsno -$$normPath(::std::)/haxe/macro/Compiler.hx:493: characters 11-39 : Called from here +$$normPath(::std::)/haxe/macro/Compiler.hx:501: characters 11-39 : Called from here (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr index a59833847b7..847a509916e 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr @@ -1,3 +1,3 @@ (unknown) : Uncaught exception Could not read file meta.jsno -$$normPath(::std::)/haxe/macro/Compiler.hx:483: characters 11-39 : Called from here +$$normPath(::std::)/haxe/macro/Compiler.hx:491: characters 11-39 : Called from here (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr index 05432e4c026..b916f1c5440 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr @@ -1,3 +1,3 @@ (unknown) : Uncaught exception Could not read file meta.jsno - $$normPath(::std::)/haxe/macro/Compiler.hx:483: characters 11-39 : Called from here + $$normPath(::std::)/haxe/macro/Compiler.hx:491: characters 11-39 : Called from here (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr index 8646a40989d..58944a79f12 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr @@ -2,9 +2,9 @@ | Uncaught exception Could not read file meta.jsno - -> $$normPath(::std::)/haxe/macro/Compiler.hx:483: characters 11-39 + -> $$normPath(::std::)/haxe/macro/Compiler.hx:491: characters 11-39 - 483 | var f = sys.io.File.getContent(path); + 491 | var f = sys.io.File.getContent(path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | Called from here diff --git a/tests/misc/projects/recursive-callbacks/compile.hxml.stderr b/tests/misc/projects/recursive-callbacks/compile.hxml.stderr index cf44340f699..0b49ab58eee 100644 --- a/tests/misc/projects/recursive-callbacks/compile.hxml.stderr +++ b/tests/misc/projects/recursive-callbacks/compile.hxml.stderr @@ -1,5 +1,4 @@ Main.hx:5: characters 20-24 : Warning : 1 -Main.hx:9: lines 9-11 : Warning : This API should only be used from initialization macros. Main.hx:5: characters 20-24 : Warning : 2 Main.hx:5: characters 20-24 : Warning : 3 Main.hx:5: characters 20-24 : Warning : 4 From c988f893304a115a8f392393cc623105b388648d Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Fri, 10 Nov 2023 11:28:26 +0100 Subject: [PATCH 19/26] [parser] check for Eof see #11368 --- src/syntax/grammar.mly | 2 +- src/syntax/parserEntry.ml | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/syntax/grammar.mly b/src/syntax/grammar.mly index 685e00424dc..186451299de 100644 --- a/src/syntax/grammar.mly +++ b/src/syntax/grammar.mly @@ -121,7 +121,7 @@ let check_redundant_var p1 = parser let parsing_macro_cond = ref false -let rec parse_file s = +let rec parse_file s = last_doc := None; match s with parser | [< '(Kwd Package,_); pack = parse_package; s >] -> diff --git a/src/syntax/parserEntry.ml b/src/syntax/parserEntry.ml index ebbc0d8a284..34d2c4fd567 100644 --- a/src/syntax/parserEntry.ml +++ b/src/syntax/parserEntry.ml @@ -363,6 +363,14 @@ let parse entry ctx code file = try let l = entry s in (match !mstack with p :: _ -> syntax_error Unclosed_conditional ~pos:(Some p) sraw () | _ -> ()); + begin match Stream.peek s with + | None -> + () (* Eof could already have been consumed *) + | Some (Eof,_) -> + () (* This is what we want *) + | Some (tok,p) -> + error (Unexpected tok) p (* This isn't *) + end; let was_display_file = !in_display_file in restore(); Lexer.restore old; From 4dc24292f83d65ad106a5e4d3f02366f79c96f99 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Mon, 13 Nov 2023 08:40:59 +0100 Subject: [PATCH 20/26] [tests] fix and add closes #10287 closes #11368 --- tests/misc/projects/Issue10287/Main.hx | 2 ++ tests/misc/projects/Issue10287/compile-fail.hxml | 1 + tests/misc/projects/Issue10287/compile-fail.hxml.stderr | 2 ++ tests/misc/projects/Issue11368/Main.hx | 8 ++++++++ tests/misc/projects/Issue11368/compile-fail.hxml | 1 + tests/misc/projects/Issue11368/compile-fail.hxml.stderr | 1 + tests/server/src/TestCase.hx | 2 +- 7 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/misc/projects/Issue10287/Main.hx create mode 100644 tests/misc/projects/Issue10287/compile-fail.hxml create mode 100644 tests/misc/projects/Issue10287/compile-fail.hxml.stderr create mode 100644 tests/misc/projects/Issue11368/Main.hx create mode 100644 tests/misc/projects/Issue11368/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11368/compile-fail.hxml.stderr diff --git a/tests/misc/projects/Issue10287/Main.hx b/tests/misc/projects/Issue10287/Main.hx new file mode 100644 index 00000000000..32a1d6f7118 --- /dev/null +++ b/tests/misc/projects/Issue10287/Main.hx @@ -0,0 +1,2 @@ +function foo() return 1; +function main() trace('${foo()blah}'); \ No newline at end of file diff --git a/tests/misc/projects/Issue10287/compile-fail.hxml b/tests/misc/projects/Issue10287/compile-fail.hxml new file mode 100644 index 00000000000..fab0aeecc3d --- /dev/null +++ b/tests/misc/projects/Issue10287/compile-fail.hxml @@ -0,0 +1 @@ +--main Main \ No newline at end of file diff --git a/tests/misc/projects/Issue10287/compile-fail.hxml.stderr b/tests/misc/projects/Issue10287/compile-fail.hxml.stderr new file mode 100644 index 00000000000..8b64c0786a8 --- /dev/null +++ b/tests/misc/projects/Issue10287/compile-fail.hxml.stderr @@ -0,0 +1,2 @@ +Main.hx:2: characters 31-35 : Unexpected blah +Main.hx:2: characters 31-35 : ... For function argument 'v' \ No newline at end of file diff --git a/tests/misc/projects/Issue11368/Main.hx b/tests/misc/projects/Issue11368/Main.hx new file mode 100644 index 00000000000..ebcbe591912 --- /dev/null +++ b/tests/misc/projects/Issue11368/Main.hx @@ -0,0 +1,8 @@ +macro function test() { + haxe.macro.Context.parseInlineSring("p:true,v:0", haxe.macro.Context.currentPos()) + return macro null; +} + +function main() { + test(); +} \ No newline at end of file diff --git a/tests/misc/projects/Issue11368/compile-fail.hxml b/tests/misc/projects/Issue11368/compile-fail.hxml new file mode 100644 index 00000000000..fab0aeecc3d --- /dev/null +++ b/tests/misc/projects/Issue11368/compile-fail.hxml @@ -0,0 +1 @@ +--main Main \ No newline at end of file diff --git a/tests/misc/projects/Issue11368/compile-fail.hxml.stderr b/tests/misc/projects/Issue11368/compile-fail.hxml.stderr new file mode 100644 index 00000000000..d0589d64f26 --- /dev/null +++ b/tests/misc/projects/Issue11368/compile-fail.hxml.stderr @@ -0,0 +1 @@ +Main.hx:3: characters 2-8 : Missing ; \ No newline at end of file diff --git a/tests/server/src/TestCase.hx b/tests/server/src/TestCase.hx index c9b689965b1..0ca5f359631 100644 --- a/tests/server/src/TestCase.hx +++ b/tests/server/src/TestCase.hx @@ -195,7 +195,7 @@ class TestCase implements ITest { } function assertSkipping(module:String, reason:SkipReason, ?p:haxe.PosInfos) { - var msg = 'skipping $module (${printSkipReason(reason))})'; + var msg = 'skipping $module (${printSkipReason(reason)})'; return Assert.isTrue(hasMessage(msg), null, p); } From 9df1e9aca8cf906ea736537e7b7534bc40b459c4 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 15 Nov 2023 07:54:08 +0100 Subject: [PATCH 21/26] update changelog --- extra/CHANGES.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/extra/CHANGES.txt b/extra/CHANGES.txt index 3eb4d6f20d0..15370ca1278 100644 --- a/extra/CHANGES.txt +++ b/extra/CHANGES.txt @@ -1,3 +1,28 @@ +2023-09-15 4.3.3 + + General improvements: + + all : improve extra field error range (#11335) + all : better error messages for --connect + hl : improve error message when hl_version is missing (#11086) + macro : update macro API restriction warnings when using -D haxe-next (#11377) + + Bugfixes: + + all : handle non existing files for positions in pretty errors (#11364) + all : metadata support for local static vars + all : catch trailing invalid syntax in string interpolation (#10287) + eval : fix Array.resize retaining values (#11317) + eval/hl : fix catching haxe.ValueException (#11321) + hl : make genhl respect Meta.NoExpr (#11257) + hl : don't add bindings for non existing methods + hl/c : add missing I64 mod support + hl/c : add bool to reserved keywords (#11293) + java/cs: fix stack overflow from closures constraints (#11350) + js : DOMElement insertAdjacentElement should not be pure (#11333) + macro : catch trailing invalid syntax in Context.parseInlineString (#11368) + macro : fix TDAbstract without flags in haxe.macro.Printer + 2023-09-01 4.3.2 General improvements: From 55ea42b64a7e3e3428a604de7dd1c04807721a94 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Mon, 10 Apr 2023 07:00:35 +0100 Subject: [PATCH 22/26] [ci] Enable missing hashlink tests (#11064) * Enabling hashlink tests depending on ssl.hdll * Fix test guard interp here is for the hashlink interpreter, not haxe's interp target * Clean up --- tests/runci/targets/Hl.hx | 12 ++-------- tests/unit/src/unit/TestHttp.hx | 37 ++++++++++++----------------- tests/unit/src/unit/TestMain.hx | 3 +-- tests/unit/src/unitstd/EReg.unit.hx | 2 +- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/tests/runci/targets/Hl.hx b/tests/runci/targets/Hl.hx index 4fdddf8d073..0dd267a6e4c 100644 --- a/tests/runci/targets/Hl.hx +++ b/tests/runci/targets/Hl.hx @@ -52,7 +52,7 @@ class Hl { "-DWITH_OPENAL=OFF", "-DWITH_SDL=OFF", "-DWITH_SQLITE=ON", - "-DWITH_SSL=OFF", + "-DWITH_SSL=ON", "-DWITH_UI=OFF", "-DWITH_UV=OFF", "-DWITH_VIDEO=OFF", @@ -72,15 +72,7 @@ class Hl { static public function run(args:Array) { getHlDependencies(); - switch (systemName) { - case "Windows": - runCommand("haxe", ["compile-hl.hxml"].concat(args)); - case _: - runCommand("haxe", [ - "compile-hl.hxml", - "-D", "no_http", // hl's ssl.hdll is only built on Windows - ].concat(args)); - } + runCommand("haxe", ["compile-hl.hxml"].concat(args)); runCommand(hlBinary, ["bin/unit.hl"]); changeDirectory(threadsDir); diff --git a/tests/unit/src/unit/TestHttp.hx b/tests/unit/src/unit/TestHttp.hx index cc6db171eb6..291b406c797 100644 --- a/tests/unit/src/unit/TestHttp.hx +++ b/tests/unit/src/unit/TestHttp.hx @@ -3,39 +3,33 @@ package unit; import utest.Async; class TestHttp extends Test { + #if flash public function setupClass() { - #if flash flash.system.Security.allowDomain("*"); flash.system.Security.allowInsecureDomain("*"); flash.system.Security.loadPolicyFile("http://localhost:20200/crossdomain.xml"); - #end } + #end - function run(async:Async, test:()->Void) { - // { comment this out to run http tests locally - #if (!github || (github && js && !nodejs)) //also don't run on sauce labs - noAssert(); - async.done(); - return; - #end - // } + static final RUN_HTTP_TESTS = + #if !github false && #end // comment out line to run http tests locally + #if (github && (java || flash || (cs && Windows))) + false + #elseif (js && !nodejs) + js.Browser.supported + #else + true + #end; - #if (js && !nodejs) - if(!js.Browser.supported) { - noAssert(); - async.done(); + function run(async:Async, test:()->Void) { + if (RUN_HTTP_TESTS) { + test(); return; } - test(); - #elseif (github && (hl || java || (flash && (Linux || Mac || Windows)) || (cs && Windows))) noAssert(); async.done(); - return; - #else - test(); - #end } -#if !(github && hl) + @:timeout(1000) public function testPostData(async:Async) run(async, () -> { var srcStr = 'hello, world'; @@ -84,5 +78,4 @@ class TestHttp extends Test { d.setPostBytes(srcData); d.request(); }); -#end } diff --git a/tests/unit/src/unit/TestMain.hx b/tests/unit/src/unit/TestMain.hx index 0552c7f6dab..8b6cd45cd76 100644 --- a/tests/unit/src/unit/TestMain.hx +++ b/tests/unit/src/unit/TestMain.hx @@ -79,8 +79,7 @@ function main() { new TestNumericCasts(), new TestHashMap(), new TestRest(), - #if !no_http new TestHttp(), - #end + new TestHttp(), #if !no_pattern_matching new TestMatch(), #end diff --git a/tests/unit/src/unitstd/EReg.unit.hx b/tests/unit/src/unitstd/EReg.unit.hx index 8b635aa0555..bcbb8d37651 100644 --- a/tests/unit/src/unitstd/EReg.unit.hx +++ b/tests/unit/src/unitstd/EReg.unit.hx @@ -87,7 +87,7 @@ pos.len == 2; ~/a/g.replace("bab", "z") == "bzb"; ~/a/g.replace("baba", "z") == "bzbz"; -#if !(interp) // not allowed in local interpreter, still allowed in hl runtime +#if !(hl && interp) // not allowed in local hl interpreter, still allowed in hl runtime // replace + $ ~/href="(.*?)"/.replace('lead href="foo" trail',"$1") == "lead foo trail"; //~/href="(.*?)"/.replace('lead href="foo" trail',"$2") == "lead $2 trail"; From 36418174ac3f7cd04910a2a43108047ecb75017e Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 16 Nov 2023 19:34:17 +0100 Subject: [PATCH 23/26] [hl/c] Run (and fix) unit tests for hl/c on linux (#11382) * [hl/c] prefix reserved identifiers with _hx_ * [tests] add test for 11378 * [tests] enable hl/c unit tests; disable 9678 for hl Technically 9678 should be disabled for cpp and hl/c but we don't have a hl/c specific define * [hl] add hlc define when compiling hl/c * [tests] hl/c tests * [hl/c] run unit tests for hl/c (on linux) * [hl/c] fix Int64 unsigned right shift overflow * hlc define is reserved * [hl/c] dodge issues until fix on hashlink side * [tests] LD_LIBRARY_PATH isn't used on windows --- src-json/define.json | 7 ++++ src/context/common.ml | 5 ++- src/generators/hl2c.ml | 12 +++--- std/hl/_std/haxe/NativeStackTrace.hx | 3 ++ .../misc/hl/reserved-keywords/Macro.macro.hx | 37 +++++++++++++++++++ tests/misc/hl/reserved-keywords/Main.hx | 4 ++ tests/misc/hl/reserved-keywords/compile.hxml | 2 + tests/runci/System.hx | 9 +++++ tests/runci/targets/Hl.hx | 28 ++++++++++++++ tests/unit/src/unit/TestExceptions.hx | 4 ++ tests/unit/src/unit/TestMain.hx | 2 +- tests/unit/src/unit/issues/Issue10109.hx | 3 +- tests/unit/src/unit/issues/Issue9678.hx | 2 +- 13 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 tests/misc/hl/reserved-keywords/Macro.macro.hx create mode 100644 tests/misc/hl/reserved-keywords/Main.hx create mode 100644 tests/misc/hl/reserved-keywords/compile.hxml diff --git a/src-json/define.json b/src-json/define.json index 1d575822d83..49718ab8f92 100644 --- a/src-json/define.json +++ b/src-json/define.json @@ -272,6 +272,13 @@ "define": "haxe-next", "doc": "Enable experimental features that are meant to be released on next Haxe version." }, + { + "name": "Hlc", + "define": "hlc", + "doc": "Defined by compiler when using hl/c target.", + "platforms": ["hl"], + "reserved": true + }, { "name": "HlVer", "define": "hl-ver", diff --git a/src/context/common.ml b/src/context/common.ml index a18bd070c2c..7d1db468504 100644 --- a/src/context/common.ml +++ b/src/context/common.ml @@ -462,7 +462,7 @@ let external_defined_value ctx k = Define.raw_defined_value ctx.defines (convert_define k) let reserved_flags = [ - "true";"false";"null";"cross";"js";"lua";"neko";"flash";"php";"cpp";"cs";"java";"python"; + "true";"false";"null";"cross";"js";"lua";"neko";"flash";"php";"cpp";"cs";"java";"python";"hl";"hlc"; "swc";"macro";"sys";"static";"utf16";"haxe";"haxe_ver" ] @@ -971,7 +971,8 @@ let set_platform com pf file = if com.platform <> Cross then failwith "Multiple targets"; init_platform com pf; com.file <- file; - if (pf = Flash) && Path.file_extension file = "swc" then define com Define.Swc; + if (pf = Flash) && Path.file_extension file = "swc" then define com Define.Swc + else if (pf = Hl) && Path.file_extension file = "c" then define com Define.Hlc; (* Set the source header, unless the user has set one already or the platform sets a custom one *) if not (defined com Define.SourceHeader) && (pf <> Hl) then define_value com Define.SourceHeader ("Generated by Haxe " ^ s_version_full) diff --git a/src/generators/hl2c.ml b/src/generators/hl2c.ml index c4ee052bcb1..871005304b2 100644 --- a/src/generators/hl2c.ml +++ b/src/generators/hl2c.ml @@ -91,8 +91,7 @@ let keywords = (* Values *) "NULL";"true";"false"; (* MS specific *) - "__asm";"dllimport2";"__int8";"naked2";"__based1";"__except";"__int16";"__stdcall";"__cdecl";"__fastcall";"__int32"; - "thread2";"__declspec";"__finally";"__int64";"__try";"dllexport2";"__inline";"__leave";"asm"; + "asm";"dllimport2";"dllexport2";"naked2";"thread2"; (* reserved by HLC *) "t"; (* GCC *) @@ -105,7 +104,7 @@ let keywords = List.iter (fun i -> Hashtbl.add h i ()) c_kwds; h -let ident i = if Hashtbl.mem keywords i then "_" ^ i else i +let ident i = if (Hashtbl.mem keywords i) || (ExtString.String.starts_with "__" i) then "_hx_" ^ i else i let s_comp = function | CLt -> "<" @@ -122,7 +121,7 @@ let core_types = let tname str = let n = String.concat "__" (ExtString.String.nsplit str ".") in - if Hashtbl.mem keywords ("_" ^ n) then "__" ^ n else n + ident n let is_gc_ptr = function | HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HType | HRef _ | HMethod _ | HPacked _ -> false @@ -844,7 +843,10 @@ let generate_function ctx f = | OSShr (r,a,b) -> sexpr "%s = %s >> %s" (reg r) (reg a) (reg b) | OUShr (r,a,b) -> - sexpr "%s = ((unsigned)%s) >> %s" (reg r) (reg a) (reg b) + (match rtype r with + | HI64 -> sexpr "%s = ((uint64_t)%s) >> %s" (reg r) (reg a) (reg b) + | _ -> sexpr "%s = ((unsigned)%s) >> %s" (reg r) (reg a) (reg b) + ); | OAnd (r,a,b) -> sexpr "%s = %s & %s" (reg r) (reg a) (reg b) | OOr (r,a,b) -> diff --git a/std/hl/_std/haxe/NativeStackTrace.hx b/std/hl/_std/haxe/NativeStackTrace.hx index eada6faf0be..cb78b66ee00 100644 --- a/std/hl/_std/haxe/NativeStackTrace.hx +++ b/std/hl/_std/haxe/NativeStackTrace.hx @@ -29,6 +29,9 @@ class NativeStackTrace { var count = callStackRaw(null); var arr = new NativeArray(count); callStackRaw(arr); + // This will avoid errors when compiling hl/c on unix + // See https://github.com/HaxeFoundation/haxe/pull/11382 for long term fix + if (arr.length == 0) return arr; return arr.sub(1, arr.length - 1); } diff --git a/tests/misc/hl/reserved-keywords/Macro.macro.hx b/tests/misc/hl/reserved-keywords/Macro.macro.hx new file mode 100644 index 00000000000..a47548b6cea --- /dev/null +++ b/tests/misc/hl/reserved-keywords/Macro.macro.hx @@ -0,0 +1,37 @@ +import haxe.macro.Context; + +using haxe.macro.Tools; + +class Macro { + public static function build() { + var fields = Context.getBuildFields(); + var keywords = [ + "auto", "bool", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", + "if", "int", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", + "void", "volatile", "while", + // Values + "NULL", "true", "false", + // MS specific + "asm", "dllimport2", "dllexport2", "naked2", "thread2", + // reserved by HLC + "t", + // GCC + "typeof", + // C11 + "_Alignas", "_Alignof", "_Atomic", "_Bool", "_Complex", "_Generic", "_Imaginary", "_Noreturn", "_Static_assert", "_Thread_local", "_Pragma", + "inline", "restrict" + ]; + + var pos = Context.currentPos(); + + for (k in keywords) + fields.push({ + pos: pos, + name: "_test_" + k, + meta: [{pos: pos, name: ":native", params: [macro $v{k}]}], + kind: FVar(macro :String, null) + }); + + return fields; + } +} diff --git a/tests/misc/hl/reserved-keywords/Main.hx b/tests/misc/hl/reserved-keywords/Main.hx new file mode 100644 index 00000000000..b38e4ddc53e --- /dev/null +++ b/tests/misc/hl/reserved-keywords/Main.hx @@ -0,0 +1,4 @@ +@:build(Macro.build()) +class Main { + public static function main() {} +} diff --git a/tests/misc/hl/reserved-keywords/compile.hxml b/tests/misc/hl/reserved-keywords/compile.hxml new file mode 100644 index 00000000000..37462699195 --- /dev/null +++ b/tests/misc/hl/reserved-keywords/compile.hxml @@ -0,0 +1,2 @@ +-main Main +-hl bin/test.c diff --git a/tests/runci/System.hx b/tests/runci/System.hx index 3e5ff48c8be..0db5c6b95fe 100644 --- a/tests/runci/System.hx +++ b/tests/runci/System.hx @@ -133,6 +133,15 @@ class System { } } + static public function addToLIBPATH(path:String):Void { + infoMsg('Prepending $path to LD_LIBRARY_PATH.'); + switch (systemName) { + case "Windows": // pass + case "Mac", "Linux": + Sys.putEnv("LD_LIBRARY_PATH", path + ":" + Sys.getEnv("LD_LIBRARY_PATH")); + } + } + static function isLibraryInstalled(library:String):Bool { return new Process("haxelib", ["path", library]).exitCode() == 0; } diff --git a/tests/runci/targets/Hl.hx b/tests/runci/targets/Hl.hx index 0dd267a6e4c..679990e9027 100644 --- a/tests/runci/targets/Hl.hx +++ b/tests/runci/targets/Hl.hx @@ -65,6 +65,7 @@ class Hl { runCommand(hlBinary, ["--version"]); addToPATH(hlBuildBinDir); + addToLIBPATH(hlBuildBinDir); haxelibDev("hashlink", '$hlSrc/other/haxelib/'); } @@ -75,6 +76,23 @@ class Hl { runCommand("haxe", ["compile-hl.hxml"].concat(args)); runCommand(hlBinary, ["bin/unit.hl"]); + runCommand("haxe", ["compile-hlc.hxml"].concat(args)); + switch (systemName) { + case "Linux" if (isCi()): + runCommand("gcc", [ + "-o", "bin/hlc/main", + "bin/hlc/main.c", + "-Ibin/hlc/", + '-I$hlSrc/src', + '$hlBuildBinDir/fmt.hdll', + "-lm", + '-L$hlBuildBinDir', "-lhl" + ]); + runCommand("bin/hlc/main", []); + case _: + // TODO hl/c for mac/windows + } + changeDirectory(threadsDir); runCommand("haxe", ["build.hxml", "-hl", "export/threads.hl"]); runCommand(hlBinary, ["export/threads.hl"]); @@ -88,6 +106,16 @@ class Hl { // TODO: check output like misc tests do runCommand(hlBinary, ["eventLoop.hl"]); + changeDirectory(getMiscSubDir("hl/reserved-keywords")); + runCommand("haxe", ["compile.hxml"]); + switch (systemName) { + case "Linux" if (isCi()): + runCommand("gcc", ["-o", "bin/test", "bin/test.c", "-Ibin/", '-I$hlSrc/src', '-L$hlBuildBinDir', "-lhl"]); + runCommand("bin/test", []); + case _: + // TODO hl/c for mac/windows + } + changeDirectory(miscHlDir); runCommand("haxe", ["run.hxml"]); } diff --git a/tests/unit/src/unit/TestExceptions.hx b/tests/unit/src/unit/TestExceptions.hx index 0d00ca01558..385af032b13 100644 --- a/tests/unit/src/unit/TestExceptions.hx +++ b/tests/unit/src/unit/TestExceptions.hx @@ -253,6 +253,10 @@ class TestExceptions extends Test { var expected = null; var lineShift = 0; for(s in stacks) { + // This will avoid errors when compiling hl/c on unix + // See https://github.com/HaxeFoundation/haxe/pull/11382 for long term fix + #if hlc if (s.length == 0) continue; #end + if(expected == null) { expected = stackItemData(s[0]); } else { diff --git a/tests/unit/src/unit/TestMain.hx b/tests/unit/src/unit/TestMain.hx index 8b6cd45cd76..cb505fd0f7f 100644 --- a/tests/unit/src/unit/TestMain.hx +++ b/tests/unit/src/unit/TestMain.hx @@ -79,7 +79,7 @@ function main() { new TestNumericCasts(), new TestHashMap(), new TestRest(), - new TestHttp(), + #if !hlc new TestHttp(), #end #if !no_pattern_matching new TestMatch(), #end diff --git a/tests/unit/src/unit/issues/Issue10109.hx b/tests/unit/src/unit/issues/Issue10109.hx index 2ddb60eeee6..7793592d944 100644 --- a/tests/unit/src/unit/issues/Issue10109.hx +++ b/tests/unit/src/unit/issues/Issue10109.hx @@ -1,7 +1,8 @@ package unit.issues; class Issue10109 extends Test { -#if hl +// Disabled for hl/c until https://github.com/HaxeFoundation/haxe/pull/11382 is implemented +#if (hl && !hlc) @:pure(false) static function foo( o : String ) { return o.length; diff --git a/tests/unit/src/unit/issues/Issue9678.hx b/tests/unit/src/unit/issues/Issue9678.hx index b1003948c49..c2c44d9fd04 100644 --- a/tests/unit/src/unit/issues/Issue9678.hx +++ b/tests/unit/src/unit/issues/Issue9678.hx @@ -1,7 +1,7 @@ package unit.issues; class Issue9678 extends unit.Test { - #if !cpp + #if (!cpp && !hlc) function test() { var called = 0; function returnVoid() { From 0a35cb56af7bd67a452103d59aa7121b644b2fc5 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 16 Nov 2023 22:46:28 +0100 Subject: [PATCH 24/26] update changelog --- extra/CHANGES.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extra/CHANGES.txt b/extra/CHANGES.txt index 15370ca1278..a1ca8221f44 100644 --- a/extra/CHANGES.txt +++ b/extra/CHANGES.txt @@ -1,10 +1,11 @@ -2023-09-15 4.3.3 +2023-09-17 4.3.3 General improvements: all : improve extra field error range (#11335) all : better error messages for --connect hl : improve error message when hl_version is missing (#11086) + hl/c : compiler now adds hlc define when targeting hl/c (#11382) macro : update macro API restriction warnings when using -D haxe-next (#11377) Bugfixes: @@ -17,7 +18,8 @@ hl : make genhl respect Meta.NoExpr (#11257) hl : don't add bindings for non existing methods hl/c : add missing I64 mod support - hl/c : add bool to reserved keywords (#11293) + hl/c : rework reserved keywords (#11293, #11378) + hl/c : fix Int64 unsigned right shift overflow (#11382) java/cs: fix stack overflow from closures constraints (#11350) js : DOMElement insertAdjacentElement should not be pure (#11333) macro : catch trailing invalid syntax in Context.parseInlineString (#11368) From e1926e01775caddbbe0e14e0e6dc58ff591018d0 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 17 Nov 2023 06:55:46 +0100 Subject: [PATCH 25/26] [tests] add missing hxml --- tests/unit/compile-hlc.hxml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/unit/compile-hlc.hxml diff --git a/tests/unit/compile-hlc.hxml b/tests/unit/compile-hlc.hxml new file mode 100644 index 00000000000..46a19098ca4 --- /dev/null +++ b/tests/unit/compile-hlc.hxml @@ -0,0 +1,5 @@ +compile-each.hxml +--main unit.TestMain +-hl bin/hlc/main.c +-D hl-check +-D hl-ver=1.13.0 From de2888959192e92ad5849b2b66c2782ba775adcc Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 17 Nov 2023 20:17:50 +0100 Subject: [PATCH 26/26] Release 4.3.3 --- haxe.opam | 2 +- src/core/globals.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/haxe.opam b/haxe.opam index 6da637e9549..e370c420337 100644 --- a/haxe.opam +++ b/haxe.opam @@ -1,6 +1,6 @@ opam-version: "2.0" name: "haxe" -version: "4.3.2" +version: "4.3.3" synopsis: "Multi-target universal programming language" description: """ Haxe is an open source toolkit based on a modern, diff --git a/src/core/globals.ml b/src/core/globals.ml index 1b81264206f..0b7750208bc 100644 --- a/src/core/globals.ml +++ b/src/core/globals.ml @@ -27,7 +27,7 @@ type platform = | Hl | Eval -let version = 4302 +let version = 4303 let version_major = version / 1000 let version_minor = (version mod 1000) / 100 let version_revision = (version mod 100)