Commit Graph

31 Commits

Author SHA1 Message Date
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Michael Gottesman
5f2aa256d7 [mangler] Add support for dumping the current buffer string. Just for the debugger. 2024-03-04 19:34:26 -08: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
Josh Soref
66663b1286 Spelling basic (#42541)
* spelling: add

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: attributes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: bridging

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: deserialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: invariants

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: lazily

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: offset

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: optimization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: our

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: process

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: substitution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the operation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-04 14:53:24 -07:00
Tony Allevato
5b1daa9055 Conditionally wrap (de)mangling symbols in an inline namespace.
Since libDemangling is included in the Swift standard library,
ODR violations can occur on platforms that allow statically
linking stdlib if Swift code is linked with other compiler
libraries that also transitively pull in libDemangling, and if
the stdlib version and compiler version do not match exactly
(even down to commit drift between releases). This lets the
runtime conditionally segregate its copies of the libDemangling
symbols from those in the compiler using an inline namespace
without affecting usage throughout source.
2020-06-19 11:20:56 -07:00
Saleem Abdulrasool
e45574e507 Merge pull request #27999 from compnerd/documentation
Basic: add a comment about the "complex" code
2019-11-01 18:42:49 -07:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07: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
Saleem Abdulrasool
dae4f207a0 Basic: add a comment about the "complex" code
This addresses comments from Joe to document the special behaviour that
we do in the `addSubsitution` functions which cause a subtle failure on
Windows.
2019-10-31 15:41:05 -07:00
Saleem Abdulrasool
41e28a8c3d Basic: avoid an assertion on Windows
The order of evaluation of the subscript operator would increase the
count of map, resulting in the decoration to be off by one.  This
enables building the swift standard library on Windows again.
2019-10-31 10:44:27 -07:00
John McCall
5e24f8d916 Remove error-prone overload of Mangler::appendOperator.
Unfortunately we're probably stuck with the bizarre behavior usage
here for dependent protocol conformances.
2019-07-09 01:18:36 -04:00
Erik Eckstein
de51f8cac6 Remangler: use the bump pointer allocator instead of std::vector for internal substitution data structures
This avoids mallocs in the runtime.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08: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
069cd57089 Don't use substiutions when mangling ObjC runtime class names.
This caused a problem for classes which had the same name as the containing module.

SR-4374, rdar://problem/31272389
2017-03-30 10:24:29 -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
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
8a6a9461d3 Only mangle non-private top-level classes and protocol with the old-style for the ObjC metadata.
Only those types can be de-mangled by the ObjC runtime anyway.
Also move this mangling logic into the ASTMangler class. This avoids keeping the old mangler around just for that purpose.
2017-02-16 18:20:05 -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
Roman Levenstein
8b6a0315a4 (De)Mangling of layout constraints and requirements. 2017-01-12 00:57:06 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
3e31a3ade4 [gardening] Fix typos. 2016-12-06 21:42:01 +01:00
practicalswift
cfdaf9f14a [gardening] Fix invalid Swift URLs. 2016-12-06 20:12:20 +01:00
Erik Eckstein
684092d7d1 Mangling: mangler, demangler and remangler classes for the new mangling scheme.
Following classes provide symbol mangling for specific purposes:
*) Mangler: the base mangler class, just providing some basic utilities
*) ASTMangler: for mangling AST declarations
*) SpecializationMangler: to be used in the optimizer for mangling specialized function names
*) IRGenMangler: mangling all kind of symbols in IRGen

All those classes are not used yet, so it’s basically a NFC.

Another change is that some demangler node types are added (either because they were missing or the new demangler needs them).
Those new nodes also need to be handled in the old demangler, but this should also be a NFC as those nodes are not created by the old demangler.

My plan is to keep the old and new mangling implementation in parallel for some time. After that we can remove the old mangler.
Currently the new implementation is scoped in the NewMangling namespace. This namespace should be renamed after the old mangler is removed.
2016-12-02 15:55:30 -08:00