Commit Graph

67 Commits

Author SHA1 Message Date
John McCall
95297f6988 Don't map Bool back to ObjCBool for SIL types in unbridged contexts.
When the Clang importer imports the components of a C function pointer
type, it generally translates foreign types into their native equivalents,
just for the convenience of Swift code working with those functions.
However, this translation must be unambiguously reversible, so (among
other things) it cannot do this when the native type is also a valid
foreign type.  Specifically, this means that the Clang importer cannot
import ObjCBool as Swift.Bool in these positions because Swift.Bool
corresponds directly to the C type _Bool.

SIL type lowering manually reverses the type-import process using
a combination of duplicated logic and an abstraction pattern which
includes information about the original Clang type that was imported.
This abstraction pattern is generally able to tell SIL type lowering
exactly what type to reverse to.  However, @convention(c) function
types may appear in positions from which it is impossible to recover
the original Clang function type; therefore the reversal must be
faithful to the proper rules.  To do this we must propagate
bridgeability just as the imported would.

This reversal system is absolutely crazy, and we should really just
- record an unbridged function type for imported declarations and
- record an unbridged function type and Clang function type for
  @convention (c) function types whenever we create them.
But for now, it's what we've got.

rdar://43656704
2018-11-30 15:23:00 -05: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
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
831cec5982 SIL: Implement remaining cases for AbstractionPattern::getFunctionParamType() 2018-09-14 13:37:43 -07:00
Slava Pestov
8b73e0b27b SIL: Don't implode parameters into a tuple in TypeConverter::getLoweredFormalTypes()
getLoweredFormalTypes() behaved differently for top-level
functions and methods:

- For functions it would bridge each parameter type and return a new
  function type with the bridged parameters.

- For methods, it would build a new function type whose argument list
  was always a tuple of the form ((Args...), Self), with all formal
  parameters of the method imploded into a single tuple argument.

This is a simple change in isolation, but AbstractionPatterns for
Objective-C methods and C functions imported as methods depended on
the old representation.

This patch reworks AbstractionPattern:getFunctionParamType() to do
the right thing for these AbstractionPattern kinds.

Note that I haven't touched the older getFunctionInputType() which
still does the old thing, but it's going away.
2018-09-14 13:37:43 -07:00
Slava Pestov
9092da33f8 SIL: Simplify AbstractionPattern::getFunctionParamType()
Use the new AnyFunctionType::Param::getParameterType() method
John added, instead of encoding knowledge of varargs directly
here.

Also don't wrap the result in an InOutType since for now,
clients only use this for Objective-C methods which don't
have inout parameters, and upcoming usages need the unwrapped
type anyway.
2018-09-14 10:55:15 -07:00
Slava Pestov
53d82f7c49 AST: Remove SubscriptDecl::getIndicesInterfaceType() 2018-08-27 21:15:38 -07:00
John McCall
e312f8ef4a Add an option to get the native abstraction pattern of a storage decl.
For the most part, code should be working with the as-declared
abstraction pattern of the storage, because that's the pattern
produced by its accessors.  However, in the special case of an
accessor synthesized on demand to satisfy a protocol conformance,
that accessor will use the native abstraction pattern of the
declaration, and so the witness thunk that uses that accessor
must use that pattern when generating its access.

This doesn't matter today because the only on-demand synthesized
accessor is materializeForSet, and witnesses for materializeForSet
don't actually call the synthetic materializeForSet --- in fact,
nothing does.  But the modify accessor uses the otherwise-standard
pattern where the witness modify calls the concrete modify, and
that modify currently uses the native abstraction pattern.
2018-08-27 02:14:21 -04:00
Slava Pestov
b210fa20e4 SIL: Stop using FunctionType::getOld() in type lowering
There are still a couple of hacks remaining because AbstractionPattern
and DestructureInputs do silly things. Refactoring those is the next step
here.
2018-08-18 01:54:17 -04: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
Slava Pestov
296ce3f312 AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked
the ParamDecl's flags instead.
2018-06-13 15:38:52 -07:00
Mark Lacey
7f805ba2bc Replace classifyAsOptionalType with isOptionalDecl. 2018-02-05 23:59:00 -08: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
Robert Widmann
ebdd126a2c [NFC] Remove more uses of <InOutType> 2017-10-22 02:00:07 -04: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
a11f9c36a0 [AST] Remove ModuleDecl from TypeBase::getCanonicalType(). 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
Robert Widmann
3b202c18d8 Use 'hasAssociatedValues'
Use 'hasAssociatedValues' instead of computing and discarding the
interface type of an enum element decl.  This change has specifically not
been made in conditions that use the presence or absence of the
interface type, only conditions that depend on the presence or absence
of associated values in the enum element decl.
2017-05-22 09:54:47 -07:00
Slava Pestov
2dc819d1d1 AST: Introduce new form of TypeBase::getCanonicalType()
I've fixed a few bugs recently where I had to switch
a getCanonicalType() call to instead use the stronger
GenericSignature::getCanonicalTypeInContext().

Avoid the 'if (genericSig = ...)' dance by adding a new
form of TypeBase::getCanonicalType() which takes a
signature, and if it's null, just falls back to the
standard getCanonicalType().
2017-03-27 00:18:26 -07:00
Slava Pestov
efff6a6922 SILGen: Fix a couple of problems with materializeForSet in constrained extensions
- Property defined in constrained extension of a class

- Subscript defined in a constrained extension with non-canonical index type

Fixes <rdar://problem/31222187>.
2017-03-27 00:18:26 -07:00
Slava Pestov
76834a12ed SIL: Rename AbstractionPattern:getLValueObjectType() to getLValueOrInOutObjectType() 2017-03-14 17:46:54 -07:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00
Hugh Bellamy
36100bf21c Fix errors and warnings building swift/SIL on Windows using MSVC 2017-01-09 09:11:20 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
a384b2a677 Don't call VarDecl::getType() on deserialized VarDecls 2016-12-15 22:46:15 -08:00
Slava Pestov
8bdbe774e0 AST: Don't call hasType()/getType()/setType() on SubscriptDecls 2016-12-01 13:00:17 -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
John McCall
34fb15e375 Abstract the object type of an optional type according to the
abstraction pattern of the type rather than always using the
most-general pattern, and erase ImplicitlyUnwrappedOptional from
the SIL type system.
2016-09-08 23:26:19 -07:00
Doug Gregor
5a83c86455 Eliminate default arguments from TupleType.
In Swift, default arguments are associated with a function or
initializer's declaration---not with its type. This was not always the
case, and TupleType's ability to store a default argument kind is a
messy holdover from those dark times.

Eliminate the default argument kind from TupleType, which involves
migrating a few more clients over to declaration-centric handling of
default arguments. Doing so is usually a bug-fix anyway: without the
declaration, one didn't really have

The SILGen test changes are due to a name-mangling fix that fell out
of this change: a tuple type is mangled differently than a non-tuple
type, and having a default argument would make the parameter list of a
single-parameter function into a tuple type. Hence,

  func foo(x: Int = 5)

would get a different mangling from

  func foo(x: Int)

even though we didn't actually allow overloading.

Fixes rdar://problem/24016341, and helps us along the way to SE-0111
(removing the significance of argument labels) because argument labels
are also declaration-centric, and need the same information.
2016-07-15 13:55:53 -07:00
Joe Groff
7feb60da04 SILGen: Handle C functions imported as labeled unit constructors. 2016-04-13 08:17:04 -07:00
Chris Willmore
3bcb169f0b Import lightweight Objective-C generics as Swift generic type
parameters.
2016-03-28 09:50:30 -07: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
df38bd1764 SILGen: More interface type abstraction pattern goodness, NFC 2016-01-18 23:17:17 -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
John McCall
1f3b3142b4 Distinguish conformance and superclass generic requirements.
As part of this, use a different enum for parsed generic requirements.

NFC except that I noticed that ASTWalker wasn't visiting the second
type in a conformance constraint; fixing this seems to have no effect
beyond producing better IDE annotations.
2016-01-11 16:07:37 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
b1667ec705 SIL: Introduce a new @inout_aliasable parameter convention.
Modeling nonescaping captures as @inout parameters is wrong, because captures are allowed to share state, unlike 'inout' parameters, which are allowed to assume to some degree that there are no aliases during the parameter's scope. To model this, introduce a new @inout_aliasable parameter convention to indicate an indirect parameter that can be written to, not only by the current function, but by well-typed, well-synchronized aliasing accesses too. (This is unrelated to our discussions of adding a "type-unsafe-aliasable" annotation to pointer_to_address to allow for safe pointer punning.)
2015-12-08 14:35:47 -08:00
John McCall
807f7f5434 Reimplement materializeForSet emission in SILGen instead of
the type-checker.  The strategy for now is to just use this
for protocol witness thunk emission, where it is required
when generating a materializeForSet for storage that is
either implemented in a protocol extension or requires
reabstraction to the requirement's pattern.

Eventually, this should be generalized to the point that
we can use it for all materializeForSet emission, which
I don't think will take much.  However, that's not really
the sort of instability we want to embrace for the current
release.

WIP towards rdar://21836671; currently disabled, so NFC.

Swift SVN r31072
2015-08-07 09:22:27 +00:00
Joe Groff
55bbcb01bb SIL: Use castAs instead of cast on clang::Type abstraction patterns.
They may be typedefs. Fixes a follow-on problem in rdar://problem/21294916.

Swift SVN r30086
2015-07-10 20:24:04 +00:00
Joe Groff
2be344aa33 Revert "SILGen: Make witness parameter translation handle single-element tuples."
This reverts commit r29572, which is breaking some external projects.

Swift SVN r29605
2015-06-24 13:59:33 +00:00
Joe Groff
7a4b80ce4d SILGen: Make witness parameter translation handle single-element tuples.
These still show up if you have a witness with a default argument, which the AST still represents as a single-element tuple, matched against a non-tuple orig type in the witness signature. Handle this by allowing getTupleElementType(0) on non-tuple AbstractionPatterns to work, and tweaking the parallel translation code to drill through single-element tuples and line up the contained scalars properly. Fixes rdar://problem/21452981. (Still left broken is the obnoxious single-element-tuple-of-tuple case, rdar://problem/21496105.)

Now with less Xcode autosave breakage.

Swift SVN r29572
2015-06-23 17:25:47 +00:00