Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return an empty list when item is not present in the attributes table #128154

Closed
wants to merge 1 commit into from

Conversation

momvart
Copy link
Contributor

@momvart momvart commented Jul 24, 2024

Fixes #128145

@rustbot
Copy link
Collaborator

rustbot commented Jul 24, 2024

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 24, 2024
@petrochenkov
Copy link
Contributor

The assert is there for a reason, it's expected that attributes (and many other properties) are never queried for ids for which they are not encoded.

If your code need to query attributes for all DefIds (in a third party tool, I assume, this situation shouldn't occur in the compiler), then it should filter ids with something like fn should_encode_attrs first.

@momvart
Copy link
Contributor Author

momvart commented Jul 25, 2024

then it should filter ids with something like fn should_encode_attrs first.

Thanks. Didn't know about it. Is any public equivalent of it available?

The assert is there for a reason, it's expected that attributes (and many other properties) are never queried for ids for which they are not encoded.

I agree and for an internal function this is probably the best.

However, for a public API in TyCtxt that supports both local and external ids, such expectation is not obvious. Can't we change/introduce the API to something like opt_get_attrs to return None if an item is not expected to have attributes?

@BoxyUwU BoxyUwU assigned petrochenkov and unassigned BoxyUwU Jul 28, 2024
@petrochenkov
Copy link
Contributor

Most decoder interfaces will currently panic on missing data, I'd prefer to not add "optional" interfaces for all of those just for third-party tools.

The issue can be worked around by using a condition like tcx.def_kind(def_id) != DefKind::AnonConst or copypasting the whole fn should_encode_attrs (but that is unlikely to be useful if you only process def ids with bodies).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ICE]: Querying attributes on a constant expression causes assertion failure
4 participants