Skip to content

Simplify the thunk names we generate for test functions. #750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Oct 7, 2024

Parameterized test functions with the same name but different argument types currently get the same generated names from swift-syntax, so we do some additional decorating to ensure uniqueness. This results in very long symbol names that swift-demangle has trouble with.

This PR changes the decorating formula. Previously, we would include a copy of the test function's signature (stripped of whitespace, Unicode, and non-identifier-friendly ASCII) and, if the identifier contained non-ASCII characters, the CRC32 of the identifier for further uniqueness. This change drops the copy of the identifier name and always includes the CRC32. Collisions are only possible for fully-qualified test function names that are identical, and I naïvely judge the risk of those collisions to be sufficiently low that we can make this change.

For ZipTests.allElementsEqual😀(i:j:) we currently generate a thunk named:

$s12TestingTests03ZipB0V0022allElementsEqual_oxFJo4TestfMp_43funcallElementsEqual__i_Int_j_Int__5bcb7b35fMu_

This change would change it to:

$s12TestingTests03ZipB0V0022allElementsEqual_oxFJo4TestfMp_9Z5bcb7b35fMu_

Which demangles to:

$s12TestingTests03ZipB0V0022allElementsEqual_oxFJo4TestfMp_9Z5bcb7b35fMu_ ---> unique name #1 of Z5bcb7b35 in peer macro @Test expansion #1 of allElementsEqual😀 in TestingTests.ZipTests

The benefit of the change is that the generated names are shorter and easier to read when expanding a macro, and play better with the demangler. There may also be some benefit on Windows where the linker has a 65KB symbol name cap, although we're not exporting these symbols so probably not.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

Parameterized test functions with the same name but different argument types
currently get the same generated names from swift-syntax, so we do some
additional decorating to ensure uniqueness. This results in very long symbol
names that `swift-demangle` has trouble with.

This PR changes the decorating formula. Previously, we would include a copy of
the test function's signature (stripped of whitespace, Unicode, and
non-identifier-friendly ASCII) and, if the identifier contained non-ASCII
characters, the CRC32 of the identifier for further uniqueness. This change
drops the copy of the identifier name and always includes the CRC32. Collisions
are only possible for fully-qualified test function names that are _identical_,
and I naïvely judge the risk of those collisions to be sufficiently low that we
can make this change.

For `ZipTests.allElementsEqual😀(i:j:)`` we currently generate a thunk named:

```
$s12TestingTests03ZipB0V0022allElementsEqual_oxFJo4TestfMp_43funcallElementsEqual__i_Int_j_Int__5bcb7b35fMu_
```

This change would change it to:

```
$s12TestingTests03ZipB0V0022allElementsEqual_oxFJo4TestfMp_9Z5bcb7b35fMu_
```

The benefit of the change is that the generated names are shorter and easier to
read when expanding a macro. There may also be some benefit on Windows where the
linker has a 65KB symbol name cap, although we're not exporting these symbols so
probably not.
@grynspan grynspan added enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later) labels Oct 7, 2024
@grynspan grynspan added this to the Swift 6.1 milestone Oct 7, 2024
@grynspan grynspan self-assigned this Oct 7, 2024
@grynspan
Copy link
Contributor Author

grynspan commented Oct 7, 2024

@swift-ci test

@grynspan
Copy link
Contributor Author

grynspan commented Oct 7, 2024

@swift-ci test

@grynspan
Copy link
Contributor Author

grynspan commented Oct 7, 2024

@swift-ci test Windows

@grynspan
Copy link
Contributor Author

grynspan commented Oct 7, 2024

@stmontgomery previously gave me a thumbs-up on the concept of the change, though not the diff itself.

@stmontgomery
Copy link
Contributor

This results in very long symbol names that swift-demangle has trouble with.

Is there some bug there that needs to be reported?

@grynspan
Copy link
Contributor Author

grynspan commented Oct 7, 2024

Is there some bug there that needs to be reported?

I don't think so. It's not a bug with swift-demangle per se. It's that we end up generating names that are incorrectly mangled, hence can't be demangled.

@grynspan grynspan merged commit 7dd3d27 into main Oct 7, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/simplify-thunk-names branch October 7, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants