Commit Graph

53 Commits

Author SHA1 Message Date
Max Moiseev
02006f20bc Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-09 16:05:03 -08:00
Joe Groff
77dd9b2992 Split exact-subclass and bindable-to-subclass queries.
In many places, we're interested in whether a type with archetypes *might be* a superclass of another type with the right bindings, particularly in the optimizer. Provide a separate Type::isBindableToSuperclassOf method that performs this check. Use it in the devirtualizer to fix rdar://problem/24993618. Using it might unblock other places where the optimizer is conservative, but we can fix those separately.
2016-03-09 11:14:45 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Erik Eckstein
506ab9809f SIL: remove getTyp() from SILValue 2016-01-25 15:00:49 -08:00
Max Moiseev
08e1e4a043 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-11 16:51:11 -08:00
Erik Eckstein
6ff2f09796 [SIL] Let alloc_stack return a single value.
Having a separate address and container value returned from alloc_stack is not really needed in SIL.
Even if they differ we have both addresses available during IRGen, because a dealloc_stack is always dominated by the corresponding alloc_stack in the same function.

Although this commit quite large, most changes are trivial. The largest non-trivial change is in IRGenSIL.

This commit is a NFC regarding the generated code. Even the generated SIL is the same (except removed #0, #1 and @local_storage).
2016-01-06 17:35:27 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
22e10737e2 Fix typos 2015-12-26 01:19:40 +01:00
Doug Gregor
a97ab6dd14 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-18 10:15:47 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
Ben Langmuir
4082355244 Split KnownProtocolKind enum case from protocol name
This avoids us using reserved identifiers as the enum case names of all
our underscored protocols like _ObjectiveCBridgeable. I used the
convention PROTOCOL_WITH_NAME to mirror how the known identifiers work.

Swift SVN r32924
2015-10-27 23:10:36 +00:00
Roman Levenstein
05a51b752e [cast-optimizer] Small bug-fix to avoid a compiler crash.
It fixes a compiler crash which occurs on the following code if Foundation is not imported:
class C {}
let x: Int = C() as! Int

The crash happened because Int was considered ObjC-bridgeable, but its ObjC counterpart was not known as Foundation was not imported.

Swift SVN r32594
2015-10-10 05:06:06 +00:00
Slava Pestov
fd141bead9 Sema: Remove unused inExpression parameter from ASTContext::getBridgedToObjC(), NFC
Progress on <rdar://problem/21215099>.

Swift SVN r29968
2015-07-08 06:49:27 +00:00
Joe Groff
8b0e39d776 SIL: Casts from class types to potentially-class metatypes may succeed.
Another step toward fixing rdar://problem/16238475, though Sema-level warnings still need to be suppressed, and container bridging still needs to be exercised.

Swift SVN r29962
2015-07-08 05:03:28 +00:00
Joe Groff
e6a535a0ef The dice has been casted^H^H
Swift SVN r29960
2015-07-08 05:03:19 +00:00
Mark Lacey
d45acfb536 Fix typo in comment.
Swift SVN r29759
2015-06-27 04:42:24 +00:00
Joe Groff
6e9ffc72dd SIL: Dynamic casts from non-throws to throws may succeed.
Swift SVN r29361
2015-06-10 20:27:10 +00:00
Joe Groff
9c0695875e SIL: Casts that may be to NSError must use indirect cast instructions.
checked_cast_br promises to maintain RC identity, but a cast from an ErrorType-conforming class to NSError may change the RC identity by bridging. Make sure that potential class-to-NSError casts go through the indirect cast entry points for now. The runtime implementation still needs to be fixed to handle the class-to-NSError case, but this is part of rdar://problem/21116814.

Swift SVN r29089
2015-05-27 22:50:37 +00:00
Slava Pestov
9e5898e694 SIL: Don't crash when casting something known to not be a metatype to a metatype
eg,

class C {}
func bad(c: C) -> Bool { return c is C.Type }

Swift SVN r28731
2015-05-18 23:59:45 +00:00
Slava Pestov
d368700a6e SILGen: Object to metatype casts have to take the slow path
It looks like we don't know how to open-code the "is-a metatype" check
for scalar casts, so just tighten up canUseScalarCheckedCastInstructions()
so that if the target type is a metatype, the source also has to be a
metatype.

This fixes a regression from "SIL: Use scalar casts more".

Fixes <rdar://problem/21003923>.

Swift SVN r28729
2015-05-18 23:59:43 +00:00
Roman Levenstein
fa5109aaa1 [casts-optimizations] Properly handle casts to protocol compositions.
This fixes wrong results produced at run-time by interpreter/protocol_lookup.swift when it is compiled with optimizations.

Swift SVN r28721
2015-05-18 21:10:40 +00:00
Slava Pestov
085d1fee03 SIL: Use scalar casts more
Now that scalar casts work better, we can make the
canUseScalarCheckedCastInstructions() predicate a bit more
permissive.

This patch can be reverted if it is found that emitting scalar
casts in these additional cases introduces a regression.

Swift SVN r28713
2015-05-18 18:25:32 +00:00
Roman Levenstein
8dac375b4a Loosen the assertion a bit to make the test suite pass with -O.
Running the test quite with check-swift-optimize revealed that metatypes were not covered by the assert, even though it may occur in the real code.

Swift SVN r28297
2015-05-07 22:29:18 +00:00
Ted Kremenek
9f9bb725cf Rename '_ErrorType' to 'ErrorType'.
Swift SVN r28293
2015-05-07 21:59:29 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Doug Gregor
c180bfc423 Remove the SIL dynamic-cast checking's dependency on getProtocols(). NFC
Swift SVN r27977
2015-04-30 16:13:44 +00:00
Chris Lattner
7185252a2b remove dead argument to canUseScalarCheckedCastInstructions.
Swift SVN r27455
2015-04-18 22:12:50 +00:00
Roman Levenstein
1a58b365b7 Fix a bug in the casts optimizations.
DynamicCasts was not considering the fact that subclasses of a given class may implement a protocol, even if the class does not implement it.

Swift SVN r27265
2015-04-14 00:17:23 +00:00
Chris Willmore
0c52a76918 Revert "Fix two bugs related to the casts optimizations."
This reverts commit r27260, which broke the following tests:
* SILPasses/cast_folding.swift
* SILPasses/sil_combine_enum_addr.sil

Swift SVN r27261
2015-04-13 22:43:38 +00:00
Roman Levenstein
194aed3df2 Fix two bugs related to the casts optimizations.
The protocol_lookup the testcase from Interpreter test-cases exposed two bugs, once I tried to compiler with with -O:
 - SILCloner was generating an open_existential_ref from an open_existential_metatype instruction during cloning even if the existential in question was not a class existential.
 - DynamicCasts was not considering the fact that subclasses of a given class may implement a protocol, even if the class does not implement it.

Swift SVN r27260
2015-04-13 22:12:54 +00:00
Roman Levenstein
2bdba63740 Minor clean-ups and improvements as a preparation for the bridging casts optimizations.
Swift SVN r27099
2015-04-07 22:53:53 +00:00
Roman Levenstein
f63cae6f13 Add initial support into DynamicCasts for handling bridging between error types.
Teach it that casts between error types do not always fail and may succeed, in general.

Swift SVN r27098
2015-04-07 22:53:52 +00:00
Roman Levenstein
55ea9ec0e3 [sil-combine] Minor clean-up of casts optimizations. NFC.
Add more checks and logic into emitSuccessfulIndirectUnconditionalCast and emitSuccessfulScalarUnconditionalCast, so that its clients in sil-combine can be simplified by avoiding looking into special cases.

Swift SVN r26885
2015-04-02 19:57:35 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
Arnold Schwaighofer
d6ec9f2640 Make isObjectiveCBridgeable an available function so it can be used elsewhere.
Swift SVN r26265
2015-03-18 17:43:09 +00:00
Roman Levenstein
eddfc3c57a Improve casts analysis for bridged types.
Check if the outcome of a cast from an ObjC type to a Swift type or from a Swift type to an ObjC type can be statically determined.
This allows for folding of many such casts.

Swift SVN r26125
2015-03-14 02:23:07 +00:00
Roman Levenstein
340f20968d Improve the logic for analyzing casts between metatypes.
Do not fall through from the metatypes analysis code if the analysis could not decide whether the cast would succeed or fail. Make a more explicit decision instead based on the instance type of a metatype.

This fixes some logical errors in analysis of casts between bridged types. They were caused by falling through from the metatypes analysis.

Swift SVN r26120
2015-03-14 02:23:03 +00:00
Roman Levenstein
ad566f229d Add a missing case into assert.
SILFunctionType and FunctionType are different types.

Swift SVN r26119
2015-03-14 02:23:02 +00:00
Roman Levenstein
a081647f83 Add a FIXME about upcasts between existential metatypes.
Swift SVN r26118
2015-03-14 02:23:01 +00:00
Roman Levenstein
6047ec5547 Handle types conforming to _BridgedToObjectiveC protocol in a special way during cast folding.
This fixes the broken build of validation suite.

Swift SVN r25710
2015-03-03 06:03:54 +00:00
Roman Levenstein
a4055afc15 Third part of the cast folding and type-casts re-factoring. Addressing JoeG's comments.
This patch does the following:
- Improvements and correctness fixes for conversions of existential metatypes. They may succeed if you have a concrete or existential metatype that conforms to the protocol. Based on Joe's review of my previous patch.
- Removes special-cases for AnyObject. AnyObject is handled as any other class existential.
- Improves folding of conversions from class existential metatypes to concrete non-class metatypes
- Improves comments.
- Adds more tests to cover new test-cases.
- Adjusts a few existing tests.

Swift SVN r25690
2015-03-02 22:28:21 +00:00
Roman Levenstein
62cc75f4f1 Fix a small bug in getAnyMetatypeDepth.
getAnyMetatypeDepth was looping over the chain of metatypes, but it was not actually counting the depth.

Swift SVN r25689
2015-03-02 22:28:19 +00:00
Roman Levenstein
c199905a2f Second part of the cast folding and type-casts re-factoring.
This patch does the following:
- Moves the logic for handling special-case of converting to/from AnyObject.Protocol (and existential.Protocol in general) into DynamicCasts, where all other cases are handled already.
- Moves the peephole which was folding checked_cast_br into an unchecked cast and branch from sil-combine into sil-simplify-cfg, because it is a better place for it, since this peephole affects the CFG. The corresponding test is also moved from sil_combine.sil into simplify_cfg.sil.
- Adds a few checked_cast_br peepholes to sil-combine.   They try to simplify checked_cond_br instructions using existential metatypes by propagating a concrete type whenever it can be determined statically.
- Adds a new test with a lot of test-cases that make sure we are really folding many type-checks at compile-time now.

Swift SVN r25504
2015-02-24 17:31:08 +00:00
Roman Levenstein
c97f748fb9 Move the logic for folding type casts using statically known protocol conformances into DynamicCasts.cpp.
The logic for different special cases of type casting is spread over multiple places currently. This patch simply re-factors some of that  code (folding of of type casts using statically known protocol conformances) and moves it into one central place, which makes it easier to maintain. Plus, it allows other clients of DynamicCasts benefit from it as well, e.g. the inliner can use this now. NFC.

Swift SVN r25486
2015-02-23 21:30:48 +00:00
Joe Groff
f44e94da97 Remove debug spew
Swift SVN r24777
2015-01-28 02:38:44 +00:00
Joe Groff
04f44ba038 SIL: Classify potentially bridgeable checked casts as MaySucceed.
Fixes rdar://problem/19482567.

Swift SVN r24773
2015-01-28 02:14:35 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +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