Commit Graph

51 Commits

Author SHA1 Message Date
Kuba Mracek
a3eefa8025 [embedded] Start using a new mangling prefix for Embedded Swift: $e 2024-12-03 09:10:38 -08:00
Kuba Mracek
576616307f [Mangling] Temporarily stage out (#ifdef out) the ASTMangler API changes and Embedded Swift prefix 2024-12-02 15:01:24 -08:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Erik Eckstein
ef6cedcdb7 Mangler: enable mangling verification also in non-assert compiler builds
Not verifying mangled names can result in crashes later in the optimizer in case of mangling errors.

Related to rdar://137298914
2024-10-21 12:31:43 +02:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Joe Groff
6263956225 Mangler: Fix substitution ordering when mangling opaque return types.
When a declaration has a structural opaque return type like:

  func foo() -> Bar<some P>

then to mangle that return type `Bar<some P>`, we have to mangle the `some P`
part by referencing its defining declaration `foo()`, which in turn includes
its return type `Bar<some P>` again (this time using a special mangling for
`some P` that prevents infinite recursion). Since we mangle `Bar<some P>`
once as part of mangling the declaration, and we register substitutions for
bound generic types when they're complete, we end up registering the
substitution for `Bar<some P>` twice, once as the return type of the
declaration name, and again as the actual type. This would be fine, except
that the mangler doesn't check for key collisions, and it picks
substitution indexes based on the number of entries in its hash map, so
the duplicated substitution ends up corrupting the substitution sequence,
causing the mangler to produce an invalid mangled name.

Fixing that exposes us to another problem in the remangler: the AST
mangler keys substitutions by type identity, but the remangler
uses the value of the demangled nodes to recognize substitutions.
The mangling for `Bar<current declaration's opaque return type>` can
appear multiple times in a demangled tree, but referring to different
declarations' opaque return types, and the remangler would reconstruct
an incorrect mangled name when this happens. To avoid this, change the
way the demangler represents `OpaqueReturnType` nodes so that they
contain a backreference to the declaration they represent, so that
substitutions involving different declarations' opaque return types
don't get confused.
2023-01-03 09:33:07 -08:00
Alastair Houghton
3f01f853a6 [Demangling] Add error handling to the remangler.
Mangling can fail, usually because the Node structure has been built
incorrectly or because something isn't supported with the old remangler.
We shouldn't just terminate the program when that happens, particularly
if it happens because someone has passed bad data to the demangler.

rdar://79725187
2021-09-06 17:49:09 +01:00
Doug Gregor
b57a73ab42 [Concurrency ABI] Add standard substitutions for _Concurrency types.
Introduce a second level of standard substitutions to the mangling,
all of the form `Sc<character>`, and use it to provide standard
substitutions for most of the _Concurrency types.

This is a precursor to rdar://78269642 and a good mangling-size
optimization in its own right.
2021-06-01 17:15:02 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Slava Pestov
3e4b95f234 ASTMangler: Fix substitution round-tripping in the DWARF mangler
When mangling sugared types for DWARF debug info, we would
occassionally mix generic parameter types from different
generic environments. Since the mangling for a generic
parameter type only recorded the depth and the index, even
for distinct sugared forms, the remangler would produce a
more 'compact' mangling, by folding together generic parameters
that have the same depth/index, but distinct sugarings in the
AST.

Prevent this from happening by desugaring DWARF types the
correct amount, substituting away generic parameters while
preserving everything else.

Also, re-enable the round-trip verification with the remangler.

Fixes <rdar://problem/59496022>, <https://bugs.swift.org/browse/SR-12204>.
2020-04-06 18:19:57 -04:00
Erik Eckstein
4845d81c64 Temporarily disable mangler verification.
I still need to investigate the failures.
To unblock CI I'm disabling the verification for now.

Failing to correctly remangle a symbol should work, but failing so will not cause any severe damage (miscompile, etc.) in most cases.

rdar://problem/59813007
rdar://problem/59496022
https://bugs.swift.org/browse/SR-12204
2020-02-27 10:26:54 +01:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Slava Pestov
0882695f64 Mangler: Tighten up round-trip check 2019-01-29 02:15:56 -05:00
Ben Cohen
a1adf9f347 Squash a few more unused warnings (#17743) 2018-07-05 08:24:17 -07:00
Sho Ikeda
eaf33e0998 [gardening][lib/Basic] Replace typedef with using 2018-03-13 13:46:38 +09:00
Erik Eckstein
7ddfa9a9b6 mangling: remove the round-trip check for mangled runtime names (in the old mangling scheme).
This check doesn't make sense anymore because we are still making changes to the old remangler, but not to the old demangler.
Also, this check didn't work in most cases anyway.

rdar://problem/37241935
2018-02-05 14:02:18 -08:00
Erik Eckstein
f343659a75 Mangler: add a dump() function for debugging 2017-10-16 17:30:34 -07:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00
Erik Eckstein
9f33bc96c8 Mangler: add a beginManglingWithoutPrefix function
Mostly cosmetic, because usually the mangling functions are called only once per mangling instance anyway.
2017-05-24 17:00:18 -07:00
Jordan Rose
5de0a39f62 [Mangler] Verify USR manglings as well. 2017-04-17 11:31:15 -07:00
Erik Eckstein
487896edca Mangling: relax the re-mangling verification check a little bit.
There are cases where the re-mangling doesn't yield the original mangled name.
This is no problem for the compiler as it only affects how mangling substitutions are handled.

rdar://problem/31539542
2017-04-10 15:37:37 -07:00
Erik Eckstein
c4a11f4c92 tests: remove the now unused option -new-mangling-for-tests 2017-03-22 11:28:43 -07:00
Erik Eckstein
977b5c05ad Mangling: add a verifier that checks if every mangled symbol can be demangled and remangled. 2017-03-20 16:12:23 -07:00
Erik Eckstein
d70bfc5de2 rename namespace NewMangling -> Mangle 2017-03-20 10:09:30 -07:00
Erik Eckstein
0f87b5efb2 Remove the useNewMangling function
NFC
2017-03-17 16:10:36 -07:00
Erik Eckstein
1625345b90 Remove the old mangler.
NFC
2017-03-17 16:10:36 -07:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Erik Eckstein
a04a29af4f mangling: efficient mangling of repeated substitutions
Instead of appending a character for each substitution, we now prefix the substitution with the repeat count, e.g.
AbbbbB -> A5B

The same is done for known-type substitutions, e.g.
SiSiSi -> S3i

This significantly shrinks mangled names which contain large lists of the same type, like
  func foo(_ x: (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int))

rdar://problem/30707433
2017-03-05 17:41:43 -08:00
Erik Eckstein
dfcad1a2ca Mangler: print statistic about substitutions, which don’t fit into the a-z range. 2017-03-05 17:40:07 -08:00
Erik Eckstein
7d7dc5aaac Demangler: Use a bump-pointer allocator for node allocation.
This makes the demangler about 10 times faster.
It also changes the lifetimes of nodes. Previously nodes were reference-counted.
Now the returned demangle  node-tree is owned by the Demangler class and it’s lifetime ends with the lifetime of the Demangler.

Therefore the old (and already deprecated) global functions demangleSymbolAsNode and demangleTypeAsNode are no longer available.

Another change is that the demangling for reflection now only supports the new mangling (which should be no problem because
we are generating only new mangled names for reflection).
2017-02-24 19:04:13 -08:00
Erik Eckstein
8542e13bf7 Revert "Temporarily disable the re-mangling check."
rdar://problem/30592808 is fixed

This reverts commit 03a5c2449c.
2017-02-20 16:39:37 -08:00
Erik Eckstein
03a5c2449c Temporarily disable the re-mangling check.
Until rdar://problem/30592808 is fixed
2017-02-18 13:01:51 -08:00
Erik Eckstein
2d127e4192 Reinstate ”Use the new mangling for reflection."
It also uses the new mangling for type names in meta-data (except for top-level non-generic classes).
lldb has now support for new mangled metadata type names.

This reinstates commit 21ba292943.
2017-02-15 09:47:22 -08:00
Erik Eckstein
254f36aba5 Revert "Use the new mangling for reflection."
This needs some changes in lldb.
Disabled for now until lldb supports the new mangling.

This reverts commit 21ba292943.
2017-02-08 09:01:51 -08:00
Erik Eckstein
21ba292943 Use the new mangling for reflection.
For this we are linking the new re-mangler instead of the old one into the swift runtime library.
Also we are linking the new de-mangling into the swift runtime library.

It also switches to the new mangling for class names of generic swift classes in the metadata.
Note that for non-generic class we still have to use the old mangling, because the ObjC runtime in the OS depends on it (it de-mangles the class names).
But names of generic classes are not handled by the ObjC runtime anyway, so there should be no problem to change the mangling for those.
The reason for this change is that it avoids linking the old re-mangler into the runtime library.
2017-02-07 08:36:21 -08:00
Erik Eckstein
2ced2f2b49 Mangling: fix selectMangling for Release build
rdar://problem/30387928
2017-02-06 19:31:29 -08:00
swift-ci
9580f41a0e Merge pull request #7054 from JaSpa/fix-ndebug-linker-error 2017-01-26 11:34:31 -08:00
Erik Eckstein
39c21c92c8 Mangling: better check for the -new-mangling-for-tests option 2017-01-26 08:54:31 -08:00
Janek Spaderna
98f5eaddf6 [Mangling] Fix linker error in NDEBUG build 2017-01-26 11:57:22 +01:00
Erik Eckstein
4c7d68b590 Mangling: fix compile error in release build 2017-01-25 12:37:57 -08:00
Erik Eckstein
f15075f88b Mangling: fix the check if a new mangled name contains an old mangled function name.
This is used to decide whether a symbol should be tested for correct re-mangling.
2017-01-24 17:46:18 -08:00
Erik Eckstein
4d00ac1bba New mangling: add a -new-mangling-for-tests option.
This option enables the new mangling for everything except the Swift stdlib module.
Used to switch test files explicitly to the new mangling.
2017-01-24 15:27:45 -08:00
Erik Eckstein
a56a97c89f Mangling: prepare for using new mangling for USR and debug-info type generation.
Select between old and new mangling as we already do in other places in the compiler.
NFC as long as the new mangling is not enabled yet.
2017-01-23 17:49:00 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Erik Eckstein
947996ceaf Mangling: encode an optional unique ID in the function specialization mangling, instead of appending _unique_suffix 2016-12-20 13:47:48 -08:00
Erik Eckstein
268436aa9d Mangling: check if we can de-mangle everything we mangle
And don't compare old and new mangling trees if the old demangling didn't succeed
2016-12-20 13:47:48 -08:00
Erik Eckstein
ad1c079632 Mangling: support new mangling of partial apply forwarders in IRGen 2016-12-09 10:28:34 -08:00
Erik Eckstein
af24045941 Mangling: correct mangling of partial apply forwarders
Plus some refactoring in the demangler
2016-12-09 09:05:18 -08:00
practicalswift
cfdaf9f14a [gardening] Fix invalid Swift URLs. 2016-12-06 20:12:20 +01:00