Commit Graph

73 Commits

Author SHA1 Message Date
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Nate Chandler
e3fbad50fe [SILGen] Forward addr self to borrow accessors.
Utilize and expand the pre-existing peephole.

rdar://127115078
2024-06-08 10:15:08 -07:00
Joe Groff
69e4b95fb8 SIL: Model noescape partial_applys with ownership in OSSA.
Although nonescaping closures are representationally trivial pointers to their
on-stack context, it is useful to model them as borrowing their captures, which
allows for checking correct use of move-only values across the closure, and
lets us model the lifetime dependence between a closure and its captures without
an ad-hoc web of `mark_dependence` instructions.

During ownership elimination, We eliminate copy/destroy_value instructions and
end the partial_apply's lifetime with an explicit dealloc_stack as before,
for compatibility with existing IRGen and non-OSSA aware passes.
2023-02-16 21:43:53 -08:00
swift-ci
fd6fd76dae Merge pull request #42513 from jsoref/spelling-silgen
Spelling silgen
2022-11-09 23:28:43 -08:00
Josh Soref
9a6bf46c0f Spelling silgen
* actually
* arbitrary
* cargo-culted
* clazz
* constrained
* continuation
* coordinator
* coroutine
* derivative
* destroyer
* given
* have
* imported
* initialization
* items
* necessarily
* occurring
* omitting
* overridden
* parameter
* possible
* predecessor
* preparation
* resilience
* should
* struct
* that
* the
* throwing
* unexpectedly
* uniqueness
* using
* value
* villain

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-11-09 21:44:17 -05:00
Nate Chandler
ed623d7b64 [NFC] Shortened SIL [init] flag.
Instead of writing out [initalization] for some instructions, use [init]
everywhere.
2022-10-27 10:38:54 -07:00
Meghana Gupta
8e800e49bf Recommit #29812 with fixes (#30342) 2020-03-13 19:34:16 -07:00
Rintaro Ishizaki
ccbc26d947 Revert "Use in_guaranteed for let captures (#29812)"
This reverts commit 13b9915c6f.
2020-03-10 16:08:08 -07:00
Meghana Gupta
13b9915c6f Use in_guaranteed for let captures (#29812)
* Use in_guaranteed for let captures

With this all let values will be captured with in_guaranteed convention
by the closure. Following are the main changes :

SILGen changes:
- A new CaptureKind::Immutable is introduced, to capture let values as in_guaranteed.
- SILGen of in_guaranteed capture had to be fixed.
  in_guaranteed captures as per convention are consumed by the closure. And so SILGen should not generate a destroy_addr for an in_guaranteed capture.
  But LetValueInitialization can push Dealloc and Release states of the captured arg in the Cleanup stack, and there is no way to access the CleanupHandle and disable the emission of destroy_addr while emitting the captures in SILGenFunction::emitCaptures.
  So we now create, temporary allocation of the in_guaranteed capture iduring SILGenFunction::emitCaptures without emitting destroy_addr for it.

SILOptimizer changes:
- Handle in_guaranteed in CopyForwarding.
- Adjust dealloc_stack of in_guaranteed capture to occur after destroy_addr for on_stack closures in ClosureLifetimeFixup.

IRGen changes :
  - Since HeapLayout can be non-fixed now, make sure emitSize is used conditionally
  - Don't consider ClassPointerSource kind parameter type for fulfillments while generating code for partial apply forwarder.
    The TypeMetadata of ClassPointSource kind sources are not populated in HeapLayout's NecessaryBindings. If we have a generic parameter on the HeapLayout which can be fulfilled by a ClassPointerSource, its TypeMetaData will not be found while constructing the dtor function of the HeapLayout.
    So it is important to skip considering sources of ClassPointerSource kind, so that TypeMetadata of a dependent generic parameters gets populated in HeapLayout's NecessaryBindings.
2020-03-10 12:23:02 -07:00
Slava Pestov
16d5716e71 SIL: Use the best resilience expansion when lowering types
This is a large patch; I couldn't split it up further while still
keeping things working. There are four things being changed at
once here:

- Places that call SILType::isAddressOnly()/isLoadable() now call
  the SILFunction overload and not the SILModule one.

- SILFunction's overloads of getTypeLowering() and getLoweredType()
  now pass the function's resilience expansion down, instead of
  hardcoding ResilienceExpansion::Minimal.

- Various other places with '// FIXME: Expansion' now use a better
  resilience expansion.

- A few tests were updated to reflect SILGen's improved code
  generation, and some new tests are added to cover more code paths
  that previously were uncovered and only manifested themselves as
  standard library build failures while I was working on this change.
2019-04-26 22:47:59 -04:00
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -04:00
Michael Gottesman
3ebd8df493 [gardening] Remove unnecessary -enable-sil-ownership from tests that now just get it from their pattern.
This just eliminates -enable-sil-ownership from all target-swift-frontend and
target-swift-emit-silgen RUN lines. Both of those now include
enable-sil-ownership in their expansion.
2019-03-12 20:39:18 -07:00
Michael Gottesman
40a09c9c21 Fixup tests for -assume-parsing-unqualified-ownership-sil => [ossa] transition. 2018-12-18 00:49:32 -08:00
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
Slava Pestov
0ec5ac282a AST: Don't mangle weak/unowned as part of a property's type
LibraryEvolution.rst stipulates that adding or removing 'weak',
'unowned' and 'unowned(unsafe)' is a resilient change if the type
is resilient. This means we should not mangle these attributes as
part of the accessor declaration.
2018-11-27 18:04:25 -05:00
Slava Pestov
3e864b26aa AST: @inline(__always) no longer implies @inlinable
Fixes <rdar://problem/44657000>.
2018-11-12 21:00:15 -05:00
Slava Pestov
9dd63a4918 AST: Use resilient access pattern for stored properties of resilient types visible via -enable-testing
Fixes <rdar://problem/45919829>.
2018-11-08 19:43:31 -05:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04:00
Alex Hoppen
560c22b18e [tests] Verify the libSyntax tree on SILGen tests
The SILGen testsuite consists of valid Swift code covering most language
features. We use these tests to verify that no unknown nodes are in the
file's libSyntax tree. That way we will (hopefully) catch any future
changes or additions to the language which are not implemented in
libSyntax.
2018-04-27 09:33:03 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Michael Gottesman
cb80f65f1e Remove plus_zero_test,plus_one_test from lit tests since they are no longer needed.
I am going to leave in the infrastructure around this just in case. But there is
no reason to keep this in the tests themselves. I can always just revert this
and I don't think merge conflicts are likely due to previous work I did around
the tooling for this.
2018-03-21 20:49:52 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
Michael Gottesman
6f4e87ad3f [+0-all-args] Be explicit about the module-name for tests that have plus_zero_* counterparts.
Otherwise, the plus_zero_* tests will have plus_zero_* as a module name, causing
massive FileCheck problems.

The reason why I am doing it with the main tests is so that I can use it when
syncing branches/etc.

radar://34222540
2018-03-11 21:55:24 -07:00
Michael Gottesman
8dd5ea9b60 [+0-all-args] Add a space after REQUIRES: plus_one_runtime to eliminate avoidable merge conflicts when editing other parts of the file.
This helps my tooling for enabling +0.
2018-03-11 16:19:09 -07:00
Michael Gottesman
e6e55df5ea [+0-all-args] Mark all tests that will need updates for +0 as requiring a plus_one_runtime. 2018-03-10 02:37:51 -08:00
Arnold Schwaighofer
3a63c0fc76 Update tests 2018-02-13 04:19:59 -08:00
Arnold Schwaighofer
d981bb1d96 Mangling: noescape functions will be trivial and no longer compatible with escape function types.
Mangle escapeness as part of the type.

Part of:
SR-5441
rdar://36116691
2018-02-06 08:51:43 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Pavel Yaskevich
6519d99736 [Mangling/ABI] NFC: Fix SILGen tests to reflect label mangling changes 2017-12-18 15:44:24 -08:00
Arnold Schwaighofer
0971d82f70 SILGen: Remaining fixes for @callee_guaranteed closures and enable it
- Fix block to func reabstraction thunks block argument handling
- Forward cast ownership
- Fix applyPartiallyAppliedSuperMethod ownership for @callee_guaranteed closures
- Avoid a copy in buildBlockToFuncThunkBody
- Update tests for callee_guaranteed closures

SR-5441
rdar://33255593
2017-11-15 19:46:08 -08:00
Slava Pestov
0b895bbf44 SILGen: Use resilience expansion when deciding if we need to use materializeForSet or not 2017-11-10 17:21:17 -08:00
Slava Pestov
2a0cb060f8 SILGen: Look up the callee method after evaluating arguments 2017-11-08 01:31:55 -08: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
Slava Pestov
065cbd8015 AST: Struct initializers that assign to self can now be resilient
Initializers for non-fixed-layout structs that are inlinable or
are defined in a different module are treated as delegating
initializers.

Previously, only initializers containing a 'self.init' call were
delegating; initializers that assigned to 'self' were not, which
resulted in DI treating them as a root initializer where the
stored 'self' value was exploded into a series of stores to each
stored property member.

They were not resilient as a result.

Fixes <https://bugs.swift.org/browse/SR-5649>,
<rdar://problem/33767516>.
2017-10-13 23:51:15 -07:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00
Michael Gottesman
3eb4cfd7da [sil-ownership] Enable sil ownership verification on 84 more tests.
rdar://33358110
2017-08-29 19:17:25 -07:00
John McCall
80b180a9a1 Implement a syntactic peephole to recognize explicit bridging
conversions that reverse an implicit conversion done to align
foreign declarations with their imported types.

For example, consider an Objective-C method that returns an NSString*:
  - (nonnull NSString*) foo;
This will be imported into Swift as a method returning a String:
  func foo() -> String
A call to this method will implicitly convert the result to String
behind the scenes.  If the user then casts the result back to NSString*,
that would normally be compiled as an additional conversion.  The
compiler cannot simply eliminate the conversion because that is not
necessarily semantically equivalent.

This peephole recognizes as-casts that immediately reverse a bridging
conversion as a special case and gives them special power to eliminate
both conversions.  For example, 'foo() as NSString' will simply return
the original return value.  In addition to call results, this also
applies to call arguments, property accesses, and subscript accesses.
2017-07-15 01:13:41 -04:00
Robert Widmann
71bf312a25 Migrate the rest of the tests to %empty-directory 2017-06-04 11:08:39 -07:00
Andrew Trick
588b578498 [Exclusivity] Update SILGen tests for static access markers. 2017-04-24 08:32:15 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Erik Eckstein
c4a11f4c92 tests: remove the now unused option -new-mangling-for-tests 2017-03-22 11:28:43 -07:00
Erik Eckstein
a04a29af4f mangling: efficient mangling of repeated substitutions
Instead of appending a character for each substitution, we now prefix the substitution with the repeat count, e.g.
AbbbbB -> A5B

The same is done for known-type substitutions, e.g.
SiSiSi -> S3i

This significantly shrinks mangled names which contain large lists of the same type, like
  func foo(_ x: (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int))

rdar://problem/30707433
2017-03-05 17:41:43 -08:00
Michael Gottesman
5a15f880ee [silgen] Change a bunch of self accesses to use true formal evaluation scopes and formal accesses.
This is in preparation for removing the +0 self hack.

This commit in more detail does the following:

1. It adds Formal Evaluation Scopes to certain places where the scopes were
missing. Specifically:

   a. The SILGenLValue cases are places where we are invoking accessors. In each
      one of these cases, we had a formal evaluation scope in the accessor
      itself, but we did not have a scope that closed over the base access and
      the accessor access. The base access is a formal evaluation in the sense
      that just like with inout bases, we must create a new reference to the
      base and re-destroy the base in a chain of accesses. This is to ensure
      that we do not extend the lifetime of the base inappropriately.

   b. The SILGenPoly case is a place where we have never properly placed a
      Formal Evaluation Scope and have completely been relying on the +0 self
      hack to make sure that archetype callees are properly destroyed
      immediately after a +0 call.

2. It changes all of the places in SILGen that emit self to using formal access
cleanups instead of normal cleanups.

rdar://29791263
2017-02-23 10:36:48 -08:00
Michael Gottesman
d4ae7a3f8a [semantic-sil] When calling emitRValueForDecl, borrow the value before deciding whether or not to copy the value.
rdar://29791263
2017-02-15 15:29:30 -08:00
Erik Eckstein
1d3724666f tests: convert about 400 tests to the new mangling by using the -new-mangling-for-tests option
When the new mangling is enabled permanently, the option can be removed from the RUN command lines again.
2017-01-24 15:27:45 -08:00
Slava Pestov
022c28344b Update resilience tests to not use -enable-source-import
This flag is hopefully going away one day, and using it for testing
resilience is especially suspect. Just invoke the frontend directly
to build the necessary modules with -emit-module first.
2017-01-20 01:22:51 -08:00
Joe Groff
4444d83756 SIL: Lower captures to boxes with an appropriate generic context.
Officially kick SILBoxType over to be "nominal" in its layout, with generic layouts structurally parameterized only by formal types. Change SIL to lower a capture to a nongeneric box when possible, or a box capturing the enclosing generic context when necessary.
2016-12-16 20:23:25 -08:00
Joe Groff
277608a69b Print and parse SILBoxTypes with a new syntax.
Use a syntax that declares the layout's generic parameters and fields,
followed by the generic arguments to apply to the layout:

  { var Int, let String } // A concrete box layout with a mutable Int
                          // and immutable String field
  <T, U> { var T, let U } <Int, String> // A generic box layout,
                                        // applied to Int and String
                                        // arguments
2016-12-02 13:44:22 -08:00
Michael Gottesman
34ec32bc14 [semantic-arc] Handle the rest of the unqualified mem opts in SILGen.
Keep in mind that these are approximations that will not impact correctness
since in all cases I ensured that the SIL will be the same after the
OwnershipModelEliminator has run. The cases that I was unsure of I commented
with SEMANTIC ARC TODO. Once we have the verifier any confusion that may have
occurred here will be dealt with.

rdar://28685236
2016-11-09 11:37:52 -08:00