Skip to content

Track application boundaries #9847

@josevalim

Description

@josevalim

After a conversation with @sasa1977, it seems now possible to track application boundaries in Mix by using compilation tracers. The idea is: if a user calls a module that does not belong to any of the applications listed in the mix.exs, a warning should be emitted. The process is roughly this:

  1. Move the application computation code in here to Mix.Project and cache it. It should return a map like this: %{app => :runtime | :compile}. Only runtime deps should go to the .app file.

  2. When compiling Elixir code, get all of the applications above, load them, and store their modules in a ETS table with runtime | compile as value. Note :mix and :ex_unit need to be special cased to always be introduced.

  3. Define a tracer that runs module invocations against the ETS table. The tracer should always be added here. If a call violates the application boundary, it is stored somewhere.

  4. Once all code is compiled, we go through all violations, rule out any violation to modules for the current application itself, and define warnings for the remaining ones. This needs to be done inside "lib/mix/compilers/elixir.ex".

We don't need to cache lookups because a change in the applications/dependencies will recompile the whole project. Furthermore, if warnings are emitted during compilation, they are automatically cached for replayability. The only concern about this task is time spent on building the ETS table but this can likely be cached.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions