@@ -561,15 +561,6 @@ defmodule Module.Types.Descr do
561561 def number_type? ( % { bitmap: bitmap } ) when ( bitmap &&& @ bit_number ) != 0 , do: true
562562 def number_type? ( _ ) , do: false
563563
564- @ doc """
565- Optimized version of `not empty?(intersection(list(), type))`.
566- """
567- def list_type? ( :term ) , do: true
568- def list_type? ( % { dynamic: :term } ) , do: true
569- def list_type? ( % { dynamic: % { list: _ } } ) , do: true
570- def list_type? ( % { list: _ } ) , do: true
571- def list_type? ( _ ) , do: false
572-
573564 ## Bitmaps
574565
575566 defp bitmap_to_quoted ( val ) do
@@ -917,7 +908,7 @@ defmodule Module.Types.Descr do
917908 end )
918909 end
919910
920- defp list_only ?( descr ) , do: subtype ?( Map . delete ( descr , :list ) , empty_list ( ) )
911+ defp non_empty_list_only ?( descr ) , do: empty ?( Map . delete ( descr , :list ) )
921912
922913 @ doc """
923914 Returns the head of a list.
@@ -931,22 +922,19 @@ defmodule Module.Types.Descr do
931922 def list_hd ( % { } = descr ) do
932923 case :maps . take ( :dynamic , descr ) do
933924 :error ->
934- has_empty = empty_list_type? ( descr )
935- is_list_type = list_only? ( descr )
925+ static_value = list_hd_static ( descr )
936926
937- if is_list_type and not has_empty do
938- { false , list_hd_static ( descr ) }
927+ if non_empty_list_only? ( descr ) and not empty? ( static_value ) do
928+ { false , static_value }
939929 else
940930 :badnonemptylist
941931 end
942932
943933 { dynamic , static } ->
944- has_empty = empty_list_type? ( static )
945- only_list = list_only? ( static )
946- is_dynamic_list = list_type? ( dynamic )
934+ dynamic_value = list_hd_static ( dynamic )
947935
948- if is_dynamic_list and only_list and not has_empty do
949- { is_dynamic_list , union ( dynamic ( list_hd_static ( dynamic ) ) , list_hd_static ( static ) ) }
936+ if non_empty_list_only? ( static ) and not empty? ( dynamic_value ) do
937+ { true , union ( dynamic ( dynamic_value ) , list_hd_static ( static ) ) }
950938 else
951939 :badnonemptylist
952940 end
@@ -981,22 +969,19 @@ defmodule Module.Types.Descr do
981969 def list_tl ( descr ) do
982970 case :maps . take ( :dynamic , descr ) do
983971 :error ->
984- has_empty = empty_list_type? ( descr )
985- is_list_type = list_only? ( descr )
972+ static_value = list_tl_static ( descr )
986973
987- if is_list_type and not has_empty do
988- { false , list_tl_static ( descr ) }
974+ if non_empty_list_only? ( descr ) and not empty? ( static_value ) do
975+ { false , static_value }
989976 else
990977 :badnonemptylist
991978 end
992979
993980 { dynamic , static } ->
994- has_empty = empty_list_type? ( static )
995- only_list = list_only? ( static )
996- is_dynamic_list = list_type? ( dynamic )
981+ dynamic_value = list_tl_static ( dynamic )
997982
998- if is_dynamic_list and only_list and not has_empty do
999- { is_dynamic_list , union ( dynamic ( list_tl_static ( dynamic ) ) , list_tl_static ( static ) ) }
983+ if non_empty_list_only? ( static ) and not empty? ( dynamic_value ) do
984+ { true , union ( dynamic ( dynamic_value ) , list_tl_static ( static ) ) }
1000985 else
1001986 :badnonemptylist
1002987 end
0 commit comments