Commit Graph

3168 Commits

Author SHA1 Message Date
Michael Gottesman
b0e4c68f61 [ownership-verifier] When we determine the OwnershipKind that select enum forwards, we should not look at the condition operand, just the case operands.
rdar://29791263
2017-02-05 20:18:24 -08:00
Slava Pestov
a4fd57647c AST: Remove unused resolver parameter from getTypeOfMember() 2017-02-03 19:55:39 -08:00
Joe Groff
a7f23f5019 SIL: Canonicalize capture types with the AST function's generic signature.
When lowering closures, we avoid capturing the enclosing generic context when possible. However, the generic context may still be necessary to canonicalize types mentioned inside the closure, such as when an associated type is referred to that is same-typed to a concrete type. Fixes rdar://problem/30254048.
2017-02-03 12:08:57 -08:00
swift-ci
83fcb32ad5 Merge pull request #7189 from atrick/master 2017-02-01 12:53:51 -08:00
Andrew Trick
a6ebb4e914 Add an option -Xllvm -sil-print-on-error.
Print the SIL function body on an assert. Recovering the SIL code is the
critical path for pretty much any SIL development. The only alternative is
rebuilding the library with string matching or building a debug compiler and
hoping lldb works. The standard library takes a very long time to build with a
debug compiler.
2017-02-01 10:51:53 -08:00
Doug Gregor
f7f703ad04 [Archetype builder] Canonicalize and minimize same-type constraints.
Introduce an algorithm to canonicalize and minimize same-type
constraints. The algorithm itself computes the equivalence classes
that would exist if all explicitly-provided same-type constraints are
ignored, and then forms a minimal, canonical set of explicit same-type
constraints to reform the actual equivalence class known to the type
checker. This should eliminate a number of problems we've seen with
inconsistently-chosen same-type constraints affecting
canonicalization.
2017-02-01 10:51:02 -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
Slava Pestov
e338a50bc3 SIL: Stored property initializers get the linkage of their containing type
This allows inlineble initializers to be defined on types that
have stored property initializers.

This is not the final behavior we want; in Swift 4 mode, we want
to give these shared linkage and make them fragile, and enforce
that stored property initializer expressions only reference other
public and versioned symbols.

This will match the behavior of default argument expressions in
Swift 4 mode, and I'll implement it when I do those.
2017-01-29 22:43:41 -08:00
Slava Pestov
5ce84060ca SIL: Enum case constructors are fragile if the enum is public or @_versioned 2017-01-29 22:43:40 -08:00
Andrew Trick
e9c559b718 [SILGen] Bootstrapping opaque values (#7113)
[NFC] Add -enable-sil-opaque-values frontend option.

This will be used to change the SIL-level calling convention for opaque values,
such as generics and resilient structs, to pass-by-value.  Under this flag,
opaque values have SSA lifetimes, managed by copy_value and destroy_value.

This will make it easier to optimize copies and verify ownership.

* [SILGen] type lowering support for opaque values.

Add OpaqueValueTypeLowering.
Under EnableSILOpaqueValues, lower address-only types as opaque values.

* [SIL] Fix ValueOwnershipKind to support opaque SIL values.

* Test case: SILGen opaque value support for Parameter/ResultConvention.

* [SILGen] opaque value support for function arguments.

* Future Test case: SILGen opaque value specialDest arguments.

* Future Test case: SILGen opaque values: emitOpenExistential.

* Test case: SIL parsing support for EnableSILOpaqueValues.

* SILGen opaque values: prepareArchetypeCallee.

* [SIL Verify] allow copy_value for EnableSILOpaqueValues.

* Test cast: SIL serializer support for opaque values.

* Add a static_assert for ParameterConvention layout.

* Test case: Mandatory SILOpt support for EnableSILOpaqueValues.

* Test case: SILOpt support for EnableSILOpaqueValues.

* SILGen opaque values: TypeLowering emitCopyValue.

* SILBuilder createLoad. Allow loading opaque values.

* SIL Verifier. Allow loading and storing opaque values.

* SILGen emitSemanticStore support for opaque values.

* Test case for SILGen emitSemanticStore.

* Test case for SIL mandatory support for inout assignment.

* Fix SILGen opaque values test case after rebasing.
2017-01-27 18:56:53 -08:00
Roman Levenstein
400f3381cf Merge pull request #7078 from swiftix/wip-textual-sil-sildeclrefs
Use function signatures for SILDeclRefs in witness_tables, vtables and witness_method instructions
2017-01-27 15:11:23 -08:00
Roman Levenstein
8ad61d5cd6 Use function signatures for SILDeclRefs in witness_tables, vtables and witness_method instructions.
Textual SIL was sometimes ambiguous when SILDeclRefs were used, because the textual representation of SILDeclRefs was the same for functions that have the same name, but different signatures.
2017-01-27 12:16:14 -08:00
Erik Eckstein
b8ebd41b50 Reinstate "SIL: fix conformance collection for super_method instruction""
Re-instates commit 1a8980687b
with a fixed test file
2017-01-27 09:38:49 -08:00
Mishal Shah
490e2dc089 Revert "SIL: fix conformance collection for super_method instruction" 2017-01-26 17:57:55 -08:00
swift-ci
38f1ca8708 Merge pull request #7064 from gottesmm/emit_struct_extract_using_borrows 2017-01-26 17:53:35 -08:00
swift-ci
42879895c0 Merge pull request #7070 from apple/revert-4048-wip-textual-sil-sildeclrefs 2017-01-26 16:49:48 -08:00
Michael Gottesman
10ad10e8bc [ownership-verifier] mark_uninitialized is a forwarding instruction, not always trivial.
This can be seen in the case of a [rootself] variable.

rdar://29791263
2017-01-26 16:46:42 -08:00
Michael Gottesman
95a30e44f4 [sil] Use GenericContextScope in SILResultInfo::getOwnershipKind instead of pushing/popping manually.
I may refactor this differently, but no reason not to use cleaner APIs when
possible.
2017-01-26 16:46:42 -08:00
Michael Gottesman
24dfae0716 [sil] Add a new API SILFunction::getTypeLowering(SILType).
This API is meant to enable people working in SIL to be able to retrieve the
type lowering of a lowered type within the GenericSignature associated with a
given SILFunction's SILFunctionType.
2017-01-26 16:46:03 -08:00
swift-ci
bfff1c884f Merge pull request #6922 from atrick/silconv 2017-01-26 16:35:08 -08:00
Maxim Moiseev
96dc4817f3 Revert "Use function signatures for SILDeclRefs in witness_tables, vtables and witness_method instructions" 2017-01-26 16:28:57 -08:00
Andrew Trick
978b2fc80b Fix terminology. There's no such thing as a "formal SIL type".
Formal types are defined by the language's type system. SIL types are
lowered. They are no longer part of that type system.

The important distinction here is between the SIL storage type and the SIL value
type. To make this distinction clear, I refer to the SILFunctionTypes "formal"
conventions. These conventions dictate the SIL storage type but *not* the SIL
value type. I call them "formal" conventions because they are an immutable
characteristic of the function's type and made explicit via qualifiers on the
function type's parameters and results. This is in contrast to to SIL
conventions which depend on the SIL stage, and in the short term whether the
opaque values flag is enabled.
2017-01-26 15:35:48 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
Erik Eckstein
0fe5a03228 SIL: let the ConformanceCollector handle more instructions which potentially require a meta type.
fixes SR-3741, SR-3744, SR-3745
also related to rdar://problem/30166968
2017-01-26 15:27:22 -08:00
Roman Levenstein
b74c786ec9 Merge pull request #4048 from swiftix/wip-textual-sil-sildeclrefs
Use function signatures for SILDeclRefs in witness_tables, vtables and witness_method instructions
2017-01-26 14:50:47 -08:00
Roman Levenstein
bf2dcbf25e Use function signatures for SILDeclRefs in witness_tables, vtables and witness_method instructions.
Textual SIL was sometimes ambiguous when SILDeclRefs were used, because the textual representation of SILDeclRefs was the same for functions that have the same name, but different signatures.
2017-01-26 14:29:59 -08:00
Huon Wilson
92e9d2d84f [SIL] Extract reoccuring allocation patterns.
No need to write a pile of manual memcpy's.
2017-01-26 12:42:13 -08:00
Erik Eckstein
1a8980687b SIL: fix conformance collection for super_method instruction
fixes rdar://problem/30166968
2017-01-25 19:57:31 -08:00
Michael Gottesman
e16f01529e [ownership-verifier] Until we agree on a list of uses that are considered as preserving the lifetime of a mark_dependence, just propagate the mark_dependence into the use set of the base rather than the uses of the value.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
a9fcfcb272 [ownership-verifier] When verifying forwarded values, make sure to ignore
trivial ownership in aggregates that are non-trivial.

rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
74fc8d9067 [ownership-verifier] Allow for trivial enum args to be passed into non-trivial phi nodes.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
ea8d11f6a1 [ownership-verifier] WillThrow has a trivial tuple return value.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
659a93ba99 [ownership-verifier] alloc_ref, alloc_ref_dynamic can have trivial arguments for tail stored data.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
ad9cd2ade1 [ownership-verifier] project_existential_box takes a non-trivial existential argument, not a trivial argument.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
cf7e480765 [ownership-verifier] Throw takes in an Error parameter which is an @owned protocol.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
1ef8ea6bc1 [ownership-verifier] alloc_value_buffer/dealloc_value_buffer have single trivial address operands.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
7476f16a00 [ownership-verifier] Forwarding instructions only are lifetime ending uses when forwarding owned semantics.
rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
c7aa4e294e [ownership-verifier] We accept owned/guaranteed/unowned in unowned positions.
Unowned is a +0 convention that requires the user to "copy" the relevant value
before any side effects occur in the callee. This means that it is safe to pass
owned/guaranteed/unowned to such functions.

rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
f78ffdb941 [ownership-verifier] Ignore type dependent operands when checking for uses since we don't care about them.
This also avoids undefined behavior when we try to look up the
ParameterConvention of a type dependent operand. Since type dependent operands
do not have a convention, this causes us to hit an assertion.

rdar://29791263
2017-01-25 18:03:05 -08:00
Michael Gottesman
4c7ec6e4dd [ownership-verifier] switch_enum, checked_cast_br, dynamic_method_br can have trivial and owned operands.
In the case of switch_enum this is just trivial enums. In the case of
checked_cast_br and dynamic_method_br, the potential trivial arguments are
metatypes.

rdar://29791263
2017-01-24 19:38:38 -08:00
Michael Gottesman
adb85df969 [ownership-verifier] Use a check against ValueOwnershipKind::Trivial instead of SILType::isTrivial to determine trivial ownership in isValueAddressOrTrivial.
Without this enums with non-trivial cases are always treated as non-trivial even
if a just created enum is trivial. For example the following no payload enum
would be considered non-trivial.

    %0 = enum $Optional<Builtin.NativeObject>, #Optional.none!enumelt

rdar://29791263
2017-01-24 18:11:02 -08:00
Michael Gottesman
e8ede8b32c [ownership-verifier] We should always stop at the dominating block definition when verifying.
I think this was introduced relatively recently. I added a test so that it does
not happen again.

rdar://29791263
2017-01-24 16:43:27 -08:00
Michael Gottesman
e826d431a9 [ownership-verifier] When verifying a def that is immediately consumed in the same block, do not add the block's predecessors to the worklist for visiting purposes.
rdar://29791263
2017-01-24 16:40:10 -08:00
Erik Eckstein
a56a97c89f Mangling: prepare for using new mangling for USR and debug-info type generation.
Select between old and new mangling as we already do in other places in the compiler.
NFC as long as the new mangling is not enabled yet.
2017-01-23 17:49:00 -08:00
Michael Gottesman
0a4618e93e [semantic-sil] Implement parsing and printing of ownership attributes on SILArguments.
This is only enabled when semantic sil is enabled /and/ we are not parsing
unqualified SIL.

*NOTE* To properly write tests for this, I had to rework how we verified
Branch/CondBranch insts to be actually correct (instead of pseudo-correct). I
have to put this functionality together in order to write tests.

rdar://29791263
2017-01-22 22:02:31 -08:00
Michael Gottesman
d045f20867 [semantic-sil] Add a new instruction end_borrow_argument.
I need this instruction in order to model the end of life of a guaranteed phi
arguments.

rdar://29791263
2017-01-22 20:46:25 -08:00
Michael Gottesman
7f70847e8c [gardening] Refactor printing of block arguments by extracting some large code into methods.
rdar://29791263
2017-01-22 19:54:21 -08:00
Michael Gottesman
682087e376 [value-ownership-kind] Builtin.unreachable /does/ return a value.
Specifically, Builtin.unreachable returns a Never value.

rdar://29791263
2017-01-22 19:54:19 -08:00
practicalswift
65ec8385c7 Merge pull request #6976 from practicalswift/typo-fixes-20170122
[gardening] Fix recently introduced typos
2017-01-22 21:48:29 +01:00
practicalswift
a9d6d8938c [gardening] Fix recently introduced typos 2017-01-22 20:40:45 +01:00