Commit Graph

458 Commits

Author SHA1 Message Date
Michael Gottesman
0af0d5fddc [ownership] Replace ValueOwnershipKind::Trivial with ValueOwnershipKind::Any.
In a previous commit, I banned in the verifier any SILValue from producing
ValueOwnershipKind::Any in preparation for this.

This change arises out of discussions in between John, Andy, and I around
ValueOwnershipKind::Trivial. The specific realization was that this ownership
kind was an unnecessary conflation of the a type system idea (triviality) with
an ownership idea (@any, an ownership kind that is compatible with any other
ownership kind at value merge points and can only create). This caused the
ownership model to have to contort to handle the non-payloaded or trivial cases
of non-trivial enums. This is unnecessary if we just eliminate the any case and
in the verifier separately verify that trivial => @any (notice that we do not
verify that @any => trivial).

NOTE: This is technically an NFC intended change since I am just replacing
Trivial with Any. That is why if you look at the tests you will see that I
actually did not need to update anything except removing some @trivial ownership
since @any ownership is represented without writing @any in the parsed sil.

rdar://46294760
2018-12-04 23:01:43 -08:00
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Arnold Schwaighofer
89e19693aa Cleanups 2018-11-06 09:58:36 -08:00
Arnold Schwaighofer
52c1903e54 Add SIL support for [dynamic_replacement_for: ] functions 2018-11-06 09:58:28 -08:00
Arnold Schwaighofer
7e32c68e1d Add new SIL instruction for calling dynamically_replaceable funtions
%0 = dynamic_function_ref @dynamically_replaceable_function
  apply %0()
  Calls a [dynamically_replaceable] function.

  %0 = prev_dynamic_function_ref @dynamic_replacement_function
  apply %0
  Calls the previous implementation that dynamic_replacement_function
  replaced.
2018-11-06 09:53:22 -08:00
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00
Nathan Lanza
fcd2b97b55 Merge pull request #19510 from jmittert/NsStdError
Hoist CFGState and BBState out of function scope
2018-10-25 12:33:55 -07:00
Michael Gottesman
62b5110357 [sil] Add a new CastConsumptionKind called BorrowAlways.
This means that:

1. SILGenPattern always borrows the object before it emits a case.
2. Any cast with this cast has a +0 result.

NOTE: That one can not use this with address types (so we assert if you
pass this checked_cast_addr_br).
NOTE: Once we have opaque values, checked_cast_br of a guaranteed value will
lower to a copy + checked_cast_addr_br (assuming the operation is a consuming
cast). To make sure this does not become a problem in terms of performance, we
will need a pass that can transform SILGenPattern +0 cases to +1 cases. This is
something that we have talked about in the past and I think it is reasonable to
implement.

This is an incremental commit towards fixing SILGenPattern for ownership.

rdar://29791263
2018-10-10 21:02:58 -07:00
Jason Mittertreiner
c71d24bdfe Hoist CFGState and BBState out of function scope
MSVC (Version 19.15.26726) has some really wonky behaviour with enums and
structs in function scopes. Hoisting them outside seems to work around
it.
2018-10-04 16:33:06 -07:00
Slava Pestov
21bcf3fdef SIL: Remove GenericEnvironment from SILConstantInfo
Most of the time we don't need it, and accessing a generic environment
on a deserialized declaration creates a GenericSignatureBuilder.
2018-09-27 09:08:43 -07:00
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
Jordan Rose
0bb7108e1b [SIL] Adopt std::unique_ptr for SILVerifier's DominanceInfo 2018-09-18 09:43:47 -07:00
Doug Gregor
2ef9363bd1 [ABI] Add default associated type witnesses to resilient protocols.
When an associated type witness has a default, record that as part of
the protocol and emit a default associated type metadata accessor into the
default witness table. This allows a defaulted associated type to be
added to a protocol resiliently.

This is another part of rdar://problem/44167982, but it’s still very
limiting because the new associated type cannot have any conformances.
2018-09-15 22:04:46 -07:00
Doug Gregor
4ed973329a [SIL] Unify default witness table entries with witness table entries.
SILWitnessTable::Entry already contains a superset of what was supported
by SILDefaultWitnessTable::Entry, the latter of which only had “no entry”
and “method” states. Make SILDefaultWitnessTable::Entry an alias for
SILWitnessTable::Entry, and unify all of the parsing/printing/
(de)serialization logic.
2018-09-15 22:04:46 -07:00
Jordan Rose
71760bcc4e Replace StringMap with DenseMap when the keys don't need to be owned
StringMap always copies its strings into its own storage. A DenseMap
of StringRefs has the same caveats as any other use of StringRef, but
in the cases I've changed the string has very clear ownership that
outlives the map.

No functionality change, but should reduce memory usage and malloc
traffic a little.
2018-09-13 15:15:27 -07:00
Doug Gregor
cffe3869a6 Merge pull request #19034 from DougGregor/protocol-override
Introduce overrides of protocol members and drop them from witness tables
2018-09-05 20:57:21 -07:00
Doug Gregor
0cdede2bdf [SIL] Make witness_methods always refer to a non-overriding requirement.
When forming a witness_method instruction, follow the override chain of
a protocol requirement to reach a requirement that doesn’t override any
other protocol requirement. These will be the requirements that introduce
new witness table entries.
2018-09-05 13:51:26 -07:00
Joe Groff
4985746970 SIL verifier: Fix polarity of consuming check through (unchecked_addr_cast (open_existential_addr)).
This was looking for a single non-consuming use instead of checking for the absence of any consuming
uses, leading to false-positives when there were multiple non-consuming uses.
Fixes rdar://problem/44116763.
2018-09-05 09:50:15 -07:00
Michael Gottesman
c599539044 [sil] Eliminate the src parameter from end_borrow.
This does not eliminate the entrypoints on SILBuilder yet. I want to do this in
two parts so that it is functionally easier to disentangle changing the APIs
above SILBuilder and changing the underlying instruction itself.

rdar://33440767
2018-09-04 16:38:24 -07:00
Andrew Trick
918c36e154 Guard verifyCriticalEdges with #ifndef NDEBUG.
This could noticeably improve compile time in Release builds.

Once we eliminate all calls to splitAllCriticalEdges, the we can even
remove this verification in asserts builds since normal SIL
verification will catch the issues.
2018-08-30 16:34:48 -07:00
Andrew Trick
1e88e44ce8 Add critical edge verification and fix SIL passes.
SIL passes were violating the existing invariant on non-cond-br
critical edges in several places. I fixed the places that I could
find.  Wherever there was a post-pass to "clean up" critical edges, I
replaced it with a a call to verification that the critical edges
aren't broken in the first place.

We still need to eliminate critical edges entirely before enabling
ownership SIL.
2018-08-30 13:01:39 -07:00
Andrew Trick
b3a3220e38 Merge pull request #19020 from atrick/fix-critical-edges
Fix critical edges
2018-08-29 09:51:05 -07:00
Joe Groff
965a2d16d1 Merge pull request #19025 from jckarter/verify-class-method-inst
[SIL] Verify that the method referenced in {Class,Super}MethodInsts appears in the class vtable.
2018-08-29 09:38:53 -07:00
Joe Groff
a0fced451d Verify that the method referenced in {Class,Super}MethodInsts appears in the class vtable. 2018-08-28 19:00:44 -07:00
Andrew Trick
61bae5b933 Handle critical edges consistently in all SIL stages.
This will allow passes that optimize phis to be run in the mandatory
pipeline. It also simplifies SIL invariants and will unblock
much needed simplification of BlockArgument handling.
2018-08-27 23:55:45 -07:00
John McCall
348fda2c2f More optimizer fixes for coroutines. 2018-08-24 15:19:14 -04:00
John McCall
94b748a14c Update SIL devirtualization to handle begin_apply instructions.
In order to make this reasonable, I needed to shift responsibilities
around a little; the devirtualization operation is now responsible for
replacing uses of the original apply.  I wanted to remove the
phase-separation completely, but there was optimization-remark code
relying on the old apply site not having been deleted yet.

The begin_apply aspects of this aren't testable independently of
replacing materializeForSet because coroutines are currently never
called indirectly.
2018-08-19 19:50:13 -04:00
swift-ci
7e623dd927 Merge remote-tracking branch 'origin/master' into master-next 2018-08-01 11:09:11 -07:00
Jordan Rose
2dcac4bcb2 Merge pull request #18408 from jrose-apple/default-on-your-futures
[SIL] Don't drop a default when switching on a non-exhaustive enum

rdar://problem/42775178
2018-08-01 10:54:19 -07:00
Jordan Rose
e96886a819 [SIL] Honor @inlinable in resilient modules for enum exhaustivity
Otherwise, we'll generate inlinable code over a supposedly non-frozen
enum that doesn't actually contain a 'default'.
2018-08-01 08:34:57 -07:00
Jordan Rose
ec8aa9f014 Add EnumDecl::isEffectivelyExhaustive, and use it consistently
...rather than copying the same check around all over the place.
2018-07-31 19:01:00 -07:00
swift-ci
bf137ae65b Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 18:59:26 -07:00
Andrew Trick
06d0973ebe Merge pull request #18315 from atrick/fix-argument-convention
Fix several incorrect uses of ApplySite::getArgumentConvention.
2018-07-31 18:09:54 -07:00
swift-ci
5830e237ff Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 13:29:50 -07:00
Doug Gregor
9eb9898321 Merge pull request #18364 from DougGregor/name-lookup-requests
[Name lookup] Introduce requests for several name lookup operations.
2018-07-31 13:23:38 -07:00
Jordan Rose
c5a86e0386 [SIL] Don't drop a default when switching on a non-exhaustive enum
This was undoing the effects of 36eae9d4f, which is supposed to
guarantee trapping behavior on unexpected values. Worse, it put
switches that *actually had defaults* back into
undefined-behavior-land if a case were added.

The verifier changes are in lieu of test changes; this was originally
caught by IRGen/CoreGraphics_test.swift.

rdar://problem/42775178
2018-07-31 11:54:10 -07:00
swift-ci
cae543166c Merge remote-tracking branch 'origin/master' into master-next 2018-07-31 11:29:51 -07:00
Doug Gregor
d07fa5ab69 Switch many callers of ClassDecl::getSuperclass() to ClassDecl::getSuperclassDecl().
ClassDecl::getSuperclass() produces a complete interface type describing the
superclass of a class, including any generic arguments (for a generic type).
Most callers only need the referenced ClassDecl, which is (now) cheaper
to compute: switch those callers over to ClassDecl::getSuperclassDecl().

Fixes an existing test for SR-5993.
2018-07-31 10:14:44 -07:00
Slava Pestov
2bd217e58a AST: Change AbstractStorageDecl::getValueInterfaceType() to strip off reference storage qualifiers
Also, remove AbstractStorageDecl::getStorageInterfaceType(), which was
almost identical.
2018-07-31 00:38:09 -07:00
swift-ci
fc9bbd98c5 Merge remote-tracking branch 'origin/master' into master-next 2018-07-29 21:29:01 -07:00
Michael Gottesman
53403e29ac [+0-all-args] Remove the SILOption EnableGuaranteedNormalArguments and minimally simplify code.
I made this change by removing the SILOption and then doing a compile, fix loop. I
purposely did not move around the code to make the refactoring really easy to
see.
2018-07-29 20:15:51 -07:00
Andrew Trick
89ed064808 Fix several incorrect uses of ApplySite::getArgumentConvention.
At least most of these were latent bugs since the code was
unreachable in the PartialApply case. But that's no excuse to misuse
the API.

Also, whenever referring to an integer index, be explicit about
whether it is an applied argument or callee argument.
2018-07-28 00:05:40 -07:00
swift-ci
a39a50d142 Merge remote-tracking branch 'origin/master' into master-next 2018-07-25 21:09:25 -07:00
Joe Groff
d6af6992ae SIL: Tighten verification rule for property descriptors.
A property descriptor shouldn't refer to yet another external declaration.
2018-07-25 11:09:04 -07:00
Bob Wilson
ffa88c3d28 Merge remote-tracking branch 'origin/master' into master-next 2018-07-23 14:38:55 -07:00
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
swift-ci
2507876125 Merge remote-tracking branch 'origin/master' into master-next 2018-07-06 17:08:57 -07:00
Joe Groff
849d9397d6 SIL: Generate external key path references with local candidate components.
The other side of #17404. Since we don't want to generate up front key path metadata for properties/subscripts with no withheld implementation details, the client should generate a key path component that can be used to represent a key path component based on its public interface.
2018-07-06 14:24:07 -07:00
swift-ci
decf2b1130 Merge remote-tracking branch 'origin/master' into master-next 2018-07-05 11:49:26 -07:00