Commit Graph
3514 Commits
Author SHA1 Message Date
Sven Gehring a6cc1cc881 Fix formatter removing nested parens in call on call (#9211) 2019-07-10 20:18:57 +02:00
José Valim 0934eb6317 Only run tests if epmd is available, closes #9167 2019-07-10 19:14:48 +02:00
Eric Meadows-Jönsson eb33048dd0 Use Code.compiler_options[:no_warn_undefined] (#9207)
Closes #9192.
2019-07-09 22:22:39 +02:00
Eric Meadows-Jönsson f418ed247c Add ExCk chunk (#9203) 2019-07-09 21:23:38 +02:00
Allen Madsen f2c63bf030 Add Module.has_attribute?/2 (#9200) 2019-07-09 17:21:04 +02:00
Eric Meadows-Jönsson f88676db9b Move deprecation check to group pass (#9176) 2019-07-03 09:56:35 +02:00
Eric Meadows-Jönsson 9b6ec7bae7 Move unreachable function check from xref to group pass (#9168) 2019-06-28 10:25:49 +02:00
José Valim f38895cebb Add literal encoder option to Code.string_to_quoted 2019-06-19 00:04:08 +02:00
Eric Meadows-Jönsson 8a743c1ea9 Move module writing from mix to compiler (#9149) 2019-06-18 16:35:58 +02:00
José Valim 776225f4e1 Add end of expression token information
This also renames pairing_metadata to token_metadata,
as it mostly contains information about related tokens
and not necessarily pairs.
2019-06-18 00:25:22 +02:00
José Valim faefb0b882 Exposing pairing metadata (#9146)
This introduces five new metadata nodes:

  * `do` - contains metadata about do location in a function call with
    `do/end` blocks
  * `end` - contains metadata about end location in a function call with
    `do/end` blocks
  * `closing` - contains metadata about the closing pair, such as a `}`
    in a tuple or in a map, or such as the closing `)` in a function call
    with parens
  * `eol` - is set to true when the opening pair, such as `{` or `(`, are
    followed by the end of the line
  * `delimiter` - contains the opening for sigils (such as `"{"`, `"/"`,
    etc)
2019-06-17 16:38:52 +02:00
José Valim e2c78e8ba9 Rename :end metadata to less ambiguous :closing 2019-06-16 00:01:48 +02:00
Kip Cole 23a68035be Add inspect/2 callback to Calendar (#9128)
This commit introduces an optional callback `inspect/2`
that allows custom calendars to define a implementation 
for the `Inspect` protocol for `Time`,  `Date`,  
`DateTime`, and `NaiveDateTime`.
2019-06-12 16:25:03 +02:00
José Valim 6f3e1e021a build_info revision is at leasts 7 bytes 2019-06-11 13:50:36 +02:00
José Valim 78f5e9730b Keep struct fields ordered in types
Closes https://github.com/elixir-lang/ex_doc/issues/1016
2019-06-11 13:49:32 +02:00
José Valim 63a70cb19f Do not crash formatter on false positive sigils, closes #9123 2019-06-10 11:19:00 +02:00
José Valim a369190f42 Improve undefined struct messages 2019-06-10 11:19:00 +02:00
José Valim 98e60a8425 Add v1.10-ready deprecations 2019-06-04 17:28:08 +02:00
Fernando Tapia Rico c0c5a486f9 Use :timer.tc/1 to measure time diff in tests (#9113) 2019-06-04 11:44:44 +02:00
José Valim e1b68261b3 Raise on recursive macros (#9111)
Closes #9101.
2019-06-03 17:34:15 +02:00
José Valim 7e1d1650b3 Support unary functions in String.replace/4 (#9073)
We also deprecate the :insert_replaced option since the
anonymous functions is strictly superior.

Closes #9023.
2019-05-30 11:09:27 +02:00
Aleksei Matiushkin bb0e8a8850 Inspect.Opts.custom_options (#9096) 2019-05-30 10:10:48 +02:00
Eksperimental d4f8d419e4 Use https instead of http when servers are redirecting (#9094)
The servers are automatically redirecting from http:// to https://
2019-05-29 07:37:54 +02:00
José Valim dd17800b86 Do not expand ~ when not followed by a path separator 2019-05-27 00:16:39 +02:00
Fernando Tapia Rico 2490cc8e6a Add possible Windows errors to File.cd!/1 tests 2019-05-21 18:47:32 +02:00
Daniil Fedotov 145b7019ae Make regexes fall back to binary matching on incompatible runtime version (#9040)
Regexes are precompiled to binary values during code compilation.
These binary values may be incompatible between different PCRE versions
and OS endianness. This makes code less portable to achieve slight
performance improvement.

PCRE version and endianness are parts of Regex structure and may be
checked in runtime.

This commit adds this check and makes regex execution fall back 
to binary matching if versions are incompatible.

This slightly reduces performance (around 5% for simple regexes) for
compatible versions because there is an additional version read.
Also for incompatible versions it's as fast as binary matching.
2019-05-21 09:34:55 +02:00
kw7oe f44adfbeb0 Improve heredoc error message (#9048) 2019-05-19 10:10:11 +02:00
mguimas d63a7a46a7 Support default value when reading inexistent module attribute (#9041)
The private function Module.put_attribute/4 has been renamed to
Module.__put_attribute__/4 for consistency.
2019-05-15 09:28:35 +02:00
Eksperimental c8e700bec1 Improve List.duplicate/2 (#9044) 2019-05-15 09:17:10 +02:00
Eksperimental 341a2d1da8 Improve List.flatten/1,2 (#9045) 2019-05-15 09:16:31 +02:00
Eksperimental 30ab4ad968 Revert #8777 (#9042)
Revert "Remove Integer.to_string/1 and Integer.to_charlist/1 (#8777)"

This reverts commit 2622fd6b0a.
2019-05-15 09:15:55 +02:00
Eksperimental 3038401b09 Improve List.delete/2 (#9043) 2019-05-15 09:14:38 +02:00
Victor Rodrigues 7e6bac3450 Do not allow defmodule with special atoms (#9032)
Fixes #9030
2019-05-10 20:47:36 +02:00
José Valim 0229358f88 Ensure third element in location tuple is either nil or an integer 2019-05-09 10:59:13 +02:00
José Valim dc154f5db7 Allow developers to choose between sname and name in releases (#9024)
We default to --sname which provides safer security defaults.
2019-05-08 11:14:28 +02:00
Wojtek Mach 9a75975769 Add inspect_fun to Inspect.Opts (#8980)
Let's see some use cases. First we configure IEx to use our custom
function:

    iex> IEx.configure(inspect: [inspect_fun: &Pretty.inspect/2])
    :ok

1. Pretty-printing integers

    iex> :math.pow(2, 32) |> trunc()
    4_294_967_296

2. Inspect tuples as records

    iex> {:foo, :bar}
    {:foo, :bar}

    iex> {:person, "Alice", 30}
    #person(name: "Alice", age: 30)

3. Overwrite struct's Inspect implementation

    iex> URI.parse("https://elixir-lang.org")
    #URI<https://elixir-lang.org>

---

Code for the `Pretty.inspect/2` function:

    defmodule Pretty do
      def inspect(integer, opts) when is_integer(integer) do
        PrettyIntegers.inspect(integer, opts)
      end

      def inspect(tuple, opts) when is_tuple(tuple) do
        records = %{
          {:person, 2} => [:name, :age]
        }

        PrettyTuples.inspect(tuple, records, opts)
      end

      def inspect(%URI{} = uri, _opts) do
        Inspect.Algebra.concat(["#URI<", URI.to_string(uri), ">"])
      end

      def inspect(term, opts) do
        Inspect.inspect(term, opts)
      end
    end

    defmodule PrettyIntegers do
      def inspect(term, %Inspect.Opts{base: :decimal}) do
        pretty_decimal(term, "_")
      end

      def inspect(term, %Inspect.Opts{base: base}) do
        Integer.to_string(term, base_to_value(base))
        |> prepend_prefix(base)
      end

      def pretty_decimal(n, separator) when n < 0 do
        "-" <> pretty_decimal(abs(n), separator)
      end

      def pretty_decimal(n, separator) when n >= 1000 do
        left = div(n, 1_000)
        right = rem(n, 1_000)
        right_str = :io_lib.format("~3..0B", [right]) |> IO.iodata_to_binary
        pretty_decimal(left, separator) <> separator <> right_str
      end

      def pretty_decimal(n, _) do
        Integer.to_string(n)
      end

      defp base_to_value(base) do
        case base do
          :binary  -> 2
          :octal   -> 8
          :hex     -> 16
        end
      end

      defp prepend_prefix(value, base) do
        prefix = case base do
          :binary -> "0b"
          :octal  -> "0o"
          :hex    -> "0x"
        end
        prefix <> value
      end
    end

    defmodule PrettyTuples do
      import Inspect.Algebra

      def inspect({}, _records, opts), do: inspect_tuple([], opts)

      def inspect(tuple, records, opts) do
        list = Tuple.to_list(tuple)
        [record_name | values] = list

        case record_fields(records, record_name, tuple) do
          {:ok, fields} ->
            inspect_record(record_name, fields, values, opts)

          _ ->
            inspect_tuple(list, opts)
        end
      end

      defp record_fields(records, record_name, tuple) do
        fields_size = tuple_size(tuple) - 1
        Map.fetch(records, {record_name, fields_size})
      end

      defp inspect_tuple(list, opts) do
        inspect("{", list, "}", &to_doc/2, :flex, opts)
      end

      defp inspect_record(record_name, fields, values, opts) do
        kwlist = Enum.zip(fields, values)
        inspect("##{record_name}(", kwlist, ")", &Inspect.List.keyword/2, :strict, opts)
      end

      defp inspect(open, list, close, fun, break, opts) do
        open = color(open, :tuple, opts)
        sep = color(",", :tuple, opts)
        close = color(close, :tuple, opts)
        container_opts = [separator: sep, break: break]
        container_doc(open, list, close, opts, fun, container_opts)
      end
    end
2019-05-03 17:42:58 +02:00
José Valim 141915625d Consider @file attribute on undefined locals, closes #9005 2019-05-02 20:20:21 +02:00
José Valim 59fcce0b92 Unify error handling and compiler deadlock checking (#9009) 2019-05-02 16:27:13 +02:00
José Valim 89216bbe06 Do not raise on deadlock on ensure_compiled 2019-04-30 12:52:56 +02:00
Andrea Leopardi b3fb4bd7f7 Deprecate Enumerable keys in Map.{take|drop|split} (#8999)
"Keyword.{take|drop|split}" don't offer support for an Enumerable of
keys to take/drop/split based on. However, the "Map" counterparts do.
With this commit, we hard-deprecate support for Enumerables of keys in
"Map.{take|drop|split}". Only lists of keys are allowed.
2019-04-30 09:58:07 +02:00
Tomáš Janoušek 8d079862dc Fix columns in tokenize of dot_call_op (#8995)
handle_dot already gets the column of `(` from strip_dot_space.
2019-04-29 23:34:08 +02:00
José Valim 44fae5cc7a Support :force_do_end_blocks in formatter (#8978) 2019-04-24 09:27:59 +02:00
Frank Hunleth 649339aa95 Fix ETS leak in Registry.register
This fixes an issue where a registry's PIDPartition table would gain an
entry each time after the first call to Registry.register on a unique
registry.

We also guarantee unregistered works generally with "tricky keys".

Closes #8611.

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2019-04-23 12:34:51 +02:00
Johanna Larsson e261b42413 Add Registry.select/2 (#8963) 2019-04-22 17:43:07 +02:00
José Valim 459319fb75 Improve warning for duplicate behaviours, closes #8965 2019-04-19 12:52:24 +02:00
Fernando Tapia Rico 075339a342 Optimize &super/arity and &super(&1) (#8962)
The previous implementation was generating an unnecessary
intermediate function when using `&super/arity`.

In addition, capture expressions using `super` with sequential
value placeholders (`&n`) were not optimized like other functions.
For example, the capture expression `&foo(&1, &2, &3)` is
optimized to `&foo/3` because the value placeholders (`&n`) are
sequential `&1, &2, &3`.
2019-04-18 19:22:04 +02:00
José Valim 8faa40ebff Add config providers (#8957) 2019-04-18 16:34:50 +02:00
Arjan Scherpenisse cef19c9365 Implement static_atom_encoder tokenizer option (#8956) 2019-04-14 19:44:17 +02:00
Glauber Campinho 382d363254 Check that the first letter of alias is upcase (#8947)
The current approach discards the __aliases__ tuple and
do a simple check that allows some strange behavior like:

```elixir
iex(1)> alias :lists, as: :"Elixir.foobar"
:lists
iex(2)> :"Elixir.foobar"
:"Elixir.foobar"
iex(3)> alias :"Elixir.foobar", as: Baz
:"Elixir.foobar"
iex(3)> Baz
:lists
```
2019-04-13 16:54:04 +02:00
José Valim 391e4f6c56 Improve invalid interpolation error message 2019-04-11 12:53:09 +02:00