Commit Graph

294 Commits

Author SHA1 Message Date
John McCall
7f22faf968 Substantially rework how SILGen handles bridging as part of laying the
ground work for the syntactic bridging peephole.

- Pass source and dest formal types to the bridging routines in addition
  to the dest lowered type.  The dest lowered type is still necessary
  in order to handle non-standard abstraction patterns for the dest type.

- Change bridging abstraction patterns to store bridged formal types
  instead of the formal type.

- Improve how SIL type lowering deals with import-as-member patterns.

- Fix some AST bugs where inadequate information was being stored in
  various expressions.

- Introduce the idea of a converting SGFContext and use it to regularize
  the existing id-as-Any conversion peephole.

- Improve various places in SILGen to emit directly into contexts.
2017-07-11 12:45:13 -04:00
Alex Hoppen
949968a182 Adjust printing to take into account special DeclNames
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
2017-06-24 11:39:09 +02:00
Doug Gregor
68164ade6d [AST] Use ParenType for the input type of canonical function types.
As a step toward eliminating the single input type
representation of function parameters, add more constraints on that
input type. It can be one of:

* A tuple type, for multiple parameters,
* A parenthesized type, for a single parameter, or
* A type variable type, for specific cases in the type checker

Enforce these constraints for *canonical* types as well, so the
canonical form of:

    typealias MyInt = Int
    typealias MyFuncType = (MyInt) -> Int

is now:

    (Int) -> Int

rather than:

    Int -> Int

This affects canonicalization of FunctionType and
GenericFunctionType. Enchance both, as well as their Can*Type
counterparts, with "get" operators that take an array of
AnyFunctionType::Param, and start switching a few clients over to this
new, preferred API.
2017-06-23 10:48:06 -07:00
Slava Pestov
ab4d37a422 Reflection: Record superclass as its own field instead of an associated type of AnyObject
The "superclass as associated type" modeling was put in to
maintain backward compatibility.

We just bumped the version number because of new mangling so
we may as well fix this sillyness too.
2017-05-02 01:18:49 -07:00
Slava Pestov
cb95ee3581 IRGen: Don't crash when emitting a capture descriptor containing an opened existential 2017-04-25 01:32:45 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Doug Gregor
ebdd56a1f0 [AST] Eliminate the "interface type" from protocol conformances.
We don't need this notion.
2017-04-18 17:15:15 -07:00
Slava Pestov
497336c4bc IRGen: Use the right reference counting for subclass existentials 2017-04-17 17:22:28 -06:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Slava Pestov
d49f8fb6d9 AST: Introduce primitive AnyObject type
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.
2017-04-13 21:17:05 -07:00
Huon Wilson
31b92b1b46 Merge pull request #8473 from huonw/symbol-list-2
Remove dependency on IRGenModule of some linkage computations
2017-04-05 16:39:04 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Huon Wilson
3105c6ed00 [IRGen] Expose LinkInfo publicly, like LinkEntity. 2017-04-05 09:54:19 -07:00
John McCall
3c5de5fa0a Preserve type canonicality better in several places and
idiomatize some uses of SILType::getSwiftRValueType().
2017-03-14 14:59:43 -04:00
John McCall
f0cc98a71e Adopt ConstantInitBuilder in reflection metadata emission. NFC. 2017-03-06 15:15:49 -05:00
Erik Eckstein
2d127e4192 Reinstate ”Use the new mangling for reflection."
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.
2017-02-15 09:47:22 -08:00
Slava Pestov
5296d02485 AST: More include-what-you-use gardening 2017-02-12 00:51:26 -08:00
Erik Eckstein
254f36aba5 Revert "Use the new mangling for reflection."
This needs some changes in lldb.
Disabled for now until lldb supports the new mangling.

This reverts commit 21ba292943.
2017-02-08 09:01:51 -08:00
David Farler
1b141d368e Fix two more duplicate case llvm::Triple::Wasm 2017-02-07 17:20:00 -08:00
Hugh Bellamy
86d204c6fe Merge pull request #7052 from hughbe/object-model
Fix warnings for llvm::Triple::Wasm after updating LLVM to upstream
2017-02-08 08:01:55 +07:00
Erik Eckstein
21ba292943 Use the new mangling for reflection.
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.
2017-02-07 08:36:21 -08:00
Slava Pestov
36433f126e IRGen: Fix some non-exhaustive switch warnings 2017-02-06 22:39:26 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
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>.
2017-02-06 21:36:33 -08:00
Hugh Bellamy
35eaf68461 Fix warnings for llvm::Triple::Wasm after updating LLVM to upstream
> warning C4062: enumerator 'llvm::Triple::Wasm' in switch of enum
'llvm::Triple::ObjectFormatType' is not handled
2017-01-26 10:12:23 +00:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
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.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
fb0f372e94 AST: Move mapType{In,OutOf}Context() out of ArchetypeBuilder and clean up headers
- 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.
2016-12-18 19:55:41 -08:00
Michael Gottesman
96c63e9e76 Merge pull request #6324 from practicalswift/cpp-gardening
[gardening] C++ gardening: Terminate namespaces, fix argument names, …
2016-12-16 23:30:33 -08:00
Joe Groff
4444d83756 SIL: Lower captures to boxes with an appropriate generic context.
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.
2016-12-16 20:23:25 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
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.
2016-12-17 00:32:42 +01:00
Joe Groff
3871cda205 Push SILBoxType::getFieldType into SIL and make it take a SILModule.
Applying nontrivial generic arguments to a nontrivial SIL layout requires lowered SILType substitution, which requires a SILModule. NFC yet, just an API change.
2016-12-09 16:21:13 -08:00
Joe Groff
7429ffb228 Mangle SILBoxTypes with their layout.
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.
2016-12-08 20:02:44 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
78d11de396 IRGen: Emit fixed type descriptors for structs and enums with @_alignment attributes
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.
2016-11-16 19:23:04 -08:00
Slava Pestov
94f0ffd591 IRGen: Don't emit reflection metadata for builtin types unless we're building the standard library
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>.
2016-10-27 16:13:40 -07:00
Slava Pestov
30b1efa87b IRGen: Emit superclass information for remote reflection
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.
2016-09-24 02:17:46 -07:00
Slava Pestov
7dbab3cc32 IRGen: Clean up reflection metadata emission
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.
2016-09-24 02:17:45 -07:00
Slava Pestov
6f074f7677 IRGen: Fix capture descriptor emission for @pseudogeneric functions
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.
2016-09-15 21:45:52 -07:00
Slava Pestov
47d7cacb98 IRGen: Fix emission of builtin reflection descriptors in multi-threaded mode
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>.
2016-09-12 19:44:53 -07:00
Slava Pestov
b677a2e6a7 AST: Use the new Type::subst() in a few places
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.
2016-09-08 21:59:13 -07:00
Slava Pestov
a993e36c06 AST: Add a new SubstitutionMap data structure
This replaces the TypeSubstitutionMap / ConformanceMap pair that
has been appearing more and more lately.
2016-09-08 21:59:11 -07:00
David Farler
14192bfa99 [IRGen] Use hidden visibility for __swift_reflection_version constant
This prevents it from having weak external linkage.

rdar://problem/27367632
2016-07-15 00:30:12 -07:00
David Farler
fd46a60785 IRGen: Emit reflection metadata version into Swift binaries
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
2016-07-08 17:21:25 -07:00
Slava Pestov
95bc009e3e Reflection: Multi-payload enum layout
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.
2016-07-01 01:31:25 -07:00
John McCall
266fa150db Bring PolymorphicConvention back into GenProto.cpp and expose
just the targeted operation that GenReflection actually needs.

NFC.
2016-06-30 18:34:00 -07:00
Slava Pestov
48c928938a Reflection: Single-payload enum layout
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.
2016-06-30 12:57:14 -06:00
practicalswift
f7deb79dcb [gardening] Remove addObjCClassRecord()
The last in-repo usage was removed in 97fd1a7411
2016-06-07 19:38:57 +02:00
Saleem Abdulrasool
83b2b5994a IRGen: support reflection for swift 3 on COFF
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.
2016-06-02 23:23:42 -07:00
Slava Pestov
60dff01093 Reflection: Simplify associated type metadata emission
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.
2016-05-26 19:33:00 -07:00
Slava Pestov
7a46b0f23f Reflection: Emit descriptors for referenced imported protocols
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.
2016-05-26 19:33:00 -07:00