Commit Graph
289 Commits
Author SHA1 Message Date
Jonatan Kłosko 1c19c60abb Add source and behaviour information to docs chunk metadata (#13914) 2024-10-30 09:18:00 +01:00
José Valim c7fa5f95fc Add Macro.struct_info! 2024-10-26 09:21:04 +02:00
José Valim 8c5c421b58 Avoid compiling some values twice when building .beam 2024-06-14 09:06:56 +02:00
José Valim 1b6c31a0eb Avoid the number of duplicate traces on imports 2024-05-25 11:10:22 +02:00
José Valim d120affb11 Emit defmodule tracing event 2024-02-26 18:28:40 +01:00
José Valim aabe46536e Disable compiler optimizations only in module body 2023-12-10 03:23:45 +11:00
José Valim 08f315016f Add @nifs attributes 2023-10-25 23:53:24 +02:00
José Valim 44d3faad45 No longer track module as context inside after_compile 2023-10-11 15:53:41 +02:00
José Valim 58bb5194d3 Propagate diagnostics from inner compiler process 2023-07-06 09:41:57 +02:00
José Valim d4d7c8bcfd Raise when macros are given to dialyzer, closes #12597 2023-05-25 11:38:23 +02:00
José Valim a0f0f75ee8 Add Code.with_diagnostics/2, closes #12276 2023-05-16 11:52:59 +02:00
José Valim b24869687b Introduce mechanism to collect several errors in a module (#12275) 2022-11-28 15:40:30 +01:00
José Valim 749349205d Do not include module variables in prune_binding 2022-11-08 11:34:55 +01:00
José Valim 439a138089 Revert pruning of defmodule 2022-11-08 00:40:20 +01:00
José Valim 1fc747c75e Add prune binding to module tracing event 2022-11-08 00:40:20 +01:00
Marc-André Lafortune b5d40c6f99 Behaviour as runtime dependency (#12103) 2022-08-30 08:34:08 +02:00
José Valim c94924a6c2 List compile-time deps for after_verify 2022-08-29 23:37:21 +02:00
José Valim 03514d70eb Add @after_verify callback
@after_verify hooks are invoked right after the current module is verified for
undefined functions, deprecations, etc. A module is always verified after
it is compiled. In Mix projects, a module is also verified when any of its
runtime dependencies change. Therefore this is useful to perform verification
of the current module while avoiding compile-time dependencies.

Here are some sample use cases:

  * Ecto can use this validate associations consistently and effectively
  * Phoenix can use this to verify routes
  * Surface can use this to verify component attributes
2022-07-20 16:34:15 +02:00
José Valim 7913d5d02e Lazily expand module attributes to avoid compile-time deps
Before this patch, this code would add a compile-time
dependency to Bar and Baz:

    defmodule Foo do
      @mods [Bar, Baz]
      def example(arg) when arg in @mods, do: arg
    end

That's because Bar and Baz were read in the module body,
even though ultimately they are only expanded and used
inside a function.

This patch postpones the expansion of aliases until they
are used. So if `@mods` is only used inside functions,
no compile-time deps are added.

Closes #11714.
2022-07-14 16:36:43 +02:00
José Valim ed82538f9a Simplify passing of values to the checker 2022-07-12 12:55:48 +02:00
José Valim 5f0454d27d Start checker processes lazily 2022-07-12 12:13:04 +02:00
José Valim 4a5efd5ec3 Improve Inspect for structs (#11897)
* Inspect in the defstruct order
* Mark optional fields that match the default value when deriving
* Add __info__(:struct) with metadata
2022-06-03 23:32:17 +02:00
José Valim 7c8d6ffb46 Warn on underived derives, closes #11799 2022-05-06 12:44:06 +02:00
Daven 7ef962fe30 Warn if any of True, False, and Nil aliases are used (#11731) 2022-03-28 07:28:34 +02:00
José Valim 080528a308 Simplify contract between checker and compiler 2021-12-18 22:05:49 +01:00
José Valim 03d3119b53 Do not allow slashes in module names
Closes #11216.
2021-08-29 10:13:22 +02:00
José Valim 92a2eb6328 Add mix xref trace that shows all deps for a given file (#11184) 2021-08-17 18:04:15 +02: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
José Valim d65349b47c Add {:on_module, bytecode, :none} to compilation tracers
See #11145.
2021-07-27 13:17:31 +02:00
José Valim a355450af8 Ensure waiting is tracked across typespecs
The Elixir compiler spawns a separate process per file.
When a file has to wait on another module, Elixir tracks
in the compiler that the file is waiting.

However, every time a module is defined, the Elixir compiler
spawns a separate process to compile to .beam, and this
process may expand structs in the typespec. Since this
new process is no longer the original file process, Elixir
was not able to track its waiting time.

This PR address this issue by passing the original file_pid
to the .beam compiler process. Note though that, if we
change typespecs to be compiled in the original file process,
this change is no longer required, but at the moment there are
no plans to make such change.

Closes #11036.
2021-06-05 19:21:12 +02:00
José Valim 3c45984d2c Assume Elixir is not started when accessing configs 2021-05-21 12:02:15 +02:00
José Valim f2689a4b48 Clean up shared parallel checker table 2021-05-09 09:08:39 +02:00
José Valim 189fca62ca Reduce the amount of module map copies when compiling
Prior to this commit, compilation would copy the module map
(which is the map with the module definitions, attriubutes,
etc) multiple times. In particular, the module execution
process would pass it to the compiler. Then the module
execution process would send it to the parallel compiler
coordinator, which would pass it to the parallel checker
coordinator and then to each individual parallel checker.
That's four copies, which can be quite expensive since it
has the whole Elixir AST.

This commit makes it so it is copied only once. The map
is assembled inside the compiler process and then copied
to the checker process.

This has yielded good improvements in Elixir's test suite.

Before:

    Finished in 27.3 seconds (14.4s on load, 7.0s async, 5.8s sync)

After:

    Finished in 22.0 seconds (9.4s on load, 6.7s async, 5.8s sync)
2021-05-07 16:41:10 +02:00
José Valim 7f1f2dc13d Improve undefined function compilation errors 2021-04-18 08:58:20 +02:00
José Valim dcd0b6d4d1 Use persistent term for tokenizer and bootstrap 2021-04-01 10:45:15 +02:00
José Valim 1ab2c0b275 All @dialyzer module attributes also work for functions 2021-03-11 21:42:19 +01:00
José Valim 71d57f61a3 Validate dialyzer attributes, closes #10534 2021-03-10 11:13:41 +01:00
José Valim 7e84a615c1 Do not warn for attributes used in after_compile
Closes #10579.
2020-12-17 13:05:02 +01:00
José Valim eaa48e4f5b Allow @on_load to be private, closes #10438 2020-10-17 20:08:06 +02:00
Eksperimental 6d30dc12bc Rename struct attribute in defstruct (#10354)
Rename `@struct` to `@__struct__`.

Closes #10352
2020-09-20 20:26:25 +02:00
José Valim 4389a63c57 Do not propagate tracers to dynamic definitions, closes #10271 2020-08-18 20:06:44 +02:00
José Valim c58af67b84 Also track exports API via local deps 2020-06-25 15:09:14 +02:00
Ioannis Pinakoulakis 367fc1cb34 Typos on the erlang files (#10118) 2020-06-21 11:14:11 +02:00
Eric Meadows-Jönsson 6be29a5c41 Do not warn for functions generated by Erlang compiler (#9713) 2020-01-12 12:15:21 +01:00
José Valim dbf8a7a9fe Use version metadata in Erlang pass 2019-11-16 02:45:55 +01:00
Eric Meadows-Jönsson 623a91936b Track variable version globally (#9536)
Instead of incrementing the version for each variable individually we increment it globally for all variables. This means we can uniquely identify each variable assignment with only the version.
2019-11-15 17:18:39 +01:00
José Valim cf881389cf Remove unecessary Erlang macro 2019-11-01 19:19:54 +01:00
José Valim acc9b49208 Move unused_vars to its own variable 2019-10-29 17:17:53 +01:00
Glauber Campinho 688b1c6cc8 Execute callbacks on :elixir_compiler after all warnings are emitted (#9447)
Currently the callbacks on :elixir_compiler are called before the warnings of unused aliases and imports are emitted, causing the messages to not consumed during the compilation. This commit changes `:elixir_lexical.run/2` to `:elixir_lexical.run/3` splitting the callback in two, one during the execution to evaluate the forms and another to be called after all the warnings are emitted.

Fixes #9440
2019-10-26 10:58:28 +02:00
Eric Meadows-Jönsson 03e0a5dd5b Run checker on Code.require_file/1 (#9393)
Closes #9362.
2019-10-10 23:11:10 +02:00