Commit Graph
77 Commits
Author SHA1 Message Date
José Valim da637b7523 Collect function errors where possible in elixir_bitstring and elixir_expand 2022-11-28 16:15:34 +01:00
José Valim b24869687b Introduce mechanism to collect several errors in a module (#12275) 2022-11-28 15:40:30 +01:00
sabiwara e58f70a65c Refactor: use :elixir_bitstring to avoid duplication (#12271) 2022-11-25 16:00:37 +01:00
Michael Adkins 4dd730267a Add commas to bare usage of "however" where appropriate (#12119) 2022-09-06 20:29:01 +02:00
Andreas Lappe 487c24d518 Fix typo (#12068) 2022-08-12 12:49:10 +02:00
sabiwara 7dc718b292 Replace inner AST for bitstring modifiers (#12055) 2022-08-06 09:28:07 +02:00
sabiwara c64606b765 Warn on missing parentheses in bitstring modifiers (#11862) 2022-07-27 13:28:24 +02:00
José Valim 239f8f9e3b Require Erlang/OTP 24 2022-07-27 13:20:42 +02:00
José Valim 07cc16717b Allow any expression in bitstring size outside of matches/guards 2022-01-12 01:47:11 +01:00
Jorge Bejar 4c40630c08 EEP 52: Support for size expression in bitstring matching (#11558) 2022-01-11 21:42:28 +01:00
José Valim 5eb2efe543 Break Macro.Env apart (#11164)
Previously, the internal Elixir expansion pass worked directly on
Macro.Env. However, this poised an issue, if we want to track
more information in the pass, we ended up exposing it on
Macro.Env, making it larger, and potentially slowing down
operations such as __ENV__ serialization.

This commit refactors the expansion pass to work with two
structures, the Macro.Env struct and a #elixir_ex{} record.
2021-08-03 13:35:15 +02:00
Eksperimental 784b881b76 Standardize use of Erlang/OTP VERSION (#10867) 2021-04-03 17:11:57 +02:00
Wojtek Mach 68661dfa91 Support 16bit floats in bitstrings (#10740)
On OTP 24:

    iex> <<x::float-16>> = <<60, 0>>
    iex> x
    1.0
    iex> <<x::float-16>>
    <<60, 0>>

Before OTP 24 we'd get errors or wouldn't match:

    iex> <<1.0::float-16>>
    ** (ArgumentError) argument error while evaluating iex at line 1

    <<x::float-16>> = <<60, 0>>
    ** (MatchError) no match of right hand side value: <<60, 0>>

    iex> (fn <<x::float-16>> -> x; _ -> :nomatch end).(<<60, 0>>)
    :nomatch
2021-02-20 11:24:58 +01:00
José Valim 63837a720b Refactor binary handling 2020-04-05 20:15:50 +02:00
José Valim ba5a9030fe Improve error message for nested binaries in match without specifiers, closes #9908 2020-04-04 12:35:46 +02:00
José Valim 05eb5b2375 Do not show binary types if they are inferred 2020-02-23 10:26:11 +01:00
Eric Meadows-Jönsson e98284fbb0 Add checking of patterns in body (#9828) 2020-02-20 16:46:06 +01:00
José Valim d3b011947f Do not expand interpolation twice, closes #9709 2020-01-12 17:19:50 +01:00
José Valim dbf8a7a9fe Use version metadata in Erlang pass 2019-11-16 02:45:55 +01:00
José Valim c74bfa4a52 Only transform environment in match if necessary 2019-10-29 17:17:53 +01:00
José Valim 1c9b55ae6d Further optimize variable merging 2019-10-29 17:17:53 +01:00
José Valim acc9b49208 Move unused_vars to its own variable 2019-10-29 17:17:53 +01:00
José Valim 4992622be1 Remove a need to merge unused vars 2019-10-29 17:17:53 +01:00
José Valim 31e4a93bc6 Clean up Macro.Env and hide private fields 2019-07-25 22:07:51 +02:00
José Valim e80b55b21c Unify error handling and compiler deadlock checking (#9009) 2019-05-02 16:27:13 +02:00
Fernando Tapia Rico 94c0dd23d2 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 4c87c902c9 Ensure we support counters in bitstring size vars 2019-01-07 22:31:31 +01:00
Fernando Tapia Rico 7104ca20fd 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
Wojtek Mach c0317dcd64 Expand operands in size*unit bitstring modifier (#8375) 2018-11-08 19:42:55 +01:00
Glauber Campinho 6af3110b6a Small optimization on elixir_bitstring:expand/4 (#8074)
`elixir_env:mergea(EV, EC)` is always equivalent to `EV` so we can avoid the operation.
Similar to #8069
2018-08-12 10:05:59 +02:00
José Valim 2af6e62626 Ensure Macro.expand/2 does not change the meaning of interpolations 2018-08-11 20:42:24 +02:00
Tan Jay Jun d555a7fdbc Fix error typo in elixir_bitstring.erl (#8030)
[ci skip]
2018-08-02 15:02:17 +02:00
Aleksei Magusev d1156f4161 Handle nested bitstring pattern matching failures in a better way (#7370) 2018-02-20 23:43:14 +01:00
José Valim 90cd4e7050 Merge binaries and bitstrings when possible 2018-01-25 15:40:44 -02:00
José Valim d2fb3279f1 Perform merging of bitstring subinaries 2018-01-25 09:25:09 -02:00
José Valim 9d40e110d9 Move unused_vars check to Elixir land
This gives us better control over when and how unused variables are printed.

As a result, we are able to emit unused variable warnings in situations
we could not before. This also opens up the way for us to remove a
dependency on erl_lint and track types information, which allows us to
speed up compilation times about 5% and allow us to emit more performant
code in some situations.
2018-01-20 19:45:48 +01:00
José Valim 85becb02e8 Merge match_vars and prematch_vars 2018-01-20 19:42:08 +01:00
José Valim fd4dc4474a Process variable versioning on Elixir pass 2018-01-20 19:42:08 +01:00
Ivan Kozik dbabe33349 Fix a few spelling errors (#6525) 2017-09-01 10:17:57 +02:00
Glauber Campinho 953a3b2890 Do not crash for unknown var inside binary pattern in match (#6459) 2017-08-15 11:53:19 +02:00
José Valim 7acdd4e019 Do not raise when expanding dynamic size 2017-04-16 17:30:46 +02:00
José Valim beb4ce260c Fix bootstraping of elixir_bitstring 2017-03-05 18:42:38 +01:00
José Valim 62055875ba Inline binaries inside interpolation 2017-03-05 18:10:11 +01:00
José Valim 3cb4f2d3ad Do not require size for bound literals 2017-02-24 00:38:59 +01:00
José Valim c7b06a0ddb Check for float size on elixir_bitstring 2017-02-24 00:29:01 +01:00
José Valim 7f488e16ca Check for binary size in bitstring matches 2017-02-24 00:29:01 +01:00
José Valim cdaabf1824 Split bitstring logic into proper modules 2017-02-23 23:53:12 +01:00
José Valim 98745273fb Improve checking of bitstrings 2017-02-23 22:55:35 +01:00
Aleksei Magusev 30ba2c8527 Rename elixir_exp module to elixir_expand 2017-02-19 21:57:50 +01:00
Aleksei Magusev c1c009537a Rename m/2 helper macro to key/2 in the main header file 2017-02-19 21:56:05 +01:00