From 150a8a1dcd3610d5ff875e00a1c8779894456ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 23 Dec 2014 22:26:04 +0100 Subject: [PATCH] Fix bootstrap issues --- lib/elixir/lib/macro.ex | 2 +- lib/elixir/lib/module.ex | 12 +++++------ lib/elixir/lib/protocol.ex | 26 ++++++++++++----------- lib/elixir/src/elixir_bootstrap.erl | 2 +- lib/elixir/src/elixir_code_server.erl | 6 +----- lib/elixir/src/elixir_def_overridable.erl | 6 +++--- lib/elixir/src/elixir_lexical.erl | 6 +++--- lib/elixir/src/elixir_locals.erl | 6 +++--- lib/elixir/src/elixir_module.erl | 13 ++++++------ 9 files changed, 37 insertions(+), 42 deletions(-) diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex index 50c4448202..7042519e06 100644 --- a/lib/elixir/lib/macro.ex +++ b/lib/elixir/lib/macro.ex @@ -833,7 +833,7 @@ defmodule Macro do :elixir_lexical.record_remote(receiver, env.lexical_tracker) {receiver, true} aliases -> - aliases = for alias <- aliases, do: elem(do_expand_once(alias, env), 0) + aliases = :lists.map(&elem(do_expand_once(&1, env), 0), aliases) case :lists.all(&is_atom/1, aliases) do true -> diff --git a/lib/elixir/lib/module.ex b/lib/elixir/lib/module.ex index 0ecebaad90..e0d8fb5495 100644 --- a/lib/elixir/lib/module.ex +++ b/lib/elixir/lib/module.ex @@ -684,7 +684,7 @@ defmodule Module do def make_overridable(module, tuples) do assert_not_compiled!(:make_overridable, module) - for tuple <- tuples do + :lists.foreach(fn tuple -> case :elixir_def.lookup_definition(module, tuple) do false -> {name, arity} = tuple @@ -692,10 +692,10 @@ defmodule Module do clause -> :elixir_def.delete_definition(module, tuple) - neighbours = if loaded?(Module.LocalsTracker) do - Module.LocalsTracker.yank(module, tuple) - else + neighbours = if :elixir_compiler.get_opt(:internal) do [] + else + Module.LocalsTracker.yank(module, tuple) end old = :elixir_def_overridable.overridable(module) @@ -704,7 +704,7 @@ defmodule Module do end, {1, clause, neighbours, false}, old) :elixir_def_overridable.overridable(module, merged) end - end + end, tuples) end @doc """ @@ -967,6 +967,4 @@ defmodule Module do raise ArgumentError, "could not call #{fun} on module #{inspect module} because it was already compiled" end - - defp loaded?(module), do: is_tuple :code.is_loaded(module) end diff --git a/lib/elixir/lib/protocol.ex b/lib/elixir/lib/protocol.ex index 205b6208a1..29d308209b 100644 --- a/lib/elixir/lib/protocol.ex +++ b/lib/elixir/lib/protocol.ex @@ -19,11 +19,12 @@ defmodule Protocol do defmacro def({name, _, args}) when is_atom(name) and is_list(args) do arity = length(args) - type_args = for _ <- :lists.seq(2, arity), do: quote(do: term) + type_args = :lists.map(fn _ -> quote(do: term) end, + :lists.seq(2, arity)) type_args = [quote(do: t) | type_args] - call_args = for i <- :lists.seq(2, arity), - do: {String.to_atom(<>), [], __MODULE__} + call_args = :lists.map(fn i -> {String.to_atom(<>), [], __MODULE__} end, + :lists.seq(2, arity)) call_args = [quote(do: t) | call_args] quote do @@ -440,7 +441,7 @@ defmodule Protocol do end # Define the implementation for builtins. - for {guard, mod} <- builtin do + :lists.foreach(fn {guard, mod} -> target = Module.concat(__MODULE__, mod) Kernel.def impl_for(data) when :erlang.unquote(guard)(data) do @@ -449,7 +450,7 @@ defmodule Protocol do false -> any_impl_for end end - end + end, builtin) @spec impl_for!(term) :: atom() | no_return() Kernel.def impl_for!(data) do @@ -609,16 +610,17 @@ defmodule Protocol do @doc false def __spec__?(module, name, arity) do signature = {name, arity} - specs = Module.get_attribute(module, :spec) + specs = Module.get_attribute(module, :spec) found = - for {:spec, expr, caller} <- specs, - Kernel.Typespec.spec_to_signature(expr) == signature do - Kernel.Typespec.define_spec(:callback, expr, caller) - true - end + :lists.map(fn {:spec, expr, caller} -> + if Kernel.Typespec.spec_to_signature(expr) == signature do + Kernel.Typespec.define_spec(:callback, expr, caller) + true + end + end, specs) - found != [] + :lists.any(& &1 == true, found) end ## Helpers diff --git a/lib/elixir/src/elixir_bootstrap.erl b/lib/elixir/src/elixir_bootstrap.erl index 97cf07fb21..647e09f9cf 100644 --- a/lib/elixir/src/elixir_bootstrap.erl +++ b/lib/elixir/src/elixir_bootstrap.erl @@ -44,7 +44,7 @@ define({Line,E}, Kind, Call, Expr) -> unless_loaded(Fun, Args, Callback) -> case code:is_loaded(?kernel) of {_, _} -> apply(?kernel, Fun, Args); - false -> Callback() + false -> Callback() end. env() -> diff --git a/lib/elixir/src/elixir_code_server.erl b/lib/elixir/src/elixir_code_server.erl index d9ee6525a6..8da5006462 100644 --- a/lib/elixir/src/elixir_code_server.erl +++ b/lib/elixir/src/elixir_code_server.erl @@ -30,12 +30,8 @@ start_link() -> init(ok) -> %% We attempt to load those modules here so throughout - %% the codebase we can use a code:is_loaded/1 check on - %% bootstrap instead of using the more expensive - %% code:ensure_loaded/1 multiple times. + %% the codebase we can avoid code:is_loaded/1 checks. _ = code:ensure_loaded('Elixir.Macro.Env'), - _ = code:ensure_loaded('Elixir.Module.LocalsTracker'), - _ = code:ensure_loaded('Elixir.Kernel.LexicalTracker'), %% The table where we store module definitions _ = ets:new(elixir_modules, [set, protected, named_table, {read_concurrency, true}]), diff --git a/lib/elixir/src/elixir_def_overridable.erl b/lib/elixir/src/elixir_def_overridable.erl index 46e2836ebc..b74d9ebe4c 100644 --- a/lib/elixir/src/elixir_def_overridable.erl +++ b/lib/elixir/src/elixir_def_overridable.erl @@ -47,10 +47,10 @@ store(Module, Function, GenerateName) -> false -> {Kind, Name} end, - case code:is_loaded('Elixir.Module.LocalsTracker') of - {_, _} -> + case elixir_compiler:get_opt(internal) of + false -> 'Elixir.Module.LocalsTracker':reattach(Module, Kind, {Name, Arity}, Neighbours); - _ -> + true -> ok end, diff --git a/lib/elixir/src/elixir_lexical.erl b/lib/elixir/src/elixir_lexical.erl index 999032ebcd..420c245d37 100644 --- a/lib/elixir/src/elixir_lexical.erl +++ b/lib/elixir/src/elixir_lexical.erl @@ -10,8 +10,8 @@ -define(tracker, 'Elixir.Kernel.LexicalTracker'). run(File, Dest, Callback) -> - case code:is_loaded(?tracker) of - {file, _} -> + case elixir_compiler:get_opt(internal) of + false -> {ok, Pid} = ?tracker:start_link(Dest), try Callback(Pid) @@ -20,7 +20,7 @@ run(File, Dest, Callback) -> warn_unused_imports(File, Pid), unlink(Pid), ?tracker:stop(Pid) end; - false -> + true -> Callback(nil) end. diff --git a/lib/elixir/src/elixir_locals.erl b/lib/elixir/src/elixir_locals.erl index ac7c5ad6f0..c3d857cbff 100644 --- a/lib/elixir/src/elixir_locals.erl +++ b/lib/elixir/src/elixir_locals.erl @@ -72,12 +72,12 @@ rewrite_clause(Else, _) -> Else. %% TRACKING setup(Module) -> - case code:is_loaded(?tracker) of - {file, _} -> + case elixir_compiler:get_opt(internal) of + false -> {ok, Pid} = ?tracker:start_link(), ets:insert(elixir_module:data_table(Module), {?attr, Pid}), ok; - false -> + true -> ok end. diff --git a/lib/elixir/src/elixir_module.erl b/lib/elixir/src/elixir_module.erl index 08b835d3a2..fe3ce719bb 100644 --- a/lib/elixir/src/elixir_module.erl +++ b/lib/elixir/src/elixir_module.erl @@ -202,8 +202,8 @@ process_external_resource(Line, File, Value) -> %% Types types_form(Line, File, Data, Forms0) -> - case code:ensure_loaded('Elixir.Kernel.Typespec') of - {module, 'Elixir.Kernel.Typespec'} -> + case elixir_compiler:get_opt(internal) of + false -> Types0 = get_typespec(Data, type) ++ get_typespec(Data, typep) ++ get_typespec(Data, opaque), @@ -215,7 +215,7 @@ types_form(Line, File, Data, Forms0) -> Forms2 = export_types_attributes(Types1, Forms1), typedocs_attributes(Types1, Forms2); - {error, _} -> + true -> Forms0 end. @@ -246,8 +246,8 @@ typedocs_attributes(Types, Forms) -> %% Specs specs_form(Data, Defmacro, Defmacrop, Forms) -> - case code:ensure_loaded('Elixir.Kernel.Typespec') of - {module, 'Elixir.Kernel.Typespec'} -> + case elixir_compiler:get_opt(internal) of + false -> Specs0 = get_typespec(Data, spec) ++ get_typespec(Data, callback), Specs1 = ['Elixir.Kernel.Typespec':translate_spec(Kind, Expr, Caller) || {Kind, Expr, Caller} <- Specs0], @@ -255,8 +255,7 @@ specs_form(Data, Defmacro, Defmacrop, Forms) -> translate_macro_spec(Spec, Defmacro, Defmacrop) end, Specs1), specs_attributes(Forms, Specs2); - - {error, _} -> + true -> Forms end.