Skip to content

xref: Add -doc and -unsafe support#10839

Open
jhogberg wants to merge 4 commits intoerlang:maintfrom
jhogberg:john/tools/xref-undocumented
Open

xref: Add -doc and -unsafe support#10839
jhogberg wants to merge 4 commits intoerlang:maintfrom
jhogberg:john/tools/xref-undocumented

Conversation

@jhogberg
Copy link
Contributor

This PR is required to make #10431 happen. It's up for review but will not be merged as-is, as bootstrap etc must be wrangled separately before merging.

This commit must be followed by an update of preloaded and
bootstrap modules before any `-unsafe` directives are added to
OTP.
@jhogberg jhogberg requested a review from bjorng March 12, 2026 08:59
@jhogberg jhogberg self-assigned this Mar 12, 2026
@jhogberg jhogberg added the team:VM Assigned to OTP team VM label Mar 12, 2026
@garazdawi
Copy link
Contributor

Is the -unsafe attribute only meant to be used by Erlang/OTP, or is it meant to be available to everyone? Should the functions that are unsafe have metadata in the doc chunk so that ExDoc can render it?

@jhogberg
Copy link
Contributor Author

Is the -unsafe attribute only meant to be used by Erlang/OTP, or is it meant to be available to everyone? Should the functions that are unsafe have metadata in the doc chunk so that ExDoc can render it?

The idea is to make it available to everyone, the only privilege is that there will be compiler warnings for calls to unsafe functions within Erlang/OTP (everyone else will have to leave that to xref). I'll update EEP48/ExDoc separately.

%% Finds all cross-application calls to explicitly hidden
%% functions
xref:q(XR, "((Fun) strict AE) || DC_2", []).
@jhogberg jhogberg force-pushed the john/tools/xref-undocumented branch from 5ef6b33 to 7789ff1 Compare March 12, 2026 10:47
Comment on lines +42 to +62
crypto:private_decrypt/4 unsafe=29
crypto:private_encrypt/4 unsafe=29
crypto:public_decrypt/4 unsafe=29
crypto:public_encrypt/4 unsafe=29
erlang:binary_to_atom/_ unsafe=29
erlang:binary_to_term/_ unsafe=29
erlang:list_to_atom/1 unsafe=29
file:consult/_ unsafe=29
file:path_consult/_ unsafe=29
http_uri:_/_ unsafe=29
os:cmd/_ unsafe=29
public_key:decrypt_private/2 unsafe=29
public_key:decrypt_public/2 unsafe=29
public_key:encrypt_private/2 unsafe=29
public_key:encrypt_public/2 unsafe=29

## Possibly unsafe
public_key:decrypt_private/3 unsafe=29
public_key:decrypt_public/3 unsafe=29
public_key:encrypt_private/3 unsafe=29
public_key:encrypt_public/3 unsafe=29
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, I'm still on the fence whether to put this in 28 (maint) or 29 (master), so the version's off for the time being.

Copy link
Contributor

@bjorng bjorng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. I only found a few things.

-compile(nowarn_deprecated_catch).
-compile([{nowarn_unsafe_function, {erlang, list_to_atom, 1}},
{nowarn_unsafe_function, {erlang, binary_to_atom, 2}},
nowarn_deprecated_catch]).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nowarn_deprecated_catch is not needed if you merge this PR to master; the old-style catch has been eliminated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants