Commit Graph

857 Commits

Author SHA1 Message Date
Doug Gregor
21dcd07846 Extend the optional-injection-of-erroneous-nil hack for more entities.
r21096 introduces an optimization barrier for failing initializers
that allows the pattern

  let x: NSFoo? = NSFoo()

be used to detect whether NSFoo() returned nil, even though the type
system says it cannot. Extend this check to Objective-C methods and
properties, where the non-optional annotation may be incorrect
<rdar://problem/17984530>.




Swift SVN r21176
2014-08-13 16:44:53 +00:00
Joe Groff
bde47cfe44 SILGen: Keep the 'let x: NSFoo? = NSFoo()' failing initializer hack from being optimized.
If we see that we're injecting the result of an @objc initializer into an optional, perform the T -> T? conversion using unchecked_ref_bit_cast, which is opaque to the optimizer, instead of doing a proper optional injection. This prevents the optimizer from defeating our workaround for failing initializers. <rdar://problem/17941601>

Swift SVN r21096
2014-08-07 17:40:38 +00:00
Chris Lattner
dd803a39f8 change LValue from holding its segments as a DiverseList to holding them
as a std::vector<std::unique_ptr<PathComponent>>.   DiverseList memcpy's
around its buffer on copy and move operations.  This seems safe with all
of the current implementations of Cleanup, but is absolutely not with the
LValue PathComponents.  These things hold std::vectors, RValue (which has
an std::vector in it), and a bunch of other probably non-trivial things.

While we're in here, disable the copy constructor, since it isn't safe.
This doesn't harm mainline, but was burning me on a patch I'm working on.

When/if someone cares about performance optimizing this code, a better
approach would be to use an ilist + bump pointer allocator.



Swift SVN r21057
2014-08-06 00:50:09 +00:00
Doug Gregor
79d5c69d5a Remove CheckedCastKind::ArrayDowncastBridged. Nobody F'ing Cares about it now.
Swift SVN r20730
2014-07-30 04:26:16 +00:00
Dave Abrahams
6e7f83fe98 Internalize old array casting entry-points
The core compiler now uses just two entry points for array casting

Swift SVN r20725
2014-07-29 23:56:51 +00:00
Chris Lattner
e466b4621b revert r20658, restoring us back to producing the "inout writeback to computed property"
error when detecting an inout writeback problem.


Swift SVN r20681
2014-07-29 18:12:51 +00:00
Chris Lattner
7676259ecc Fix http://swiftwtf.tumblr.com/post/91934970718/xcode-6-beta-3 to compile into the
behaviorly correct code by CSE'sing subscripts that are identical.

Also, add a dump() method to PathComponent to help visualize / debug LValue structures.



Swift SVN r20661
2014-07-29 00:27:43 +00:00
Chris Lattner
4d03ef63f7 Rip out my previous work that produced perplexing "inout writeback to
computed property" errors when SILGen could determine that there was
an inout writeback alias, and have the code instead perform CSE of the
writebacks directly.

This means that we produce more efficient code, that a lot of things
now "just work" the way users would expect, and that the still erroneous
cases now get diagnosed with the "inout arguments are not allowed to 
alias each other" error, which people have a hope of understanding.

There is still more to do here in terms of detecting identical cases,
but that was true of the previous diagnostic as well.




Swift SVN r20658
2014-07-28 23:55:14 +00:00
Chris Lattner
1c80e6454f fix <rdar://problem/17828355> curried final method on a class crashes in irgen
getNextUncurryLevelRef was using it's own local test to determine whether a
FuncDecl is dynamically dispatched (which didn't check for "final"), change it 
to use SILGenFunction::getMethodDispatch instead.


Swift SVN r20623
2014-07-28 15:42:24 +00:00
Joe Groff
4bacaffaa7 SILGen: Implement lvalue BindOptionalExprs.
Factor out the code for emitting the "bind" branching logic, and share it to implement an LValueComponent for optional binds, which makes optional assignments work.

Swift SVN r20614
2014-07-28 04:05:28 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +00:00
Joe Groff
b5d5cf0c8d SILGen: Don't crash when peepholing a ForceValue of nested OptionalEvaluations.
The type checker produces nested optional evaluations for expressions of the form 'x.optionalProperty?.optionalProperty as NonOptionalType'. SILGen had a peephole for this case that was apparently never tested, because we tried to dereference a null failure BB. Fixes <rdar://problem/17576873> and at least half a dozen dupes. The codegen is still kind of ridiculous, but correct.

Swift SVN r20358
2014-07-23 01:34:02 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Chris Lattner
d473159814 Implement the start of a diagnostic to detect cases where inout aliasing violations are
introduced, as these are obvious miscompilations and clearly mystifying to our user base.

This is enough to emit diagnostics like this:

writeback_conflict_diagnostics.swift:58:70: error: inout writeback aliasing conflict detected on computed property 'c_local_struct_property'
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
                                             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
writeback_conflict_diagnostics.swift:58:33: note: concurrent writeback occurred here
  swap(&c_local_struct_property.stored_int, &c_local_struct_property.stored_int)
        ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

which isn't great, but is better than nothing (better wording is totally welcome!).

This doesn't handle subscripts (or many other kinds of logical lvalue) at all yet, so 
it doesn't handle the swift WTF case, but this is progress towards that.



Swift SVN r20297
2014-07-22 05:37:42 +00:00
Chris Lattner
2c1bfc6d74 add a "kind" discriminator to PathComponent to pave the way for new functionality, NFC.
Swift SVN r20281
2014-07-21 21:47:30 +00:00
Chris Lattner
b199da570b in top-level code, have SILGen memoize the global_addr instructions it generates into VarLoc,
to give it a trivial amount of CSE.  This isn't important generally (global_addr turns into
a trivial constant in LLVM IR) but unblocks some other SILGen stuff I'm working on.

This doesn't affect lazy global addressors.


Swift SVN r20259
2014-07-21 17:25:14 +00:00
Chris Lattner
fdaa28ce16 fix a warning about a zero length array, by ripping out all of the old declattributes code. :-)
Swift SVN r20071
2014-07-17 04:48:34 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Joe Groff
a14a94942d SILGen: Give dynamic thunks a proper mangling.
This lets us make them 'shared' and teach the demangler about them.

Swift SVN r19945
2014-07-14 21:01:45 +00:00
Joe Groff
76114d7f8a SILGen: Use dynamic thunk as the vtable entry of dynamic overrides.
If a dynamic definition overrides a non-dynamic one, then we need to go through objc_msgSend even if we try vtable dispatch on the non-dynamic superclass definition. Also, if we have a dynamic definition that doesn't override, we don't need a vtable entry for it at all.

Swift SVN r19944
2014-07-14 20:29:47 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Joe Groff
fed9b8daa2 SILGen: Honor 'dynamic' when invoking initializing ctors from allocating ctors.
Swift SVN r19866
2014-07-12 00:06:35 +00:00
Joe Groff
893ca42780 SILGen: Have protocol witnesses honor 'dynamic'.
The witness table entry needs to dispatch through the ObjC entry point if the witness is dynamic. Slot this into the existing code path by consing up a small transparent thunk to exercise the existing code paths for adjusting calling convention from ObjC to Swift.

Swift SVN r19864
2014-07-11 23:13:51 +00:00
Joe Groff
68a7ac055a SILGen: Don't reemit the magic __FUNCTION__ literal into the same std::string on every use.
Fixes <rdar://problem/17127704>.

Swift SVN r19835
2014-07-10 23:12:28 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Joe Groff
b1cc0a2455 SILGen: Forward an upcast existential when we take it.
Fixes a double-release when an existential was implicitly converted to a more general existential. <rdar://problem/17228707>

Swift SVN r19522
2014-07-03 17:51:35 +00:00
Joe Groff
2f02a854db Remove unused variable.
Swift SVN r19484
2014-07-02 22:15:30 +00:00
Joe Groff
1a332dbc80 Remove the UIKit overlay for UIApplicationMain.
UIApplicationMain now naturally gets imported with the correct argv type.

Swift SVN r19481
2014-07-02 20:53:10 +00:00
Joe Groff
8500acd7ff SILGen: Implement StringToPointerExpr.
Lower it to a call to the _convertConstStringToUTF8PointerArgument helper.

Swift SVN r19374
2014-06-30 22:00:50 +00:00
John McCall
e57d928c44 Remove the last code in SILGen which was making address-only
casts with the non-address checked_cast instructions.

Swift SVN r19338
2014-06-30 12:04:50 +00:00
John McCall
f40e9ef0ae Rewrite switch dispatch emission.
Specialization now recurses on only that prefix of the
current matrix which shares a specialization form
(essentially, a pattern kind) with the head row.  This is
inferior to the previous algorithm in a number of ways: we
may require more switches to perform a single dispatch, and
we may introduce more redundant variables in the leaves.
However, it also means that we will have fully specialized a
row along exactly one path in the decision tree, which makes
it much easier to work with dispatches that introduce new
cleanups.

This change also changes switch-dispatch to use the new
dynamic-cast instructions.

Incidentally fixes rdar://16401831.

Swift SVN r19336
2014-06-30 11:55:28 +00:00
Adrian Prantl
3ae5326d21 Tweak the scope guessing for instructions without SILDebugScopes to reuse
the scope of the previous instruction.

<rdar://problem/17021591> Gap in lexical block coincides with the first line-table entry for a line => no variables at that line

Swift SVN r19318
2014-06-28 02:08:26 +00:00
Joe Groff
151ed6143d Add a StringToPointerExpr node.
To represent string-to-pointer argument conversions.

Swift SVN r19314
2014-06-28 00:36:43 +00:00
Doug Gregor
5a08a69ebc Remove NewArrayExpr entirely; reject "new" expressions in the parser.
Swift SVN r19293
2014-06-27 15:57:48 +00:00
Joe Groff
9a190ea59e AST: Remove unneeded expression nodes for __inout_conversion and __writeback_conversion.
We no longer need this language feature. The Sema support is still skeletally kept in place because removing it seems to totally break pointer conversions; I need to work with Joe and Doug to figure out why that's the case.

Swift SVN r19289
2014-06-27 04:23:35 +00:00
Joe Groff
f722d3f6a6 Remove tons of now-dead code for dealing with the C*Pointer bridging types.
Swift SVN r19280
2014-06-27 00:11:36 +00:00
Joe Groff
0db8de1341 SILGen: Implement inout-to-pointer conversion.
For writeback through an AutoreleasingUnsafePointer, create an intrinsic AutoreleasingWritebackComponent we can append to lvalues.

Swift SVN r19134
2014-06-24 15:11:41 +00:00
Joe Groff
ccd8cca9bd SILGen: Implement array-to-pointer conversion.
Use the _convert*ArrayToPointerArgument stdlib helpers.

Swift SVN r19112
2014-06-24 01:09:10 +00:00
Joe Groff
954f746b92 SILGen: Implement pointer-to-pointer conversions.
Perform pointer-to-pointer argument conversions with the help of the _convertPointerToPointerArgument stdlib helper function.

Swift SVN r19105
2014-06-23 23:22:02 +00:00
John McCall
20b1f2de3e Switch isa and as? processing over to use the new
indirect cast instructions when necessary.

Swift SVN r19079
2014-06-22 09:53:36 +00:00
John McCall
e8428377de Add some functions to query a CastConsumptionKind.
Swift SVN r19077
2014-06-22 09:53:31 +00:00
John McCall
385879beea Remove the CheckedCastKind from SIL dynamic casts.
It is straightforward and less redundant to recover this
information from the operand types.

Swift SVN r19056
2014-06-20 22:43:53 +00:00
John McCall
48d6a833a5 SILGen unconditional dynamic casts using the new
unconditional_dynamic_cast_addr instruction.

Also, fix some major semantic problems with the
existing specialization of unconditional dynamic
casts by handling optional types and being much
more conservative about deciding that a cast is
infeasible.

This commit regresses specialization slightly by
failing to turn indirect dynamic casts into scalar
ones when possible; we can fix that easily enough
in a follow-up.

Swift SVN r19044
2014-06-20 07:47:03 +00:00
Joe Groff
dba8a23d64 AST: Refactor get*UnsafePointerDecl() lookups onto the AST context.
These types are needed by enough of the stack now that it makes sense to centralize their lookup and caching onto the AST context like other core types.

Swift SVN r19029
2014-06-20 03:02:29 +00:00
Joe Groff
08a48565fb Sema: Introduce intrinsic pointer argument conversions.
Add primitive type-checker rules for pointer arguments. An UnsafePointer argument accepts:

- an UnsafePointer value of matching element type, or of any type if the argument is UnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is UnsafePointer<Void>, or
- an inout Array parameter of matching element type, or of any type if the argument is UnsafePointer<Void>.

A ConstUnsafePointer argument accepts:

- an UnsafePointer, ConstUnsafePointer, or AutoreleasingUnsafePointer value of matching element type, or of any type if the argument is ConstUnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>, or
- an inout or non-inout Array parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>.

An AutoreleasingUnsafePointer argument accepts:

- an AutoreleasingUnsafePointer value of matching element type, or
- an inout parameter of matching element type.

This disrupts some error messages in unrelated tests, which is tracked by <rdar://problem/17380520>.

Swift SVN r19008
2014-06-19 18:03:10 +00:00
John McCall
7effec113c Change ImplicitlyUnwrappedOptional to be an enum type itself,
not a struct wrapping an Optional.

Among other things, this means you can now pattern-match on
an IUO.  It also makes it more convenient to build and destroy
them.

SILGen's type lowering should probably canonicalize one kind
of optional to the other so that we don't get silly abstraction
costs from conversion.

Swift SVN r18991
2014-06-18 23:27:08 +00:00
Doug Gregor
4eeee3580f Remove *CollectionDowncastExpr; wen're not using them any more.
This simplifies constraint application quite a bit, and eliminates
some code duplication.


Swift SVN r18980
2014-06-18 13:10:22 +00:00
Doug Gregor
39e1b0886d Start using ConditionalCheckedCastExpr and ForcedCheckedCastExpr for collection downcasts.
NFC; just a cleanup.


Swift SVN r18979
2014-06-18 13:00:57 +00:00
Doug Gregor
0563f9b0cb Make emitCollectionDowncastExpr not depend on a *CollectionDowncastExpr. NFC
Swift SVN r18976
2014-06-18 09:22:11 +00:00