File 5402-features-Speed-up-check-for-atoms-being-feature-keyw.patch of Package erlang
From 80cb66eadf5ebbb6799e49643e86fa46480def33 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cons=20T=20=C3=85hs?= <cons@erlang.org>
Date: Mon, 23 May 2022 16:39:21 +0200
Subject: [PATCH 2/3] [features] Speed up check for atoms being feature
keywords
---
lib/stdlib/src/erl_lint.erl | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index 1d9f723185..c2a38ca441 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -167,6 +167,9 @@ value_option(Flag, Default, On, OnVal, Off, OffVal, Opts) ->
:: #{ta() => #typeinfo{}},
exp_types=gb_sets:empty() %Exported types
:: gb_sets:set(ta()),
+ feature_keywords = %Keywords in
+ %configurable features
+ feature_keywords() :: #{atom() => atom()},
bvt = none :: 'none' | [any()], %Variables in binary pattern
gexpr_context = guard %Context of guard expression
:: gexpr_context()
@@ -4168,15 +4171,19 @@ test_overriden_by_local(Anno, OldTest, Arity, St) ->
St
end.
+feature_keywords() ->
+ Features = erl_features:all(),
+ G = fun(Ftr, Map) ->
+ Keywords = erl_features:keywords(Ftr),
+ Add = fun(Keyword, M) -> maps:put(Keyword, Ftr, M) end,
+ lists:foldl(Add, Map, Keywords)
+ end,
+ lists:foldl(G, #{}, Features).
+
%% keyword_warning(Anno, Atom, State) -> State.
%% Add warning for atoms that will be reserved keywords in the future.
%% (Currently, no such keywords to warn for.)
keyword_warning(Anno, Atom, St) ->
- Reserved =
- fun(Ftr) ->
- lists:member(Atom, erl_features:keywords(Ftr))
- end,
-
case is_warn_enabled(keyword_warning, St) of
true ->
case erl_anno:text(Anno) of
@@ -4184,10 +4191,10 @@ keyword_warning(Anno, Atom, St) ->
%% Don't warn for quoted atoms
St;
_ ->
- Ftrs = erl_features:all(),
- case lists:filter(Reserved, Ftrs) of
- [] -> St;
- [Ftr] ->
+ Keywords = St#lint.feature_keywords,
+ case maps:find(Atom, Keywords) of
+ error -> St;
+ {ok, Ftr} ->
add_warning(Anno, {future_feature, Ftr, Atom}, St)
end
end;
--
2.35.3