Commit Graph

206 Commits

Author SHA1 Message Date
Arnold Schwaighofer
44b3a47e56 Merge pull request #20333 from aschwaighofer/dynamic_function_replacement
Dynamic function replacement
2018-11-07 13:08:46 -08:00
John McCall
3ea61ef4a0 Fix some IRGen bugs with coroutine lowering:
- The large-loadable-types pass was not rewriting function signatures
  correctly if only a yield type was rewritten.

- GenCall was not rewriting multiple yield types correctly.
2018-11-06 13:31:00 -05: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
534bdc4083 Fix yield bugs with the large-loadable-types pass. 2018-11-05 18:59:03 -05:00
John McCall
fde1ce759b [NFC] Clean up some of the code in the loadable-by-address pass 2018-11-05 18:59:03 -05:00
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
Doug Gregor
18d0ee9774 [Loadable-by-address] Replace a never-fails dyn_cast with a cast. 2018-09-07 14:12:10 -07:00
Davide Italiano
6545a91cb8 [LoadableByAddress] Improve a comment, pointed out by Adrian. 2018-08-27 16:37:20 -07:00
Davide Italiano
66731b4da9 [LoadableByAddress] Set the correct debug scope to avoid verification failures.
We need to skip over AllocStackInsts as they can be hoisted and mess
up with the scope (and, FWIW, they're always skipped as part of verification
as they have no semantic value associated).

<rdar://problem/43498112>
2018-08-27 16:04:22 -07:00
Andrew Trick
c9033ed938 Add a SIL attribute [without_actually_escaping].
ConvertFunction and reabstraction thunks need this attribute. Otherwise,
there is no way to identify that withoutActuallyEscaping was used
to explicitly perform a conversion.

The destination of a [without_actually_escaping] conversion always has
an escaping function type. The source may have either an escaping or
@noescape function type. The conversion itself may be a nop, and there
is nothing distinctive about it. The thing that is special about these
conversions is that the source function type may have unboxed
captures. i.e. they have @inout_aliasable parameters. Exclusivity
requires that the compiler enforce a SIL data flow invariant that
nonescaping closures with unboxed captures can never be stored or
passed as an @escaping function argument. Adding this attribute allows
the compiler to enforce the invariant in general with an escape hatch
for withoutActuallyEscaping.
2018-08-14 17:14:25 -07:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -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
Ding Ye
3b377ebe1e Address comments from Joe Shajrawi. 2018-07-10 23:19:42 +10:00
Ding Ye
068ec2ab4f Transform tuple return types that contain function signatures. 2018-07-10 09:03:23 +10:00
Ding Ye
60d7ef0acf [IRGen] Add proper conditions for LoadableByAddress transformation.
When it comes to functions with tuple result types in
the LoadableByAddress pass, we do not intend to perform
relevant transformation, but somehow some implementation
is not right. This patch adds appropriate checks to correct
such transformation conditions.

Resolves: SR-8076.
2018-07-10 09:02:10 +10:00
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