Commit Graph

3168 Commits

Author SHA1 Message Date
Slava Pestov
0f4a7d246f AST: Remove GenericSignature::getAllDependentTypes()
This was a remnant of the old generics implementation, where
all nested types were expanded into an AllArchetypes list.

For quite some time, this method no longer returned *all*
dependent types, only those with generic requirements on
them, and all if its remaining uses were a bit convoluted.

- In the generic specialization code, we used this to mangle
  substitutions for generic parameters that are not subject
  to a concrete same-type constraint.

  A new GenericSignature::getSubstitutableParams()
  function handles this use-case instead. It is similar
  to getGenericParams(), but only returns generic parameters
  which require substitution.

  In the future, SubstitutionLists will only store replacement
  types for these generic parameters, instead of the list of
  types that we used to produce from getAllDependentTypes().

- In specialization mangling and speculative devirtualization,
  we relied on SubstitutionLists having the same size and
  order as getAllDependentTypes(). It's better to turn the
  SubstitutionList into a SubstitutionMap instead, and do lookups
  into the map.

- In the SIL parser, we were making a pass over the generic
  requirements before looking at getAllDependentTypes();
  enumeratePairedRequirements() gives the correct information
  upfront.

- In SIL box serialization, we don't serialize the size of the
  substitution list, since it's available from the generic
  signature. Add a GenericSignature::getSubstitutionListSize()
  method, but that will go away soon once SubstitionList
  serialization only serializes replacement types for generic
  parameters.

- A few remaining uses now call enumeratePairedRequirements()
  directly.
2017-03-02 22:57:52 -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
John McCall
fe7915d09e Rework a number of SIL and IRGen witness-table abstractions
to correctly handle generalized protocol requirements.

The major missing pieces here are that the conformance search
algorithms in both the AST (type substitution) and IRGen
(witness table reference emission) need to be rewritten to
back-track requirement sources, and the AST needs to actually
represent this stuff in NormalProtocolConformances instead
of just doing ???.

The new generality isn't tested yet; I'm looking into that,
but I wanted to get the abstractions in place first.
2017-03-02 01:34:13 -05: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
Slava Pestov
5b44e358be SIL: Fix verifier crash with metatypes of dynamic Self
Fixes <rdar://problem/30786388>.
2017-03-01 15:54:13 -08:00
Slava Pestov
8c1027472c SIL: Address FIXME in SILBoxType::getFieldLoweredType() 2017-03-01 00:28:25 -08:00
Slava Pestov
5dea03e1b7 SIL: Use SILType::subst() to implement SILFunction::mapTypeIntoContext()
Now that we no longer rely on the push/pop context in
SILType::subst(), we can use that here instead of
duplicating the "visit types in lowered position" logic.
2017-03-01 00:28:25 -08:00
Slava Pestov
2b5d974301 SIL: SILType::subst() can now take a generic signature
In order to lower replacement types that appear in lowered
position, we need to know the generic signature of the
original type.

Allow this to be passed in explicitly, but fall back to
the push/pop generic context if not present.

This is a first step toward eliminating the push/pop of
the generic context.

Fixes <rdar://problem/29711782>.
2017-03-01 00:28:23 -08:00
Slava Pestov
ec1d9fcfc7 SIL: Remove TypeConverter::substFunctionType() 2017-03-01 00:27:57 -08:00
Slava Pestov
581675e64b SIL: Fix latent bug in SILType::subst()
If a SILFunctionType has its own generic parameters, we should
not recurse into it here. The correct way to apply generic
arguments is to use SILType::substGenericArgs().
2017-03-01 00:27:56 -08:00
Slava Pestov
4138381e4e SIL: Remove SILType::substFuncType() 2017-02-28 20:52:43 -08:00
swift-ci
4240d011a1 Merge pull request #7829 from gottesmm/checked_cast_br_1 2017-02-28 16:30:05 -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
Joe Shajrawi
7cdc55d07c Support opaque values inside open existential boxes 2017-02-28 10:52:47 -08:00
Joe Shajrawi
48c10aa00b Merge pull request #7815 from shajrawi/composition_erasure
Add support for composition erasure + copy into for opaque value types
2017-02-28 09:52:15 -08:00
Joe Shajrawi
4cdf894caa Add support for composition erasure + copy into for opaque value types 2017-02-28 09:28:15 -08:00
Slava Pestov
0611d663b8 SIL: Remove SILType::getSwiftType() 2017-02-27 20:01:35 -08:00
Joe Shajrawi
4b6cfaf533 Merge pull request #7796 from shajrawi/deinit_existential
Support for deinit of opaque existentials: deinit_existential_opaque instruction + SILGen support
2017-02-27 15:43:32 -08:00
Joe Shajrawi
16b6cb5e1d Support for deinit of opaque existentials: deinit_existential_opaque instruction + SILGen support 2017-02-27 14:46:43 -08: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
0af2845c6d SILGen: Emission of materializeForSet for generic subscripts
First, use the correct generic environment to compute the substituted
storage type. Substitutions derived from 'self' are not enough,
because we also want the archetypes of the generic subscript's
innermost generic parameters.

Also, use the method and witness_method calling conventions for the
materializeForSet callback, depending on if we have a protocol
witness or concrete implementation.

Since the materializeForSet callback is called with a more
abstract type at the call site than the actual function type
of the callback, we used to rely on these two SIL types being
ABI compatible:

@convention(thin) <Self : P, T, U) (..., Self.Type) -> ()
@convention(thin) <T, U> (..., Foo<T, U>.Type) -> ()

The IRGen lowering is roughly the following -- the call site
passes two unused parameters, but that's fine:

(..., Self.Type*, Self.Type*, Self.P*)
(..., Foo<T, U>.Type*)

However if the callback has its own generic parameters because
the subscript is generic, we might have SIL types like so,

@convention(thin) <Self : P, T, U, V) (..., Self.Type) -> ()
@convention(thin) <T, U, V> (..., Foo<T, U>.Type) -> ()

And the IRGen lowering is the following:

(..., Self.Type*, Self.Type*, Self.P*, V.Type*)
(..., Foo<T, U>.Type*, V.Type*)

The parameters no longer line up, because the caller still passes
the two discarded arguments, and type metadata for V cannot be
derived from the Self metadata so must be passed separately.

The witness_method calling convention is designed to solve this
problem; it puts the Self metadata and protocol conformance last,
so if you have these SIL types:

@convention(witness_method) <Self : P, T, U, V) (..., swiftself Self.Type) -> ()
@convention(witness_method) <T, U, V> (..., swiftself Foo<T, U>.Type) -> ()

The IRGen lowering is the following:

(..., Self.Type*, V.Type*, Self.Type*, Self.P*)
(..., Foo<T, U>.Type*, V.Type*, Self.Type*, unused i8*)

However, the problem is now that witness_method and thin functions
are not ABI compatible, because thin functions don't have a
distinguished 'self', which is passed differently in LLVM's swiftcc
calling convention:

@convention(witness_method) <Self : P, T, U, V) (..., Self.Type) -> ()
@convention(thin) <T, U, V> (..., Foo<T, U>.Type) -> ()

So instead of using 'thin' representation for the concrete callback
case, use 'method', which is essentially the same as 'thin' except if
the last parameter is pointer-size, it is passed as the 'self' value.

This makes everything work out.
2017-02-26 21:27:04 -08:00
Mikio Takeuchi
488d531846 Enhance -assume-single-threaded option (SR-3945) 2017-02-27 12:17:53 +09:00
Joe Groff
a0c03d0a5b Merge pull request #7761 from jckarter/nserror-linux-bridging
Sema/SIL: NSError has no special powers without ObjC interop.
2017-02-25 12:14:15 -08:00
Joe Groff
d998692b60 Sema/SIL: NSError has no special powers without ObjC interop.
In particular, it doesn't "toll-free bridge" to the Error existential on non-ObjC-interop platforms, and we would miscompile as if it could. This should fix SR-585.
2017-02-25 09:20:24 -08:00
Joe Shajrawi
acc33e895b Support load and load of copy for globals in opaque value types 2017-02-24 13:11:21 -08:00
Michael Gottesman
2a75a12fc7 Fix ownership classification of opaque instructions and re-enable opaque_values_silgen test. 2017-02-23 16:49:03 -08:00
Joe Shajrawi
ec1e3ee20e Add support for unconditional checked cast instruction for opaque value types + SILGen support for it 2017-02-22 16:35:46 -08:00
Joe Shajrawi
147f844ce4 Merge pull request #7654 from shajrawi/init_opaque
Add support for Init Existentials for opaque value types
2017-02-20 19:37:01 -08:00
Joe Shajrawi
1e521c453b Add support for Init Existentials for opaque value types 2017-02-20 16:40:02 -08:00
Michael Gottesman
81dcdba0a9 Revert "Make sure we always de-serialize transparent functions."
This reverts commit 821b365054.

It caused a bunch of execution time regressions.
2017-02-18 13:36:34 -08:00
Roman Levenstein
c050e04401 Merge pull request #7524 from swiftix/debug-info-fixes
Tighten a SILVerifier check: there should be at most one debug variable defined per function argument
2017-02-16 19:57:08 -08:00
Erik Eckstein
821b365054 Make sure we always de-serialize transparent functions.
We didn’t do that if an optimization looked up a witness table.

Fixes rdar://problem/30544344

I couldn’t come up with an isolated test case, but this should be covered with our existing tests.
(The problem shows up when inlining of generics are enabled)
2017-02-16 17:04:58 -08:00
Roman Levenstein
476d552a39 Tighten a SILVerifier check: there should be at most one debug variable defined per function argument 2017-02-16 16:58:06 -08:00
Andrew Trick
6d5b417ecc Allow DestroyValueInst before addresses are lowered. 2017-02-16 09:24:07 -08:00
swift-ci
cca3398543 Merge pull request #7517 from gottesmm/revert_cmake_changes 2017-02-15 23:51:44 -08:00
Joe Shajrawi
9178030d92 Merge pull request #7514 from shajrawi/store_opaque_values
support stores of non-loadable types under opaque mode
2017-02-15 23:32:48 -08:00
Michael Gottesman
8437819b5a [CMake] Revert recent changes.
These changes caused a number of issues:

1. No debug info is emitted when a release-debug info compiler is built.
2. OS X deployment target specification is broken.
3. Swift options were broken without any attempt any recreating that
functionality. The specific option in question is --force-optimized-typechecker.

Such refactorings should be done in a fashion that does not break existing
users and use cases.

This reverts commit e6ce2ff388.
This reverts commit e8645f3750.
This reverts commit 89b038ea7e.
This reverts commit 497cac64d9.
This reverts commit 953ad094da.
This reverts commit e096d1c033.

rdar://30549345
2017-02-15 22:26:06 -08:00
Joe Shajrawi
992caba90e support stores of non-loadable types under opaque mode 2017-02-15 17:19:18 -08:00
Arnold Schwaighofer
876cea81ae SIL: Add an allowed access kind to the opened value of an open_existential_addr instruction
Once we move to a copy-on-write implementation of existential value buffers we
can no longer consume or destroy values of an opened existential unless the
buffer is uniquely owned.

Therefore we need to track the allowed operation on opened values.

Add qualifiers "mutable_access" and "immutable_access" to open_existential_addr
instructions to indicate the allowed access to the opened value.

Once we move to a copy-on-write implementation, an "open_existential_addr
mutable_access" instruction will ensure unique ownership of the value buffer.
2017-02-15 14:23:12 -08:00
Chris Bieneman
e096d1c033 [CMake] Simplify add_swift_library
This patch splits add_swift_library into two functions one which handles
the simple case of adding a library that is part of the compiler being
built and the second handling the more complicated case of "target"
libraries, which may need to build for one or more targets.

The new add_swift_library is built using llvm_add_library, which re-uses
LLVM's CMake modules. In adapting to use LLVM's modules some of
add_swift_library's named parameters have been removed and
LINK_LIBRARIES has changed to LINK_LIBS, and LLVM_LINK_COMPONENTS
changed to LINK_COMPONENTS.

This patch also cleans up libswiftBasic's handling of UUID library and
headers, and how it interfaces with gyb sources.

add_swift_library also no longer has the FILE_DEPENDS parameter, which
doesn't matter because llvm_add_library's DEPENDS parameter has the same
behavior.
2017-02-14 14:28:10 -08:00
practicalswift
8af31961b2 Merge pull request #7464 from practicalswift/gardening-20170214b
[gardening] Fix recently introduced typos
2017-02-14 21:10:52 +01:00
practicalswift
65b0219f7b [gardening] Fix typos 2017-02-14 20:04:08 +01:00
practicalswift
1c64f04997 [gardening] Fix header inconsistencies 2017-02-14 20:04:05 +01:00
Michael Gottesman
9a136cfc1e [ownership-verifier] Teach the ownership verifier how to handle control dependent ownership from cond_br.
Rememebering that the verifier ensures that any edge that propagates ownership
along a cond_br can not be critical, we do this by sinking the use by the
cond_br into the destination blocks.

rdar://29791263
2017-02-14 11:03:29 -08:00
Roman Levenstein
fc7b9e1081 [sil-linker] Minor clean-ups of function lookup code in SILModule and SIL linker. NFC.
Stop using SILLinkage::Private as a flag for "linkage doesn't matter". Use Optional instead.
2017-02-14 08:15:51 -08:00
Michael Gottesman
8b0fc4e6ed [sil] Ban critical edges from cond_br with non-trivial arguments in Semantic SIL.
This is a small corner case that simplifies the ownership verifier.
Specifically, today the ownership verifier has problems with the control
dependent nature of a cond_br's condition operand on the arguments of the
cond_br. By eliminating the possibility of values with ownership being
propagated along critical edges, the verifier can associate the arguments of the
cond_br with the destination blocks safely.

*NOTE* I ran a full testing run with sil-verify-all and this check did not
trigger once after SILGen.  Thus I think it is safe to say that there is no real
effect of this change today. It is change ensuring that we maintain the current
behavior. As part of teaching the optimizer how to handle ownership, this
property will need to be pushed back there as well.

rdar://29791263
2017-02-13 17:49:30 -08:00
Andrew Trick
10b118dfa9 [Lowering] Make the AddressLowering pass functional. 2017-02-13 17:10:02 -08:00
Andrew Trick
855918c620 [Lowering] Add an AddressLowering pass. 2017-02-13 17:10:02 -08:00
swift-ci
b454c78ea9 Merge pull request #7443 from gottesmm/ownership_unreachable_code 2017-02-13 17:06:46 -08:00
Michael Gottesman
ed67bf9f21 [ownership-verifier] Teach the ownership verifier how to handle unreachable code.
There are a few different use cases here:

1. In Raw SIL, no return folding may not have been run yet implying that a call
to a no-return function /can/ have arbitrary control flow after it (consider
mandatory inlined functions). We need to recognize that the region of code that
is strictly post dominated by the no-return function is "transitively
unreachable" and thus leaking is ok from that point. *Footnote 1*.

2. In Canonical and Raw SIL, we must recognize that unreachables and no-return
functions constitute places where we are allowed to leak.

rdar://29791263

----

*Footnote 1*: The reason why this is done is since we want to emit unreachable
code diagnostics when we run no-return folding. By leaving in the relevant code,
we have preserved all of the SILLocations on that code allowing us to create
really nice diagnostics.
2017-02-13 16:36:01 -08:00