Commit Graph

116 Commits

Author SHA1 Message Date
Hamish Knight
d4c25f55c2 [AST] Reject GenericFunctionType in TypeBase::getTypeOfMember
Remove the default argument for the `memberType`
parameter and enforce that GenericFunctionType is
not passed. Also add a defaulted overload for the
property case, as they should never have a
GenericFunctionType interface type.
2021-07-20 14:11:31 +01:00
Egor Zhdan
7141ae24cf C++ Interop: import call operators
This change adds support for calling `operator()` from Swift code.

As the C++ interop manifesto describes, `operator()` is imported into Swift as `callAsFunction`.
2021-03-02 21:13:57 +03:00
Joe Groff
4bb49ba521 SILGen/ClangImporter: Handle async imports with a boolean error flag argument.
Import APIs with the `swift_async_error` attribute in `zero_argument` or `nonzero_argument`
modes by checking the corresponding boolean argument to indicate the error status, instead of
treating it as part of the result tuple. rdar://70594666
2021-02-19 17:31:09 -08:00
Joe Groff
6db85203db SIL: Abstraction pattern support for multiple foreign async returns.
An ObjC API maybe imported as async that had multiple non-error arguments to
its completion handler, which we treat in Swift as returning a tuple. Use a new
form of abstraction pattern to represent this return type, to maintain the
correct relation between individual tuple elements and the Clang block parameter
types they map to.
2020-11-12 16:53:21 -08:00
Joe Groff
577f83a260 SIL: Type lowering for imported ObjC async decls.
When lowering the type for `@objc` entry points of async declarations, restore
the original ObjC signature with the completion handler argument in the lowered
SIL type.
2020-10-27 09:00:45 -07:00
Michael Forster
26358c4588 Import member operator functions as static members (#32293)
This adds support to `ClangImporter` to import C++ member function operators as static methods into Swift, which is part of SR-12748.

The left-hand-side operand, which gets passed as the `this` pointer to the C++ function is represented as an additional first parameter in the Swift method. It gets mapped back in SILGen.

Two of the tests are disabled on Windows because we can't yet call member functions correctly on Windows (SR-13129).
2020-07-03 11:06:22 +02:00
marcrasi
495b571278 [AutoDiff upstream] Add @differentiable function reabstraction. (#30692)
Add SILGen logic for reabstracting `@differentiable` functions.

Resolves TF-1223.

Co-authored-by: Dan Zheng <danielzheng@google.com>
2020-03-28 12:27:14 -07:00
John McCall
be576c6246 Require types to be contextually canonical in AbstractionPatterns.
Because violations of this might have made an AbstractionPattern incorrectly show up as abstract, it's possible that this will cause an ABI change.  However, I haven't been able to find any examples where it does, and certainly there's no way we can promise to maintain the old behavior, especially since it's not done consistently.
2020-03-08 01:37:49 -05:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
Joe Groff
5140174eb5 SIL: Plumb abstraction patterns through type lowering.
Lowering a SIL type should be a pure function of the formal type of a value and the
abstraction pattern it's being lowered against, but we historically did not carry
enough information in abstraction patterns to lower generic parameter types, so we
relied on a generic context signature that would be pushed and popped before lowering
interface types. This patch largely eliminates the necessity for that, by making it
so that `TypeClassifierBase` and its subclasses now take an `AbstractionPattern`
all the way down, and fixing up the visitor logic so that it derives appropriate
abstraction patterns for tuple elements, function arguments, and aggregate fields too.
This makes it so that type lowering is independent of the current generic context.
(Unfortunately, there are still places scattered across the code where we use the
current generic context in order to build abstraction patterns that we then feed
into type lowering, so we can't yet completely eliminate the concept.)

This then enables us to integrate substituted function type construction into type
lowering as well, since we can now lower a generic parameter type against an
abstraction pattern without that generic parameter having to be tied to the same
generic signature (or any generic signature at all, which in the case of a
substituted function type hasn't necessarily even been finalized yet.)
2019-12-02 12:15:56 -08:00
Sasha Krassovsky
63a81fd864 Fix warnings in SIL 2019-09-13 09:57:48 -07:00
Parker Schuh
4a5dae5ed4 Add importing cxx function decls and the basic requisite AbstractionPattern support. 2019-07-30 15:46:47 -07:00
Joe Groff
78b4870721 Relax some assertions to allow opaque-type values at global scope in scripts.
rdar://problem/49818962
2019-04-17 14:46:22 -07:00
Joe Groff
0255baa97f SILGen: Start supporting opaque result types resiliently.
Tear out the hacks to pre-substitute opaque types before they enter the SIL type system.
Implement UnderlyingToOpaqueExpr as bitcasting the result of the underlying expression from the
underlying type to the opaque type.
2019-04-17 14:43:32 -07:00
Joe Groff
e3bbd8ce9e Remove ResilienceExpansion from substOpaqueTypes for now.
It's currently meaningless, and it'll require thought to pass the correct value when it becomes
meaningful.
2019-04-17 14:43:32 -07:00
Joe Groff
7a8b9401ab Respond to Slava's feedback 2019-04-17 14:43:32 -07:00
Joe Groff
c771a7e71b SILGen: Substitute away opaque types. 2019-04-17 14:43:32 -07:00
Slava Pestov
ebe769a58c SIL: Stop imploding parameter list into a single value with opaque abstraction pattern
The constraint solver support for the Swift 3 function type behavior
has been removed, so it's no longer possible to pun the same value as
both a function taking multiple parameters and a function taking a
single tuple argument.

This means the entire parameter list is no longer a target for
substitution as a single value, so the most general form of a function
value passes each parameter indirectly instead of passing a single
tuple parameter indirectly.
2018-09-26 23:20:54 -07:00
Slava Pestov
e7b911e3fe SIL: Remove no longer used AbstractionPattern kinds 2018-09-25 23:13:07 -07:00
Slava Pestov
e8bb14c106 SIL: Remove AbstractionPattern::getFunctionInputType() 2018-09-25 23:13:07 -07:00
Slava Pestov
c99c0c52fb SIL: Remove AbstractionPattern::getWithoutSpecifierType() 2018-09-25 23:13:07 -07:00
Slava Pestov
55814b530d SIL: Remove AbstractionPattern::getTupleElements() 2018-09-24 22:59:07 -07:00
Slava Pestov
c70f9396c2 SIL: Add AbstractionPattern::getNumFunctionParams() 2018-09-24 22:59:07 -07:00
Slava Pestov
a64521e77e SIL: Remove AbstractionPattern::transformType() 2018-09-14 13:37:43 -07:00
Slava Pestov
a323fd8f31 SIL: Remove AbstractionPattern::dropLastTupleElement() 2018-09-14 13:37:43 -07:00
Slava Pestov
dd3364a7d1 SIL: Add AbstractionPattern::getFunctionParamType()
I will need to rip out AbstractionPattern::getFunctionInputType().
This is the eventual replacement.
2018-08-18 01:54:18 -04:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Mark Lacey
944a5c6cb6 IUO: Remove some uses of the two-param form of OptionalType::get.
These are cases where it's clearly always identical to just using the
single-parameter form of OptionalType::get.
2018-01-09 03:19:29 -08:00
David Zarzycki
82e08ed3b7 [AST] NFC: Repack misc AbstractFunctionDecl bits 2017-12-10 20:38:01 -05:00
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -07:00
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
Robert Widmann
957d633185 Rename getInOutOrLValueObjectType to getWithoutSpecifierType
Prepares the AST for a future in which more than just inout and
@lvalue need to be stripped off of ephemeral types.
2017-07-06 09:35:04 -07:00
Slava Pestov
76834a12ed SIL: Rename AbstractionPattern:getLValueObjectType() to getLValueOrInOutObjectType() 2017-03-14 17:46:54 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01: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
Doug Gregor
93e7862ae5 [AST] Remove AbstractTypeParamType; NFC.
This abstract class isn't providing any value anywhere, and represents
a false distinction.
2016-11-15 13:52:22 -08:00
Joe Groff
f42e579040 Change SILGen to use ImportAsMemberStatus populated by ClangImporter. 2016-03-17 17:09:41 -07:00
Joe Groff
c4a69e9d5d SILGen: Basic code generation for C functions imported as methods.
Introduce abstraction patterns for curried C-functions-as-methods for type lowering, and plumb the "foreign self parameter index" through call emission so that we emit the "self" parameter in the right position. This gets us handling C functions imported as methods with explicit swift_name attributes in simple, fully-applied cases. There's still more work to be done for properties, partial applications, and initializers introduced by extensions.
2016-03-17 10:43:25 -07:00
John McCall
e249fd680e Destructure result types in SIL function types.
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.

The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results.  It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.

The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*.  The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list.  The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.

A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple.  It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.

Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction.  It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
2016-02-18 01:26:28 -08:00
Slava Pestov
cb3ddc2200 SIL: Fix type lowering to correctly handle concrete same-type constraints
When a dependent type is mapped into context, the result will either be
an archetype or a concrete type. The latter occurs if a same-type
constraint exists between the dependent type and the concrete type.

The logic to decide if a type should be passed directly or indirectly
was not handling this case if an interface type was passed down -- we
would just check if there was a class constraint present.

This resulted in mismatching conventions between an interface type and
its corresponding contextual type, which would trigger assertions.

Note that same-type constraints between generic parameters and concrete
types are still not supported for other reasons; the subject of the
constraint must still be an associated type of a generic parameter.

Fixes <rdar://problem/24687460>.
2016-02-17 00:22:03 -08:00
Slava Pestov
b0e455a8bd SIL: Fix type lowering cache for interface types in abstraction pattern
If an abstraction pattern has interface types in it, we
already enforce that it was constructed with a generic
signature.

This generic signature is only used to answer questions
about the abstraction pattern's own formal type, and
not with the substituted type.

So only put type lowering cache entries in the dependent
cache if they contain interface types in the substituted
type. Otherwise, if only the abstraction pattern has
interface types in it, the entry can live in the
independent cache, allowing it to be looked up without
a pushGenericContext() / popGenericContext() call.

For correctness, we now have to store the generic signature
in the type key as well. Subsequent changes should reduce
the size of the cache, by lowering fewer archetypes.

NFC, since nothing uses this for now.
2016-01-18 21:06:40 -08:00
Slava Pestov
7d1bbb371f SIL: Fixes for abstraction patterns containing interface types
When lowering the original unsubstituted type to check for parameters
and results being passed indirectly, be careful to map it to archetypes,
since the abstraction pattern's generic signature might not equal
M.Types.getCurGenericContext().

Also, don't use '==' to compare canonical interface types.

NFC for now, since this code is largely not exercised.
2016-01-18 21:06:39 -08:00
Slava Pestov
879a8966ac SIL: Split up AbstractionPattern::isOpaque() into two predicates
- isTypeParameter() -- check if this is an archetype or dependent
  interface type.

- requiresClass() -- check if this is a class-constrained type
  parameter.

The old isOpaque() check has been replaced by
(isTypeParameter() && !requiresClass(moduleDecl)).

This allows us to pass the ModuleDecl on down to
GenericSignature::requiresClass(), enabling the use of
interface types in abstraction patterns.

NFC for now.
2016-01-14 14:07:56 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
b76c0abc37 SIL: Lower closure capture params out-of-band from the formal type.
Instead of bodging a representation of the SIL capture parameters for a closure into the formal type of closure SILDeclRefs, introduce those parameters in a separate lowering step. This lets us clean up some TypeLowering code that was tolerating things like SILBoxTypes and naked LValueTypes in formal types for nefarious ends (though requires some hacks in SILGen to keep the representation of curry levels consistent, which is something I hope to clean up next). This also decouples the handling of captures from the handling of other parameters, which should enable us to make them +0. For now, there should be NFC.
2015-12-30 10:32:36 -08:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
Slava Pestov
91cf4c11da SIL: Move description of abstraction patterns to AbstractionPattern.h and write new comment in SILGenPoly describing function thunks, NFC
Probably SILGenPoly.cpp should be named SILGenThunk.cpp, but I'm saving
that for if I ever extract the duplication between bridging thunks and
re-abstraction thunks.
2015-11-05 21:49:23 -08:00
Doug Gregor
3023a710fc Split TypeBase::isDependentType() into isTypeParameter() and hasTypeParameter().
The isDependentType() query is woefully misunderstood. Some places
seem to want it to mean "a generic type parameter of dependent member
type", which corresponds to what is effectively a type parameter in
the language, while others want it to mean "contains a type parameter
anywhere in the type". Tease out these two meanings in
isTypeParameter() and hasTypeParameter(), respectively, and sort out
the callers.

Swift SVN r29945
2015-07-07 21:20:54 +00:00
John McCall
73258f2b21 Generate method/property @encodings from the foreign
SILFunctionType of the method instead of its formal type.

Gives more accurate information to the @encoding, makes
foreign error conventions work implicitly, and allows
IRGen's Swift-to-Clang to avoid duplicating arbitrary
amounts of the bridging logic from SILGen.

Some finagling was required in order to avoid calling
getConstantFunctionType from within other kinds of
lowering, which might have re-entered a generic context.

Also required fixing a bug with the type lowering of
optional DynamicSelfTypes where we would end up with
a substituted type in the lowered type.

Also, for some reason, our @encoding for -dealloc
methods was pretending that there was a formal parameter.
There didn't seem to be any justification for this,
and it's not like Clang does that.  Fixed.

This commit reapplies r29266 with a conservative build fix
that disables ObjC property descriptors for @objc properties
that lack a getter.  That should only be possible in SIL
files, because @objc should force accessors to be synthesized.
Arguably, Sema shouldn't be marking things implicitly @objc
in SIL files, but I'll leave that decision open for now.

Swift SVN r29272
2015-06-03 04:59:54 +00:00