Commit Graph

93 Commits

Author SHA1 Message Date
Daniel Rodríguez Troitiño
ada8217c0f [windows] Enable symbolic references in PE/COFF.
In order for the cross-module optimization to work, it needs to generate
symbolic references, which were disabled in PE/COFF. This commit enables
them and marks some Reflection tests with XFAIL since
swift-reflection-dump still doesn't handle symbolic references.
2019-12-05 13:42:57 -08:00
Xi Ge
7e8ed50233 ASTMangler: use specified module names from @_originalDefinedIn to mangle symbols names
When an original module name is specified via @_originalDefinedIn attribute, we need to
use the original module name for all related runtime symbol names instead of the current
module names.

rdar://55268186
2019-12-02 16:58:31 -08:00
Joe Groff
ce6de7e81d swift-reflection-dump: ELF ObjectMemoryReader support for relocations
Collect the relative and symbol relocations from ELF images in order to resolve pointer values
read from disk. This allows us to enable symbolic-referencing-all-the-things for ELF platforms.
2019-10-03 14:28:24 -07:00
Joe Groff
c39a2aeb0a IRGen: Always use symbolic references in mangled names (on Mach-O platforms)
Now that `swift-reflection-dump` correctly handles pointer values and unresolved
cross-image references (for Mach-O, at least), we can safely unconditionally use
symbolic references in runtime mangled names without regressing offline reflection
support.
2019-10-01 12:36:55 -07:00
Joe Groff
0ae86c9c9d IRGen: Backward-deploy fix using open-coded accessors.
If we mangled an opaque associated type while targeting an older OS, we can use a \9
accessor reference string to instantiate the associated type.
2019-09-04 10:22:17 -07:00
Joe Groff
95c43f4e18 Decode opaque types in the runtime demangler. 2019-04-17 14:44:40 -07:00
Arnold Schwaighofer
2c33b72b11 IRGen: Mangle symbolic type references as private types even with enable-private-imports 2019-03-20 11:54:56 -07: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
John McCall
2ba7090fe8 Remove the extra-inhabitant value witness functions.
This is essentially a long-belated follow-up to Arnold's #12606.
The key observation here is that the enum-tag-single-payload witnesses
are strictly more powerful than the XI witnesses: you can simulate
the XI witnesses by using an extra case count that's <= the XI count.
Of course the result is less efficient than the XI witnesses, but
that's less important than overall code size, and we can work on
fast-paths for that.

The extra inhabitant count is stored in a 32-bit field (always present)
following the ValueWitnessFlags, which now occupy a fixed 32 bits.
This inflates non-XI VWTs on 32-bit targets by a word, but the net effect
on XI VWTs is to shrink them by two words, which is likely to be the
more important change.  Also, being able to access the XI count directly
should be a nice win.
2018-12-11 22:18:44 -05:00
Doug Gregor
f759296cc8 [Keypaths] Encode generic environment in the key-path pattern.
Extend the key-path pattern with a representation of the generic environment
of the key-path, which includes the generic parameters and generic
requirements of the environment.
2018-11-16 10:13:06 -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
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
Doug Gregor
54615ff699 [IRGen] Use symbolic references to (file)private entities in mangled names.
(file)private entities are always available in the current file, so use
symbolic references to refer to them within mangled names (always). This
also eliminates problems stemming from our inability to demangle names
referring to private entities, because we (intentionally) don't allow
lookup for them.

Should fix rdar://problem/44977236.
2018-10-23 20:48:40 -07:00
Doug Gregor
5b41ac16db [ABI] Introduce indirect symbolic references to context descriptors.
Extending the mangling of symbolic references to also include indirect
symbolic references. This allows mangled names to refer to context
descriptors (both type and protocol) not in the current source file.

For now, only permit indirect symbolic references within the current module,
because remote mirrors (among other things) is unable to handle relocations.

Co-authored-by: Joe Groff <jgroff@apple.com>
2018-10-23 16:06:42 -07:00
Greg Parker
46b105e4d6 Revert "[IRGen] Use symbolic references to (file)private entities in mangled names" 2018-10-13 04:56:02 -07:00
Doug Gregor
a4d53b8985 [IRGen] Use symbolic references to (file)private entities in mangled names.
(file)private entities are always available in the current file, so use
symbolic references to refer to them within mangled names (always). This
also eliminates problems stemming from our inability to demangle names
referring to private entities, because we (intentionally) don't allow
lookup for them.

Should fix rdar://problem/44977236.
2018-10-11 21:27:07 -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
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07:00
Doug Gregor
f232af5535 [Mangling] Allow standard substitutions in protocol mangling.
Protocol name mangling didn’t always go through a path that allowed the use
of standard substitutions. Enable standard substitutions for protocol name
manglings where they make sense.

Removes ~277k from the standard library binary size.
2018-06-19 23:24:38 -07:00
Joe Groff
14fd26a6ed IRGen: More specifically curtail JIT use of relative references to the integrated REPL.
The other JIT modes all still build an entire local context into one LLVM module, so it's safe to form relative references, and necessary for reflection to work with private and local contexts. Only the integrated REPL needs this prohibition. Fixes rdar://problem/40607819.
2018-06-12 14:11:36 -07:00
Arnold Schwaighofer
6267860a7e IRGen: Remove initializeBufferWithTakeOfBuffer in favor of memcpy
And update the existential container's initializeWithTake implementation
in the runtime. After only allowing bitwise takable values in the
inline buffer we can use memcpy to move existential container values.

rdar://31414907
SR-343
2018-05-22 13:05:00 -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
Slava Pestov
19982ebaaa IRGen: Header gardening 2018-03-27 16:24:19 -07:00
John McCall
738bff0089 Move ValueWitnessFlags into MetadataValues.h. NFC. 2018-03-17 11:40:30 -04: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
Arnold Schwaighofer
865d85bd1c Reapply the enum value witness patch
Revert "Revert "Merge pull request #12606 from aschwaighofer/single_payload_enum_witness""

This reverts commit c422f80307.
2017-10-31 17:28:15 -07:00
Arnold Schwaighofer
c422f80307 Revert "Merge pull request #12606 from aschwaighofer/single_payload_enum_witness"
This reverts commit 0b414e45c5, reversing
changes made to fb27e7d32a.

There are failures on the resilient bot and lldb test case fails.
2017-10-31 08:24:26 -07:00
Arnold Schwaighofer
43b9d13a2e Add value witnesses for single payload enums
So far single payload enums were implemented in terms of runtime functions which
internally emitted several calls to value witnesses.

This commit adds value witnesses to get and store the enum tag side stepping the
need for witness calls as this information is statically available in many cases

/// int (*getEnumTagSinglePayload)(const T* enum, UINT_TYPE emptyCases)
/// Given an instance of valid single payload enum with a payload of this
/// witness table's type (e.g Optional<ThisType>) , get the tag of the enum.

/// void (*storeEnumTagSinglePayload)(T* enum, INT_TYPE whichCase,
///                                   UINT_TYPE emptyCases)
/// Given uninitialized memory for an instance of a single payload enum with a
/// payload of this witness table's type (e.g Optional<ThisType>), store the
/// tag.

A simple 'for element in array' loop in generic code operating on a
ContigousArray of Int is ~25% faster on arm64.

rdar://31408033
2017-10-23 13:31:46 -07:00
Arnold Schwaighofer
8a85a9efd5 Use array copy runtime implementation instead of the array value witnesses
And add builtins for the added runtime functions (assign-take, assign-copy).

rdar://27412867
SR-3376
2017-09-12 12:43:26 -07:00
Arnold Schwaighofer
ca63326e1b Delete unused existential value witnesses from the old existential
implementation

And remove the SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS flag.
2017-06-02 14:34:41 -07:00
Slava Pestov
a2c1548055 IRGen: Fix type conversion of protocol compositions containing a generic superclass constraint
Do the same thing we do for nominal types, where if the type
contains an archetype, just mangle the unbound generic form,
since the name is just for documentation purposes in LLVM IR
dumps and does not have to be unique.

This is tested as part of an upcoming patch.
2017-04-25 01:32:45 -07:00
Slava Pestov
7bf2f7d6fc IRGen: Start using ExistentialLayout
Replace a few usages of TypeBase::getExistentialTypeProtocols(),
which I'm going to remove.

NFC for now, since subclass existentials are still not fully
plumbed through here.
2017-04-13 21:29:57 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -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
8e3b05d2f4 IRGen: Use new mangling for llvm type names.
This should have no effect on the generated binary.
2017-02-22 09:19:10 -08:00
Erik Eckstein
e6f2e7bc88 Mangling: add a few utility functions in the new mangler and demangler which will be used by reflection mangling 2017-02-07 08:36:21 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Erik Eckstein
ad1c079632 Mangling: support new mangling of partial apply forwarders in IRGen 2016-12-09 10:28:34 -08:00
practicalswift
8f11e162d7 [gardening] Fix headers. 2016-12-06 21:39:23 +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