Commit Graph

785 Commits

Author SHA1 Message Date
Michael Gottesman
a3b68e6df5 [silgen] When SILGenLValue accesses ref_elt_addr, emit unsafe access for immutable or non accessing uses instead of not emitting any begin_access. 2020-01-09 15:22:09 -08:00
Arnold Schwaighofer
33f4f57cc4 SILGen: Add TypeExpansionContext to SILGen 2019-11-11 14:21:52 -08:00
Michael Gottesman
7ee5ad7318 [sil] Rename {,Strong}Copy{Unowned,Unmanaged}. 2019-10-26 17:03:47 -07:00
Joe Groff
03c7919b4a SIL: Add fields to SILFunctionType for substituted function types.
https://forums.swift.org/t/improving-the-representation-of-polymorphic-interfaces-in-sil-with-substituted-function-types/29711

This prepares SIL to be able to more accurately preserve the calling convention of
polymorphic generic interfaces by letting the type system represent "substituted function types".
We add a couple of fields to SILFunctionType to support this:

- A substitution map, accessed by `getSubstitutions()`, which maps the generic signature
  of the function to its concrete implementation. This will allow, for instance, a protocol
  witness for a requirement of type `<Self: P> (Self, ...) -> ...` for a concrete conforming
  type `Foo` to express its type as `<Self: P> (Self, ...) -> ... for <Foo>`, preserving the relation
  to the protocol interface without relying on the pile of hacks that is the `witness_method`
  protocol.

- A bool for whether the generic signature of the function is "implied" by the substitutions.
  If true, the generic signature isn't really part of the calling convention of the function.
  This will allow closure types to distinguish a closure being passed to a generic function, like
  `<T, U> in (*T, *U) -> T for <Int, String>`, from the concrete type `(*Int, *String) -> Int`,
  which will make it easier for us to differentiate the representation of those as types, for
  instance by giving them different pointer authentication discriminators to harden arm64e
  code.

This patch is currently NFC, it just introduces the new APIs and takes a first pass at updating
code to use them. Much more work will need to be done once we start exercising these new
fields.

This does bifurcate some existing APIs:

- SILFunctionType now has two accessors to get its generic signature.
  `getSubstGenericSignature` gets the generic signature that is used to apply its
  substitution map, if any. `getInvocationGenericSignature` gets the generic signature
  used to invoke the function at apply sites. These differ if the generic signature is
  implied.
- SILParameterInfo and SILResultInfo values carry the unsubstituted types of the parameters
  and results of the function. They now have two APIs to get that type. `getInterfaceType`
  returns the unsubstituted type of the generic interface, and
  `getArgumentType`/`getReturnValueType` produce the substituted type that is used at
  apply sites.
2019-10-25 13:38:51 -07:00
Doug Gregor
43da5c9744 Remove dead flag disable-tsan-inout-instrumentation 2019-10-14 21:42:33 -07:00
Doug Gregor
f9f63bdf65 [DI] Don't allow assign_by_wrapper formation to break access control.
Fixes rdar://problem/54352235
2019-10-11 20:02:32 -07:00
Arnold Schwaighofer
e0ce37e0da SILGen: Fix setting variables with property wrappers marked objc dynamic
rdar://54181647
2019-10-03 07:57:23 -07:00
eeckstein
66a2f62a99 Merge pull request #27300 from eeckstein/fix-silgen-crash
SILGen: use the correct forwarding substitutions for the setter of an assign_by_wrapper.
2019-09-25 08:37:41 +02:00
Doug Gregor
8613b05445 [DI] Support definite initialization for composed property wrappers.
Use the newly-introduced property wrapper backing initializer function
in definite initialization (DI) to form the assign_by_wrapper
instruction, rather than forming a reference to the (only) property
wrapper's `init(wrappedValue:)`. This allows DI to work on properties
that have multiple, composed property wrappers applied to them.
2019-09-24 09:11:53 -07:00
Erik Eckstein
7d65012f27 SILGen: use the correct forwarding substitutions for the setter of an assign_by_wrapper.
Fixes a crash when a function, which assigns to a wrapped property has additional generic parameters.

https://bugs.swift.org/browse/SR-11484
rdar://problem/55442328
2019-09-24 09:41:35 +02:00
Doug Gregor
a7fce599f5 [SILGen] Properly substitute contextual archetypes when generating assign_by_wrapper
Fixes SR-11303 / rdar://problem/54311335
2019-09-19 13:03:27 -07:00
Slava Pestov
d434188157 SIL: Refactor TypeConverter to not require a SILModule
This mostly requires changing various entry points to pass around a
TypeConverter instead of a SILModule. I've left behind entry points
that take a SILModule for a few methods like SILType::subst() to
avoid creating even more churn.
2019-09-06 21:50:15 -04:00
Michael Gottesman
1cc3ed0b6f [gardening] Eliminate two unused variables. 2019-08-28 10:56:59 -07:00
Michael Gottesman
6a54531811 [silgen] Add SILGen support for emitting copy_unmanaged_value instead of unmanaged_to_ref + strong_retain.
This will ensure that the optimizer never eliminates the strong_retain. This
operation is meant to be unmanaged, we should respect the user's choice here
even in optimized builds.
2019-08-26 09:40:27 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Doug Gregor
1284878ad8 [SE-0258] Rename init(initialValue:) --> init(wrappedValue:).
Addresses core team decision on acceptance of property wrappers.

Fixes rdar://problem/48871069.
2019-07-10 14:26:53 -07:00
Doug Gregor
c0bb33483d [Property wrappers] Make sure to canonicalize a type properly in DI.
Fixes a crash/assertion involving sugared types rdar://problem/51581937.
2019-06-25 08:53:44 -07:00
Doug Gregor
82ed5e9a02 [SE-0258] Implement basic support for property wrapper composition.
When multiple property wrapper attributes are provided on a declaration,
compose them outside-in to form a composite property wrapper type. For
example,

  @A @B @C var foo = 17

will produce

  var $foo = A(initialValue: B(initialValue: C(initialValue: 17)))

and foo's getter/setter will access "foo.value.value.value".
2019-06-13 18:26:29 -07:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Michael Gottesman
dccd6eb0d6 [silgen] Change ManagedValue::copyInto to have same paramter order as ManagedValue::{forward,assign}Into.
ManagedValue::{forward,assign}Into both have the signature SILGenFunction &,
SILLocation, SILValue. For some reason copyInto has SILLocation and SILValue
swapped. This commit standardizes copyInto to match the others.
2019-05-15 13:47:39 -07:00
Slava Pestov
9a1abf705a SILGen: Remove SILGenSILBuilder
This reverts commit 59cc3c1216fbb1719e5357dcef3f8b249528fc74.
2019-04-25 02:06:14 -04:00
Doug Gregor
03704fc635 [Definite initialization] Avoid performing DI via nonmutating setters.
Nonmutating setters for properties with attached delegates inside
value-semantic types cause SIL verifier errors. Avoid performing DI on
them for now.
2019-04-23 11:32:28 -07:00
Erik Eckstein
573a82ba93 SILGen: generate assign_by_delegate for property delegates 2019-04-23 11:32:28 -07:00
Slava Pestov
7fe577fddb Sema: Clean up modeling of non-member VarDecl references
Give them substitutions just like with everything else, which
eliminates some special cases from SILGen.
2019-04-14 23:28:14 -04:00
Slava Pestov
18e8feac8f SILGen: Kill OpaqueValueState and clean up code for opening existentials
OpaqueValueState used to store a SILValue, so back then the IsConsumable flag
was meaningful. But now we can just check if the ManagedValue has a cleanup
or not.

Also, we were passing around an opened ArchetypeType for no good reason.
2019-03-27 17:41:40 -04:00
Michael Gottesman
4ebd6d0bdb [ownership] Eliminate the Nominal Type RValue Peephole.
NOTE: The TranslationComponent change is tested by a bunch of tests. As an
example: guaranteed-let-peephole-reabstraction.swift.

rdar://48521061
2019-03-24 17:33:16 -07:00
Slava Pestov
8915f96e3e SIL: Replace SILType::isTrivial(SILModule) with isTrivial(SILFunction) 2019-03-12 01:16:04 -04:00
Slava Pestov
a4f560dc73 SIL: Use getLoweredRValueType() in various places 2019-03-04 20:33:19 -05:00
Slava Pestov
1944254253 SIL: Use SILFunction type lowering APIs in various places 2019-03-01 02:07:16 -05:00
Azoy
5af2663c57 Textualize assign init kind
Rename [assign] to [reassign]

fix some tests

AssignOwnershipQualifier

formatting

moar formatting
2019-02-12 20:16:25 -06:00
Arnold Schwaighofer
e4006b949d SILGen: Soften assertions it is okay for an base value of an boxed existentials not to be an address
rdar://46343977
2018-12-13 10:34:38 -08:00
Slava Pestov
06c2e980cb Merge pull request #21133 from slavapestov/lazy-implicit-inits
Lazy synthesis of implicit constructors in non-primary files
2018-12-07 22:45:40 -05:00
Slava Pestov
6c012b2aec AST: Remove some unnecessary LazyResolver * parameters from ASTContext methods 2018-12-07 20:39:27 -05:00
Slava Pestov
aa747dcd81 Remove property behaviors 2018-12-07 20:38:33 -05:00
Slava Pestov
0a8ee10621 AST: Refactor AbstractStorageDecl::getAccessStrategy() for keypath resilience
Instead of passing in a DeclContext, which we don't have when emitting a keypath
accessor, pass in a ModuleDecl and ResilienceExpansion.

Keypaths now work well enough in inlinable contexts that we can check in an
end-to-end resilience test.
2018-11-16 23:18:30 -05:00
John McCall
a4ea4d1756 Tolerate scalars when opening a non-opaque existential l-value component.
rdar://45956703
2018-11-12 15:36:56 -05:00
John McCall
44e0f44040 Merge pull request #20493 from rjmccall/keypath-compiler-abi
Change the compiler ABI of keypaths.
2018-11-10 14:18:44 -05:00
John McCall
3e5165d1ab Change the compiler ABI of keypaths.
Previously, the stdlib provided:

- getters for AnyKeyPath and PartialKeyPath, which have remained;

- a getter for KeyPath, which still exists alongside a new read
  coroutine; and

- a pair of owned mutable addressors that provided modify-like behavior
  for WritableKeyPath and ReferenceWritableKeyPath, which have been
  replaced with modify coroutines and augmented with dedicated setters.

SILGen then uses the most efficient accessor available for the access
it's been asked to do: for example, if it's been asked to produce a
borrowed r-value, it uses the read accessor.

Providing a broad spectrum of accessor functions here seems acceptable
because the code-size hit is fixed-size: we don't need to generate
extra code per storage declaration to support more alternatives for
key paths.

Note that this is just the compiler ABI; the implementation is still
basically what it was.  That means the implementation of the setters
and the read accessor is pretty far from optimal.  But we can improve
the implementation later; we can't improve the ABI.

The coroutine accessors have to be implemented in C++ and used via
hand-rolled declarations in SILGen because it's not currently possible
to declare independent coroutine accessors in Swift.
2018-11-10 02:08:04 -05:00
John McCall
731da3b991 [NFC] Improve some SILGen functions for working with begin_apply. 2018-11-10 02:08:04 -05:00
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
John McCall
c0285a744c Always use the l-value logic for emitting key path applications.
Not NFC because it also fixes an evaluation order bug (and reorders
some less-important stuff): the key-path expression needs to be
evaluated immediately during formal evaluation and cannot be delayed
until start-of-access.
2018-11-09 02:42:17 -05:00
Arnold Schwaighofer
9b889e72ea Fix a use-after-free error I introduced
rdar://45894044
2018-11-07 19:31:45 -08:00
Arnold Schwaighofer
b102c7f6b4 Parser/Sema/SILGen changes for @_dynamicReplacement(for:)
Dynamic replacements are currently written in extensions as

extension ExtendedType {
  @_dynamicReplacement(for: replacedFun())
  func replacement() { }
}

The runtime implementation allows an implementation in the future where
dynamic replacements are gather in a scope and can be dynamically
enabled and disabled.

For example:

dynamic_extension_scope CollectionOfReplacements {
  extension ExtentedType {
    func replacedFun() {}
  }

  extension ExtentedType2 {
    func replacedFun() {}
  }
}

CollectionOfReplacements.enable()
CollectionOfReplacements.disable()
2018-11-06 09:58:36 -08:00
John McCall
c1b31b4e2f Make the general path of emitRValueForStorageLoad use LValues.
Beyond just being better code, this also fixes problems where
the duplicate code didn't handle e.g. _read accessors.

I believe this finishes unblocking _read in the stdlib (rdar://45230566).
2018-11-06 01:58:59 -05:00
John McCall
71e2e8eae8 [NFC] Move some storage-access code into SILGenLValue. 2018-11-06 01:58:59 -05:00
John McCall
90ca9fe8b4 Fix a bunch of minor issues with read accessors. 2018-11-05 20:57:58 -05:00
John McCall
7da688d75a Always manage subobject projections with formal-access cleanups.
To make that work, enter appropriate scopes (ArgumentScopes and
FormalEvaluationScopes) at a bunch of places.  But note that l-value
emission generally can't enter such a scope, so in generic routines
like emitOpenExistentialExpr we have to just assert that we're
already in a scope.
2018-11-03 02:14:06 -04: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