Skip to content

Commit 5ce8e28

Browse files
authored
rustfmt: manually split up string literals crossing the maximum line width. (#24)
There's an unfortunate `rustfmt` bug/limitation, where string literals that cross the max width breaks reformatting in everything it's nested in. The resulting files were tested for reformatting ability by (un)indenting the entire file (e.g. `Ctrl+A Tab Ctrl+S` in VSCode), and inspecting the resulting diff - complete success leads to only whitespace changes in lines that are string `\` continuations (because `rustfmt` doesn't touch those). In fact, to ensure all instances are caught, I ended up doing this instead: ```sh sed -E -i 's/^./ \0/' src/**.rs && cargo fmt --all && git diff ``` (sadly, macros also don't get reformatted, so this is a bit annoying to skim, but still useful) --- You can see in the diff that there was some positive overall impact by looking for formatting changes that are *not* directly around the changed strings, but rather in nearby (sibling-ish) AST nodes.
2 parents f549980 + 927220e commit 5ce8e28

File tree

5 files changed

+121
-99
lines changed

5 files changed

+121
-99
lines changed

src/qptr/analyze.rs

Lines changed: 104 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,11 @@ impl UsageMerger<'_> {
379379
MergeResult {
380380
merged: a.kind.clone(),
381381
error: Some(AnalysisError(Diag::bug([
382-
format!("merge_mem: unimplemented non-intra-element merging into stride={a_stride} (")
383-
.into(),
382+
format!(
383+
"merge_mem: unimplemented \
384+
non-intra-element merging into stride={a_stride} ("
385+
)
386+
.into(),
384387
QPtrUsage::Memory(a).into(),
385388
" vs ".into(),
386389
QPtrUsage::Memory(b).into(),
@@ -1019,12 +1022,16 @@ impl<'a> InferUsage<'a> {
10191022
QPtrUsage::Handles(_) => {
10201023
return Err(AnalysisError(Diag::bug([format!(
10211024
"Offset({offset}): cannot offset Handles"
1022-
).into()])));
1025+
)
1026+
.into()])));
10231027
}
10241028
QPtrUsage::Memory(usage) => usage,
10251029
};
10261030
let offset = u32::try_from(offset).ok().ok_or_else(|| {
1027-
AnalysisError(Diag::bug([format!("Offset({offset}): negative offset").into()]))
1031+
AnalysisError(Diag::bug([format!(
1032+
"Offset({offset}): negative offset"
1033+
)
1034+
.into()]))
10281035
})?;
10291036

10301037
// FIXME(eddyb) these should be normalized
@@ -1037,9 +1044,16 @@ impl<'a> InferUsage<'a> {
10371044
Ok(QPtrUsage::Memory(QPtrMemUsage {
10381045
max_size: usage
10391046
.max_size
1040-
.map(|max_size| offset.checked_add(max_size).ok_or_else(|| {
1041-
AnalysisError(Diag::bug([format!("Offset({offset}): size overflow ({offset}+{max_size})").into()]))
1042-
})).transpose()?,
1047+
.map(|max_size| {
1048+
offset.checked_add(max_size).ok_or_else(|| {
1049+
AnalysisError(Diag::bug([format!(
1050+
"Offset({offset}): size overflow \
1051+
({offset}+{max_size})"
1052+
)
1053+
.into()]))
1054+
})
1055+
})
1056+
.transpose()?,
10431057
// FIXME(eddyb) allocating `Rc<BTreeMap<_, _>>`
10441058
// to represent the one-element case, seems
10451059
// quite wasteful when it's likely consumed.
@@ -1059,19 +1073,25 @@ impl<'a> InferUsage<'a> {
10591073
.and_then(|usage| {
10601074
let usage = match usage {
10611075
QPtrUsage::Handles(_) => {
1062-
return Err(AnalysisError(Diag::bug(["DynOffset: cannot offset Handles".into()])));
1076+
return Err(AnalysisError(Diag::bug([
1077+
"DynOffset: cannot offset Handles".into(),
1078+
])));
10631079
}
10641080
QPtrUsage::Memory(usage) => usage,
10651081
};
10661082
match usage.max_size {
10671083
None => {
1068-
return Err(AnalysisError(Diag::bug(["DynOffset: unsized element".into()])));
1084+
return Err(AnalysisError(Diag::bug([
1085+
"DynOffset: unsized element".into(),
1086+
])));
10691087
}
10701088
// FIXME(eddyb) support this by "folding"
10711089
// the usage onto itself (i.e. applying
10721090
// `%= stride` on all offsets inside).
10731091
Some(max_size) if max_size > stride.get() => {
1074-
return Err(AnalysisError(Diag::bug(["DynOffset: element max_size exceeds stride".into()])));
1092+
return Err(AnalysisError(Diag::bug([
1093+
"DynOffset: element max_size exceeds stride".into(),
1094+
])));
10751095
}
10761096
Some(_) => {}
10771097
}
@@ -1082,19 +1102,22 @@ impl<'a> InferUsage<'a> {
10821102
.as_ref()
10831103
.map(|index_bounds| {
10841104
if index_bounds.start < 0 || index_bounds.end < 0 {
1085-
return Err(AnalysisError(
1086-
Diag::bug([
1087-
"DynOffset: potentially negative offset"
1088-
.into(),
1089-
])
1090-
));
1105+
return Err(AnalysisError(Diag::bug([
1106+
"DynOffset: potentially negative offset"
1107+
.into(),
1108+
])));
10911109
}
1092-
let index_bounds_end = u32::try_from(index_bounds.end).unwrap();
1093-
index_bounds_end.checked_mul(stride.get()).ok_or_else(|| {
1094-
AnalysisError(Diag::bug([
1095-
format!("DynOffset: size overflow ({index_bounds_end}*{stride})").into(),
1096-
]))
1097-
})
1110+
let index_bounds_end =
1111+
u32::try_from(index_bounds.end).unwrap();
1112+
index_bounds_end
1113+
.checked_mul(stride.get())
1114+
.ok_or_else(|| {
1115+
AnalysisError(Diag::bug([format!(
1116+
"DynOffset: size overflow \
1117+
({index_bounds_end}*{stride})"
1118+
)
1119+
.into()]))
1120+
})
10981121
})
10991122
.transpose()?,
11001123
kind: QPtrMemUsageKind::DynOffsetBase {
@@ -1165,50 +1188,65 @@ impl<'a> InferUsage<'a> {
11651188
self.layout_cache
11661189
.layout_of(ty)
11671190
.map_err(|LayoutError(e)| AnalysisError(e))
1168-
.and_then(|layout| match layout {
1169-
TypeLayout::Handle(handle) => {
1170-
let handle = match handle {
1171-
shapes::Handle::Opaque(ty) => {
1172-
shapes::Handle::Opaque(ty)
1173-
}
1174-
// NOTE(eddyb) this error is important,
1175-
// as the `Block` annotation on the
1176-
// buffer type means the type is *not*
1177-
// usable anywhere inside buffer data,
1178-
// since it would conflict with our
1179-
// own `Block`-annotated wrapper.
1180-
shapes::Handle::Buffer(..) => {
1181-
return Err(AnalysisError(Diag::bug(["ToSpvPtrInput: whole Buffer ambiguous (handle vs buffer data)".into()])
1182-
));
1183-
}
1184-
};
1185-
Ok(QPtrUsage::Handles(handle))
1186-
}
1187-
// NOTE(eddyb) because we can't represent
1188-
// the original type, in the same way we
1189-
// use `QPtrMemUsageKind::StrictlyTyped`
1190-
// for non-handles, we can't guarantee
1191-
// a generated type that matches the
1192-
// desired `pointee` type.
1193-
TypeLayout::HandleArray(..) => {
1194-
Err(AnalysisError(Diag::bug(["ToSpvPtrInput: whole handle array unrepresentable".into()])
1195-
))
1196-
}
1197-
TypeLayout::Concrete(concrete) => {
1198-
Ok(QPtrUsage::Memory(QPtrMemUsage {
1199-
max_size: if concrete
1200-
.mem_layout
1201-
.dyn_unit_stride
1202-
.is_some()
1203-
{
1204-
None
1205-
} else {
1206-
Some(
1207-
concrete.mem_layout.fixed_base.size,
1208-
)
1209-
},
1210-
kind: QPtrMemUsageKind::StrictlyTyped(ty),
1211-
}))
1191+
.and_then(|layout| {
1192+
match layout {
1193+
TypeLayout::Handle(handle) => {
1194+
let handle = match handle {
1195+
shapes::Handle::Opaque(ty) => {
1196+
shapes::Handle::Opaque(ty)
1197+
}
1198+
// NOTE(eddyb) this error is important,
1199+
// as the `Block` annotation on the
1200+
// buffer type means the type is *not*
1201+
// usable anywhere inside buffer data,
1202+
// since it would conflict with our
1203+
// own `Block`-annotated wrapper.
1204+
shapes::Handle::Buffer(..) => {
1205+
return Err(AnalysisError(
1206+
Diag::bug(["ToSpvPtrInput: \
1207+
whole Buffer ambiguous \
1208+
(handle vs buffer data)"
1209+
.into()]),
1210+
));
1211+
}
1212+
};
1213+
Ok(QPtrUsage::Handles(handle))
1214+
}
1215+
// NOTE(eddyb) because we can't represent
1216+
// the original type, in the same way we
1217+
// use `QPtrMemUsageKind::StrictlyTyped`
1218+
// for non-handles, we can't guarantee
1219+
// a generated type that matches the
1220+
// desired `pointee` type.
1221+
TypeLayout::HandleArray(..) => {
1222+
Err(AnalysisError(Diag::bug([
1223+
"ToSpvPtrInput: \
1224+
whole handle array \
1225+
unrepresentable"
1226+
.into(),
1227+
])))
1228+
}
1229+
TypeLayout::Concrete(concrete) => {
1230+
Ok(QPtrUsage::Memory(QPtrMemUsage {
1231+
max_size: if concrete
1232+
.mem_layout
1233+
.dyn_unit_stride
1234+
.is_some()
1235+
{
1236+
None
1237+
} else {
1238+
Some(
1239+
concrete
1240+
.mem_layout
1241+
.fixed_base
1242+
.size,
1243+
)
1244+
},
1245+
kind: QPtrMemUsageKind::StrictlyTyped(
1246+
ty,
1247+
),
1248+
}))
1249+
}
12121250
}
12131251
}),
12141252
);

src/qptr/layout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ impl<'a> LayoutCache<'a> {
475475
}
476476
Ordering::Greater => {
477477
return Err(LayoutError(Diag::bug([
478-
"structs with explicit offsets must provide them for all fields"
478+
"structs with explicit offsets \
479+
must provide them for all fields"
479480
.into(),
480481
])));
481482
}

src/qptr/lift.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,11 @@ impl LiftToSpvPtrInstsInFunc<'_> {
603603
// FIXME(eddyb) this could include the chosen indices,
604604
// and maybe the current type and/or layout.
605605
return Err(LiftError(Diag::bug([format!(
606-
"offset {offset} not found in type layout, after {} access chain indices",
606+
"offset {offset} not found in type layout, \
607+
after {} access chain indices",
607608
access_chain_inputs.len() - 1
608-
).into()])));
609+
)
610+
.into()])));
609611
}
610612
(Some(idx), Some(_)) => {
611613
// FIXME(eddyb) !!! this can also be illegal overlap

0 commit comments

Comments
 (0)