Commit Graph
306 Commits
Author SHA1 Message Date
José Valim 7945446cb4 Allow preserving sigil metadata in container cursor to quoted
Closes #14243.
2026-03-13 20:03:34 +01:00
José Valim 85b1ad0764 Do not emit warnings during IEx parsing
Closes #15090.

Unfortunately, I could not write a test for this as the error
only happens when using actual I/O devices. When using the mock
device we use in tests, the warning appears as expected.
2026-02-18 13:45:56 +01:00
Łukasz Samson 65ff52aadf Catch-all clause for unbalanced terminators (#14694) 2025-08-31 09:50:55 +02:00
José Valim c1c8ebaa8f Tag / as an operator in fragments, closes #14643 2025-07-11 11:12:24 +02:00
José Valim 2350e83f5b Update ... to an operator in Code.Fragment 2025-07-11 11:12:24 +02:00
Eksperimental 352f2723a9 Use backticks around literals in documentation (#14633) 2025-07-10 09:36:20 +02:00
José Valim cf8689e498 Remove specs which are pass through and from private modules 2025-07-01 10:44:03 +02:00
Łukasz Samson e3f7759fde Replace keyword with concrete keyword lists in specs (#14611) 2025-06-30 17:24:28 +02:00
José Valim 9d4c91be2a Ensure block_keyword_or_binary_operator is handled in surround context, closes #14590 2025-06-21 03:25:36 -07:00
José Valim b82d2dfa02 Reduce allocation on Inspect.Algebra by using cons cells 2025-06-07 09:57:36 +02:00
José Valim 7f1fe47f6d Add Code.Fragment.lines/1 (#14493) 2025-05-28 11:04:30 +02:00
José Valim 32f7646eb4 Add block_keyword_or_binary_operator to Code.Fragment (#14414) 2025-04-08 12:06:24 +02:00
José Valim f628d9563b Add optimistic/pessimistic groups to Inspect.Algebra (#14403)
This is a simplified implementation of next_break_fits
with fewer corner cases.
2025-04-07 15:07:38 +02:00
José Valim 148135988c Fix flex break at group end 2025-04-06 23:14:30 +02:00
Jonatan Männchen 980500551c Inline Licence Info & Copyright for non-test files (#14256) 2025-02-07 21:11:09 +01:00
José Valim a56886969a Allow <<_::3*8>> in typespecs 2025-01-30 10:23:39 +01:00
José Valim ba945e918c Provide more AST around cursor fragments, closes #14118 2025-01-21 10:36:09 +01:00
José Valim 4285cea166 Improve container_cursor_to_quoted with trailing fragment, closes #14087 2024-12-23 12:23:58 +01:00
José Valim a1fe483e27 Do not convert fun() into (... -> any()) and vice-versa in typespecs 2024-12-15 15:17:57 +01:00
Jean Klingler 5f657f90b8 Add :migrate_call_parens_on_pipe formatter option (#14056) 2024-12-12 18:14:14 +09:00
José Valim 768fa4963e Optimize inspection of binaries
We have used this code:

    data = Base.encode64(:crypto.strong_rand_bytes(2_000_000))

    Mix.Tasks.Profile.Tprof.profile(
      fn -> inspect(data, printable_limit: :infinity) end,
      type: :memory
    )

The first result reported this:

    Profile results of #PID<0.106.0>
    #                                    CALLS      %      WORDS PER CALL
    Total                             10666685 100.00 9268308211   868.90
    :code.ensure_loaded/1                    1   0.00          3     3.00
    Inspect.BitString.inspect/2              1   0.00          4     4.00
    Inspect.Algebra.group/2                  1   0.00          4     4.00
    Inspect.Algebra.format/2                 1   0.00          6     6.00
    Inspect.Algebra.format/3                 3   0.00          8     2.67
    :erlang.iolist_to_binary/1               2   0.00         11     5.50
    anonymous fn/2 in Kernel.struct/2        1   0.00         17    17.00
    Inspect.Opts.new/1                       1   0.00         17    17.00
    Code.Identifier.escape/5           2666669   0.06    5333344     2.00
    String.recur_printable?/2          2666669   0.29   26666778    10.00
    Code.Identifier.escape_map/1       2666668  28.72 2662035405   998.26
    Code.Identifier.escape_char/1      2666668  70.93 6574272614  2465.35

As you can see, most of the allocations were in escape_char,
which makes sense: it will be invoked a lot for raw binaries
and it allocated lists, instead of relying on binary optimizations.

We reimplemented Code.Identifier.escape/5 to rely on binary
optimizations which then yielded this:

    Profile results of #PID<0.112.0>
    #                                   CALLS      %    WORDS PER CALL
    Total                             5333350 100.00 26666864     5.00
    :code.ensure_loaded/1                   1   0.00        3     3.00
    Inspect.BitString.inspect/2             1   0.00        4     4.00
    Inspect.Algebra.group/2                 1   0.00        4     4.00
    Inspect.Algebra.format/2                1   0.00        6     6.00
    Code.Identifier.escape/4                1   0.00        8     8.00
    Code.Identifier.escape/5          2666669   0.00        8     0.00
    Inspect.Algebra.format/3                3   0.00        8     2.67
    :erlang.iolist_to_binary/1              2   0.00       11     5.50
    anonymous fn/2 in Kernel.struct/2       1   0.00       17    17.00
    Inspect.Opts.new/1                      1   0.00       17    17.00
    String.recur_printable?/2         2666669 100.00 26666778    10.00

Now the allocations are all on `recur_printable?/2`. By running this
command, we can find out why it is allocating so much:

    ERL_COMPILER_OPTIONS=bin_opt_info elixir lib/elixir/lib/string.ex

It happens that, due to a catch all, new binary contexts had to be
allocated. By addressing that, we now get:

    Profile results of #PID<0.119.0>
    #                                   CALLS      % WORDS PER CALL
    Total                             5333350 100.00    91     0.00
    :code.ensure_loaded/1                   1   3.30     3     3.00
    Inspect.BitString.inspect/2             1   4.40     4     4.00
    Inspect.Algebra.group/2                 1   4.40     4     4.00
    String.recur_printable?/2         2666669   5.49     5     0.00
    Inspect.Algebra.format/2                1   6.59     6     6.00
    Code.Identifier.escape/4                1   8.79     8     8.00
    Code.Identifier.escape/5          2666669   8.79     8     0.00
    Inspect.Algebra.format/3                3   8.79     8     2.67
    :erlang.iolist_to_binary/1              2  12.09    11     5.50
    anonymous fn/2 in Kernel.struct/2       1  18.68    17    17.00
    Inspect.Opts.new/1                      1  18.68    17    17.00

Which is several orders of magnitude fewer words. We basically
allocate the new escaped binary and a few extra bytes.

Closes #14029.
2024-12-03 18:34:59 +01:00
José Valim 8eba863f8f Properly track stab inside container_cursor_to_quoted, closes #13826 2024-11-25 14:46:23 +01:00
Jonatan Kłosko e54b87c181 Fix formatter adding extra escapes to remote call functions (#13960) 2024-11-04 14:37:46 +01:00
José Valim 76faed3cb9 Add ansi escapes to typing violations 2024-10-27 11:02:39 +01:00
José Valim 09d43562e7 Fix edge case in normalizer for keyword args (#13924)
Closes #13895.
Closes #13916.
2024-10-22 16:56:01 +02:00
Jean Klingler 673fe4a893 Fix crash in Macro.to_string/1 on invalid sigils (#13905) 2024-10-17 15:38:49 +09:00
Jean Klingler f99c856927 Code.Fragment.surround_context/2 handles &123 as :capture_arg (#13847) 2024-10-17 07:18:56 +09:00
José Valim e2556fd478 Clarify behaviour of Macro.to_string on invalid ASTs
Closes #13875.
2024-10-02 08:48:49 +02:00
Matt Enlow 2a25d4e1f4 migrate_unless: don't use |> Kernel.!() in conditions in the head (#13857) 2024-09-25 06:18:28 +09:00
Jean Klingler b5282802a7 Disable migrate_unless within defmacro and remove dbg for unless (#13850)
* Disable migrate_unless within defmacro

* Delete test for unless expression dbg

* Remove dbg support for unless
2024-09-22 20:04:23 +09:00
Jean Klingler 5902c29ad5 Add :migrate_unless option to formatter (#13844) 2024-09-20 23:00:01 +09:00
Jean Klingler fb065b7709 Fix Code.Fragment.surround_context for keyword keys (#13843) 2024-09-20 17:53:32 +09:00
Jean Klingler 5eddb4bbfe Rework migrate options for the formatter (#13841) 2024-09-20 17:34:59 +09:00
Jean Klingler 8e31621327 Format charlists as ~c sigils in doc (#13842) 2024-09-20 16:14:30 +09:00
José Valim b799e9eda4 Revert formatter changes to ||| and &&&, closes #13711 2024-07-29 02:23:57 +02:00
José Valim d9cf285d71 Enforce parens when formatting on more operators (#13711)
* On bitwise operators

* On right precedence operators which are semantically
  non-associative (such as -- and potentially ---)
2024-07-08 18:23:14 +02:00
Jean Klingler 0793fc91b9 Inspect special purpose chars using their unicode representation (#13676)
This reduces confusion when working with zero-width characters or alternative spaces.

Relates to #13673
2024-06-19 16:05:17 +09:00
José Valim 25e6ce4271 Add pending deprecations 2024-05-24 13:11:29 +02:00
José Valim d7ea2fa2e4 Handle cursor completion inside fn/rescue/catch/else/after 2024-05-14 17:04:57 +02:00
José Valim 67c3ad5196 Add brackets around keyword lists when formatting with when, closes #13503 2024-04-23 09:34:03 +02:00
José Valim 80af632a7e Wrap (a -> b) into literals instead of plain lists, closes #13358 2024-02-24 22:48:05 +01:00
Jean Klingler 5ec63f0e1a Fix charlist formatting issue on '\"' (#13364) 2024-02-24 00:02:00 +09:00
José Valim 6655d40376 Streamline and document the parser 2024-02-07 15:06:48 +01:00
José Valim d68c8d6cdd Unify handling of .. and ... 2024-02-07 12:26:39 +01:00
José Valim ef0ce41d4d Remove unecessary line in code normalizer 2024-02-06 13:25:01 +01:00
Jean Klingler bc50d94943 Fix Code.Normalizer for keyword operand with :do key (#13250) 2024-01-13 17:58:45 +09:00
José Valim b135a12aeb Revert "Consider surround context until end whenever possible"
This reverts commit a65dae971f.

Closes #13150.
2023-12-04 22:35:27 +10:00
Jean Klingler e58e267586 Formatter keeps quotes in atom keys (#13108) 2023-11-15 21:35:25 +09:00
Wojtek Mach 8b7ce389de Preserve column when translating typespecs (#13101) 2023-11-14 09:58:36 +01:00
José Valim a48c2d5dd2 Remove deprecated code and add TODOs 2023-11-14 00:51:34 +01:00