Skip to content

Commit

Permalink
compiler: Remove opaque type deps from doc type analysis
Browse files Browse the repository at this point in the history
The types referred to by an opaque type should not be
included into the documentation chunk.
  • Loading branch information
garazdawi committed Feb 8, 2024
1 parent 78ebd83 commit f772331
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Binary file modified bootstrap/lib/compiler/ebin/beam_doc.beam
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/compiler/src/beam_doc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ extract_type_defs0(_, State) ->
%%
extract_type_dependencies({attribute, _Anno, TypeOrOpaque, {TypeName, TypeDef, TypeArgs}},
#docs{type_dependency = TypeDependency}=State)
when TypeOrOpaque =:= type; TypeOrOpaque =:= opaque ->
when TypeOrOpaque =:= type ->
Types = extract_user_types([TypeArgs, TypeDef], State),
Type = {TypeName, length(TypeArgs)},
digraph:add_vertex(TypeDependency, Type),
Expand Down
7 changes: 4 additions & 3 deletions lib/compiler/test/beam_doc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private_types(Conf) ->
MapValue2T, MapKey2T, MapValueT, MapKeyT,
FunRet2T, FunRetT, FunT, Complex, BoundedRetT,
ArgT, BoundedArgT, Private, HiddenExportT, PrivateCBT,
PublicT, PrivateT,
OpaqueT, PublicT, PrivateT,
%% Callbacks
CBar,
%% Functions
Expand All @@ -324,14 +324,15 @@ private_types(Conf) ->
?assertMatch({{type,bounded_ret_t,0}, _, _, none, #{exported := false}},BoundedRetT),
?assertMatch({{type,arg_t,0}, _, _, none, #{exported := false}},ArgT),
?assertMatch({{type,bounded_arg_t,0}, _, _, none, #{exported := false}},BoundedArgT),
?assertMatch({{type,private,0}, {28,2}, [<<"private()">>], hidden, #{exported := false}},Private),
?assertMatch({{type,private,0}, {30,2}, [<<"private()">>], hidden, #{exported := false}},Private),
?assertMatch({{type,hidden_export_t,0},_,[<<"hidden_export_t()">>],hidden,#{exported := true}},HiddenExportT),
?assertMatch({{type,private_cb_t,0},_,_,none,#{exported := false}},PrivateCBT),
?assertMatch({{type,opaque_t,0},_, [<<"opaque_t()">>], none,#{ exported := true}},OpaqueT),
?assertMatch({{type,public_t,0},_, [<<"public_t()">>], none,#{ exported := true}},PublicT),
?assertMatch({{type,private_t,0},_, [<<"private_t()">>], none,#{ exported := false}},PrivateT),
?assertMatch({{callback,bar,1},_,_,none,#{}},CBar),
?assertMatch({{function,bounded,2},_,_,none,#{}},Bounded),
?assertMatch({{function,hidden_type_exposed,0},{32,1},[<<"hidden_type_exposed()">>],none,#{}},HiddenTypeExposed),
?assertMatch({{function,hidden_type_exposed,0},{34,1},[<<"hidden_type_exposed()">>],none,#{}},HiddenTypeExposed),
?assertMatch({{function,hidden,0},_,[<<"hidden()">>],hidden,#{}},Hidden),
?assertMatch({{function,bar,0},_,[<<"bar()">>],none,#{}},Bar),

Expand Down
4 changes: 3 additions & 1 deletion lib/compiler/test/beam_doc_SUITE_data/private_types.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
-module(private_types).

-export([bar/0, hidden/0, hidden_type_exposed/0, bounded/2]).
-export_type([public_t/0, hidden_export_t/0, complex/1]).
-export_type([public_t/0, hidden_export_t/0, complex/1, opaque_t/0]).

-type private_t() :: integer(). %% In chunk because referred to by exported bar/0
-type public_t() :: integer(). %% In chunk because exported
-opaque opaque_t() :: local_t() | private_t(). %% In chunk because exported,
%% but local_t() not in chunk
-type private_cb_t() :: integer(). %% In chunk because referred to by callback
-type local_t() :: integer(). %% Not in chunk because only referred by non-exported function

Expand Down

0 comments on commit f772331

Please sign in to comment.