Commit Graph

141 Commits

Author SHA1 Message Date
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
Joe Shajrawi
2cfe74a930 [IRGen] Fix a large-types corner case wherein we have a module without any signature modifications but with callee modifications
Assume we have a module with functions that keep their signatures as-is. And assume we have a method call callee for which we modified the return type to be indirect.
In that case we need to re-create the applies to said callee.

The large loadable types pass had a check that if we did not modify any function signatures, we can exit the module pass early to reduce compile time, that check breaks the situation described above.

This commit changes the early-exit check so that we can skip the rest of of the module pass if we did not change any function signatures AND we did not change any applies.
2018-06-06 14:43:41 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
Andrew Trick
fe326266cc [exclusivity] Add a [builtin] flag to begin_[unpaired_]access.
This flag supports promoting KeyPath access violations to an error in
Swift 4+, while building the standard library in Swift 3 mode. This is
only necessary as long as the standard library continues to build in
Swift 3 mode. Once the standard library build migrates, it can all be
ripped out.

<rdar://problem/40115738> [Exclusivity] Enforce Keypath access as an error, not a warning in 4.2.
2018-05-09 21:42:37 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Joe Shajrawi
cb4391d409 [LoadableByAddress] Improve compile time by adding a cache that of previously computed SIL types.
This algorithm for calculating the SIL type used to take quite a while if the type contained a very large number of closures (see attached test case)
2018-04-18 19:15:38 -07:00
Arnold Schwaighofer
36d5408125 SIL: Add an [escaped] attribute to convert_escape_to_noescape instruction
To mark when a user of it is known to escape the value. This happens
with materializeForSet arguments which are captured and used in the
write-back. This means we need to keep the context alive until after
the write-back.

Follow-up patches to fully replace the PostponedCleanup hack in SILGen
by a mandatory SIL transformation pass to guarantee the proper lifetime
will use this flag to be more conservative when extending the lifetime.

The problem:

%pa = partial_apply %f(%some_context)
%cvt = convert_escape_to_noescape [not_guaranteed] [escaped] %pa
%ptr = %materialize_for_set(..., %cvt)
...  write_back
... // <-- %pa needs to be alive until after write_back
2018-04-13 12:40:10 -07:00
Joe Shajrawi
bef7b45086 LargeLoadableTypes: fix a corner case with optional function types
Fixes a bug where we have an optional function type for which we changed the signature, and, in addition, gotten said type via a modified struct/enum extract
That is, the function type is contained inside a large loadable type which we transformed into its address variant
There is a check that we have to explode (load instruction) the extract value if it is a function type, however, we did not check if it is an optional function type.
2018-04-03 16:14:39 -07:00
Joe Shajrawi
ce32847195 Merge pull request #15693 from shajrawi/large_load_bugfix_small
LargeLoadableTypes: Support applies of objc applies
2018-04-03 09:39:24 -07:00
Joe Shajrawi
774b0842c6 LargeLoadableTypes: Support applies of objc applies
Fixes a bug where we have an apply of an AppleSite that returns a large type.
Normally, we should change the ‘apply’ to one that returns @out of the large type.
This, however, does not hold true if the ApplySite got the old calling conventions - detect and avoid changing that case.
2018-04-02 15:56:06 -07:00
Andrew Trick
4ed120e46c Merge branch 'master' into add-access-tracking-flag 2018-03-30 19:25:46 -07:00
Arnold Schwaighofer
80e7a1914d Add a convert_escape_to_noescape [not_guaranteed] variant 2018-03-30 08:53:40 -07:00
Andrew Trick
ed8a604c27 Merge branch 'master' into add-access-tracking-flag 2018-03-29 18:26:22 -07:00
Davide Italiano
dfaf133d27 [LoadableByAddress] Fix debug info holes when expanding alloc_stack.
<rdar://problem/36876376>
2018-03-28 11:54:03 -07:00
Andrew Trick
e50faa5125 [exclusivity] Add 'no_nested_conflict' flag to begin_access.
This statically guarantees that the access has no inner conflict within
its own scope.

IRGen will turn this into a "nontracking" access in which an
exclusivity check is performed for conflicts on an outer scope. However,
unlike normal accesses the runtime does not record the access, and the
access will not be checked for subsequent conflicts.

end_unpaired_access [no_nested_conflict] is not currently
supported. Making a begin_unpaired_access [no_nested_conflict] requires
deleting the corresponding end_unpaired_access. Future runtimes
could support this for verification by storing inline data in the
valud buffer. However, the runtime can never assume that a
[no_nested_conflict] begin_unpaired_access will have a corresponding
end_unpaired_access call without adding a new ExclusivityFlag for
that purpose.
2018-03-27 10:50:07 -07:00
Slava Pestov
76349a0f87 Squash some unused variable warnings 2018-03-08 17:05:59 -07:00
Adrian Prantl
9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
Joe Shajrawi
82fdc3afbe LoadableByAddress: Fix commit 0ca90b8 - add tuple check that went missing when committing the code 2018-02-19 23:17:53 +02:00
swift-ci
0ca90b8eeb Merge pull request #14637 from shajrawi/tuples 2018-02-19 06:26:25 -08:00
Joe Shajrawi
e28fc903c4 LoadableByAddress: Add better tuples support
When working with tuples, if the tuple does not contain a large loadable type but does contain a function signature, we currently do nothing.

We should convert the function signature inside the tuple type instead.
2018-02-19 13:41:51 +02:00
Arnold Schwaighofer
51c31a3506 LoadableByAddress: Handle escape to noescape casts 2018-02-13 04:19:59 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Joe Shajrawi
350e92119b IRGen: fix a corner-case wherein a partial_apply was not converted in LoadableByAddress
It cleans up shouldTransformParameter, fixing a corner-case for optional function parameter, and re-creates *all* partial applies that only contain function/optional function parameters
2018-01-26 10:09:44 -08:00
Adrian Prantl
cb125bd3f9 Don't drop function argument debug info in the LoadableByAddress transformation
rdar://problem/36392957
2018-01-10 08:58:56 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Slava Pestov
1b153ae5ac LoadableByAddress: I don't think these GenericContextScopes are necessary 2017-12-22 22:01:06 -08:00
Slava Pestov
57e206850b LoadableByAddress: If a SILFunction has a polymorphic lowered type it also has a generic environment 2017-12-22 22:01:06 -08:00
Slava Pestov
41c4afcdd3 LoadableByAddress: An ApplySite's substituted type is never polymorphic 2017-12-22 22:01:06 -08:00
Slava Pestov
0306519ff9 LoadableByAddress: Fix typo 2017-12-22 22:01:06 -08:00
Slava Pestov
b6157c0ab9 LoadableByAddress: Don't transform substitutions
Substitutions are always in terms of AST types and do not contain
SILFunctionTypes that need to be transformed here.
2017-12-22 22:01:06 -08:00
Slava Pestov
2356acceac LoadableByAddress: Idiomatic code cleanups 2017-12-22 22:01:06 -08:00
Joe Shajrawi
9c9b8527e5 LoadableByAddress: take the function type's generic environment when converting BB args 2017-12-21 16:05:12 -08:00
Joe Shajrawi
8fd6dc155e LoadableByAddress: use deterministic containers 2017-12-15 11:09:01 -08:00
Joe Shajrawi
cb33716475 Set SIL stage to lowered at the *start* of address lowering
SIL is not in a consistent state during the lowering pass. We just make sure it is correct at the end of the pass. This broke PR https://github.com/apple/swift/pull/13283 (verifying convert_function instructions in the builder)

To workaround this issue we will be running the builder’s verifier when the SIL stage != SILStage::Lowered

The SIL stage is set to lowered at the end of the module pass. This means that if this is the first lowering pass said workaround would not work.

This commit sets the SIL stage to lowered at the beginning of the module pass instead
2017-12-05 17:18:58 -08:00
swift-ci
5e7aba6568 Merge pull request #13228 from gottesmm/pr-5feef94b3c080c9a6cf510b23576b94c19fbe1a9 2017-12-02 18:38:14 -08:00
Michael Gottesman
5263e9e74e [sil] Eliminate redundant method SILFunction::hasUnqualifiedOwnership().
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
2017-12-02 17:42:34 -08:00
Adrian Prantl
521de91ba7 Fix the debug info generated by the LoadableByAddress transformation.
And unbreak the LLDB testsuite.

This patch fixes three problems with the original implementation:
- Use SILBuilderWithScope instead of SILBuilder to avoid holes in the
  lexical scopes.
- Use an artificial location for stores to the alloca to avoid the debugger
  stopping before the variable is initialized.
- Recognize debug_value_addr instructions referring to an alloc_stack
  instruction to avoid introducing an extra indirection in the debug info.

rdar://problem/31975108
2017-12-02 16:48:34 -08:00
Joe Shajrawi
86ea17a85f Revert "Large Types Lowering: workaround LLDB issue by adding debug_value_addr for some new alloc_stack instrs" 2017-11-30 16:28:52 -08:00
swift-ci
1e2fad5164 Merge pull request #13168 from shajrawi/large_type_lldb_workaround 2017-11-29 18:57:41 -08:00
Joe Shajrawi
db5229330e Large Types Lowering: workaround LLDB issue by adding debug_value_addr for some new alloc_stack instrs 2017-11-29 18:13:23 -08:00
Slava Pestov
1f79af7504 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 16:26:43 -08:00
Arnold Schwaighofer
ea9907ae15 Revert "SIL: Use objc_method instruction for Objective-C protocol method calls" 2017-11-29 11:19:46 -08:00
Slava Pestov
1ee0970934 SIL: Use objc_method instruction for Objective-C protocol method calls
Fixes <rdar://problem/15933365>.
2017-11-29 01:22:05 -08:00
Arnold Schwaighofer
7100a09143 IRGen: Properly communicate ownership to IRGen from the LoadableByAddress pass
Communicate to IRGen whether a indirect promoted value was guaranteed or owned

rdar://35674625
2017-11-28 16:23:22 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Andrew Trick
2874e18713 Fix LoadableByAddress to handle convert_functions.
Handle function_ref -> convert_function -> thin_to_thick.

Fixes <rdar://problem/35059942> Failed - Lark, 3.0, Swift Package - Source Compatibility Suite (master)
2017-10-19 00:34:16 -07:00
Andrew Trick
d369aa4070 Support @noescape SIL function types. (#12420)
Support for @noescape SILFunctionTypes.

These are the underlying SIL changes necessary to implement the new
closure capture ABI.

Note: This includes a change to function name mangling that
primarily affects reabstraction thunks.

The new ABI will allow stack allocation of non-escaping closures as a
simple optimization.

The new ABI, and the stack allocation optimization, also require
closure context to be @guaranteed. That will be implemented as the
next step.

Many SIL passes pattern match partial_apply sequences. These all
needed to be fixed to handle the convert_function that SILGen now
emits. The conversion is now needed whenever a function declaration,
which has an escaping type, is passed into a @NoEscape argument.

In addition to supporting new SIL patterns, some optimizations like
inlining and SIL combine are now stronger which could perturb some
benchmark results.

These underlying SIL changes should be merged now to avoid conflicting
with other work. Minor benchmark discrepancies can be investigated as part of
the stack-allocation work.

* Add a noescape attribute to SILFunctionType.

And set this attribute correctly when lowering formal function types to SILFunctionTypes based on @escaping.

This will allow stack allocation of closures, and unblock a related ABI change.

* Flip the polarity on @noescape on SILFunctionType and clarify that
we don't default it.

* Emit withoutActuallyEscaping using a convert_function instruction.

It might be better to use a specialized instruction here, but I'll leave that up to Andy.

Andy: And I'll leave that to Arnold who is implementing SIL support for guaranteed ownership of thick function types.

* Fix SILGen and SIL Parsing.

* Fix the LoadableByAddress pass.

* Fix ClosureSpecializer.

* Fix performance inliner constant propagation.

* Fix the PartialApplyCombiner.

* Adjust SILFunctionType for thunks.

* Add mangling for @noescape/@escaping.

* Fix test cases for @noescape attribute, mangling, convert_function, etc.

* Fix exclusivity test cases.

* Fix AccessEnforcement.

* Fix SILCombine of convert_function -> apply.

* Fix ObjC bridging thunks.

* Various MandatoryInlining fixes.

* Fix SILCombine optimizeApplyOfConvertFunction.

* Fix more test cases after merging (again).

* Fix ClosureSpecializer. Hande convert_function cloning.

Be conservative when combining convert_function. Most of our code doesn't know
how to deal with function type mismatches yet.

* Fix MandatoryInlining.

Be conservative with function conversion. The inliner does not yet know how to
cast arguments or convert between throwing forms.

* Fix PartialApplyCombiner.
2017-10-17 13:07:25 -07:00
swift-ci
3d53e7baa2 Merge pull request #12451 from lattner/SILValue-getLoc 2017-10-15 16:14:45 -07:00
Chris Lattner
cd99f859e3 NFC code cleanup changes:
- Hoist a duplicated static function with a fixme out to SILValue::getLoc()
 - Fix a whitespace issue.
2017-10-15 15:31:41 -07:00