Commit Graph

779 Commits

Author SHA1 Message Date
Slava Pestov
198e8d1a1f AST: Introduce a new debug-only mangling for @escaping @convention(block) functions
Our mangling did not encode if an Objective-C block was escaping or
not. This is not a huge problem in practice, but for debug info we
want type reconstruction to round-trip exactly. There was a previous
workaround to paper over this specific problem.

Remove the workaround, and add a new 'XL' mangling for escaping
blocks. Since we don't actually want to break ABI compatibility,
only use the new mangling in DWARF debug info.
2019-06-12 19:10:19 -07:00
Brent Royal-Gordon
affcefc1ae [ASTMangler] Mangle nested imported error structs correctly
Error structs synthesized by ClangImporter can be renamed using SWIFT_NAME() to syntactically appear anywhere in the type hierarchy with any name, but they should always be mangled as `__C_Synthesized.related decl ‘e’ of <Objective-C enum name>`. Unforunately, when SWIFT_NAME() was used to nest the error struct inside another type, an ASTMangler bug would cause it to be mangled as `<parent type>.related decl ‘e’ of <Objective-C enum name>`, and an ASTDemangler bug would also require a valid parent type. This created a mismatch between the compiler’s and runtime’s manglings which caused crashes when you tried to match the imported error struct in a `catch`.

This PR corrects the compiler bugs so that it generates the mangling the runtime expects. This is theoretically ABI-breaking, but as far as I can determine nobody has shipped the incorrectly mangled names, presumably because they crash when you try to use them.

Fixes <rdar://problem/48040880>.
2019-05-15 11:28:24 -07:00
Joe Groff
6c779bb487 Merge pull request #24445 from jckarter/opaque-type-remote
Debugger support for opaque types.
2019-05-03 08:18:59 -07:00
Erik Eckstein
0d971eebfe IRGen: mangle conformance access paths with opaque result type as a root
Fixes a crash in IRGen

TODO: also fix the demangler/remangler part of this mangling change.
Currently it's not a problem because we never demangle such a symbol (it's even not round-trip checked in Mangler::verify).

rdar://problem/50405691
2019-05-02 17:19:20 -07:00
Joe Groff
fc8be62895 RemoteAST: Add a request to get the underlying type from an opaque type descriptor. 2019-05-01 15:42:57 -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
Joe Groff
5bb22b0b42 Allow OpaqueTypeDecls to be (de)mangled as contexts, rdar://problem/49831658 2019-04-17 14:46:22 -07:00
Joe Groff
399332b75b Parsable interface and type reconstruction support for opaque types.
When printing a swiftinterface, represent opaque result types using an attribute that refers to
the mangled name of the defining decl for the opaque type. To turn this back into a reference
to the right decl's implicit OpaqueTypeDecl, use type reconstruction. Since type reconstruction
doesn't normally concern itself with non-type decls, set up a lookup table in SourceFiles and
ModuleFiles to let us handle the mapping from mangled name to opaque type decl in type
reconstruction.

(Since we're invoking type reconstruction during type checking, when the module hasn't yet been
fully validated, we need to plumb a LazyResolver into the ASTBuilder in an unsightly way. Maybe
there's a better way to do this... Longer term, at least, this surface design gives space for
doing things more the right way--a more request-ified decl validator ought to be able to naturally
lazily service this request without the LazyResolver reference, and if type reconstruction in
the future learns how to reconstruct non-type decls, then the lookup tables can go away.)
2019-04-17 14:46:22 -07:00
Joe Groff
95c43f4e18 Decode opaque types in the runtime demangler. 2019-04-17 14:44:40 -07:00
Joe Groff
42e1824a30 Mangle opaque result types. 2019-04-17 14:43:32 -07:00
Joe Groff
e3bbd8ce9e Remove ResilienceExpansion from substOpaqueTypes for now.
It's currently meaningless, and it'll require thought to pass the correct value when it becomes
meaningful.
2019-04-17 14:43:32 -07:00
Joe Groff
a6c9254612 Mangle opaque types without underlying types as ErrorType for now. 2019-04-17 14:43:32 -07:00
Joe Groff
c771a7e71b SILGen: Substitute away opaque types. 2019-04-17 14:43:32 -07:00
Joe Groff
dd2b51d6dc Add an OpaqueTypeArchetypeType subclass. 2019-04-17 14:43:32 -07:00
Slava Pestov
189a38dea4 Merge pull request #23985 from slavapestov/dynamic-self-thunks
SILGen: Fix function conversions involving DynamicSelfType
2019-04-15 07:42:48 -04:00
Slava Pestov
39a22f3d6a AST: Remove ParameterTypeFlags::Escaping
Escapingness is a property of the type of a value, not a property of a function
parameter. Having it as a separate parameter flag just meant one more piece of
state that could get out of sync and cause weird problems.

Instead, always look at the noescape bit in a function type as the canonical
source of truth.

This does mean that '@escaping' is now printed in a few diagnostics where it was
not printed before; we can investigate these as separate issues, but it is
correct to print it there because the function types in question are, in fact,
escaping.

Fixes <https://bugs.swift.org/browse/SR-10256>, <rdar://problem/49522774>.
2019-04-15 00:25:03 -04:00
Slava Pestov
a5675a8edd SILGen: Fix function conversions involving DynamicSelfType
This was partially implemented but the check looked at the lowered
types and not the AST types, and DynamicSelfType is erased at the
top level of a lowered type.

Also use the new mangling for reabstraction thunks with self, to
ensure we don't emit the same symbol with two different lowered
types.

Fixes <https://bugs.swift.org/browse/SR-10309>, <rdar://problem/49703441>.
2019-04-14 19:17:32 -04:00
Slava Pestov
75673f1d90 AST: Fix mangling of entities in subscript context
For now, this means USRs of ParamDecls. Soon, default argument generators
for subscripts will need this too.

Fixes <https://bugs.swift.org/browse/SR-8660>, <rdar://problem/44435221>.
2019-04-02 19:51:41 -04:00
Doug Gregor
b5f45f8f72 [IRGen] Mangle Swift @objc(renamed) protocols as Objective-C in metadata.
When emitting metadata for a Swift-defined @objc protocol that has
provided a specific Objective-C name (e.g., via @objc(renamed)),
mangle such protocols using their Objective-C names so they can be
found at runtime.

Only do this for metadata, because doing it anywhere else would cause
an ABI break. Fixes rdar://problem/47877748.
2019-02-25 17:31:08 -08:00
Slava Pestov
68b0d133ad ASTMangler: Fix mangling of type aliases in fully-constrained extensions
We should still mangle these as generic types.

Fixes <rdar://problem/47980487>.
2019-02-13 19:17:27 -05:00
Slava Pestov
a4cccaf46c ASTMangler: Fix mangling of invalid dependent member types
Fixes <rdar://problem/48014983>.
2019-02-13 19:17:27 -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
cc8236f7d0 AST: ASTMangler should not depend on ASTDemangler
ASTDemangler depends on ClangImporter, etc.
2019-02-05 21:03:33 -05:00
Slava Pestov
c2029db223 ASTMangler: Verify that debug manglings round-trip
Add an IRGen flag to disable this verification, since it doesn't work from within
lldb itself for some reason, and I don't want to investigate it right now.
2019-02-05 00:07:53 -05:00
Slava Pestov
2b90ad1b4a ASTMangler: Don't optimize protocol names in debugger mangling 2019-01-30 01:28:48 -05:00
Slava Pestov
c14cbe0230 ASTMangler: Add mangleTypeAsUSR()
For now this just duplicates mangleTypeForDebugger(), but the latter's
behavior is going to change.
2019-01-30 01:28:48 -05:00
Slava Pestov
aaf4b88008 AST: Add MangleLocalTypeDeclRequest 2019-01-30 01:28:48 -05:00
Slava Pestov
ad4cb5fb38 Mangler: Correctly record substitutions when dropping protocols from associated types 2019-01-29 02:15:56 -05:00
Slava Pestov
ed209084f9 AST: Don't use standard substitutions when mangling typealiases
Swift.UnicodeScalar is a typealias now, and for the TypeDecoder
to work correctly we need to mangle it as a typealias and not as
a struct.

However, we still want to demangle old names that used the
substitution, so don't remove it, instead just skip checking for
a substitution when mangling a typealias.

This does not change the ABI; typealiases are only mangled as
part of debug info.
2019-01-25 21:44:02 -05:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08: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
d5cbd3ea04 [Mangling] Only look for retroactive conformances in conditional reqs
Previously, the mangler searched for retroactive conformances in /any/
of a generic type's substitutions, but really we only care about the
ones that affect the generic type's conformance, i.e. those that
affect generic parameters. Refining this results in shorter mangled
names involving instantiations of generic types.

Follow-up work for rdar://problem/46735592
2018-12-19 17:23:35 -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
Joe Groff
20a2f3ea9f Merge pull request #21244 from jckarter/archetype-subclasses
Split subclasses out of ArchetypeType.
2018-12-12 11:49:48 -08:00
Joe Groff
f1648a1b3e Split subclasses out of ArchetypeType.
Context archetypes and opened existential archetypes differ in a number of details, and this simplifies the overlapping storage of the kind-specific fields. This should be NFC; for now, this doesn't change the interface of ArchetypeType, but should allow some refinements of how the special handling of certain archetypes are handled.
2018-12-12 08:55:56 -08:00
Slava Pestov
544e0a02d5 AST: Don't link together GenericParamLists of nested generic types
GenericParamList::OuterParameters would mirror the nesting structure
of generic DeclContexts. This resulted in redundant code and caused
unnecessary complications for extensions and protocols, whose
GenericParamLists are constructed after parse time.

Instead, lets only use OuterParameters to link together the multiple
parameter lists of a single extension, or parameter lists in SIL
functions.
2018-12-11 23:55:41 -05:00
Slava Pestov
929bf610e0 Runtime: Fix demangling of function with single tuple-typed argument
While declaration mangling now does the right thing for parameter lists,
the function type mangling unfortunately still models the parameter list
as a single tuple node.

Change the runtime's behavior to match the AST mangler, which wraps
a single tuple-typed parameter in a tuple node, so that we can produce
different mangling trees for function types taking multiple arguments
versus a single tuple argument.
2018-12-08 23:57:21 -05:00
Slava Pestov
aa747dcd81 Remove property behaviors 2018-12-07 20:38:33 -05:00
Erik Eckstein
2fe8fac812 Mangling: mangle box field types as they are.
Instead of trying to mangle a tuple type.
This change avoids mangling tuple element names in case a field type is a tuple with named elements.
Fixes a "can't demangle" crash in the closure specializer.

This mangling is only used for specializations, so no ABI effect.

rdar://problem/46380088
2018-12-06 11:11:12 -08:00
Adrian Prantl
d63debeb60 Experimental: Extend ClangImporter to import clang modules from DWARF
When debugging Objective-C or C++ code on Darwin, the debug info
collected by dsymutil in the .dSYM bundle is entirely
self-contained. It is possible to debug a program, set breakpoints and
print variables even without having the complete original source code
or a matching SDK available. With Swift, this is currently not the
case. Even though .dSYM bundles contain the binary .swiftmodule for
all Swift modules, any Clang modules that the Swift modules depend on,
still need to be imported from source to even get basic LLDB
functionality to work. If ClangImporter fails to import a Clang
module, effectively the entire Swift module depending on it gets
poisoned.

This patch is addressing this issue by introducing a ModuleLoader that
can ask queries about Clang Decls to LLDB, since LLDB knows how to
reconstruct Clang decls from DWARF and clang -gmodules producxes full
debug info for Clang modules that is embedded into the .dSYM budle.

This initial version does not contain any advanced functionality at
all, it merely produces an empty ModuleDecl. Intertestingly, even this
is a considerable improvement over the status quo. LLDB can now print
Swift-only variables in modules with failing Clang depenecies, and
becuase of fallback mechanisms that were implemented earlier, it can
even display the contents of pure Objective-C objects that are
imported into Swift. C structs obviously don't work yet.

rdar://problem/36032653
2018-12-05 13:54:13 -08:00
Slava Pestov
0ec5ac282a AST: Don't mangle weak/unowned as part of a property's type
LibraryEvolution.rst stipulates that adding or removing 'weak',
'unowned' and 'unowned(unsafe)' is a resilient change if the type
is resilient. This means we should not mangle these attributes as
part of the accessor declaration.
2018-11-27 18:04:25 -05:00
Slava Pestov
bc119d0d6d SILGen: Emit inlinable keypath thunks from inlinable contexts
It's still not resilient because we emit direct references to stored
properties, but its progress.
2018-11-16 23:18:30 -05:00
John McCall
1065f99c71 Assorted fixes for the self-conformance infrastructure 2018-11-15 22:41:58 -05:00
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Pavel Yaskevich
3ffda7e440 [ASTManger] Refactor parameter mangling code a bit based on feedback 2018-11-10 11:59:29 -08:00
Pavel Yaskevich
a1df238d47 Associate @autoclosure only with parameter types
Mangled implicit closures shouldn't have `@autoclosure` flag
associated with them, because their type is just a regular
function type.
2018-11-10 11:59:28 -08:00
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
Slava Pestov
6786ceb3a8 AST: Fix mangling of nominal types with a type alias parent type
The mangling AST cannot represent this, and we were incorrectly
pulling generic arguments from the type alias type. Instead let's
just desugar the parent type when mangling a nominal type.

Fixes <rdar://problem/45900947>.
2018-11-09 00:44:29 -05:00