Commit Graph

37 Commits

Author SHA1 Message Date
Slava Pestov
6e3609dc22 AST: ProtocolConformanceRef::getTypeWitnessByName() should be an instance method 2019-05-14 19:28:55 -04:00
Slava Pestov
644b6adcd2 AST: Simplify ProtocolConformanceRef::getTypeWitnessByName() 2019-05-10 15:00:48 -04:00
Slava Pestov
fb8bd3a056 Merge pull request #24267 from slavapestov/unused-conformances
Remove per-SourceFile "used conformances" lists
2019-04-26 18:10:28 -04:00
Slava Pestov
400063eafe SIL: Handle incomplete conformances in TypeConverter::getLoweredCBridgedType()
Currently Sema completes all _ObjectiveCBridgeable conformances it thinks
are needed in SILGen and runtime dynamic casts, but that's about to change.

Make sure SIL passes a LazyResolver down so that if a conformance doesn't
have a type witness for _ObjectiveCType yet, one can be resolved.

Note that in practice, ClangImporter-synthesized conformances use a special
LazyMemberLoader implementation to fill in type witnesses without any
intervention from the type checker. However, that might go away now that
we have a long-lived type checker instance. Furthermore, various tests use
-enable-source-import and start to fail once Sema no longer completes
_ObjectiveCBridgeable conformances.
2019-04-25 22:27:41 -04:00
Saleem Abdulrasool
83b290438c Windows: bridge BOOL to Bool
This allows the conversion of the Windows `BOOL` type to be converted to
`Bool` implicitly.  The implicit bridging allows for a more ergonomic
use of the native Windows APIs in Swift.

Due to the ambiguity between the Objective C `BOOL` and the Windows
`BOOL`, we must manually map the `BOOL` type to the appropriate type.
This required lifting the mapping entry for `ObjCBool` from the mapped
types XMACRO definition into the inline definition in the importer.

Take the opportunity to simplify the mapping code.

Adjust the standard library usage of the `BOOL` type which is now
eclipsed by the new `WindowsBool` type, preferring to use `Bool`
whenever possible.

Thanks to Jordan Rose for the suggestion to do this and a couple of
hints along the way.
2019-04-25 17:52:08 -07:00
Slava Pestov
a4f560dc73 SIL: Use getLoweredRValueType() in various places 2019-03-04 20:33:19 -05:00
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
957805da44 SIL: Refactor a usage of AbstractionPattern::transformType() 2018-09-14 13:37:43 -07: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
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Joe Groff
2f6e1a4e3a SIL: Lower the self argument of an @objc protocol class method requirement as an @objc_metatype.
Fixes rdar://problem/18921650.
2018-08-06 19:07:36 -07:00
Slava Pestov
175b40919f AST: Fewer headers include Expr.h, Module.h, Stmt.h 2018-04-26 22:55:26 -07:00
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08: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
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Slava Pestov
a16faae73b AST: Move ProtocolConformance::getTypeWitnessByName() to ProtocolConformanceRef
I need to move some #includes around ("include what you use") to
break circularities for an upcoming refactoring.
2017-02-08 15:33:46 -08:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -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
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
e045429471 [Type Checker] Improve interface to TypeChecker::conformsToProtocol().
This function had a weird, pre-ProtocolConformanceRef interface that
returned true when the type conformed to the protocol, then had a
separate indirect return value for the concrete conformance (if there
is one). Refactor this API, and the similar
TypeChecker::containsProtocol(), to produce an optional
ProtocolConformanceRef, which is far more idiomatic and easier to
use. Push ProtocolConformanceRef into a few more places. Should be NFC
2016-11-14 16:00:58 -08:00
Joe Groff
aac85cb93f SIL: Introduce a 'closure' convention for unapplied invocation functions.
We don't want the machine calling conventions for closure invocation functions to necessarily be tied to the convention for normal thin functions or methods. NFC yet; for now, 'closure' follows the same behavior as the 'method' convention, but as part of partial_apply simplification it will be a requirement that partial_apply takes a @convention(closure) function and a box and produces a @convention(thick) function from them.
2016-10-17 15:55:04 -07:00
Doug Gregor
51529ae888 Eliminate the -enable-id-as-any flag; it's always on now anyway.
Simplify e.g., ASTContext::getBridgedToObjC(), which no longer needs
the optional return.

Eliminate the now-unused constraint kind for checking bridging to
Objective-C.
2016-08-19 21:17:09 -07:00
Doug Gregor
ca4a32b5a9 [SE-0112] Bridge NSError to ErrorProtocol.
Introduce bridging of NSError to ErrorProtocol, so an Objective-C API
expressed via an "NSError *" will be imported using ErrorProtocol in
the Swift. For example, the Objective-C method:

  - (void)handleError:(NSError *)error userInteractionPermitted:(BOOL)userInteractionPermitted;

will now be imported as:

  func handleError(_ error: ErrorProtocol, userInteractionPermitted: Bool)

This is bullet (3) under the proposed solution of SE-0112. Note that
we made one semantic change here: instead of removing the conformance
of NSError to ErrorProtocol, which caused numerous problems both
theoretical and actual because the model expects that an NSError
conforms to ErrorProtocol without requiring wrapping, we instead limit
the ErrorProtocol -> NSError conversion that would be implied by
bridging. This is defensible in the short term because it also
eliminates the implicit conversion, and aligns with SE-0072, which
eliminates implicit bridging conversions altogether.
2016-07-12 10:53:52 -07:00
Joe Groff
e6ba22fc0e SILGen: Look through ErasureExprs when bridging to AnyObject.
When we have an argument expr of type Any that's being emitted as a bridged ObjC object parameter, look through any ErasureExprs and directly bridge the concrete value. This saves us emitting an intermediate 'Any' value in the common case where a value of known concrete type is passed in from Swift.
2016-07-06 21:25:13 -07:00
Jordan Rose
eeac42c13f Cache the Identifier for "_ObjectiveCType". NFC. 2016-05-26 17:55:18 -07:00
Doug Gregor
09d2d63555 [SIL] Teach type lowering to use _ObjectiveCBridgeable.
Eliminate the String/Array/Dictionary/Set special cases, using
_ObjectiveCBridgeable conformances instead.

Note: Clang update required for the test to success.
2016-03-17 14:27:51 -07: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
Slava Pestov
3933d8a4f0 SIL: getAbstractionPattern(var) never returns opaque pattern, NFC 2015-12-22 15:30:16 -08:00
Jordan Rose
0b5428fcd3 Import DarwinBoolean as Bool in fully-bridgeable contexts.
These are contexts where we have enough information to bridge /back/
properly; that is, where we can distinguish CBool, ObjCBool, and
DarwinBoolean. In cases where we can't, we keep the three separate;
only CBool is really the same type as Bool.

This also affects current import behavior for ObjCBool, which was previously
incorrectly conflated with CBool in certain cases.

More rdar://problem/19013551

Swift SVN r30051
2015-07-10 01:11:30 +00:00
John McCall
9638611277 Use AbstractionPattern to find Clang types for inputs and
results when finding bridged types, rather than reinventing
(well, pre-inventing) the same thing elsewhere.

Doing this apparently forces AbstractionPattern to deal
with ObjC protocol methods for the first time, which are
generic and therefore require even the Clang-based
abstraction patterns to propagate generic signatures.

Use this infrastructure to allow foreign error conventions
to suppress the wrapping of nonnull bridged collection results
in a level of optionality.  We can't treat nil results as
an empty collection while simultaneously treating them as
an error signal.

Swift SVN r28022
2015-05-01 04:38:17 +00:00
John McCall
b3dcf0fb2b Move getLoweredASTFunctionType back to SILFunctionType.cpp.
NFC.

Swift SVN r27350
2015-04-16 05:41:08 +00:00
John McCall
6d2326f08a Test (and fix) some simple calls to foreign-error methods.
Swift SVN r27296
2015-04-14 23:52:53 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
John McCall
dc4b8ff2c2 Incorporate an optional Clang type into AbstractionPattern.
This is necessary for correctly dealing with non-standard
ownership conventions in secondary positions, and it should
also help with non-injective type imports (like BOOL/_Bool).
But right now we aren't doing much with it.

Swift SVN r26954
2015-04-03 21:39:31 +00:00