Commit Graph
1844 Commits
Author SHA1 Message Date
José Valim 10fd316439 Delegate Erlang/OTP version check to Elixir 2019-05-15 17:23:26 +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 81e5a57d51 Nest all terminator metadata under :end key 2019-05-09 10:28:18 +02:00
José Valim 7cd6ce4a32 Also provide nice error message on null bytes 2019-05-06 16:37:54 +02:00
José Valim 6ac1b99e0c Rely on bootstrap only during compilation 2019-05-04 16:43:18 +02:00
José Valim 141915625d Consider @file attribute on undefined locals, closes #9005 2019-05-02 20:20:21 +02:00
José Valim 7f41fa903b Only linify if keep was given 2019-05-02 18:57:44 +02:00
José Valim 59fcce0b92 Unify error handling and compiler deadlock checking (#9009) 2019-05-02 16:27:13 +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
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
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
José Valim b68ef52b94 No longer keep a field for tracking type in __ENV__ vars 2019-04-11 00:42:48 +02:00
José Valim e809326d81 Allow Code.ensure_compiled/2 to not raise on deadlocks
This is important when you may want to check if a module
is available but if that module is running a similar check
on you, you don't want the compiler to fail.
2019-04-01 13:04:00 +02:00
José Valim 51d1c4de4d Pass env compiler options to v3_core 2019-04-01 09:48:32 +02:00
José Valim 22bcddfa1b Ensure debug_info is kept in protocols, closes #8923 2019-03-31 10:57:55 +02:00
Fernando Tapia Rico ae6666f0d6 Ensure the struct name matches the given module
This change fixes inconsistencies when building structs: if the
struct was built using the map syntax the `:__struct__` key
was overridden by the given module name; however, if the struct
was built using `struct/1,2` the `:__struct__` key was kept.

For example:

    defmodule X do
      defstruct [:x]
    end

    defmodule Y do
      defdelegate __struct__, to: X
      defdelegate __struct__(args), to: X
    end

    iex> %Y{}
    %Y{x: nil}

    iex> struct(Y)
    %X{x: nil}

Closes #8800
2019-03-31 09:52:58 +02:00
José Valim 3673849e36 Use System.no_halt/1 instead of Process.sleep/1 in mix run
Otherwise :init.get_status will stay in
{:starting, :started} forever.
2019-03-27 00:17:21 +01:00
Fernando Tapia Rico 861ba87db4 Ensure guard checks when expanding string interpolations (#8905)
During the bitstring expansion, guard checks were avoided due to
a special case for inlining binaries during interpolation. These
changes ensure guards are checked.
2019-03-22 11:26:02 +01:00
José Valim a3c5820d12 Properly track files instead of modules in mix integration with lexical tracker 2019-03-15 00:06:41 +01:00
José Valim 914e32a741 Pass lexical_tracker on each_file callback 2019-03-14 23:22:34 +01:00
José Valim 018df4fbfd Simplify acquiring lock on Code.require_file 2019-03-14 21:55:46 +01:00
José Valim 88338bb99b Take nil lexical_tracker into account 2019-03-14 21:22:59 +01:00
José Valim b80ee75e2d Pass lexical tracker forward if available, closes #8893 2019-03-14 20:42:02 +01:00
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