Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ jobs:
name: TestCoverage
path: cover/*

- name: Check specs vs inferred type signatures
if: ${{ matrix.deterministic }}
run: make check_specs

- name: Check reproducible builds
if: ${{ matrix.deterministic }}
run: taskset 1 make check_reproducible
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ GIT_TAG = $(strip $(shell head="$(call GIT_REVISION)"; git tag --points-at $$hea
SOURCE_DATE_EPOCH_PATH = lib/elixir/tmp/ebin_reproducible
SOURCE_DATE_EPOCH_FILE = $(SOURCE_DATE_EPOCH_PATH)/SOURCE_DATE_EPOCH

.PHONY: cover install install_man build_plt clean_plt dialyze test check_reproducible clean clean_elixir clean_man format docs Docs.zip Precompiled.zip zips
.PHONY: cover install install_man build_plt clean_plt dialyze test check_reproducible check_specs clean clean_elixir clean_man format docs Docs.zip Precompiled.zip zips
.NOTPARALLEL:

#==> Functions
Expand Down Expand Up @@ -141,6 +141,11 @@ install: compile
done
"$(MAKE)" install_man

check_specs: compile
$(Q) echo "==> Checking @specs against inferred type signatures..."
$(Q) bin/elixir lib/elixir/scripts/compare_specs_and_signatures.exs \
--exclusions lib/elixir/scripts/compare_specs_exclusions.txt

check_reproducible: compile
$(Q) echo "==> Checking for reproducible builds..."
$(Q) rm -rf lib/*/tmp/ebin_reproducible/
Expand Down
28 changes: 25 additions & 3 deletions lib/elixir/lib/module/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,33 @@ defmodule Module.Types do

@doc false
def warnings(module, file, attrs, defs, no_warn_undefined, cache) do
{warnings, _sigs} =
warnings(module, file, attrs, defs, no_warn_undefined, cache, fn _ -> :default end)

warnings
end

# Variant that allows type checking each definition against a custom
# argument domain (for example derived from its typespec): `domains`
# receives each fun_arity and returns either :default (the usual list of
# dynamics) or {mode, [arg_descr]} to be used as the expected argument
# types, where mode is :dynamic or :static. Also returns the local
# signatures inferred under those domains so callers can compare return
# types. Used by lib/elixir/scripts/compare_specs_and_signatures.exs.
@doc false
def warnings(module, file, attrs, defs, no_warn_undefined, cache, domains) do
impl = impl_for(attrs)

domain = fn def, fun_arity ->
case domains.(fun_arity) do
:default -> default_domain(:dynamic, def, fun_arity, impl)
{mode, args} when mode in [:dynamic, :static] and is_list(args) -> {mode, def, args}
end
end

finder = fn fun_arity ->
case :lists.keyfind(fun_arity, 1, defs) do
{_, _, _, _} = def -> default_domain(:dynamic, def, fun_arity, impl)
{_, _, _, _} = def -> domain.(def, fun_arity)
false -> false
end
end
Expand All @@ -233,13 +255,13 @@ defmodule Module.Types do
context =
Enum.reduce(defs, context(), fn {fun_arity, _kind, meta, _clauses} = def, context ->
# Optimized version of finder, since we already have the definition
finder = fn _ -> default_domain(:dynamic, def, fun_arity, impl) end
finder = fn _ -> domain.(def, fun_arity) end
{_kind, _inferred, context} = local_handler(meta, fun_arity, stack, context, finder)
context
end)

context = warn_unused_clauses(defs, stack, context)
context.warnings
{context.warnings, context.local_sigs}
end

defp warn_unused_clauses(defs, stack, context) do
Expand Down
Loading