Commit Graph

152 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
7887912a94 [OpaqueValues] Pass direct to willThrowTyped.
The runtime function `swift_willThrowTyped` takes its argument
`@in_guaranteed`.  In opaque values SIL, that's passed directly.  Don't
store non-address errors before passing them to the function.
2024-03-22 18:01:12 -07:00
Slava Pestov
f6ec97db80 SIL: Fix isPotentiallyAnyObject(), and move from AST to SIL 2024-02-29 18:13:28 -05:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
Doug Gregor
252a3cb62e Update test for @_silgen_name fix on allocating initializers 2024-01-13 09:00:48 -08:00
Doug Gregor
61579af185 Avoid use of typed throws in SIL opaque values test
SIL opaque values do not yet support typed throws, so avoid the API that
uses them.
2024-01-12 10:17:59 -08:00
Nate Chandler
5a71b61f82 [OpaqueValues] Assign tuple into tuple.
In address-lowered mode, to initialize tuple-typed memory in a single
step, tuple_addr_constructor must generally be used because it's not
possible to construct a tuple any of whose fields are address-only.  In
opaque values mode, there is no problem constructing such a tuple.  So
construct the tuple and then assign it into the tuple-typed memory; the
single instruction that initializes the memory will be the assign.
2024-01-05 13:28:37 -08:00
Nate Chandler
10ce0c6b16 [SILGen] Used move_value for lexical lets.
Instead of using begin_borrow [lexical] + copy_value.
2023-12-14 13:35:26 -08:00
Nate Chandler
9bb0187be1 [SILGen] Add begin_borrow [var_decl] lifetimes. 2023-11-28 07:26:09 -08:00
Doug Gregor
3baf6ac31a Revert "[Typed throws] Support overrides that are contravariant in the thrown error" 2023-11-16 10:40:23 -08:00
Doug Gregor
3173a3d4b3 Avoid use of typed throws in SIL opaque values test
SIL opaque values do not yet support typed throws, so avoid the API that
uses them.
2023-11-13 14:16:22 -08:00
Nate Chandler
49e76caca5 [OpaqueValues] Consume addr-only vars as loadable. 2023-08-22 17:41:15 -07:00
Nate Chandler
8c48ca2e8c [OpaqueValues] Addr-only consumes emit loadably. 2023-08-22 11:18:44 -07:00
Nate Chandler
b15b4a03f1 [Test] Deleted unused register. 2023-08-22 11:18:44 -07:00
Nate Chandler
999f2b023a [OpaqueValues] AnyHashable src gets new context.
When storing an instance of some type that conforms to Hashable into an
lvalue of type AnyHashable, the source rvalue needs to be emitted within
a new SGFContext.  Otherwise, the LocalVarInitialization for the var of
type AnyHashable would be used and an attempt would be made to store the
instance of the conforming type into the projected box.
2023-08-09 07:03:07 -07:00
Nate Chandler
b616d14ff5 [OpaqueValues] Emit weak copies.
In opaque values mode, emit the new weak copy instructions to convert as
follows:

strong_copy_weak_value: `@owned $sil_weak T?` -> `@owned $T?`
weak_copy_value: `@owned $T?` -> `@owned $@sil_weak T?`

Doing so is necessary in opaque values mode where it is needed to deal
with weak values directly rather than indirectly via `load_weak`s and
`store_weak`s.
2023-08-08 15:47:13 -07:00
Nate Chandler
8c2ed17c9a [OpaqueValues] Open opaque existential value.
When a value's preferred existential representation is opaque, if the
value is not an address (which can only happen in opaque values mode),
emit open_existential_value rather than open_existential_addr.
2023-08-04 08:26:35 -07:00
Nate Chandler
4c6fc1ae8b [OpaqueValues] Skip keypath lvalue temporary.
When emitting key-path functions on behalf of a base that's an l-value,
copy the l-value into a temporary only when using lowered addresses.
2023-08-03 06:25:26 -07:00
Nate Chandler
0ae2c0748d [OpaqueValues] Keypath setters observe triviality.
When constructing r-values during keypath setter emission, consider
whether the argument's type is trivial and construct the relevant
r-value based on that.  This worked before without opaque values because
the value is always an address.
2023-08-02 13:45:35 -07:00
Nate Chandler
53522638fe [OpaqueValues] Skip temp when setting at key-path.
When setting a value at a key-path, in opaque values mode, don't create
a temporary and store the new value into it.  That is necessary when
using lowered addresses because intrinsic's signature is

```
sil @swift_setAtWritableKeyPath : $@convention(thin) <τ_0_0, τ_0_1> (@inout τ_0_0, @guaranteed WritableKeyPath<τ_0_0, τ_0_1>, @in τ_0_1) -> ()
```

but is incorrect in opaque values mode where values are passed directly
to `@in` parameters.
2023-08-01 17:16:51 -07:00
Nate Chandler
e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00
Allan Shortlidge
f1a8740ba5 AST: Only treat @backDeployed functions as fragile on platforms with an active attribute.
Previously, typechecking and SILGen would treat a function body as fragile as long as the declaration had a `@backDeployed` attribute, regardless of the platform specified by the attribute. This was overly conservative since back deployed functions are only emitted into the client on specific platforms. Now a `@backDeployed` function can reference non-`public` declarations on the platforms it is resilient on:

```
@backDeployed(before: iOS 15)
public func foo() {
  #if os(iOS)
  // Fragile; this code may be emitted into the client.
  #else
  // Resilient; this code won't ever be exposed to clients.
  #endif
}
```

Resolves rdar://105298520
2023-02-23 10:39:42 -08:00
Allan Shortlidge
022abe4d3b NFC: Update tests to use accepted spelling for @backDeployed. 2023-02-01 22:04:33 -08:00
Nate Chandler
921c6a0e34 [OpaqueValues] Map back-deploy thunk results.
When a throwing function which returns a generic (this is the simplest
example) is back deployed, it gets a back deploy thunk.  This back
deploy thunk calls one of two variations of the function, depending on
availability, both which have the same signature and in particular both
return a generic.  The result type of that function signature is an
unbound generic.

Previously, that result type was used as is.  Consequently the success
blocks for the try_apply instructions in these thunks had arguments of
unbound generic type.

Here, that type is mapped into the context of the function being
emitted.  The thunks now have the appropriate bound generic type.
2023-01-04 16:11:49 -08:00
nate-chandler
5f3664ef94 Merge pull request #62563 from nate-chandler/opaque-values/1/20221212
[OpaqueValues] Initial key-path support.
2022-12-15 13:14:23 -08:00
Nate Chandler
d2af3435bb [OpaqueValues] Emit addr-only patterns.
When opaque values are enabled, pattern match emission now emits a copy
and a store to the destination rather than a copy-addr to it.
2022-12-13 18:09:25 -08:00
Nate Chandler
cd03615a1a [OpaqueValues] Initial key-path support.
Enough support for emitting key-paths SIL to build _Regex and
_StringProcessing.
2022-12-13 18:06:56 -08:00
Nate Chandler
8067882ed6 [Test] Added @out tuple rebuilding in SILGen. 2022-11-03 13:52:42 -07:00
Nate Chandler
332750d1fd [SILGen] Handle @out tuple expansion.
When branching to the exit block, flatten an @out tuple return value
into its components, as is done for all other return values.

In the exit block, when constructing the @out tuple to return, visit the
tuple-type-tree of the return value to reconstruct the nested tuple
structure: @out tuple returns are not flattened, unlike regular tuple
returns.
2022-11-01 13:02:32 -07:00
Holly Borla
8713d78704 [PrintOptions] Print explicit 'any' in SIL. 2022-08-18 01:15:12 -04:00
Slava Pestov
d222ac5f6e Sema: New syntax for @opened archetypes in textual SIL
The old syntax was

    @opened("UUID") constraintType

Where constraintType was the right hand side of a conformance requirement.

This would always create an archetype where the interface type was `Self`,
so it couldn't cope with member types of opened existential types.

Member types of opened existential types is now a thing with SE-0309, so
this lack of support prevented writing SIL test cases using this feature.

The new syntax is

    @opened("UUID", constraintType) interfaceType

The interfaceType is a type parameter rooted in an implicit `Self`
generic parameter, which is understood to be the underlying type of the
existential.

Fixes rdar://problem/93771238.
2022-08-07 19:03:46 -04:00
Meghana Gupta
3480eecc99 Fix SILGen to generate switch_enum at +1 for opaque value operand 2022-05-11 21:15:21 -07:00
Meghana Gupta
f3870767b4 Fixes in SILGen for opaque value support in coroutines (#58696) 2022-05-11 01:01:09 -07:00
Meghana Gupta
67af3a1324 [SIL Opaque Value] Fix SILGen to not generate store_borrow for +0 opaque values (#42488) 2022-04-22 13:47:13 -07:00
Andrew Trick
a7c6a94ceb CheckedBranchInst now uses doesCastPreserveOwnership.
Use the new API that determines whether a cast preserves
ownership. Remove an old hack.
2022-04-12 22:23:17 -07:00
Meghana Gupta
3b8656cada Create phi argument for only non-empty direct result in epilog bb 2022-04-06 22:29:01 -07:00
Meghana Gupta
f65dac9824 Use addresses to represent inout/inout_aliasable when using opaque values 2022-04-06 22:26:09 -07:00
Nate Chandler
a532c53cc5 [SIL-opaque] Don't override arg value category.
Previously, when emitting block arguments, the value category of the
SILType was overridden to be address for indirect arguments.  With
opaque types, that distinction is made later during AddressLowering.  So
only do that when opaque types are disabled.
2022-03-23 12:36:14 -07:00
Andrew Trick
439b36277c [SIL-opaque] Cleanup and reenable SILGen unit tests
CHECK lines still need to be updated for OSSA
2022-03-22 18:09:48 -07:00
Erik Eckstein
6a020f8f15 Stabilize and simplify SIL linkage and serialization
The main point of this change is to make sure that a shared function always has a body: both, in the optimizer pipeline and in the swiftmodule file.
This is important because the compiler always needs to emit code for a shared function. Shared functions cannot be referenced from outside the module.
In several corner cases we missed to maintain this invariant which resulted in unresolved-symbol linker errors.

As side-effect of this change we can drop the shared_external SIL linkage and the IsSerializable flag, which simplifies the serialization and linkage concept.
2022-03-09 15:28:05 +01:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Ravi Kandhadai
614a87279d [Tests] Fix places where "CHECK" and similar file check commands are
used without a colon.
2019-07-10 15:49:24 -07:00
John McCall
abdba1d3f4 Change the integer-literal type from Int2048 to IntLiteral.
Part of SR-290.
2018-10-31 23:14:58 -04: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
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
Doug Gregor
f232af5535 [Mangling] Allow standard substitutions in protocol mangling.
Protocol name mangling didn’t always go through a path that allowed the use
of standard substitutions. Enable standard substitutions for protocol name
manglings where they make sense.

Removes ~277k from the standard library binary size.
2018-06-19 23:24:38 -07: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
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
Slava Pestov
694fcddf4e Remove build-script flag to disable resilience 2018-03-16 19:56:17 -07:00