Commit Graph

266 Commits

Author SHA1 Message Date
Erik Eckstein
5daf48b0d9 Demangler: fix substitutions for OpaqueType in the remangler.
rdar://problem/50132625
2019-05-02 10:22:46 -07:00
Arnold Schwaighofer
43a7b44577 Merge pull request #24201 from aschwaighofer/opaque_result_types_dyn_replacement_and_specialization
Opaque result types: dynamic replacement
2019-04-24 07:58:50 -07:00
Erik Eckstein
65bbb9c4c3 Demangler: handle symbols with .<n> suffix in isThunkSymbol()
rdar://problem/48382772
2019-04-23 11:15:18 -07:00
Doug Gregor
e29469b9c0 [Opaque result types] Fix mangling issues with opaque result types.
Fix a trio of issues involving mangling for opaque result types:
* Symbolic references to opaque type descriptors are not substitutions
* Mangle protocol extension contexts correctly
* Mangle generic arguments for opaque result types of generic functions

The (de-)serialization of generic parameter lists for opaque type
declarations is important for the last bullet, to ensure that the
mangling of generic arguments of opaque result types works across
module boundaries.

Fixes the rest of rdar://problem/50038754.
2019-04-22 17:10:45 -07:00
Arnold Schwaighofer
84c7b77d02 Make opaque type descriptors dynamically replaceable
This is to support dynamic function replacement of functions with opaque
result type.

This approach requires that all state is thrown away (that could contain the
old returned type for an opaque type) between replacements.

rdar://48887938
2019-04-22 07:31:07 -07:00
Joe Groff
b87a5664d9 Demangler: Register substitution for opaque archetype manglings 2019-04-17 16:09:51 -07:00
Joe Groff
5bb22b0b42 Allow OpaqueTypeDecls to be (de)mangled as contexts, rdar://problem/49831658 2019-04-17 14:46:22 -07:00
Joe Groff
be0140fe56 Switch __opaque to some, per the latest rev of the proposal 2019-04-17 14:46:21 -07:00
Joe Groff
95c43f4e18 Decode opaque types in the runtime demangler. 2019-04-17 14:44:40 -07:00
Joe Groff
05dfec0cda Push the conformance accessor hack down into getTypeByMangledName. 2019-04-17 14:44:40 -07:00
Joe Groff
42e1824a30 Mangle opaque result types. 2019-04-17 14:43:32 -07:00
Slava Pestov
42e74f28c0 Demangle: Add node for reabstraction thunk capturing DynamicSelfType
Also, NodePrinter was printing the 'from' and 'to' type backwards,
so fix that.
2019-04-14 18:06:16 -04:00
Michael Gottesman
91dbbc3088 Merge pull request #23204 from compnerd/silence-in-the-library
Remove custom handling in add_swift_host_library
2019-04-08 10:49:42 -07:00
Slava Pestov
4207738e17 Add mangling and IRGen LinkEntity for Objective-C resilient class stubs 2019-03-26 18:44:44 -04:00
Erik Eckstein
a8a18c01ad swift-demangler: Add an option -strip-specialization to get the symbol name of the origin of a specialized function. 2019-03-25 14:57:03 -07:00
Erik Eckstein
c6abbfa29d Remangler: don't construct a std::string for hashing and comparing identifiers
This avoids memory allocations.
2019-03-13 11:49:58 -07:00
Erik Eckstein
0528d8ac01 OldRemangler: cleanup and simplification of mangleIdentifier
NFC
2019-03-13 11:49:58 -07:00
Erik Eckstein
abccbd8c8c runtime: make the old remangler allocation free.
Extract common code from the old and new remangler into a common base class.
This lets the old remangler benefit from the changes I did recently in the new remangler.
2019-03-13 11:49:58 -07:00
Erik Eckstein
708b2ace3d Remangler: remove support for mangling function specializations in the old remangler
The old remangler is only used for ObjC runtime type mangling, but not for mangling optimized function names.
2019-03-13 11:49:58 -07:00
Erik Eckstein
64d5f4cd35 Demangler: remove a dead function.
NFC
2019-03-13 11:49:58 -07:00
Saleem Abdulrasool
b0005e9f87 build: remove C_COMPILE_FLAGS from add_swift_host_library
Use the appropriate CMake mechanism for controlling flags for building
the code.
2019-03-10 15:38:55 -07:00
Erik Eckstein
d7fd45d74a Remangler: Use a bump-pointer allocated string instead of std::string
Done by replacing DemanglerPrinter with a bump-pointer allocated CharVector buffer.
This avoids malloc calls.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
Erik Eckstein
9050be62de Remangler: Implement the hash map for substitutions in the spirit of llvm's SmallPtrSet.
This avoids malloc calls in the common case. Only if there are more than 16 substitutions in the fixed-sized array, the overflow goes into a std::unordered_map.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08: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
Adrian Prantl
4b1532cddc Rename swift::Demangle::archetypeName() to swift::Demangle::genericParameterName(). 2019-03-01 08:02:28 -08:00
Adrian Prantl
b36c646914 Allow for passing a custom Archetype naming schema to the demangler.
LLDB would like to substitute the original Archetype names from the
source code when demangling symbols instead of the confusing generic
'A', 'B', ...

<rdar://problem/48259889>
2019-02-28 14:01:38 -08:00
Saleem Abdulrasool
52a2d0de0c Merge pull request #22708 from TomiLahtinen/master
Fixed typo in comments
2019-02-21 17:04:10 -08:00
Erik Eckstein
706f4c8622 Demangler library: add a function swift_demangle_getModuleName to get the module name of a mangled symbol.
rdar://problem/47560963
2019-02-19 11:26:42 -08:00
Tomi Lahtinen
91a405a3dc Fixed typo in comments 2019-02-19 14:54:11 +02:00
Erik Eckstein
8404c73dba Demangler: support stack allocation for the Demangler's allocator
The demangler can be initialized with a preallocated memory on the stack. Only in case of an overflow, the bump pointer allocator mallocs new memory.
Also, support that a new instance of a demangler can "borrow" the free memory from an existing demangler. This is useful because in the runtime the demangler is invoked recursively. With this feature, all the nested demanglers can share a single stack allocated space.
2019-02-15 09:29:49 -08:00
Erik Eckstein
b04ebcfacf Demangler: improve debug logging.
Log allocated memory and indent according to the nesting level
2019-02-15 09:29:49 -08:00
Erik Eckstein
58f2d373d4 Demangler: Reduce sizeof(Node) from 48 bytes to 24 bytes
This is done by disallowing nodes with children to also have index or text payloads.
In some cases those payloads were not needed anyway, because the information can be derived later.
In other cases the fix was to insert an additional child node with the index/text payload.

Also, implement single or double children as "inline" children, which avoids needing a separate node vector for children.

All this reduces the needed size for node trees by over 2x.
2019-02-15 09:29:49 -08:00
Slava Pestov
2c015164cf Stop passing NodePointer by reference 2019-02-13 21:51:28 -05:00
Slava Pestov
d0c7b1547e ASTMangler: Mangle sugared types for the debugger
Fixes <rdar://problem/48004306>.
2019-02-13 19:17:25 -05:00
Slava Pestov
fce933910d ASTDemangler: Implement types in generic local context
If we nest a type inside a local context inside a generic type,
we have to look through the local context(s) to find the outer
generic type when stripping off generic arguments.

We don't support nominal types inside generic local context
right now, but this can happen with type aliases.
2019-01-29 19:15:17 -05:00
Slava Pestov
535f5bdedf Remangler: Fix for correct round-tripping 2019-01-29 02:15:56 -05:00
eeckstein
6b9e5e564d Merge pull request #22142 from eeckstein/fix-private-class-mangling
Runtime: fix mangling of nested private generic classes
2019-01-25 23:57:50 -08:00
Slava Pestov
b6951932b4 ASTDemangler: Implement type alias types
Debug info uses a special mangling where type aliases can be
represented without being desugared; attempt to reconstruct
the TypeAliasType in this case.
2019-01-25 21:59:48 -05:00
Erik Eckstein
cc35f385ed Runtime: fix mangling of nested private generic classes
The generated mangled names were wrong and couldn't be demangled.
For example the runtime generated class name for PrivateGeneric was wrong:

class OuterClass {
    private class PrivateGeneric<T, U> { }
}

rdar://problem/47529629
2019-01-25 16:49:08 -08:00
Doug Gregor
0181ea586d Merge pull request #22118 from DougGregor/remote-ast-private-types
[RemoteAST] Improve resolution of private types from metadata
2019-01-25 15:21:00 -08:00
Doug Gregor
61d14ed3d7 [Remote AST] Use anonymous context descriptor mangled names for private types.
When an anonymous context descriptor provides a mangled name, use that
mangled name to provide the private declaration name for its child context.
This allows us to resolve private type names correctly when the corresponding
anonymous context has its mangled name.

Fixes rdar://problem/38231646.
2019-01-25 10:20:25 -08:00
Slava Pestov
9761e5ca42 Demangler: Print BuiltinFloatType as "FPIEEE<size>" not "Float<size>"
The type checker calls these types Builtin.FPIEEE<size>; the demangler
should too.

This is just cosmetic at the moment, but it was causing problems when
I added support for builtin types to the TypeDecoder.
2019-01-24 11:12:54 -05:00
Jordan Rose
0ca4d557f4 [Mangling] Split up protocol-conformance-ref further
New(er) grammar:

    // same module as conforming type, or non-unique
    protocol-conformance-ref ::= protocol 'HP'
    // same module as protocol
    protocol-conformance-ref ::= protocol 'Hp'
    // retroactive
    protocol-conformance-ref ::= protocol module

We don't make use of this distinction anywhere yet, but we could in
the future.
2018-12-20 14:00:06 -08:00
Jordan Rose
0c9ab0048a [Mangling] Disambiguate protocol-conformance-ref better
Fix to 510b64fcd5. The mangling operator "HP" has to distinguish
between "protocol" and "protocol module", not between the presence
or absence of protocol-conformance-ref. New grammar:

    protocol-conformance-ref ::= protocol
    protocol-conformance-ref ::= protocol module 'HP'

rdar://problem/46735592, again
2018-12-19 16:17:31 -08:00
Doug Gregor
510b64fcd5 [Mangling] Give protocol-conformance-ref an operator.
Due to some unfortunate refactoring, protocol-conformance-ref is a
nonterminal in the mangling grammar that doesn't have its own
operator:

```
protocol-conformance-ref ::= protocol module?
```

Both "module" and "protocol" can be an "identifier", which introduces
a mangling collision. Address the mangling collision by using the
operator "HP".

Fixes rdar://problem/46735592.
2018-12-17 18:11:47 -08:00
Doug Gregor
735a83bb8d [Mangling] Separate mangling for associated/base conformance accessors.
It’s simpler to use separate manglings for these two cases.
2018-12-04 00:34:05 -08:00
Doug Gregor
e6620b055d [Mangling] Separate out base conformance descriptors.
Separate the mangling of base conformance descriptors from that of
associated conformance descriptors, and simplify it.
2018-12-04 00:13:54 -08:00
Doug Gregor
76794334fa [ABI] Emit associated conformance descriptors for inherited protocols.
Start emitting associated conformance requirement descriptors for
inherited protocols, so we have a symbol to reference from resilient
witness tables and mangled names in the future.
2018-12-03 17:07:44 -08:00
Doug Gregor
22b20ccd8e [Mangling] Generalize the mangling of associated witness table accessors.
Use a general ‘type’ production for the conforming type of an associated
witness table accessor mangling, so that we can mangle base protocol
witness table accessors. These entities are always internal symbols, so the
mangling itself doesn’t affect the ABI.
2018-11-29 17:05:05 -08:00
Doug Gregor
cfc0f892e3 [Mangle] Include generic arguments of extensions for the Objective-C runtime
The remangler for the Objective-C runtime was dropping generic arguments
of extension contents, leading to collisions with @objc class names.
Include the generic arguments of extensions.

Fixes rdar://problem/45956357.
2018-11-26 13:51:40 -08:00