-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
v0 mangling should avoid backrefs when they're not shorter than their target. #87511
Copy link
Copy link
Open
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesA-name-manglingArea: Name mangling / decoration aka symbol manglingArea: Name mangling / decoration aka symbol manglingC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesA-name-manglingArea: Name mangling / decoration aka symbol manglingArea: Name mangling / decoration aka symbol manglingC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
While working on #61486 / #87194 I came across backrefs in byte array values (with repeating elements), which I hadn't thought about (in terms of implications on optimizing the length of a symbol), but which is otherwise entirely expected. In order to demonstrate an edge case, I encoded
some...longer...path::<{ &[0, 0, 0, 0] }>to getKRAh0_B12_B12_B12_E, which is parsed as follows:Because this is a long enough symbol, the backrefs end up being (at least) 4 bytes each (to encode positions greater than 62), whereas an integer leaf constant with a
0..=15value gets encoded as 3 bytes, so the backrefs are each adding an extra byte (and making more pointless work for the demangler).We could avoid this by tracking the range, not just the start, of an encoded path/type/const, and one of:
print_backrefdecide between actually printing the backref, and duplicating the contents of that range, inline, depending on which would be shorterHowever, this isn't an urgent concern IMO because of the combination of these aspects:
62or62² = 3844, respectively)implon a builtin type, using a backref for theimplparent module)&strisRe,[u8]isSh,fn()isFEu, etc.)It might be interesting to measure the size difference across some larger projects (including
rustcand Cargo), by making this change (even inefficiently), after v0 becomes the default, but I don't expect a difference bigger than a handful of bytes per symbol, if that.cc @michaelwoerister