Skip to content

Commit

Permalink
Ignore implicitly defined modules
Browse files Browse the repository at this point in the history
This includes modules such as protocol implementations defined via `@derive`. Previously, such modules would be reported as unclassified.
  • Loading branch information
sasa1977 committed Mar 13, 2024
1 parent 61d0e0e commit b22ad66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/boundary/mix/compiler_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ defmodule Boundary.Mix.CompilerState do
end
end

@spec encountered_modules(Application.app()) :: [module]
def encountered_modules(app), do: ets_keys(modules_table(app))

defp module_metas(app) do
table = modules_table(app)

Expand Down
20 changes: 17 additions & 3 deletions lib/boundary/mix/view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Boundary.Mix.View do
into: view.module_to_app,
do: {module, app}

main_app_modules = Boundary.Mix.app_modules(view.main_app)
main_app_modules = main_app_modules(view.main_app)
main_app_boundaries = load_app_boundaries(view.main_app, main_app_modules, module_to_app)

if MapSet.equal?(view.external_deps, all_external_deps(view.main_app, main_app_boundaries, module_to_app)) do
Expand Down Expand Up @@ -104,7 +104,7 @@ defmodule Boundary.Mix.View do
end

defp classify(main_app, module_to_app) do
main_app_modules = Boundary.Mix.app_modules(main_app)
main_app_modules = main_app_modules(main_app)
main_app_boundaries = load_app_boundaries(main_app, main_app_modules, module_to_app)

classifier = classify_external_deps(main_app_boundaries, module_to_app)
Expand Down Expand Up @@ -189,10 +189,24 @@ defmodule Boundary.Mix.View do

defp unclassified_modules(view) do
# gather unclassified modules of this app
for module <- Boundary.Mix.app_modules(view.main_app),
for module <- main_app_modules(view.main_app),
not Map.has_key?(view.classifier.modules, module),
not Boundary.protocol_impl?(view, module),
into: MapSet.new(),
do: module
end

defp main_app_modules(app) do
# We take only explicitly defined modules which we've seen in the compilation tracer. This
# allows us to drop some implicit modules, such as protocol implementations which are injected
# via `@derive`.

MapSet.intersection(
# all app modules
MapSet.new(Boundary.Mix.app_modules(app)),

# encountered modules (explicitly defined via defmodule, defimpl, or some other macro)
MapSet.new(CompilerState.encountered_modules(app))
)
end
end

0 comments on commit b22ad66

Please sign in to comment.