Commit Graph
1818 Commits
Author SHA1 Message Date
Fernando Tapia Rico a7019ac90a Use inspect/1 with values returned by __struct__/* (#8873)
__struct__/0,1 is not meant to return an AST. Using
Macro.to_string/1 might lead to incorrect error messages:

    defmodule MyStruct do
      def __struct__, do: {:ok, :one, :two}
      def __struct__(_), do: {:ok, :one, :two}
    end

    iex> %MyStruct{}
    ** (CompileError) iex:2: expected MyStruct.__struct__/1 to
       return a map with a :__struct__ key that holds the name
       of the struct (atom), got: ok
2019-03-08 23:24:45 +01:00
Fernando Tapia Rico 9cfd989f4b Use :elixir_aliases.inspect/1 with module aliases (#8869)
The `Module` variable in these cases is guaranteed to be a module
alias.
2019-03-08 22:49:55 +01:00
Fernando Tapia Rico b88cd49d8d Validate __struct__ key in map returned by __struct__/0,1 (#8864) 2019-03-07 12:12:30 +01:00
Eksperimental 4c3967339c Use in instead of on (#8854) 2019-03-04 10:29:28 +01:00
José Valim 954f276a96 Do not change super signature, pass info as metadata 2019-03-01 08:58:53 -08:00
Fernando Tapia Rico 0a81b27861 Raise if a macro is invoked before its definition (#8822) 2019-02-25 22:48:21 +01:00
Fernando Tapia Rico 34e0fcd923 Do not allow to override macros as functions (#8816)
And vice-versa.

Overriding a macro as a function (and vice-versa) might produce
undesired effects.

For example, it's not clear if the following code should or
should not raise:

    defmodule Foo do
      def foo, do: bar()
      defmacro bar, do: :ok
      defoverridable bar: 0
      def bar, do: :ok
    end

On top of that, `super` does not currently work for such cases.
2019-02-23 09:08:16 +01:00
José Valim 4f819651eb Use proper var_context in with optimization 2019-02-19 23:20:34 +01:00
Fernando Tapia Rico 1aeb445b40 Store overridable information more efficiently (#8799)
This is part of an ongoing effort to forbid overriding macros
with functions and vice-versa. New checks will require the
overridable information to be stored more efficiently.
2019-02-16 16:05:54 +01:00
Eksperimental 99d919e0c8 Use "code point" instead of "codepoint" (#8774)
That's the term it is used in the Unicode standard.
2019-02-06 11:21:03 +01:00
José Valim 3fd6cf5e91 Do not rely on map ordering when sorting specs, see #8689 2019-01-24 21:54:05 +01:00
Eksperimental 5bd907d126 Use hexadecimal notation in code points in tokenizer error msg (#8669) 2019-01-22 13:39:40 +01:00
Fernando Tapia Rico 4f9c6e6c01 Optimize generated code for catch-all else clauses (#8661)
Elixir's with is expanded into a series of nested cases. For
example, this code:

    with {:ok, a} <- fun_a(),
         {:ok, b} <- fun_b() do
      wa = fun_w(a)
      wb = fun_w(b)
    else
      error -> {:c, error}
    end

would be expanded to something similar to this:

    case fun_a() do
      {:ok, a} ->
        case fun_b() do
          {:ok, b} ->
            wa = fun_w(a)
            wb = fun_w(b)

          var1 ->
            case var1 do
              error -> {:c, error}
              var2 -> error({with_clause, var2})
            end
        end

      var1 ->
        case var1 do
          error -> {:c, error}
          var2 -> error({with_clause, var2})
        end
    end

The generated code can be optimized for else clauses that
only contain a single catch-all clause (a variable that would
bind everything). Applying this optimization, the code of the
example above would be:

    case fun_a() do
      {:ok, a} ->
        case fun_b() do
          {:ok, b} ->
            wa = fun_w(a)
            wb = fun_w(b)

          error ->
            {:c, error}
        end

      error ->
        {:c, error}
    end
2019-01-22 08:53:24 +01:00
José Valim 0ce62a2add Rely on IO.warn whenever possible 2019-01-18 14:59:20 +01:00
José Valim 3e673ac134 Ensure we support counters in bitstring size vars 2019-01-07 22:31:31 +01:00
Fernando Tapia Rico 7ad213b289 Error on undefined variables in bitstring segments (#8598)
Binary/bitstring matching allows to dynamically define the
`size` of the binary in certain conditions:

  * if the `size` variable is defined prior to the pattern
    match:

        iex> size = 8
        iex> <<a::size(size), rest::binary>> = "hello"
        iex> a
        104

  * if the `size` variable is matched within the same
    binary/bitstring match, prior to its use:

        iex> <<name_size::size(8), name::binary-size(name_size), _rest::binary>> = <<5, "Frank the Walrus">>
        iex> name
        "Frank"

Other cases are considered illegal patterns, for example:

    {name_size, <<name::binary-size(name_size), _rest::binary>>} = {5, "Frank the Walrus"}

This commit raises a `CompileError: undefined variable ...` for such cases.
2019-01-05 17:46:33 +01:00
José Valim 091886d176 Handle unquote in remote call, closes #8588 2019-01-05 09:17:23 +01:00
Wojtek Mach ca40d1594c Show docs for callback with multiple clauses (#8553)
* Merge callback's multiple clauses in elixir_erl.erl
* Simpler callbacks deduplication
2019-01-02 13:12:01 +01:00
José Valim 0e15f809bb Avoid race conditions on behaviour checks, closes #8568 2018-12-27 16:29:33 +01:00
José Valim 0c1df34645 Standardize more TODOs 2018-12-21 13:42:54 +01:00
José Valim d85ed42765 Update removal and deprecation annotations
In particular, all deprecated code would be removed on v2.0,
so we don't need to annotate dperecated code with a TODO to
remove it on v2.0.
2018-12-21 13:27:06 +01:00
José Valim 2d139352bb Fix cond scope and improve coverage, closes #8542 (#8544) 2018-12-21 12:54:04 +01:00
José Valim 5ce4b61991 Add :reduce to for comprehensions (#8531) 2018-12-21 12:51:28 +01:00
José Valim 3f6dd0b321 No longer wrap expression in binary as Erlang/OTP 20+ does it by default (#8530) 2018-12-16 20:23:24 +01:00
José Valim ec2e092fdd Add no_spawn_compiler_process option to previous OTP releases
Because Elixir may be compiled with Erlang/OTP 20
to run on Erlang/OTP 22.
2018-12-15 23:20:26 +01:00
Eksperimental bd37919247 Improvements to Operators guide (#8512) 2018-12-14 09:58:43 +01:00
José Valim bb5a66698c Raise for capture outside of function, closes #8516 2018-12-13 11:20:18 +01:00
Eksperimental f2d1b4209b ascii -> ASCII (#8499) 2018-12-10 09:24:34 +01:00
Björn Gustavsson 122dcbe90c Eliminate warning for an unused variable (#8431)
Fix a warning that has started to occur because of a recent bug fix in
Erlang/OTP (using fun M:F/A could suppress warnings for unused
variables).
2018-11-27 14:13:42 +01:00
Hans db9314374d Add special fn case to signature_to_binary (#8429) 2018-11-27 01:04:00 +01:00
José Valim 718263f823 Raise when passing invalid compiler flags to Elixir, closes #7839 2018-11-26 10:09:58 +01:00
José Valim 741ff046b7 Preserve user's choice on operators, closes #8417 2018-11-25 23:01:53 +01:00
Lars Wikman 8e08b3c16e Add missing spaces in error message (#8412) 2018-11-21 10:59:23 +01:00
Michał Muskała e89e9d874b Compile charlist interpolation more efficiently
Today charlist interpolation is quivalent to calling `String.to_charlist`
on the equivalent string interpolation. It can be more efficient by
leveraging chardata support in the `:unicode` module and encoding as a
list of literal binaries and results of `Kernel.to_string` calls for the
interpolated segments.
2018-11-20 17:54:13 +01:00
José Valim 774a9baa93 Resolve circular struct dependencies in typespecs (#8377)
Prior to this patch, if a module depends on the struct of
another module and that other module depends on the struct
of the first module inside typespecs, it would lead to a
compiler deadlock, which this deadlock would not happen
in "regular code".

This commit also adds a test to ensure @enforce_keys are
not enforced when expanding typespecs.

For now, we are using a compiler private API, but we should
provide a public version for it in a future commit.
2018-11-13 17:47:24 +01:00
Lau Taarnskov b8b1a4ba8a Add TimeZoneDatabase behaviour for time zone data.
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2018-11-13 17:43:59 +01:00
José Valim 929e58ca0e Make __info__ docs a callback, closes #8376 2018-11-12 14:16:40 +01:00
Eksperimental 28522ccb89 Use "etc." and not "etc" (#8379)
Command used to detect these typos:
$ ag -s "\betc[^.]"
2018-11-10 14:04:49 +01:00
Wojtek Mach 616263f9de Expand operands in size*unit bitstring modifier (#8375) 2018-11-08 19:42:55 +01:00
Eric Meadows-Jönsson d14f04c950 Change else clause error to warning (#8351) 2018-10-29 21:09:52 +01:00
José Valim 95bf439828 Update TODO notes 2018-10-29 19:04:19 +01:00
Fernando Tapia Rico d24ff660cd Avoid errors with more than one duplicated key (#8346)
Closes #8345
2018-10-26 17:44:09 +02:00
Fernando Tapia Rico 2d19ae4640 Remove backticks from error messages and test desc (#8343)
To keep consistency in the codebase.
2018-10-26 08:38:01 +02:00
Mitchell Hanberg 749d89139c Improve error message for invalid quoted expression (#8336) 2018-10-25 19:37:04 +02:00
Eksperimental bd9ac87d07 Update use of numbers as adjectives (#8309)
- Replace "two element tuples" with "two-element tuples" for every number in 1..10
- Replace "2-element tuples" with "two-element tuples" for every number
- "1-based" with "one-based"
- "0-based" with "zero-based"
2018-10-21 00:03:38 +02:00
Fernando Tapia Rico c190f09d5c Allow @type, @opaque, @typep, @spec, @callback, and @macrocallback to be used as module attributes (#8289)
Closes #8085
2018-10-18 22:45:13 +02:00
Fernando Tapia Rico 83519a33cd Remove warning related to imperative assignments (#8288)
Closes #8285.

This warning has to be removed because all of the forms were
unified in v1.7, making case/with/if to behave the same.
That leads to undesired warnings in cases such as:

    a = 1

    with {:ok, a} <- my_fun(a) do
      :ok
    end
2018-10-17 15:43:24 +02:00
José Valim 4a5bcaaa8e Ensure eval_quoted properly resets last definition, closes #8261 2018-10-09 20:49:38 +02:00
José Valim 1ca25436be Use the no_spawn_compiler_process in more recent release
See https://github.com/erlang/otp/pull/1972.
2018-10-03 14:02:46 +02:00
José Valim 159e9655d5 Bypass erl_lint and spawn compiler processes manually (#8241)
This speeds up the Elixir compiler from 5-10% as we no
longer do duplicate work on erl_lint and expand_records.
We also avoid the copying of messages by controlling
exactly when the compiler spawns new processes.
2018-10-02 11:18:44 +02:00