Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/base-db/src/editioned_file_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,18 @@ const _: () = {
.relevant_crates(editioned_file_id.file_id())
.first()
.copied()
.unwrap_or_else(|| db.all_crates()[0]);
.or_else(|| db.all_crates().first().copied())
.unwrap_or_else(|| {
// What we're doing here is a bit fishy. We rely on the fact that we only need
// the crate in the item tree, and we should not create an `EditionedFileId`
// without a crate except in cases where it does not matter. The chances that
// `all_crates()` will be empty are also very slim, but it can occur during startup.
// In the very unlikely case that there is a bug and we'll use this crate, Salsa
// will panic.

// SAFETY: 0 is less than `Id::MAX_U32`.
salsa::plumbing::FromId::from_id(unsafe { salsa::Id::from_index(0) })
});
Comment on lines +225 to +236
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need that previous change (making the function non-optional). Not too fond of this hack, this might populate queries that aren't necessary if this value makes it through. I am also not too happy with the sheer amount of hacks we are slowly accumulating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "making the function non-optional"?

Copy link
Member

Choose a reason for hiding this comment

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

I meant 1671349

EditionedFileIdData { editioned_file_id, krate }
},
)
Expand Down