Commit Graph

768 Commits

Author SHA1 Message Date
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
John McCall
3162b513a9 Strengthen some assertions with cleanup scopes; NFC. 2018-10-25 21:50:00 -07:00
Vinicius Vendramini
b61df445ae Cleans up calls to print/dump for the AST Dumper
The `Stmt` and `Expr` classes had both `dump` and `print` methods that behaved similarly, making it unclear what each method was for. Following a conversation in https://forums.swift.org/t/unifying-printing-logic-in-astdumper/15995/6 the `dump` methods will be used to print the S-Expression-like ASTs, and the `print` methods will be used to print the more textual ASTPrinter-based representations. The `Stmt` and `Expr` classes seem to be where this distinction was more ambiguous. These changes should fix that ambiguity.

A few other classes also have `print` methods used to print straightforward representations that are neither the S-Expressions nor ASTPrinters. These were left as they are, as they don't cause the same ambiguity.

It should be noted that the ASTPrinter implementations themselves haven't yet been finished and aren't a part of these changes.
2018-10-22 16:04:02 -03:00
Joe Groff
dab6891573 SILGen: Borrow the base of accessor LValueComponents.
The same base value is necessary to invoke other accessors as part of the same access, but we would end up consuming it as part of materializing the base value for calls into nonmutating setters.
Fixes SR-8990 | rdar://problem/45274900.
2018-10-15 20:08:17 -07:00
John McCall
6f1fd82986 Optimize read accessors to just borrow yielded storage refs. 2018-10-09 15:34:54 -04:00
John McCall
aface462a5 Merge pull request #19558 from rjmccall/lvalue-improvements
Don't materialize l-value base components unnecessarily
2018-09-26 16:21:33 -04:00
John McCall
4e83a62c43 Don't always materialize a temporary for l-value base values. 2018-09-26 12:05:56 -04:00
Slava Pestov
53ff62ee40 SILGen: Simplify getBaseFormalType() 2018-09-25 23:12:46 -07:00
John McCall
e24964c035 Unify some LValue path component APIs; NFC. 2018-09-26 01:23:46 -04:00
Slava Pestov
493491b614 SILGen: Remove ArgumentSource::getSubstType()
This pushes an InOutType usage down to PreparedArguments, which still
needs to be refactored to use AnyFunctionType::Param.
2018-09-14 13:37:43 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
John McCall
1bc0a5b2fc Pass along the base value in the end_access writeback for diagnostics.
rdar://44147745
2018-09-05 17:02:29 -04:00
John McCall
dd77a2037e Pass the indices for writeback-conflict diagnostics on coroutines.
To do this, I had to introduce a way to unsafely copy an argument
list for the purposes of diagnostics.

rdar:://43802132
2018-08-31 04:20:47 -04:00
John McCall
6d4c724101 Distinguish different kinds of l-value reads in SILGen.
This is NFC for now, but I plan to build on this to (1) immediately
remove some unnecessary materialization and loads of the base value
and (2) to allow clients to load a borrowed value.
2018-08-30 19:42:53 -04:00
John McCall
41e4c454a1 Simplify getting a SILDeclRef for an accessor. 2018-08-30 19:42:53 -04: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
John McCall
7eb703bd74 Switch subscript index emission to use SILGenApply. NFC.
As always, most of the work here went into working around the AST
representations of parameter and argument lists.
2018-08-27 02:14:21 -04:00
Andrew Trick
7f902f5667 [SILGen] force immeidate LValue assignment cleanups.
In SILGenFunction::emitAssignToLValue, use an ArgumentScope instead of
a FormalEvaluationScope. This ensures that the lifetime of objects
needed to materialize each LValue component do not overlap.

For example in this tuple assignment:

public func testTupleAssign(x: inout [Int]) {
  (x[0], x[1]) = (0, 1)
}

Array.subscript.nativeOwningMutableAddressor keeps a reference to the
array across the assignment, unnecessarily forcing a copy of the
array.

Fixes SR-8621: SILGen creates destroys for tuple assignment at the
wrong places.
2018-08-24 16:39:43 -07:00