Skip to content

Commit 1bbf4c2

Browse files
authored
feat: Drop Debug requirements and flip implementation defaults (#756)
1 parent 1dc2438 commit 1bbf4c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+114
-97
lines changed

benches/compare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct InternedInput<'db> {
2626
pub text: String,
2727
}
2828

29-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
29+
#[derive(Clone, Copy, PartialEq, Eq, Hash, salsa::Supertype)]
3030
enum SupertypeInput<'db> {
3131
InternedInput(InternedInput<'db>),
3232
Input(Input),

components/salsa-macro-rules/src/setup_input_struct.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,12 @@ macro_rules! setup_input_struct {
223223
}
224224

225225
/// Default debug formatting for this struct (may be useful if you define your own `Debug` impl)
226-
pub fn default_debug_fmt(this: Self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
226+
pub fn default_debug_fmt(this: Self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
227+
where
228+
// rustc rejects trivial bounds, but it cannot see through higher-ranked bounds
229+
// with its check :^)
230+
$(for<'__trivial_bounds> $field_ty: std::fmt::Debug),*
231+
{
227232
$zalsa::with_attached_database(|db| {
228233
let fields = $Configuration::ingredient(db).leak_fields(db, this);
229234
let mut f = f.debug_struct(stringify!($Struct));

components/salsa-macro-rules/src/setup_tracked_struct.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,18 @@ macro_rules! setup_tracked_struct {
286286
)
287287
}
288288
)*
289+
}
289290

291+
impl<'_db> $Struct<'_db> {
290292
/// Default debug formatting for this struct (may be useful if you define your own `Debug` impl)
291-
pub fn default_debug_fmt(this: Self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
293+
pub fn default_debug_fmt(this: Self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
294+
where
295+
// `zalsa::with_attached_database` has a local lifetime for the database
296+
// so we need this function to be higher-ranked over the db lifetime
297+
// Thus the actual lifetime of `Self` does not matter here so we discard
298+
// it with the `'_db` lifetime name as we cannot shadow lifetimes.
299+
$(for<$db_lt> $field_ty: std::fmt::Debug),*
300+
{
292301
$zalsa::with_attached_database(|db| {
293302
let fields = $Configuration::ingredient(db).leak_fields(db, this);
294303
let mut f = f.debug_struct(stringify!($Struct));

components/salsa-macros/src/accumulator.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn accumulator(
1919
let ident = struct_item.ident.clone();
2020
let m = StructMacro {
2121
hygiene,
22-
args,
22+
_args: args,
2323
struct_item,
2424
};
2525
match m.try_expand() {
@@ -34,8 +34,8 @@ impl AllowedOptions for Accumulator {
3434
const RETURN_REF: bool = false;
3535
const SPECIFY: bool = false;
3636
const NO_EQ: bool = false;
37-
const NO_DEBUG: bool = true;
38-
const NO_CLONE: bool = true;
37+
const DEBUG: bool = false;
38+
const NO_CLONE: bool = false;
3939
const NO_LIFETIME: bool = false;
4040
const SINGLETON: bool = false;
4141
const DATA: bool = false;
@@ -49,7 +49,7 @@ impl AllowedOptions for Accumulator {
4949

5050
struct StructMacro {
5151
hygiene: Hygiene,
52-
args: Options<Accumulator>,
52+
_args: Options<Accumulator>,
5353
struct_item: syn::ItemStruct,
5454
}
5555

@@ -65,16 +65,7 @@ impl StructMacro {
6565

6666
let struct_item = self.struct_item;
6767

68-
let mut derives = vec![];
69-
if self.args.no_debug.is_none() {
70-
derives.push(quote!(Debug));
71-
}
72-
if self.args.no_clone.is_none() {
73-
derives.push(quote!(Clone));
74-
}
75-
7668
Ok(quote! {
77-
#[derive(#(#derives),*)]
7869
#struct_item
7970

8071
salsa::plumbing::setup_accumulator_impl! {

components/salsa-macros/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl crate::options::AllowedOptions for InputStruct {
4040

4141
const NO_EQ: bool = false;
4242

43-
const NO_DEBUG: bool = true;
43+
const DEBUG: bool = true;
4444

4545
const NO_LIFETIME: bool = false;
4646

components/salsa-macros/src/interned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl crate::options::AllowedOptions for InternedStruct {
4141

4242
const NO_EQ: bool = false;
4343

44-
const NO_DEBUG: bool = true;
44+
const DEBUG: bool = true;
4545

4646
const NO_LIFETIME: bool = true;
4747

components/salsa-macros/src/options.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ pub(crate) struct Options<A: AllowedOptions> {
2020
/// If this is `Some`, the value is the `no_eq` identifier.
2121
pub no_eq: Option<syn::Ident>,
2222

23-
/// Signal we should not generate a `Debug` impl.
23+
/// Signal we should generate a `Debug` impl.
2424
///
25-
/// If this is `Some`, the value is the `no_debug` identifier.
26-
pub no_debug: Option<syn::Ident>,
25+
/// If this is `Some`, the value is the `debug` identifier.
26+
pub debug: Option<syn::Ident>,
2727

2828
/// Signal we should not include the `'db` lifetime.
2929
///
@@ -93,7 +93,7 @@ impl<A: AllowedOptions> Default for Options<A> {
9393
return_ref: Default::default(),
9494
specify: Default::default(),
9595
no_eq: Default::default(),
96-
no_debug: Default::default(),
96+
debug: Default::default(),
9797
no_lifetime: Default::default(),
9898
no_clone: Default::default(),
9999
db_path: Default::default(),
@@ -114,7 +114,7 @@ pub(crate) trait AllowedOptions {
114114
const RETURN_REF: bool;
115115
const SPECIFY: bool;
116116
const NO_EQ: bool;
117-
const NO_DEBUG: bool;
117+
const DEBUG: bool;
118118
const NO_LIFETIME: bool;
119119
const NO_CLONE: bool;
120120
const SINGLETON: bool;
@@ -161,18 +161,15 @@ impl<A: AllowedOptions> syn::parse::Parse for Options<A> {
161161
"`no_eq` option not allowed here",
162162
));
163163
}
164-
} else if ident == "no_debug" {
165-
if A::NO_DEBUG {
166-
if let Some(old) = options.no_debug.replace(ident) {
167-
return Err(syn::Error::new(
168-
old.span(),
169-
"option `no_debug` provided twice",
170-
));
164+
} else if ident == "debug" {
165+
if A::DEBUG {
166+
if let Some(old) = options.debug.replace(ident) {
167+
return Err(syn::Error::new(old.span(), "option `debug` provided twice"));
171168
}
172169
} else {
173170
return Err(syn::Error::new(
174171
ident.span(),
175-
"`no_debug` option not allowed here",
172+
"`debug` option not allowed here",
176173
));
177174
}
178175
} else if ident == "no_lifetime" {

components/salsa-macros/src/salsa_struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ where
330330
}
331331

332332
pub fn generate_debug_impl(&self) -> bool {
333-
self.args.no_debug.is_none()
333+
self.args.debug.is_some()
334334
}
335335

336336
pub fn generate_lifetime(&self) -> bool {

components/salsa-macros/src/tracked_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl crate::options::AllowedOptions for TrackedFn {
2929

3030
const NO_EQ: bool = true;
3131

32-
const NO_DEBUG: bool = false;
32+
const DEBUG: bool = false;
3333

3434
const NO_LIFETIME: bool = false;
3535

components/salsa-macros/src/tracked_struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl crate::options::AllowedOptions for TrackedStruct {
3535

3636
const NO_EQ: bool = false;
3737

38-
const NO_DEBUG: bool = true;
38+
const DEBUG: bool = true;
3939

4040
const NO_LIFETIME: bool = false;
4141

0 commit comments

Comments
 (0)