Add a 'hasExplicitAnyObject()' bit to ProtocolCompositionType
to represent canonical composition types containing '& AnyObject'.
Serialize this bit and take it into account when building
ExistentialLayouts.
Rename ProtocolCompositionType::getProtocols() to getMembers()
since it can contain classes now, and update a few usages that
need further attention with FIXMEs or asserts.
For now, nothing actually constructs these types, and they will
trigger arounds asserts. Upcoming patches will introduce support
for this.
It also uses the new mangling for type names in meta-data (except for top-level non-generic classes).
lldb has now support for new mangled metadata type names.
This reinstates commit 21ba292943.
For this we are linking the new re-mangler instead of the old one into the swift runtime library.
Also we are linking the new de-mangling into the swift runtime library.
It also switches to the new mangling for class names of generic swift classes in the metadata.
Note that for non-generic class we still have to use the old mangling, because the ObjC runtime in the OS depends on it (it de-mangles the class names).
But names of generic classes are not handled by the ObjC runtime anyway, so there should be no problem to change the mangling for those.
The reason for this change is that it avoids linking the old re-mangler into the runtime library.
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.
For now, it's just a typedef for ArrayRef<Substitution>.
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.
Modify all the callsites, and get rid of the typedef.
- The DeclContext versions of these methods have equivalents
on the DeclContext class; use them instead.
- The GenericEnvironment versions of these methods are now
static methods on the GenericEnvironment class. Note that
these are not made redundant by the instance methods on
GenericEnvironment, since the static methods can also be
called with a null GenericEnvironment, in which case they
just assert that the type is fully concrete.
- Remove some unnecessary #includes of ArchetypeBuilder.h
and GenericEnvironment.h. Now changes to these files
result in a lot less recompilation.
Officially kick SILBoxType over to be "nominal" in its layout, with generic layouts structurally parameterized only by formal types. Change SIL to lower a capture to a nongeneric box when possible, or a box capturing the enclosing generic context when necessary.
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
Applying nontrivial generic arguments to a nontrivial SIL layout requires lowered SILType substitution, which requires a SILModule. NFC yet, just an API change.
Use a new mangling scheme that describes the layout of compound boxes. For compatibility with reflection-based clients, continue to use the legacy mangling for single-field boxes when emitting reflection TypeRefs until we fully support reflection for the new box implementation.
This attribute is used in the simd overlay. To ensure we can layout
SIMD types correctly, emit a fixed type descriptor instead of a
field type descriptor for these types.
I couldn't reduce a test case, but it seems to come up with optimizations
enabled. We should have already emitted metadata for everything when we
built the stdlib, no need to do it again.
Fixes <rdar://problem/28924516>.
In order to perform associated type lookups for an inherited
conformance of a derived class, the reflection library needs
to know superclasses of all classes.
Previously we had no way of recovering this information
(short of some kind of reverse lookup in the metadata cache).
Oops!
To avoid causing problems with old/new compiler vs old/new
libswiftRemoteMirrors.dylib, this introduces the new record
in a backward-compatible way: we emit a fake AnyObject
conformance with a fake 'super' associated type to store
the superclass of a class.
Not yet hooked up in the reflection library itself.
There was some duplication here, and also a potential
memory management issue; it appears that we were
converting a temporary std::string to a StringRef
when setting the section name of a global.
Pseudogeneric functions do not have runtime type metadata in
their closure context, so don't try to emit metadata sources
in the capture descriptor for reflection.
Also, erase generic type parameters in capture types down to
AnyObject, since the reflection library won't be able to
substitute them.
Ensure they get emitted at the end of the job by the dispatcher, and
also use a proper mangling and shared linkage for these symbols so
that if multiple threads emit the same descriptor it gets merged.
The new tests attempt to exercise these scenarios.
Fixes <rdar://problem/27906876>.
SILType substitutions are still done with the old form, and until
BoundGenericTypes hold conformances, we still have to pass around
a ModuleDecl in a few places we really shouldn't, but one step
at a time.
Emit a 16-bit constant that tracks the version of the reflection
metadata emitted into binaries. This can be used to cross-check
what is supported by the SwiftRemoteMirror library with the new
version API.
rdar://problem/27251582
The approach here is to split this into two cases:
- If all case payloads have a fixed size, spare bits may be
potentially used to differentiate between cases, and the
remote reflection library does not have enough information to
compute the layout itself.
However, the total size must be fixed, so IRGen just emits a
builtin type descriptor (which I need to rename to 'fixed type
descriptor' since these are also used for imported value types,
and now, certain enums).
- If at least one case has a size that depends on a generic
parameter or is a resilient type, IRGen does not know the size,
but this means fancy tricks with spare bits cannot be used either.
The remote reflection library uses the same approach as the
runtime, basically taking the maximum of the payload size and
alignment, and adding a tag byte.
As with single-payload enums, we produce a new kind of
RecordTypeInfo, this time with a field for every enum case.
All cases start at offset zero (but of course this might change,
if for example we put the enum tag before the address point).
Also, just as with single-payload enums, there is no remote
'project case index' operation on ReflectionContext yet.
So the the main benefit from this change is that we don't entirely
give up when doing layout of class instances containing enums;
however, tools still cannot look inside the enum values themselves,
except in the simplest cases involving optionals.
Notably, the remote reflection library finally understands all
of the standard library's collection types -- Array, Character,
Dictionary, Set, and String.
Attempt to lay out single-payload enums, using knowledge of extra
inhabitants where possible.
- The extra inhabitants of an aggregate are the extra inhabitants of
the first field. If the first field is empty, there are no extra
inhabitants, and subsequent fields do not affect anything.
- Function pointers and metatypes have different extra inhabitants
than Builtin.RawPointer, so have IRGen emit distinct builtin type
descriptors for those.
- Opaque existentials do not have extra inhabitants.
- Weak references do not have extra inhabitants.
Also, fix IRGen to emit more accurate enum reflection metadata in
these two cases:
- We now record whether enum cases are indirect or not. An indirect
case is the same as a payload case with Builtin.NativeObject.
- We now record whether a case is empty or not using the same logic
as the rest of IRGen. Previously, we would incorrectly emit a
payload type for a case with a payload that is an empty struct,
for example.
At this point we don't have a way to get the currently inhabited
enum case from a value. However, this is still an improvement because
we can still reflect other fields of aggregates containing enums,
instead of just giving up.
Finally make some methods on TypeCoverter private, and use 'friend'
to allow them to be accessed from other internal classes, making the
public API simpler.
COFF has restrictions on portable section length (8 characters). Use a FourCC
identifier for the section on COFF. Take the opportunity to replace a
std::string parameter with a StringRef.
Instead of hooking into nominal type and extension emission
and walking all conformances of those declarations, let's
just directly hook into the logic for emitting conformances.
This fixes an issue where we would apparently emit duplicate
conformances, as well as unnecessary conformances that are
defined elsewhere.
When we encounter a protocol typeref, we have to know if its @objc,
class-bound, or opaque, so make sure we provide the necessary
information when imported protocols are referenced.
While we can skip emitting metadata for imported classes (clients
should ask the Objective-C runtime instead) it was not correct to
do so for Swift-defined classes that used Objective-C reference
counting.
Previously we would emit both a builtin descriptor and field
descriptor for imported classes, but we only need the latter.
Untangle some code and fix a crash with imported Objective-C
generics in the process.
Fixes <rdar://problem/26498484>.
We were recovering metadata from generic boxes by reading
the instantiated payload metadata from the box's metadata,
but this approach doesn't work for fixed-size boxes, whose
metadata does not store the payload metadata at all.
Instead, emit a capture descriptor with no metadata sources
and a single capture, using the lowered AST type appearing
in the alloc_box instruction that emitted the box.
Since box metadata is shared by all POD types of the same
size, and all single-retainable pointer payloads, the
AST type might not accurately reflect what is actually in
the box.
However, this type is *layout compatible* with the box
payload, at least enough to know where the retainable
pointers are, because after all IRGen uses this type to
synthesize the destructor.
Fixes <rdar://problem/26314060>.
When emitting capture descriptors for functions with a smaller number of parameters
than SIL parameters, the compiler can crash indexing into the heap layout's element
types, because the capture index underflows to UINT_MAX.
rdar://problem/26404583
- Lower Objective-C class typerefs as strong references with unknown
reference counting.
- Lower other imported C types as builtin blobs of their known
size, alignment, etc.
In the future, it might be beneficial to track which stored properties
of imported types are pointers, for better conservative scanning of
outgoing pointers to the heap.
rdar://problem/26240258
rdar://problem/26240394