Skip to content

Add 'db lifetime to BuiltinDeriveMacroId - #23060

Open
ada4a wants to merge 4 commits into
rust-lang:masterfrom
ada4a:lt-for-BuiltinDeriveMacroId
Open

Add 'db lifetime to BuiltinDeriveMacroId#23060
ada4a wants to merge 4 commits into
rust-lang:masterfrom
ada4a:lt-for-BuiltinDeriveMacroId

Conversation

@ada4a

@ada4a ada4a commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Part of #22868

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 6, 2026
@rustbot

This comment has been minimized.

@ada4a
ada4a force-pushed the lt-for-BuiltinDeriveMacroId branch from 3299abc to 43c5b6d Compare August 6, 2026 13:08
@rustbot

rustbot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ada4a
ada4a force-pushed the lt-for-BuiltinDeriveMacroId branch 2 times, most recently from 913ef11 to 85dbb37 Compare August 6, 2026 13:12
ada4a and others added 3 commits August 6, 2026 15:14
- use `from_id!` for `EnumVariant{,Id}`
- use `?` for consistency with the other methods
- use `LazyCell` for lazy initialization
- rm needlessly complicated `Ordering` clause
- use chained if-lets to reduce nesting
- rm manual lifetime expansion (`parent_arc` seems to have been an Arc
  in the past)
- use `.into()` to turn things into `Definition`s
A lot of these were necessary to allow the next commit to compile, but a
few are miscellaneous.
@ada4a
ada4a force-pushed the lt-for-BuiltinDeriveMacroId branch from 85dbb37 to d3f8893 Compare August 6, 2026 13:17

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a bit hesitant to merge this while @dfireBird has its lifetimes PR in flight; this PR is much easier to review but the work there is definitely higher...

View changes since this review

) {
// Lazily initialised when we first encounter a `#[doc = macro!()]`.
let mut expander: Option<DocMacroExpander<'db>> = None;
let mut expander = LazyCell::new(|| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this change? (LazyCell has an additional branch).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mostly code clarity I'd say? LazyCell makes it very clear what's happening: a value that is initialized lazily.

LazyCell has an additional branch

You mean to check whether the value has been initialized or not? But I think Option::get_or_insert_with does a similar check for None, no?

Anyway I don't feel too strongly about this, happy to revert.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LazyCell needs to check for reentrance.

I wouldn't oppose if this was written this way to begin with, but I do oppose changing it in an unrelated PR.

fn adjust_to_nearest_non_block_module<'db, 'dm>(
db: &'db dyn SourceDatabase,
mut def_map: &'db DefMap,
mut def_map: &'dm DefMap<'db>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can just use the 'db lifetime here, after all the DefMap is stored in the db.

}

#[cfg(test)]
mod tests {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this test? Is it for the DynMap? Most of it is type gymnastics, I don't think it needs tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was a leftover from Lukas' code snippet – I'll remove it if you say it's unnecessary

Comment thread crates/hir-def/src/lib.rs
}

#[salsa::interned(debug, unsafe(no_lifetime), revisions = usize::MAX)]
#[salsa::interned(debug)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wouldn't remove revisions = usize::MAX yet. We need to take a conscious decision to enable interneds GC and in what frequency.

lang_items: &'db LangItems,
resolver: &'a Resolver<'db>,
store: &'db ExpressionStore,
store: &'a ExpressionStore,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why this change? It should remain 'db.

@ada4a

ada4a commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Happy to wait for @dfireBird's PR to land first – I honestly doubted I would be able to drive this to completion, but since I now have, fixing it up as needed (by reading) sounds doable

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants