From 6a9a3b3efeac84927d73a1adf2fc3415f280044f Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Sun, 28 Oct 2012 19:31:31 -0700 Subject: [PATCH 1/3] Reorder core modules so that elixir will compile --- lib/elixir/lib/kernel/typespec.ex | 8 ++++---- lib/elixir/src/elixir_compiler.erl | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/elixir/lib/kernel/typespec.ex b/lib/elixir/lib/kernel/typespec.ex index 6fa8f8f7df6..3982681b7a7 100644 --- a/lib/elixir/lib/kernel/typespec.ex +++ b/lib/elixir/lib/kernel/typespec.ex @@ -51,7 +51,7 @@ defmodule Kernel.Typespec do def callback_from_spec(module, name, arity) do table = spec_table_for(module) pairs = :ets.lookup(table, { :spec, { name, arity } }) - specs = Enum.reduce(pairs, [], fn { _key, specs }, acc -> acc ++ specs end) + specs = :lists.foldl(fn { _key, specs }, acc -> acc ++ specs end, [], pairs) if specs != [] do :ets.insert(table, { { :callback, { name, arity } }, specs }) @@ -65,7 +65,7 @@ defmodule Kernel.Typespec do # Handle unions defp typespec({ :|, line, [_,_] } = exprs, vars, caller) do - exprs = Enum.reverse(collect_union(exprs)) + exprs = :lists.reverse(collect_union(exprs)) union = lc e inlist exprs, do: typespec(e, vars, caller) { :type, line, :union, union } end @@ -130,8 +130,8 @@ defmodule Kernel.Typespec do # Handle funs defp typespec({:fun, line, arguments}, vars, caller) when is_list(arguments) do args = - case Enum.reverse(arguments) do - [[{:do,h}]|t] -> fn_args(line, Enum.reverse(t), h, vars, caller) + case :lists.reverse(arguments) do + [[{:do,h}]|t] -> fn_args(line, :lists.reverse(t), h, vars, caller) [] -> [] _ -> [fn_args(line, arguments, vars, caller)] end diff --git a/lib/elixir/src/elixir_compiler.erl b/lib/elixir/src/elixir_compiler.erl index ab09fc12eef..63ed4be2e6d 100644 --- a/lib/elixir/src/elixir_compiler.erl +++ b/lib/elixir/src/elixir_compiler.erl @@ -205,11 +205,12 @@ core_main() -> [ "lib/elixir/lib/kernel.ex", "lib/elixir/lib/keyword.ex", + "lib/elixir/lib/list.ex", + "lib/elixir/lib/kernel/typespec.ex", "lib/elixir/lib/record.ex", "lib/elixir/lib/macro.ex", "lib/elixir/lib/macro/env.ex", "lib/elixir/lib/module.ex", - "lib/elixir/lib/list.ex", "lib/elixir/lib/code.ex", "lib/elixir/lib/protocol.ex", "lib/elixir/lib/enum.ex", @@ -217,8 +218,7 @@ core_main() -> "lib/elixir/lib/binary/inspect.ex", "lib/elixir/lib/binary/chars.ex", "lib/elixir/lib/list/chars.ex", - "lib/elixir/lib/gen_server/behaviour.ex", - "lib/elixir/lib/kernel/typespec.ex" + "lib/elixir/lib/gen_server/behaviour.ex" ]. %% ERROR HANDLING From a2b79e4331acb4d82851be8b75018640ef65c984 Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Sun, 28 Oct 2012 19:42:19 -0700 Subject: [PATCH 2/3] Correct dialyzer option use when adding Elixir to PLT --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1b8a22e99c2..b0b7f168e54 100644 --- a/Makefile +++ b/Makefile @@ -137,6 +137,6 @@ dialyze: compile .dialyzer.base_plt @ rm -f .dialyzer_plt @ cp .dialyzer.base_plt .dialyzer_plt @ echo "==> Adding Elixir to PLT..." - @ dialyzer --output_plt .dialyzer_plt --add_to_plt -r lib/elixir/ebin lib/ex_unit/ebin lib/mix/ebin lib/iex/ebin lib/eex/ebin + @ dialyzer --plt .dialyzer_plt --add_to_plt -r lib/elixir/ebin lib/ex_unit/ebin lib/mix/ebin lib/iex/ebin lib/eex/ebin @ echo "==> Dialyzing Elixir..." @ dialyzer --plt .dialyzer_plt -r lib/elixir/ebin lib/ex_unit/ebin lib/mix/ebin lib/iex/ebin lib/eex/ebin From a6d86d9f44155be44e91474425295fbf649c5263 Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Sun, 28 Oct 2012 20:01:42 -0700 Subject: [PATCH 3/3] Protocol compilation happens during the internal phase, therefore @callback and @type are not yet available --- lib/elixir/lib/protocol.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/elixir/lib/protocol.ex b/lib/elixir/lib/protocol.ex index 24cbdea52b2..27da93aa8d2 100644 --- a/lib/elixir/lib/protocol.ex +++ b/lib/elixir/lib/protocol.ex @@ -118,7 +118,7 @@ defmodule Protocol do @doc false def meta(functions, conversions, fallback, any, env) do contents = quote do - @type t :: unquote(generate_type(conversions, any)) + Kernel.Typespec.deftype(t :: unquote(generate_type(conversions, any))) def __protocol__(:name), do: __MODULE__ def __protocol__(:functions), do: unquote(:lists.sort(functions)) @@ -353,7 +353,7 @@ defmodule Protocol.DSL do # Convert the spec to callback if possible, # otherwise generate a dummy callback Kernel.Typespec.callback_from_spec(__MODULE__, name, arity) || - @callback unquote(name)(unquote_splicing(type_args)), do: term + Kernel.Typespec.defcallback(unquote(name)(unquote_splicing(type_args)), do: term) end end end