Commit Graph

39 Commits

Author SHA1 Message Date
Slava Pestov
53bfc767a3 SIL: Track target formal type for casts
SIL type lowering erases DynamicSelfType, so we generate
incorrect code when casting to DynamicSelfType. Fixing this
requires a fair amount of plumbing, but most of the
changes are mechanical.

Note that the textual SIL syntax for casts has changed
slightly; the target type is now a formal type without a '$',
not a SIL type.

Also, the unconditional_checked_cast_value and
checked_cast_value_br instructions now take the _source_
formal type as well, just like the *_addr forms they are
intended to replace.
2019-11-20 21:30:28 -05:00
Saleem Abdulrasool
731c31f9a5 MSVC: litter the code with llvm_unreachable (NFC)
Add `llvm_unreachable` to mark covered switches which MSVC does not
analyze correctly and believes that there exists a path through the
function without a return value.
2019-06-01 19:02:46 -07:00
Michael Gottesman
d1389aded6 [cast-opt] Refactor some code onto SILDynamicCast and delete dead code.
NFC.
2019-04-12 12:23:28 -07:00
Michael Gottesman
ee02174f71 [cast-opt] Change optimize{Swift,ObjC}to{ObjC,Swift} to use SILDynamicCastInst.
I also debrided dead variables that resulted from eliminating the trampoline
argument code in optimizeBridgedCasts().
2019-03-04 10:48:13 -08:00
Michael Gottesman
e833d11720 [cast-opt] Change simplifyCheckedCast{,Value}BranchInst to use SILDynamicCastInst.
This is the last change needed to simplify the API of optimizeBridgedCasts to
take SILDynamicCastInst.
2019-03-03 16:33:11 -08:00
Michael Gottesman
807b187302 [cast-opt] Update simplifyCheckedCastAddrBranchInst to use SILDynamicCastInst.
This is another step towards eliminating the many argument call to
optimizeBridgedCasts.
2019-03-03 16:33:11 -08:00
Michael Gottesman
aaf464485b [cast-opt] Change CheckedCastBranch metatype opts to use SILDynamicCastInst. 2019-03-03 14:50:21 -08:00
Michael Gottesman
e80c394e82 [cast-opt] Update optimization of unconditional checked cast to use SILDynamicCastInst. 2019-03-03 14:50:21 -08:00
Michael Gottesman
d4e910ce5c [cast-opt] Update optimizeUnconditionalCheckedCastAddrInst to use SILDynamicCastInst. 2019-03-03 13:42:04 -08:00
Michael Gottesman
98ed241ce5 [cast-optimizer] Add an "ApplySite" like data structure "SILDynamicCastInst" that abstracts over all dynamic cast instructions.
I am going to use this to refactor a bunch of the goop in the cast optimizer. At
a high level, we are really just performing a giant switch over the casts to
grab different state. We then take that state and we pass it into the bridge
cast optimizer.

To make such code more compact/easier to understand, I am adding in this commit
a type erased dynamic cast instruction type called "SILDynamicCastInst". In
subsequent commits, I wire up each of the individual instructions to it one at a
time.

As an additional advantage it will enable us to take advantage of covered
switches when ever in the future we introduce new casts.
2019-02-26 13:23:54 -08:00
Andrew Trick
0976c1f76e Teach the SIL cast optimizer to handle conditional conformance.
Previously the cast optimizer bailed out on any conformance with
requirements.

We can now constant-propagate this:

```
protocol P {}
struct S<E> {
  var e: E
}

extension S : P where E == Int {}

func specializeMe<T>(_ t: T) {
  if let p = t as? P {
    // do fast things.
  }
}

specializeMe(S(e: 0))
```

This turns out to be as simple as calling the TypeChecker.

<rdar://problem/46375150> Inlining does not seem to handle
specialization properly for Data.

This enabled two SIL transformations required to optimize
the code above:

(1) The witness method call can be devirtualized.

(2) The allows expensive dynamic runtime checks such as:

  unconditional_checked_cast_addr Array<UInt8> in %array : $*Array<UInt8> to ContiguousBytes in %protocol : $*ContiguousBytes

Will be converted into:

  %value = init_existential_addr %existential : $*ContiguousBytes, $Array<UInt8>
  store %array to %value : $*Array<UInt8>
2018-12-11 17:37:54 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Joe Shajrawi
75939510cd PGO: Use ProfileCounter instead of Optional<uint64_t> to hold profile counts 2017-09-26 13:34:46 -07:00
Joe Shajrawi
64830c2d5e PGO: add support for checked_cast_addr_br 2017-09-26 11:14:31 -07:00
Andrew Trick
5aac427ee0 SIL Ownership: Remove consumptionKind from SIL unconditional cast and related logic.
Remove the cast consumption kind from all unconditional casts. It
doesn't make sense for unconditional casts, complicates SIL ownership,
and wasn't fully supported for all variants. Copies should be
explicit.
2017-08-18 20:44:54 -07:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Roman Levenstein
830e1c36d4 [sil-cast-optimizer] Fix casting between Swift and CF types
If a Swift type T needs to be casted to a CF type, then we first cast T to its bridged NS type and then ref_cast the result to a corresponding CF type.
For example, if we need to cast String to CFString, we first cast String to NSString and then ref_cast the NSString to CFString.

Fixes rdar://problem/29745498
2017-01-04 12:35:51 -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
232a314a9f Teach the dynamic-cast machinery how to cast collection element types. 2016-07-23 10:30:10 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07: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
aef0a11a7c remove some unneeded forward declearations 2016-01-25 15:00:49 -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
Max Moiseev
2f7b64e475 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-21 12:02:13 -08:00
practicalswift
cd7d8dfaff Fix alignment as requested by @gribozavr in #692 2015-12-21 08:54:24 +01:00
practicalswift
176f487d76 Fix incorrect filenames in headers. 2015-12-20 23:59:05 +01:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08: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
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
Chris Lattner
07d9d1bd3d fix include guard to match filename, NFC.
Swift SVN r27457
2015-04-18 23:09:52 +00:00
Chris Lattner
7185252a2b remove dead argument to canUseScalarCheckedCastInstructions.
Swift SVN r27455
2015-04-18 22:12:50 +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
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
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
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
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