Commit Graph

246 Commits

Author SHA1 Message Date
Joe Groff
43d620c7e0 IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline. We also aren't able to generate references to aliases within the same module due to an MC bug with alias refs on i386 and armv7 (rdar://problem/22450593).

Swift SVN r31523
2015-08-27 05:18:38 +00:00
Joe Groff
f705c561e3 Revert "IRGen: Export direct metadata symbols at the address point of the metadata object."
This reverts commit r31515. It causes an LLVM error on the release bots.

Swift SVN r31516
2015-08-27 01:44:56 +00:00
Joe Groff
8e2ce60f5b IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects, and also makes IR a lot less cluttered. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline.

Swift SVN r31515
2015-08-27 01:34:22 +00:00
Jordan Rose
a1ad2908b4 Use Clang's mangler for __attribute__((overloadable)) functions.
At some point we should probably just use Clang's mangler for all imported
functions, but I didn't want to rock the boat.

Swift SVN r31249
2015-08-14 19:50:28 +00:00
Slava Pestov
cdd5a4121c IRGen: Generate value witnesses to get enum tag and project payload
These will be used for reflection, and eventually to speed up generic
operations on single payload enums as well.

Progress on <rdar://problem/21739870>.

Swift SVN r30214
2015-07-15 06:03:18 +00:00
Joe Groff
feebd56bf4 IRGen: Reorder the extra inhabitant value witnesses so that the count and flags go first.
This nicely gathers all the layout information together in one contiguous bundle we can potentially emit independently for use in generic type layout. A step on the way to rdar://problem/19898165.

Swift SVN r30128
2015-07-12 01:06:15 +00:00
Jordan Rose
09664184be Move mangling logic for type metadata and field offset into Mangler.
...so that the debugger can use it too. We may end up needing to move more
things from LinkEntity to Mangler in this way, but this is the baseline for
what's needed to properly display private types.

The suffix "Full" here is intended to represent that the Swift prefix "_T"
is included already; if there's a better name for this I'd be glad to change
it.

rdar://problem/18353463

Swift SVN r22031
2014-09-17 19:27:11 +00:00
John McCall
584795e505 Replace the typeOf value witness with an
initializeBufferWithTakeOfBuffer value witness.

Attempt to use initializeBufferWithTakeOfBuffer in
some appropriate places.

There are some changes enabled by this which are
coming in a follow-up patch.

Swift SVN r20741
2014-07-30 08:24:12 +00:00
John McCall
1ae1f750d0 Move most type metadata lookups into their own readnone
functions, and make those functions memoize the result.

This memoization can be both threadsafe and extremely
fast because of the memory ordering rules of the platforms
we're targeting: x86 is very permissive, and ARM has a
very convenient address-dependence rule which happens to
exactly match the semantics we need.

Swift SVN r20381
2014-07-23 07:38:26 +00:00
John McCall
bafeb84a56 Generate unique type metadata for foreign classes.
Swift SVN r17430
2014-05-05 06:45:42 +00:00
Joe Groff
f29a156e83 IRGen/Runtime: Add value witness slots for array witnesses.
Add value witnesses for destroyArray, initializeArrayWithCopy, and initializeArrayWithTake{FrontToBack,BackToFront}, and fill out the runtime value witness table implementations. Stub out the IRGen ones for now.

Swift SVN r16772
2014-04-24 22:25:26 +00:00
Joe Groff
85ab7ed9e1 Remove mangling and demangling for block shims.
Swift SVN r16488
2014-04-18 02:36:54 +00:00
Doug Gregor
9400e890d3 Emit @objc classes using namespaced names under a new flag -enable-objc-mangling.
Centralize the logic for figuring out what name to use for a class or
protocol in the Objective-C runtime. When the flag is enabled (it's
still disabled by default), use mangled names for all Swift-defined
classes, including those that are @objc. Note that the naming is
determined in the AST, because we're also going to use this logic when
printing an Objective-C header for Clang's consumption. The mangled
names will always start with _Tt, so they're easy to recognize and
demangle in various tools or, eventually, in the Objective-C runtime.

The new test (test/IRGen/objc_mangling.sil) is the only test of this
behavior at the moment. The other test changes are due to the
centralized logic tweaking the names of internal constants (_DATA_*,
_CATEGORY_*, etc.).

This is the majority of <rdar://problem/15506580>.



Swift SVN r15588
2014-03-28 23:00:08 +00:00
Ted Kremenek
f43842e160 Change processing of @asmname to use a new internal representation.
This representation is inspired by Clang's internal representation.
The current attribute representation, which is basically a union
of "stuff" in DeclAttributes, is not amendable to richer
attributes, such as @availability, that need to be implemented.
In Clang, attributes are modeled with actual objects that
encode both semantic and syntactic information (e.g., source ranges)
that facilitate richer checking, better diagnostics, and better tools.

This change is foundational for implementing @availability, but
also is a better long-term representation.  As a migratory path,
it creates some duplications, with AttrKind and DeclAttrKind, the
two which should eventually become the same thing.

As part of this patch, there is some additional parser recovery
(for the new attribute representation) for duplicate attributes.
The parser now parses the entire duplicate attribute, which could
be quite complex, and then issues a diagnostic that the attribute
is a duplicate (and discarding it).  This delayed diagnostic
also allows us to present ranges for the duplicate attribute, which
provides a better user experience.

Swift SVN r15365
2014-03-22 14:58:30 +00:00
Doug Gregor
b5af687b6d Emit and use vtable entries for abstract initializers.
Emit vtable entries for abstract initializers. When we're constructing
an object using an abstract initializer based on a metatype value that
is not statically derivable, use the vtable entry to call the
subclass's allocating constructor.

Most of the IRGen work here is hacking around the lossy SILDeclRef ->
(Code|Function)Ref -> SILDeclRef conversion. I'd feel bad about this
if John hadn't already agreed to clean this up at some point.



Swift SVN r14238
2014-02-21 23:15:46 +00:00
John McCall
eb7dfb39ac Remove more dead code.
It was convenient to just assume that the SILModule defines
the deallocating destructor function.  This should probably
be represented somehow in e.g. the sil_vtable instead of
being an implicit dependency.

Swift SVN r12412
2014-01-16 19:35:50 +00:00
John McCall
6da9ad307a More dead code.
Swift SVN r12411
2014-01-16 19:35:48 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Doug Gregor
0ed1e6d7f5 Switch mangleDestructorEntity() tover to accepting a DestructorDecl. NFC
Swift SVN r12161
2014-01-10 23:11:06 +00:00
Adrian Prantl
946dc5678b Debug info: Provide an in interface for LLDB to mangle types and refactor
some code in IRGenDebugInfo along the way.
This is WIP for rdar://problem/15498877.

Swift SVN r12146
2014-01-10 22:35:53 +00:00
Doug Gregor
993754c1fe IR generation for the dealloc_ref SIL instruction.
Note that this lowering currently assumes that the static type of the class is its dynamic type. This should be a flag on the dealloc_ref instruction, not an assumption.

Swift SVN r12144
2014-01-10 22:32:52 +00:00
John McCall
e9e928d509 Remove the last vestiges of the 'L' local-linkage mangling prefix.
Swift SVN r11896
2014-01-04 09:11:16 +00:00
John McCall
4355a21a62 Mangle closures using their context and discriminator.
Swift SVN r11885
2014-01-04 04:37:57 +00:00
John McCall
c5aa41ffd1 Change around some manglings to make them carry more
information and be easier to demangle.

Swift SVN r11423
2013-12-18 08:33:52 +00:00
Joe Groff
15dc4967aa IRGen: Lower SILGlobalVariables.
Add support for emitting IR for SILGlobalVariables and SILGlobalAddrInst.

Swift SVN r10543
2013-11-18 17:40:45 +00:00
Adrian Prantl
da0cb5a10a [Mangler] Introduce a 'Qq' mangling format for archetypes that will be
used only for debug info and within the _Tt namespace.
The DWARF output created by swift is intentionally flat, therefore
archetypes need to be emitted with their DeclContext. While increasing the
length of the mangled names in some cases (substitutions help a lot) it
has the advantage of making names completely self-contained.
There is a lengthy thread on swift-debugger discussing this change.

Swift SVN r10348
2013-11-11 23:44:31 +00:00
Joe Groff
a0c4486808 IRGen: Emit protocol descriptors.
Produce protocol descriptors when we see a protocol definition in the current module. If the protocol is @objc, go through the existing path for generating full Protocol* metadata for objc objects; otherwise, emit our layout-compatible but strong-external-linkage Swift protocol descriptor record.

Swift SVN r9867
2013-11-01 04:28:43 +00:00
Joe Groff
b8c75769b3 IRGen: Emit nominal type descriptors in struct and enum metadata.
Build a nominal type descriptor when we emit the metadata or generic metadata pattern for a nominal type, and put a reference into the formerly null slot in the struct or enum metadata. We need to make a place for them in class metadata; that'll come next.

Swift SVN r9492
2013-10-18 21:04:58 +00:00
Argyrios Kyrtzidis
eecb56a9ad Move the Mangler from the SIL library to the AST one.
No other functionality change.

Swift SVN r8527
2013-09-20 23:10:58 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Adrian Prantl
af562d1696 Debug info: name mangling for composite types containing Archetypes.
Among other things this enables mangled names for tuples.
This adds a pointer to the DeclContext to SILFunction and which is used
to provide the necessary context to the Mangler.
Fixes rdar://problem/14808764 and rdar://problem/14813658.

Swift SVN r8070
2013-09-10 17:04:33 +00:00
Joe Groff
e6309152e5 IRGen: Kill the 'buildFakeType' abomination in GenericMetadataBuilder.
To instantiate the value witness table for generic types, we were instantiating the generic type at () for all of its parameters and hoping for the best. That's insane. Instead, let's use the DeclaredTypeInContext for the generic type so the archetypes actually get usefully bound inside the witnesses. This way, the witness implementations should be independent of generic parameters, so we can also mangle the unbound type into the witness symbols.

Swift SVN r7901
2013-09-04 17:50:12 +00:00
Joe Groff
a94489473c IRGen: Add ValueWitness enumerators for union layout and access.
These value witness table entries will be conditionally available for types that support specialized union representation through extra inhabitants and/or spare bits and for union value witnesses:

- storeExtraInhabitant, to store an extra inhabitant representation;
- getExtraInhabitantIndex, to recognize an extra inhabitant representation;
- getUnionTag, to get a union's discriminator; and
- inplaceProjectUnionData, to extract the value in place from a union.

This just sets up the enumerators and related IR types and mangling; nothing emits these witnesses yet.

Swift SVN r7234
2013-08-14 21:01:21 +00:00
Joe Groff
3503ffe4fa IRGen: Set up LinkEntities for protocol witness tables.
We need to handle three cases:

- If a protocol conformance has no associated types, or the associated type witnesses all have statically resolvable metadata, we can expose a *direct* witness table symbol.
- If a protocol conformance has associated types with runtime-instantiated metadata, we need to gate the witness table behind a *lazy* initializer function to fill in the metadata fields.
- If a protocol conformance has associated types where the type or one of its conformances are *dependent* on its parent's generic parameters, we need to instantiate multiple witness tables at runtime.

Swift SVN r6805
2013-08-01 05:25:32 +00:00
Adrian Prantl
b3050b1c04 Use SWIFT_FALLTHROUGH macro.
Swift SVN r6733
2013-07-30 01:16:59 +00:00
Adrian Prantl
5b5ba6d78a Name mangling: Add a "_Tt" prefix to all type names that are output in
the debug info, to aid the debugger in figuring out the implementation
language of a given type in multi-language environments.
FYI, where applicable, we also emit the
DW_AT_APPLE_runtime_class(DW_AT_lang_Swift) attribute.
The demangler accepts type names with the "_Tt" prefix without the --type
switch.

Swift SVN r6714
2013-07-29 22:03:15 +00:00
Joe Groff
1984cf41e0 SIL: Rename SILFunction::getMangledName to SILFunction::getName.
Swift SVN r6430
2013-07-21 18:39:51 +00:00
Joe Groff
101522bdfd Don't generate offensive words in our value witness mangling.
Swift SVN r5601
2013-06-15 22:12:50 +00:00
Doug Gregor
85f32c5c07 Prepend the magic "\01" to asm names of Clang declarations.
Should actually fix <rdar://problem/14094368> properly.


Swift SVN r5522
2013-06-07 21:26:10 +00:00
Doug Gregor
b4e68f1eaa Head Clang's AsmLabelAttr when mangling the name for the Clang declaration.
Fixes <rdar://problem/14094368>.


Swift SVN r5516
2013-06-07 20:08:27 +00:00
Joe Groff
fcd7b06eb5 IRGen: Disregard uncurry level of property accessors when mangling.
We mangle the type of the property, not the type of the accessor, so the uncurry level of the accessor is irrelevant to the mangler and causes the mangler to mangle properties of function type incorrectly--'var x : () -> ()', for instance, gets mangled to '_T6module1xfT_T_g' (with a lowercase uncurried 'f') instead of the proper '_T6module1xFT_T_g'. This broke the ListMaker test because SILGen and IRGen were coming up with inconsistent manglings for the 'handler' property of UndoManager in NSUndoManagerExts. Fixes <rdar://problem/13926113>.

Swift SVN r5229
2013-05-20 19:11:16 +00:00
John McCall
757c0ae304 Track whether a type is POD and whether it uses inline or allocated
storage in a flags word in the value witness table.  Pack the
alignment into only 16 bits of this word.  Optimize tuple value
witnesses based on whether they're POD and inline.

Swift SVN r5138
2013-05-10 06:16:33 +00:00
John McCall
d8cdb0160f Switch IR-generation to generally traffic in alignment
masks rather than raw alignments.

Swift SVN r5136
2013-05-10 06:16:28 +00:00
Joe Groff
b818405034 Replace direct use of [[clang::fallthrough]] with a macro.
Add a SWIFT_FALLTHROUGH macro that expands to [[clang::fallthrough]] for Clang and nothing for other compilers. No functionality change.

Swift SVN r5043
2013-05-05 18:54:03 +00:00
Joe Groff
08b6f87524 Add 'typeof' to value witness tables.
To be able to get the dynamic type of a generic value, the 'typeof' operation needs to be part of the value witness for the type. Add 'typeof' to the value witness table layout, and in the runtime, provide standard typeof witnesses for static, Swift class, and ObjC class values.

Swift SVN r5013
2013-05-01 18:49:25 +00:00
Joe Groff
0566088bf2 Move name mangling into SIL.
Sever the last load-bearing link between SILFunction and SILConstant by naming SILFunctions with their mangled symbol names. Move the core of the mangler up to SIL, and teach SILGen how to use it to mangle a SILConstant.

Swift SVN r4964
2013-04-28 03:32:41 +00:00