Commit Graph

581 Commits

Author SHA1 Message Date
eeckstein
cc6045b45a Merge pull request #8006 from eeckstein/demangle-lib
demangler: put the demangler into a separate library
2017-03-09 16:40:35 -08:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Arnold Schwaighofer
1eebdc1966 Merge pull request #8002 from aschwaighofer/unsafe_guaranteed_spec_devirt
Speculative Devirtualizer: Don't speculate _withUnsafeGuaranteedRef c…
2017-03-09 13:22:56 -08:00
Arnold Schwaighofer
76d0f68c2a Speculative Devirtualizer: Don't speculate _withUnsafeGuaranteedRef class_method calls
This would create control-flow that the unsafeGuaranteed optimization cannot
handle.

unmanaged._withUnsafeGuaranteedRef {
    $0.methodCall()
}

rdar://30949999
2017-03-09 11:04:03 -08:00
Arnold Schwaighofer
44e89fb595 UnsafeGuaranteedPeephole should handle virtual_method calls
Make the peephole stronger to handle retain(self), apply(self), release(self)
pairs inbetween unsafeGuaranteed pairs.

rdar://30948468
2017-03-09 09:28:35 -08:00
Slava Pestov
5465c8ca8f SIL: Remove most usages of TypeBase::gatherAllSubstitutions() 2017-03-08 13:54:28 -08:00
Roman Levenstein
be5e01af31 [function-signature-opt] Allow FSO on witness_methods when performing the dead argument signature optimization for partial_apply instructions
This improves performance of some benchmarks, which pass static operators like `Int.<` as closure arguments.

Fixes rdar://23428804
2017-03-07 19:58:49 -08:00
Slava Pestov
de2f5f78ac AST: Remove Substitution::subst()
I want to get rid of Substitution entirely, and now we have
the right abstractions to do everything with SubstitutionMap.
2017-03-07 16:04:54 -08:00
Slava Pestov
c040c71ea9 AST: Remove some unnecessary SubstitutionList copies
ASTContext::getSpecializedConformance() already copies the
substitutions, so remove some AllocateCopy() calls.

Also, add a new overload taking a SubstitutionMap instead.
This allows removing some gatherAllSubstitutions() calls,
which have an allocation inside them.

Finally, remove the now-unused ModuleDecl parameter from
ProtocolConformance::subst() and make it public.
2017-03-07 15:59:05 -08:00
Joe Shajrawi
ca77872ba8 Merge CheckedCastValueBranch with new master 2017-03-06 17:32:09 -08:00
Joe Shajrawi
1f626304f1 Add support for conditional checked cast instruction for opaque value types + SILGen support for it 2017-03-06 16:35:27 -08:00
Slava Pestov
97fce6cb79 SILOptimizer: Always create SILFunctions with a generic environment 2017-03-04 17:36:47 -08:00
Roman Levenstein
a9db867e8d Implement partial specialization behind a flag.
Partial specialization is disabled by default. Use -sil-partial-specialization to enable it.

Use -sil-partial-specialization-with-generic-substitutions to enable the partial specialization even in cases of substitutions containing generic replacement types.
2017-03-02 23:29:55 -08:00
Michael Gottesman
cfb5893663 [silgen] Fix destroying destructor to use proper ownership with its @owned return value.
rdar://29791263
2017-03-02 17:17:17 -08:00
Michael Gottesman
4bc12aedbd [sil] Add end_lifetime.
This is the lifetime ending variant of fix_lifetime. It is a lie to the
ownership verifier that a value is being consumed along a path. Its intention is
to be used to allow for the static verification of ownership in deallocating
deinits which for compatibility with objective-c have weird ownership behavior.
See the commit merged with this commit for more information.
2017-03-01 18:30:23 -08:00
Michael Gottesman
455c126238 [semantic-sil] Pass the uncasted argument as an @owned arg in the failed checked_cast_br cast.
Previously, we would put a destroy_value directly on the value that we tried to
cast. Since checked_cast_br is consuming, this would cause the destroy_value on
the failure path to be flagged as a double consume.

This commit causes SILGen to emit the value consumed by checked_cast_br as an
@owned argument to the failure BB, allowing semantic arc rules to be respected.

As an additional benefit, I also upgraded the ownership_model_eliminator test to
use semantic sil verification.

One issue that did come up though is that I was unable to use the new code in
all locations in the compiler. Specifically, there is one location in
SILGenPattern that uses argument unforwarding. I am going to need to undo
argument unforwarding in SILGenPattern in order to completely eliminate the old
code path.
2017-02-28 17:29:03 -05:00
Roman Levenstein
6c1eec81c4 Merge pull request #7557 from mtake/enhance-assume-single-threaded
Enhance -assume-single-threaded option (SR-3945)
2017-02-27 13:07:46 -08:00
Slava Pestov
4ed09b4a73 SILOptimizer: Remove some workarounds for old problems
It looks like the devirtualizer used to have problems computing
method types in the presence of generic substitutions, covariant
returns and other things, so it would bail if a perticular set
of pre-conditions was not met on the types of original method call
and the devirtualized method call.

I don't think any of this is necessary anymore. If this patch
introduces any regressions, we need to fix the root cause instead
of re-introducing this logic.
2017-02-27 00:03:46 -08:00
Mikio Takeuchi
91b8db5e11 Replace newly introduced Atomicity::Atomic 2017-02-27 12:17:53 +09:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Roman Levenstein
a71202fbae [sil-performance-inliner] Do not inline generics into thunks
This allows for about 4% code size reduction on stdlib. And the performance hit is not very significant. Only 5-6 benchmarks get somewhat slower.
2017-02-24 14:59:44 -08:00
practicalswift
d352652a72 Merge pull request #7727 from practicalswift/typos-20170223
[gardening] Fix typos
2017-02-24 09:15:12 +01:00
practicalswift
33a5601ad1 [gardening] Fix typos 2017-02-23 22:46:40 +01:00
practicalswift
59221c63c8 [gardening] Remove unused logic in SILPerformanceInliner::isProfitableToInline(...) 2017-02-23 22:18:08 +01:00
Roman Levenstein
7bcb3227fc Enable inlining of generics 2017-02-20 17:57:42 -08:00
Roman Levenstein
ef088e818d [sil-performance-inliner] Fix recent performance regressions
Do not perform any inlining of generics if it is not enabled. Don't do it even for always inline functions.
2017-02-20 16:16:18 -08:00
Erik Eckstein
a67a4e1a38 Don't de-virtualize in SILCombine.
It is important to de-serialize the devirtualized function (and its callees), especially because we must make sure that all transparent functions are de-serialized.
SILCombine did not do that. But as we have the same optimization in the Devirtualizer, it's not needed to duplicate the code in SILCombine.

The only reason we had this peephole in SILCombine is that the Devirtualizer pass could not handle partial applies.
So with this change the Devirtualizer can now also handle partial applies.

Fixes rdar://problem/30544344 (again, after my first attempt failed)
2017-02-20 09:36:26 -08:00
Roman Levenstein
dd19a13221 Merge pull request #7553 from swiftix/wip-generics-inlining-flag-6
Preparation for enabling the  inlining of generics
2017-02-17 18:41:34 -08:00
Roman Levenstein
de6328122d [sil-performance-inliner] Do not inline generic functions if they contain a partial_apply with an opened existential in its substitution list
IRGen cannot handle partial_applies containing opened_extistentials in their substitutions lists.
2017-02-17 09:07:18 -08:00
Roman Levenstein
4388593943 [sil-performance-inliner] Tweak the inlining profitability heuristic for inlining of generics
Consider the possibility of performing a specialization or devirtualization after inlining of a generic function.
2017-02-17 09:07:18 -08:00
Erik Eckstein
31469d99e3 Fix a crash in SILMem2Reg in case of a dead address projection from a function argument.
Fixes rdar://problem/30571089
2017-02-16 21:16:42 -08:00
swift-ci
776982c2ce Merge pull request #7554 from atrick/silval 2017-02-16 20:04:21 -08:00
Andrew Trick
eed44abd1d OwnershipModelEliminator should not rewrite address-only copy/destroy. 2017-02-16 18:50:31 -08:00
Erik Eckstein
bcd8ea6682 function signature opts: Have an even more stricter check if a specialized function with that name already exists.
It’s not enough to just check for public functions in other modules.
In case of fragile functions, it can also be a non-public function in another module which potentially interferes with the specialization we want to create.

Anyway, this is just a workaround until we fix the mangling for function-signature opts. It should always produce unique names.
2017-02-16 17:04:58 -08:00
Roman Levenstein
c0ba7f5195 Fix a bug in FunctionSignatureOptimization.
When FSO generates a unique mangled name it should check that it does not conflict with any symbol in the current module or any public symbol from other modules.

FSO seems to have more issues with resilience, but those are not handled in this PR. They will be covered later. This PR is only for unblocking the inlining of generics.
2017-02-14 11:11:01 -08:00
Andrew Trick
855918c620 [Lowering] Add an AddressLowering pass. 2017-02-13 17:10:02 -08:00
Jordan Rose
1c60910198 Revert "Merge pull request #6092 from swiftix/wip-generics-inlining-flag-4"
This reverts commit 1b3d29a163, reversing
changes made to b32424953e.

We're seeing a handful of issues from turning on inlining of generics,
so I'm reverting to unblock the bots.
2017-02-13 10:52:17 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Roman Levenstein
199e76d6d4 Fixes for a lookup of functions by name
Among other things it fixes a bug in the function signature optimization where it would use an already existing mangled name for a different function
2017-02-10 18:07:30 -08:00
Roman Levenstein
260eeb27e3 Adjust to recent Generics.h changes. 2017-02-10 07:41:55 -08:00
Roman Levenstein
54bd9c3863 Adjust PerformanceInliner to the recent SubstitutionMap changes 2017-02-10 07:41:54 -08:00
Roman Levenstein
55de499c99 [sil-performance-inliner] Enable inlining of generics 2017-02-10 07:41:54 -08:00
Roman Levenstein
263d3a64fb [sil-performance-inliner] Prefer specialization of generics to inlining 2017-02-10 07:41:54 -08:00
Roman Levenstein
2c3f3b461b [sil-performance-inliner] Add profitability heuristic tweaks for generic functions.
This should limit uncontrolled code size growth.

Transparent and always inline generic functions are now always inlined.
2017-02-10 07:41:54 -08:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Slava Pestov
1954665a95 AST: Remove more uses of SubstitutionMap::add{Substitution,Conformance}()
A new SubstitutionMap::getProtocolSubstitutions() method handles
the case where we construct a trivial SubstitutionMap to replace
the protocol Self type with a concrete type.

When substituting one opened existential archetype for another,
use the form of Type::subst() that takes two callbacks instead of
building a SubstitutionMap. SubstitutionMaps are intended to be
used with keys that either come from a GenericSignature or a
GenericEnvironment, so using them to replace opened archetypes
doesn't fit the conceptual model we're going for.
2017-02-06 20:33:39 -08:00
Michael Gottesman
15a12a3f34 Merge pull request #7272 from gottesmm/unmanaged_autorelease_value
[semantic-sil] Create unmanaged_autorelease_value.
2017-02-06 13:19:01 -08:00
Michael Gottesman
554feff463 [semantic-sil] Create unmanaged_autorelease_value.
This is an autorelease for use with Builtin.autorelease that does not need to be
balanced as part of the ownership model.

rdar://29791263
2017-02-06 12:11:46 -08:00
Adrian Prantl
4d1ae142c6 Remove the redundant DeclCtx field in SILFunction.
In all cases the DeclCtx field was supposed to be initialized from the
SILLocation of the function, so we can save one pointer per
SILFunction.

There is one test case change where a different (more precise)
diagnostic is being generated after this change.
2017-02-06 11:07:50 -08:00
Slava Pestov
dca292c652 Serialization: Don't serialize contextual enum argument type
Storing this separately is unnecessary since we already
serialize the enum element's interface type. Also, this
eliminates one of the few remaining cases where we serialize
archetypes during AST serialization.
2017-01-30 00:08:53 -08:00