Commit Graph

294 Commits

Author SHA1 Message Date
Slava Pestov
af83492a45 IRGen: Lazily emit reflection field descriptors
Previously even if a type's metadata was optimized away, we would still
emit a field descriptor, which in turn could reference nominal type
descriptors for other types via symbolic references, etc.
2019-04-12 01:46:23 -04:00
Slava Pestov
dd80f588dd IRGen: Emit foreign type metadata using the lazy metadata mechanism
Instead of a wholly separate lazyness mechanism for foreign metadata where
the first call to getAddrOfForeignTypeMetadataCandidate() would emit the
metadata, emit it using the lazy metadata mechanism.

This eliminates some code duplication. It also ensures that foreign
metadata is only emitted once per SIL module, and not once per LLVM
module, avoiding duplicate copies that must be ODR'd away in multi-threaded
mode.

This fixes the test case from <rdar://problem/49710077>.
2019-04-12 01:46:23 -04:00
Slava Pestov
61f21a7195 IRGen: Emit field reflection descriptors for types with custom alignment
The code to decide if field descriptors were going to be emitted was
confusing, so I've refactored it a bit.
2019-04-12 01:46:23 -04:00
Saleem Abdulrasool
b97857e99f IRGen: adjust for SVN r355989
SVN r355989 adds support for the XCOFF file format.  For now, treat it as a COFF
target, though XCOFF and COFF are different.
2019-03-13 13:31:24 -07:00
Saleem Abdulrasool
7f005414dd Merge pull request #21639 from compnerd/tinkering-linkering
ApplyIRLinkage cleanups
2019-01-04 15:26:11 -08:00
Saleem Abdulrasool
50d6b19e98 IRGen: use named IRLinkage a bit more (NFC)
Use the `IRLInkage::InternalLinkOnceODR` linkage rather than computing
that in a couple of sites.  This gives us semantic meaning to the
linkage being applied.  NFC.
2019-01-04 10:39:03 -08:00
Daniel Dunbar
1efee0c27a [Swift+WASM] Allow Wasm object format.
- This currently does nothing more than adopt the ELF conventions, but for the
   Wasm object file format.
2018-11-20 15:22:26 -07:00
swift-ci
126f9d7773 Merge pull request #20610 from DougGregor/abi-symbolic-accessor-ref-2-byte 2018-11-15 17:30:19 -08:00
Doug Gregor
3eb171d814 [ABI] Ensure that symbolic references to accessor functions are 2-byte aligned
When we emit "false" symbolic references to accesors for conformances or
type metadata, ensure that we end up with two-byte-aligned symbolic
references. This addresses a problem with ARM+Thumb compilation where the
low bit wasn't getting set for Thumb code.

Fixes rdar://problem/46067353.
2018-11-15 14:51:55 -08: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
Saleem Abdulrasool
4d4b7ecfb0 Merge pull request #20376 from compnerd/odr
IRGen: add a constant for common linkages
2018-11-13 19:02:16 -08:00
Saleem Abdulrasool
2117c46097 IRGen: add a constant for common linkages
Swift uses LinkOnceODR with Internal linkage and normal Internal linkage quite
frequently.  Define a constant for this.
2018-11-13 09:56:24 -08:00
Doug Gregor
b192cedf8d [Keypaths] Use mangled names to reference type and witness table accessors.
Switch key path metadata over to mangled names for each of the places it
refers to either a type metadata accessor or a witness table accessor. For
now, the mangled name is a symbolic reference to the existing accessors.

Part of rdar://problem/38038799.
2018-11-12 21:15:20 -08:00
Doug Gregor
81610fdc02 [ABI] Use faux mangled names for associated conformances in witness tables
The current representation of an associated conformance in a witness
tables (e.g., Iterator: IteratorProtocol within a witness table for
Sequence) is a function that the client calls.

Replace this with something more like what we do for associated types:
an associated conformance is either a pointer to the witness table (once
it is known) or a pointer to a mangled name that describes that 
conformance. On first access, demangle the mangled name and replace the
entry with the resulting witness table. This will give us a more compact
representation of associated conformances, as well as always caching
them.

For now, the mangled name is a sham: it’s a mangled relative reference to
the existing witness table accessors, not a true mangled name. In time,
we’ll extend the support here to handle proper mangled names.

Part of rdar://problem/38038799.
2018-11-12 09:42:51 -08:00
Slava Pestov
00c1279dbb Reflection: Compute if types are bitwise takable
Bitwise takability is now part of the layout of a type, because
non-bitwise takable types are never stored inline in an
existential or resilient global's buffer, even if they would
fit.

The basic rule is that weak references, unknown-refcounted
unowned references, and aggregates that contain them, are not
bitwise takable, whereas everything else is bitwise takable.

Also, since the bitwise takable for an unowned reference
depends on the reference counting style, we have to record the
superclass of a protocol, if any, to correctly determine the
reference counting style of the protocol existential.
2018-11-07 00:32:12 -05:00
Saleem Abdulrasool
86e5b2574c IRGen: introduce new IRLinkage applicator
In order to handle LinkOnceODR semantics correctly across various object
formats, introduce a new helper ApplyIRLinkage.  This abstracts the need
to create a COMDAT group and set it on the GlobalValue.  Adjust all
sites where we set the IR linkage attributes to use this mechanism
instead to avoid having to track down symbols not being added to a
COMDAT group.
2018-11-04 10:13:50 -08:00
Slava Pestov
e3efd001ca IRGen: Don't emit field descriptors for imported classes and protocols 2018-11-02 00:47:11 -04:00
Doug Gregor
4c21623a58 [IRGen] Ensure that we emit metadata for types referenced from mangled names. 2018-10-04 15:43:59 -07:00
Doug Gregor
65c0c842ed [ABI] Rework the tagging of default associated type witnesses.
Encode default associated type witnesses using a sentinel prefix byte
(0xFF) in the mangled name rather than as a second low bit on the
reference. Align all of the mangled names used for type references to
2 bytes (so we get that low bit regardless) and separate the symbol
names for default associated type witnesses vs. other kinds of
metadata or reflection metadata.
2018-09-28 23:38:38 -07:00
Doug Gregor
b531b3923f [ABI] Use mangled names for associated type witnesses.
Rather than storing associated type metadata access functions in
witness tables, initially store a pointer to a mangled type name.
On first access, demangle that type name and replace the witness
table entry with the resulting type metadata.

This reduces the code size of protocol conformances, because we no
longer need to create associated type metadata access functions for
every associated type, and the mangled names are much smaller (and
sharable). The same code size improvements apply to defaulted
associated types for resilient protocols, although those are more
rare. Witness tables themselves are slightly smaller, because we
don’t need separate private entries in them to act as caches.

On the caller side, associated type metadata is always produced via
a call to swift_getAssociatedTypeWitness(), which handles the demangling
and caching behavior.

In all, this reduces the size of the standard library by ~70k. There
are additional code-size wins that are possible with follow-on work:

* We can stop emitting type metadata access functions for non-resilient
types that have constant metadata (like `Int`), because they’re only
currently used as associated type metadata access functions.
* We can stop emitting separate associated type reflection metadata,
because the reflection infrastructure can use these mangled names
directly.
2018-09-26 23:19:33 -07:00
Joe Groff
2166dfcfdd Merge pull request #18746 from jckarter/nominal-type-field-info-xref
IRGen/Runtime: Reference field descriptor directly from type context descriptors.
2018-08-20 13:32:39 -07:00
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Joe Groff
6f45c2a36e IRGen/Runtime: Reference field descriptor directly from type context descriptors.
This saves us some expensive cross-referencing and caching in the runtime, and lets us reclaim the `isReflectable` bit from the context descriptor flags (since a null field descriptor is a suitable and more accurate indicator of whether a type is reflectable).
2018-08-15 14:19:53 -07:00
Doug Gregor
b08a6f56b4 [AST] Drop resilience expansion from TypeBase::getReferenceCounting().
We’re not using this parameter, and don’t expect to do so in the future,
so remove it. Also fold away TypeBase::usesNativeReferenceCounting()
and irgen::getReferenceCountingForType(), both of which are trivial.
2018-08-14 09:10:49 -07:00
Arnold Schwaighofer
cc7f207cec Rename swift sections from swift4 to swift5
rdar://38465220
2018-05-23 12:18:08 -07:00
Doug Gregor
d457f1c752 [IRGen/SIL] More widespread use of SubstitutionMap. 2018-05-11 13:18:06 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Slava Pestov
ea293c08b5 IRGen: Move getTypeRef() to a method on IRGenModule and clean up 2018-04-20 19:32:41 -07:00
Slava Pestov
11dfc1c357 IRGen: Don't pass around a ModuleDecl for mangling typerefs 2018-04-20 19:30:03 -07:00
Slava Pestov
a8b1723624 Reflection: Don't use the old box mangling
The TypeDecoder doesn't support the new box mangling yet and instead
just decodes it as Builtin.NativeObject, but that's OK because the
Remote Mirrors lowered the old box mangling as Builtin.NativeObject
anyway.
2018-04-20 19:24:08 -07:00
Mike Ash
0f73e32cfe [IRGen] Blacklist some more globals that caused trouble with ASAN on Linux.
rdar://problem/39128762
2018-04-11 15:21:13 -04:00
Mike Ash
e13c58dd56 [IRGen] Blacklist metadata globals from address sanitizer. Otherwise asan pads them in an attempt to detect overflows, which messes with other code which assumes that metadata is contiguous.
rdar://problem/39128762
2018-04-09 15:11:06 -04:00
Arnold Schwaighofer
0c11e1a0a3 Mark swift sections as swift4 for Swift 4.2
rdar://36363251
2018-03-14 10:27:28 -07:00
Pavel Yaskevich
877c70bae9 [Runtime/Metadata] Add support for dynamic field descriptor registration 2018-02-20 18:20:09 -08:00
Joe Groff
953dddd5d3 IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
This makes resolving mangled names to nominal types in the same module more efficient, and for eventual secrecy improvements, also allows types in the same module to be referenced from mangled typerefs without encoding any source-level name information about them.
2018-02-10 10:43:47 -08:00
Pavel Yaskevich
478ba2693a [IRGen] Emit type field descriptors for imported structs 2018-02-06 15:50:52 -08:00
Mark Lacey
8667eb6f91 Revert "[WIP][IRGen] Emit type field descriptors for imported structs" 2018-02-03 10:27:34 -08:00
Pavel Yaskevich
9e08ea4c56 [Reflection] Add support for imported structs with recorded fields
Update IRGen to trigger generation of type metadata for foreign
struct types found in fields. And fix TypeRefBuilder to handle
the case where struct has fields but at the same time has opaque
metadata.
2018-02-02 15:54:12 -08:00
Pavel Yaskevich
ca1fd0706c [IRGen] Emit type field descriptors for imported structs 2018-02-02 15:38:32 -08:00
Joe Groff
3258902f77 Preserve whether fields are var or let in the reflection metadata.
Useful for future mutable reflection features to know whether they're allowed to mutate a field after initialization.
2018-01-31 19:04:39 -08:00
Arnold Schwaighofer
17cd95efa4 Rename swift3 section and global names to swift5
Such that old and new runtimes can co-exists
rdar://36363251
2018-01-22 10:04:46 -08:00
Doug Gregor
e28e856595 [Runtime] Use bare protocol mangling for protocol descriptors.
The mangled name of protocol descriptors was the “protocol composition”
type consisting of a single protocol, which is a little odd. Instead,
use a bare protocol reference (e.g., “6Module5ProtoP”) with the “$S”
prefer to be more in line with nominal type descriptor names while still
making it clear that this is a Swift (not an Objective-C) protocol.
2018-01-09 10:21:55 -08:00
Saleem Abdulrasool
899103cfa8 COFF: restructure metadata registration
Restructure the COFF metadata handling to use the linker section
grouping to emit section start/stop markers in the appropriate location.
This allows us to lookup the sections statically without having to the
walk the entire image structure.

Introduce a constructor for PE/COFF binaries.  This will ensure that the
registration occurs for all modules appropriately.  This should resolve
rdar://problem/19045112.  The registration should occur prior to
`DllMain` being invoked from `DllMainCRTStartup`.
2017-12-08 16:15:07 -08:00
Saleem Abdulrasool
0c42b57962 ELF: restructure image metadata registration
Restructure the ELF handling to be completely agnostic to the OS.
Rather than usng the loader to query the section information, use the
linker to construct linker tables and synthetic markers for the
beginning and of the table.  Save off the values of these pointers and
pass them along through the constructor to the runtime for registration.

This removes the need for the begin/end objects.  Remove the special
construction of the begin/end objects through the special assembly
constructs, preferring to do this in C with a bit of inline assembly to
ensure that the section is always allocated.

Remove the special handling for the various targets, the empty object
file can be linked on all the targets.

The new object file has no requirements on the ordering.  It needs to
simply be injected into the link.

Name the replacement file `swiftrt.o` mirroring `crt.o` from libc.  Merge
the constructor and the definition into a single object file.

This approach is generally more portable, overall simpler to implement,
and more robust.

Thanks to Orlando Bassotto for help analyzing some of the odd behaviours
when switching over.
2017-11-28 10:04:04 -08:00
Huon Wilson
5f70f68c0d [AST] Store only interface types in NormalProtocolConformances.
Rather than storing contextual types in the type witnesses and associated
conformances of NormalProtocolConformance, store only interface types.

@huonw did most of the work here, and @DougGregor patched things up to
complete the change.
2017-11-16 11:45:18 -08:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Slava Pestov
cce30cc9bb SIL: Remove SILFunction::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Slava Pestov
55cd329cb3 Reflection: Remove logic for the parent metadata source 2017-09-25 15:45:17 -07:00
John McCall
6d9294f565 Random improvements for ArrayRefView. 2017-09-25 02:05:23 -04:00
Slava Pestov
5f1b85e704 IRGen: Fix emission of reflection metadata for @objc enums
@objc enums lower as their raw type, so should go through the same
code path as imported enums.

Fixes <https://bugs.swift.org/browse/SR-5625> and
<rdar://problem/33683103>.
2017-08-03 20:33:09 -07:00