Commit Graph

21678 Commits

Author SHA1 Message Date
Vedant Kumar 5c36f5d0cf Merge pull request #1864 from vedantk/pgo
[Coverage] Make getEquivalentPGOLinkage exhaustive (NFC)
2016-03-24 18:06:55 -07:00
Xi Ge 218010afb9 [CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863
Reported: http://stackoverflow.com/questions/36180575/struck-out-module-xcode-7-3
2016-03-24 17:44:46 -07:00
Vedant Kumar bcc54bf209 Do not check the top/bottom values in the switch 2016-03-24 17:13:29 -07:00
John McCall 3561aa5fe0 Support parent types on foreign type metadata.
This will eventually be required for C++.  It is also, apparently,
required for anonymous structs that are used as the type of a
named field.

Should unblock the Linux Foundation build.
2016-03-24 17:01:28 -07:00
Vedant Kumar 43abe6fa1b [Coverage] Make getEquivalentPGOLinkage exhaustive 2016-03-24 16:57:08 -07:00
Xin Tong f557a3253d Merge pull request #1857 from trentxintong/FSO
Rename FunctionSignatureOptCloner to FunctionSignatureOpts
2016-03-24 15:57:34 -07:00
John McCall 0ffb7278bc Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.

Includes a fix since the earlier commit to make enum metadata
writable if they have an unfilled payload size.  This didn't show
up on Darwin because "constant" is currently unenforced there in
global data containing relocations.

This patch requires an associated LLDB change which is being
submitted in parallel.
2016-03-24 15:10:31 -07:00
Stephen Canon 7b1fddfbc1 Merge pull request #1835 from stephentyrone/simd-uint-vectors
Added uint[2,3,4] to simd, bridged to vector_uintN.
2016-03-24 17:08:26 -04:00
Xin Tong 5907b8a3e2 Rename FunctionSignatureOptCloner to FunctionSignatureOpts
Eventually, we decided to do this

1. Have the function signature opts (used to be called the cloner to create
the optimized function.
2. Mark the thunk as always_inline
3. Rely on the inliner to inline the thunk to get the benefit of calling optimized
function directly.
2016-03-24 12:50:12 -07:00
Xin Tong e0ba695d17 Merge pull request #1852 from trentxintong/FSO
Remove function signature rewriter and make function signature analysis a Util
2016-03-24 12:42:05 -07:00
Xi Ge 92d520c885 ModulePrinting: Using constraint solver to decide the right overload to print in synthesized extensions. 2016-03-24 12:16:51 -07:00
Xin Tong 9a3761000c Move function signature analysis to a Util
We really only need this signature analysis in the cloner pass now.
2016-03-24 11:17:47 -07:00
John McCall 946469d71a Don't look in the parent metadata fields of structs and enums for
fulfillments, because we don't actually fill them in.

This is a minimal, temporary, speculative fix for the failure
described in rdar://25069637, for which I unfortunately do not have
a minimal test case and which I have been unable to duplicate in
my own testing due to various language restrictions that I hope
to lift given the better (but temporarily reverted) fix.
2016-03-24 11:03:52 -07:00
Xin Tong 3f075dfe47 Remove function signature rewriter.
We decided to use the inliner to rewrite the caller's callsites.

And eventually I will turn FunctionSignatureAnalysis into a Utility.
As its data should only be used and kept in the cloner pass.
2016-03-24 10:50:47 -07:00
Xin Tong c44006aa9d Merge pull request #1824 from trentxintong/RLE
Make sure non-epilogue releases do not kill redundant loads
2016-03-24 10:48:21 -07:00
Xin Tong 0a562b7fe1 Merge pull request #1847 from trentxintong/FSO
Make FSO thunks always_inline.
2016-03-24 10:38:38 -07:00
Xin Tong 2a63907a17 Make FSO thunks always_inline.
This forces the callsites to be rewritten by the inliner.

we have the issue that the thunk changes from the time the its created to
the time its reread to figure out what we have done to the original function

This results in missed opportunities.

This solution solves the problem gracefully, because the thunk carries the information
on how to set up the call to the optimized functions.

Inlining the thunk makes the callsite calling the optimized function for free. i.e.
without any rewriting.

I did not measure any regression with this change.
2016-03-24 09:18:13 -07:00
Xin Tong 7ff5156cc2 Merge pull request #1827 from trentxintong/FSO
Minor refactor in Epilogue Retain/Release matchers
2016-03-24 08:48:04 -07:00
Greg Titus 7182c58cb2 Merge pull request #1821 from gregomni/typealias
[SR-995] Handle name changes to ArrayLiteralConvertible associated type
2016-03-24 06:54:31 -07:00
Arnold Schwaighofer 7fb2cceec0 Add a method to _NSContiguousString to facilitate stack promotion
Use it for hashing and comparison.

During String's hashValue and comparison function we create a
_NSContiguousString instance to call Foundation's hash/compare function. This is
expensive because we have allocate and deallocate a short lived object on the
heap (and deallocation for Swift objects is expensive).  Instead help the
optimizer to allocate this object on the stack.

Introduces two functions on the internal _NSContiguousString:
_unsafeWithNotEscapedSelfPointer and _unsafeWithNotEscapedSelfPointerPair that
pass the _NSContiguousString instance as an opaque pointer to their closure
argument. Usage of these functions asserts that the closure will not escape
objects transitively reachable from the opaque pointer.

We then use those functions to call into the runtime to call foundation
functions on the passed strings. The optimizer can promote the strings to the
stack because of the assertion this API makes.

  let lhsStr = _NSContiguousString(self._core) // will be promoted to the stack.
  let rhsStr = _NSContiguousString(rhs._core) // will be promoted to the stack.
  let res = lhsStr._unsafeWithNotEscapedSelfPointerPair(rhsStr) {
    return _stdlib_compareNSStringDeterministicUnicodeCollationPointer($0, $1)
  }

Tested by existing String tests.

We should see some nice performance improvements for string comparison and
dictionary benchmarks.

Here is what I measured at -O on my machine

Name                          Speedup
Dictionary                      2.00x
Dictionary2                     1.45x
Dictionary2OfObjects            1.20x
Dictionary3                     1.50x
Dictionary3OfObjects            1.45x
DictionaryOfObjects             1.40x
SuperChars                      1.60x

rdar://22173647
2016-03-24 05:43:29 -07:00
Stephen Canon 8187dfb140 Added uint[2,3,4] to simd, bridged to vector_uintN. 2016-03-24 07:56:59 -04:00
Jordan Rose 9e9c80e090 Add a @_versioned attribute for testing resilience.
This attribute is a stand-in for the versioning annotations
described in docs/LibraryEvolution.rst; right now it's just present
or absent, and its only effect is to make sure versioned internal
decls are treated as public at the SIL level. (This functionality
already existed for -enable-testing, so it can probably be trusted.)

Also, allow inlineable functions to reference transparent and
inline-always functions /if/ they're only called immediately (not used
as values or partial-applied), since they'll be inlined away before
emitting IR. (We should really only allow this /before/ mandatory
inlining, but we don't have a separate SIL stage for that.)
2016-03-24 00:53:35 -07:00
Slava Pestov 37c461cc59 Serialization: Serialize shared thunks referenced from fragile functions
If a thunk is referenced from two different functions, the thunk inherits
the fragile attribute from the first function that forced it to be emitted.

This is wrong, in case the first function might not be fragile, while
the second one is. Copying the fragile attribute to an existing thunk when
checking if it has already been emitted is also wrong, because the thunk
might reference another thunk, and so on.

The correct fix is to have SIL serialization serialize the transitive
closure of all fragile functions and thunks referenced from fragile
functions. Re-work SIL function serialization to use a worklist so that
we can do this.

Part of https://bugs.swift.org/browse/SR-267.
2016-03-24 00:50:40 -07:00
Slava Pestov 98c9a9c4f4 ClangImporter: Mark generated union accessors as transparent
This ensures their bodies are fragile in SIL. While they can
be synthesized again, this change will avoid tripping up the
SIL verifier after some upcoming changes.

Part of https://bugs.swift.org/browse/SR-267.
2016-03-24 00:50:39 -07:00
Slava Pestov 3e2d7d40e0 SIL: Serialize bodies of local functions inside @_transparent functions
A transparent function might be deserialized and inlined into a function
in another module, which would cause problems if the function referenced
local functions.

Previously we would force local functions to have public linkage instead,
which worked, but was not resilient if the body of the transparent
function changed in the module that contained it.

Add a library evolution test ensuring that such a change is resilient
now.

Part of https://bugs.swift.org/browse/SR-267.
2016-03-24 00:50:39 -07:00
Slava Pestov 187facac47 SILLinker: Deserialize shared definitions too
This happens if a transparent function references a thunk or generated
Clang accessor.

Part of https://bugs.swift.org/browse/SR-267.
2016-03-24 00:50:39 -07:00
Slava Pestov 7124072859 SILGen: More thunks now get the [thunk] attribute
For now this attribute doesn't mean much, but it will matter with an
upcoming SIL serialization change.

Part of https://bugs.swift.org/browse/SR-267.
2016-03-24 00:50:39 -07:00
Xin Tong 524ed34583 Make sure epilogue releases do not kill redundant loads
I did not measure a performance improvements with this.
2016-03-23 23:59:54 -07:00
Roman Levenstein 3448b7c0f4 [let-properies-opt] Fix a bug which where a let property was wrongly considered to have a constant value.
The optimization pass was inspecting only init methods to determine if a given let property is defined
in the same way by all initializers. But this is not enough in certain cases, e.g. when some of the
initializers were inlined into the application code and the body of the inlined SIL function representing
such an initializer was removed afterwards by the dead function elimination pass. In such situations,
the Let Properties Optimization pass was assuming that there is only one initializer and considered the
constant let property value defined there as the only possible value of this let property. Therefore it
propagated it into let-property uses, which resulted in an incorrect code.

The right thing to do is to analyze all assignments to a given let property whether they are inside initializer
SIL functions or not. This makes sure that all possible values of a let property are analyzed and compared.
The propagation of a constant let property value can only happen if all found possible values are all the same.

Fixes SR-1026 and rdar://25303106
2016-03-23 22:29:56 -07:00
Xin Tong 9a020c8c7a Minor refactoring in epilogue retain matcher 2016-03-23 22:16:49 -07:00
Xin Tong b1c7bc5e4b Reinstate "Minor refactoring in epilogue retain matcher" 2016-03-23 22:16:34 -07:00
John McCall abba7f0c8b Revert "Only use metadata patterns for generic types; perform other"
This reverts commit 41efb3d4d3.
LLDB has too many tendrils into our metadata.
2016-03-23 20:26:43 -07:00
gregomni 2c51abfe15 [SR-995] Handle name changes to ArrayLiteralConvertible associated type
This is just being more general and defensive to handle name changes in
the stdlib.
2016-03-23 19:32:54 -07:00
Greg Titus cce950705a Merge pull request #1699 from gregomni/typealias
[SR-938][AST/Sema] Typealias in protocol extension, spurious conformance failure fixes
2016-03-23 18:54:18 -07:00
Xi Ge fda0751cae [SourceKit] In interface-gen request, allow clients to send SourceKit an interested USR from which we can infer the group name. 2016-03-23 17:26:44 -07:00
John McCall 41efb3d4d3 Only use metadata patterns for generic types; perform other
initialization in-place on demand.  Initialize parent metadata
references correctly on struct and enum metadata.

Also includes several minor improvements related to relative
pointers that I was using before deciding to simply switch the
parent reference to an absolute reference to get better access
patterns.
2016-03-23 17:04:04 -07:00
Xi Ge e8eba770d5 Mark a recently added function as static, NFC. 2016-03-23 15:25:03 -07:00
Xi Ge b4d0cb4ffe ModulePrinting: Avoid printing duplicated members in synthesized extensions. 2016-03-23 15:19:16 -07:00
Chris Lattner a7757dbdc6 fix <rdar://problem/24530312> Swift ++fix-it produces bad code in nested expressions
The AvailabilityWalker was creating a new AvailabilityWalker instance whenever it
recursed through an assignexpr or memberrefexpr, which produced a new ExprStack.
This caused the fixit mechanics for migrating ++/-- to think that the ++/-- was
at the top level, when it wasn't.
2016-03-23 11:58:59 -07:00
Doug Gregor 5b97f8eeb9 [Clang importer] Don't strip prefixes from swift_bridge'd classes or their subclasses.
Part of rdar://problem/24050011.
2016-03-23 11:32:36 -07:00
Michael Ilseman b7bcc294ea [Clang importer] Fix obscure issue with submodule protocols.
In the Clang importer, and only in submodules, the first protocol
typedef with NSObject that we try to import results in a hidden lookup
result. So, allow hidden lookups, which is benign and failure is
actually an issue of a malformed header. Gracefully handles failure.

Test case included that will reproduce the issue if AllowHidden is
disabled.
2016-03-23 10:07:00 -07:00
gregomni e17e7ab8ae Make resolveTypeInContext for aliases just use interface type as dependent member.
Much cleane. Also fixes one more validation crasher.
2016-03-22 23:13:10 -07:00
Chris Lattner 30ec0f4128 Fix <rdar://23036383> QoI: Invalid trailing closures in stmt-conditions produce lowsy diagnostics
It is a common problem that people use a call to a function with a
trailing closure in a if condition, foreach loop, etc.  These don't allow
trailing closures, because they are ambiguous with the brace-enclosed body
of the conditional statement.

In an effort to improve QoI on this, perform lookahead to disambiguate the most common
form of this, in a very narrow situation.  This allows us to produce a nice error
with fixit hints like:

t.swift:26:25: error: trailing closure requires parentheses for disambiguation in this context
for _ in numbers.filter {$0 > 4} {
                        ^

instead of spewing out this garbage:

t.swift:26:26: error: anonymous closure argument not contained in a closure
for _ in numbers.filter {$0 > 4} {
                         ^
t.swift:26:33: error: consecutive statements on a line must be separated by ';'
for _ in numbers.filter {$0 > 4} {
                                ^
                                ;
t.swift:26:34: error: statement cannot begin with a closure expression
for _ in numbers.filter {$0 > 4} {
                                 ^
t.swift:26:34: note: explicitly discard the result of the closure by assigning to '_'
for _ in numbers.filter {$0 > 4} {
                                 ^
                                 _ =
t.swift:26:34: error: braced block of statements is an unused closure
for _ in numbers.filter {$0 > 4} {
                                 ^
t.swift:26:18: error: type '(@noescape (Int) throws -> Bool) throws -> [Int]' does not conform to protocol 'Sequence'
for _ in numbers.filter {$0 > 4} {
                 ^
t.swift:26:34: error: expression resolves to an unused function
for _ in numbers.filter {$0 > 4} {
                                 ^
2016-03-22 22:06:06 -07:00
Chris Lattner 4a126d7c38 pass a decl into diagnostic generation directly, instead of passing in the
decl loc, this simplifies code and can theoretically handle deserialized
decls better.  Noticed by inspection, NFC.
2016-03-22 21:27:24 -07:00
Doug Gregor 593932741c Remove historical flags -enable-omit-needless-words/-enable-infer-default-arguments/-enable-swift-name-lookup-tables.
NFC; all of these options are always-on now and we no longer have a
way to turn them off.
2016-03-22 17:04:19 -07:00
Chris Lattner 59425c086d fix <rdar://problem/21523291> compiler error message for mutating immutable field is incorrect 2016-03-22 16:57:09 -07:00
Chris Lattner a12674a571 When reporting a type error relating to the result type of an overload
set where all members of the set produce the same type, produce a more
specific error.

Before:

t.swift:4:17: error: no '&&' candidates produce the expected contextual result type 'Int'
  return a == b && 1 == 2
                ^
t.swift:4:17: note: produces result of type 'Bool'
  return a == b && 1 == 2
                ^

after:

t.swift:4:17: error: '&&' produces 'Bool', not the expected contextual result type 'Int'
  return a == b && 1 == 2
                ^

This improves the situation reported in https://twitter.com/_jlfischer/status/712337382175952896
2016-03-22 15:45:52 -07:00
Doug Gregor 865288941d [Clang importer] Only strip "NS" prefix from types and protocols.
Part of rdar://problem/24050011.
2016-03-22 14:55:50 -07:00
Xi Ge f338bdfbb7 [SourceKit] Incorporate synthesized extensions into DocInfo request. rdar://24912860
This commit reuses our code for generating synthesized extensions from module printing to enhance
documentation generation.
2016-03-22 14:49:22 -07:00
Xi Ge 33c53a12eb ASTPrinter: Pass the bracket options to pre and post printing callbacks.
Need this for rdar://24912860
2016-03-22 14:49:22 -07:00