Commit Graph

1246 Commits

Author SHA1 Message Date
Slava Pestov
c7338d06ca AST: Remove owning addressors 2018-11-09 20:49:44 -05:00
Slava Pestov
564695d9bf AST: Remove DeclContext::isExtensionContext()
It's identical in every way to isa<ExtensionDecl>(), so
make code less confusing by only having one way of doing
that check.
2018-11-07 17:34:56 -05: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
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
Michael Gottesman
489910e483 [silgen] Only borrow args for coroutines rather than general applies and do not conditionalize based off of the ownership flag being set.
This is the last part of SILGen conditionalized on EnableSILOwnership being
set. It also (as you can tell from the diff) eliminates a bunch of code from the
tests.

rdar://29791263
2018-10-24 13:54:58 -07:00
Slava Pestov
73f1990bc2 AST: Use getSelfInterfaceType() instead of getProtocolSelfType() where possible
The former appears in the code base a lot more frequently than the
latter, which returns a GenericTypeParamType *. Use it only in places
where the more specific type is intended.
2018-10-15 20:34:08 -07:00
John McCall
77db3e692e Add ArgumentSource::findStorageReferenceExprForBorrow().
Per Slava's review on #19790.
2018-10-10 00:18:52 -04:00
John McCall
6f1fd82986 Optimize read accessors to just borrow yielded storage refs. 2018-10-09 15:34:54 -04:00
Slava Pestov
ebe769a58c SIL: Stop imploding parameter list into a single value with opaque abstraction pattern
The constraint solver support for the Swift 3 function type behavior
has been removed, so it's no longer possible to pun the same value as
both a function taking multiple parameters and a function taking a
single tuple argument.

This means the entire parameter list is no longer a target for
substitution as a single value, so the most general form of a function
value passes each parameter indirectly instead of passing a single
tuple parameter indirectly.
2018-09-26 23:20:54 -07:00
Michael Gottesman
d57a88af0d [gardening] Rename references to SILPHIArgument => SILPhiArgument. 2018-09-25 22:23:34 -07:00
Slava Pestov
8063cbb31d SILGen: Wean SILGenApply off AbstractionPattern::getFunctionInputType()
This requires some hacks. It will get better once we're no longer building
"scalar" PreparedArguments, since ArgEmitter::emitTopLevel() will then go
away. But lets do this one step at a time.
2018-09-24 22:59:07 -07:00
Slava Pestov
c1b7f6ddf6 SILGen: Remove most uses of 'scalar' PreparedArguments
The two that remain are in emitApplyAllocatingInitializer() (which
is annoying but trivial), and the big one, which is the
ArgEmitter(ApplyExpr *) constructor.
2018-09-24 22:59:07 -07:00
Jason Mittertreiner
8ac9a657a8 Fix 'operator ==' is ambiguous with MSVC (#19501)
When compiling with MSVC on Windows, this error among other similar
conflicts with AnyValue occur:

Defined the overloads so it selects the correct one.
2018-09-24 12:39:44 -07:00
Slava Pestov
817555254c SILGen: Change PreparedArguments to use an array of AnyFunctionType::Param
This solves a recently-added TODO, eliminating two usages of
FunctionType::getInput() from SILGen.
2018-09-15 21:19:59 -07:00
Slava Pestov
3527e54bbd SILGen: Move usages of AbstractionPattern::getFunctionInputType() closer to their uses 2018-09-15 21:19:56 -07:00
Slava Pestov
82ecbde678 SILGen: Remove ArgumentSource::Kind::Tuple 2018-09-15 21:06:03 -07:00
Slava Pestov
1913b55732 SILGen: Rename ArgumentSource::requiresCalleeToEvaluate() to ArgumentSource::isShuffle()
Also, move the check to make it explicit that only a TupleShuffleExpr
at the top level goes through the argument emission code path; a
TupleShuffleExpr appearing inside a ParenExpr or TupleExpr is a
tuple conversion, which is totally unrelated and emitted as an RValue.

This is unfortunate and we should split off ArgumentShuffleExpr from
TupleShuffleExpr, and eventually, fold ArgumentShuffleExpr into
ApplyExpr.
2018-09-15 21:06:03 -07:00
Slava Pestov
8e4bde8b97 SILGen: Remove dead code from Swift 3 removal 2018-09-15 21:06:03 -07: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
Slava Pestov
2100e23c7a SILGen: Remove InOutType usages from ArgEmitter 2018-09-14 13:37:43 -07:00
Saleem Abdulrasool
4baa775726 Merge pull request #19297 from compnerd/unreachable
litter the tree with `llvm_unreachable`
2018-09-14 09:04:56 -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
Joe Groff
8665342877 Merge pull request #19151 from jckarter/allocating-convenience-initializers
Dispatch initializers by their allocating entry point
2018-09-13 15:17:34 -07:00
Joe Groff
77a0923ca6 SILGen: Emit convenience initializers as allocating entry points.
And only dispatch designated inits by their allocating entry points. rdar://problem/29634243
2018-09-13 12:31:23 -07:00
swift-ci
cc329fee03 Merge pull request #19141 from aschwaighofer/remove_constant_string_literal 2018-09-10 15:51:47 -07:00
Doug Gregor
2246e2bf60 [SILGen] Cope with protocol requirement overrides for keypaths.
When emitting accessor calls for keypaths, make sure that we reference
protocol requirements that introduce witness table entries. Other
protocol requirements don't have the necessary dispatch thunks,
resulting in linker errors.

Fixes rdar://problem/44187969.
2018-09-09 20:13:54 -07:00
swift-ci
59efeed943 Merge pull request #19062 from rudkx/rdar19785368 2018-09-06 10:32:23 -07:00
Doug Gregor
0cdede2bdf [SIL] Make witness_methods always refer to a non-overriding requirement.
When forming a witness_method instruction, follow the override chain of
a protocol requirement to reach a requirement that doesn’t override any
other protocol requirement. These will be the requirements that introduce
new witness table entries.
2018-09-05 13:51:26 -07:00
Arnold Schwaighofer
73df12c09f Remove dead constant_string_literal
constant_string_literal was added to support a one word representation
of String that never materialized.
2018-09-05 12:13:57 -07: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
Mark Lacey
90139d7685 [SILGen] Make #function printing more consistent.
Print parens and "_:" in cases where a function has no named
parameters.

We already print the parens in cases with no parameters, and the "_:"
for unnamed parameters in cases where there are already named
parameters.

Fixes: rdar://problem/19785368
2018-08-29 18:27:55 -07:00
Joe Groff
15e4094544 Merge pull request #18937 from jckarter/mutating-opened-existential-covariant-return
SILGen: Fix order of operations when a mutating existential method returns Self.
2018-08-28 18:21:45 -07:00
Joe Groff
7f14a3bf48 SILGen: Fix order of operations when invoking a mutating method on an existential that returns Self.
Delay allocating the result buffer for an opened Self return until right before it's needed. When a mutating method is invoked on an existential, the Self type won't be opened until late, when the formal access to the mutable value begins. Fixes rdar://problem/43507711.
2018-08-28 09:52:04 -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
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
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
Erik Eckstein
6ba45473df Remove the pinning addressors
It was used for Array + related types.
With exclusivity checking the pinned addressors are not useful anymore.

rdar://problem/35401528
2018-08-23 12:47:56 -07:00
John McCall
a30d91e3cb Implement vararg expansion well enough to support argument forwarding.
I needed this for materializeForSet remission, but it makes inherited
variadic initializers work, too.

I tried to make this a reasonable starting point for a real language
feature.  Here's what's still missing:

- syntax
- semantic restrictions to ensure that the expression isn't written in
  invalid places or arbitrarily converted
- SILGen support for expansions that aren't the only variadic argument

rdar://16331406
2018-08-22 06:46:08 -04:00
Michael Gottesman
3f13aa2f0b [silgen] Change SILGenApply to use destructure, eliminating copies at -Onone, and simplifying code.
rdar://43493020
2018-08-20 20:53:51 -07:00
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Slava Pestov
a54251074c AST: ExtInfo just wraps an unsigned integer, no need to pass it by reference 2018-08-17 19:27:43 -04:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
John McCall
af1fbee3de Thread ForUnwind_t into emitCleanupsForReturn.
Some "return" edges are for unwinding due to errors and some aren't.
They'll need to be distinguished if we ever want to support throwing
cleanups.
2018-08-16 02:27:54 -04:00
Slava Pestov
bf094b60f0 SIL: Fix some corner cases with tuple type lowering
1) It's possible to materialize a tuple value with an @escaping or
@autoclosure element in it.

I don't think this causes any bad behavior in 4.2 because these
flags have no semantic effect after the type checker, but now
I'm adding an assertion that will fire when such types are
serialized, so let's make sure it doesn't happen by explicitly
clearing out these flags when lowering tuples types.

2) It's also possible to materialize a tuple with a single vararg
element. Again, this was not a problem in 4.2, but with the above
change to start clearing tuple flags, we now end up in a
situation where the lowered type is not a tuple, because
TupleType::get() returns a ParenType if the tuple has one
element that is not vararg (which it no longer is, because we
just cleared all the flags).

Fix the second problem by treating one-element vararg tuples just
like tuples with inout, __shared and __owned elements, that is,
by always exploding them when they appear at the top level of a
function parameter list, ensuring we never try to materialize
a value whose type is the entire tuple type.

These problems all stem from the fact that lowering a function type
with the opaque abstraction pattern treats the top level argument
list as a single tuple argument. Once that is fixed, much of the
above will simplify down to assertions.
2018-08-12 01:09:46 -07:00
Slava Pestov
80a7ae100b SIL: Treat __shared and __owned just like inout when lowering function types
Even with an opaque abstraction pattern, we must explode a
parameter list containing __shared and __owned elements.

Otherwise, we produce invalid lowered SIL types.

Note that this is already an issue, because the stdlib has a
handful of declarations using __owned.
2018-08-12 01:09:45 -07:00
swift-ci
1623f42447 Merge pull request #18292 from mhong/master_bytes_string 2018-08-06 09:05:58 -07:00
Robert Widmann
917e94d11c Introduce SourceManager::getDisplayNameForLoc
Add an abstraction to retrieve a name suitable for display for a given
source location for use with diagnostics, debug locations, and magic
file literals.
2018-07-31 13:16:14 -07:00
Mingsheng Hong
ba38bcb279 Introduce a new 'bytes' form of the string_literal SIL instruction. Have it
print and parse as a stable hexadecimal form that isn't interpreted as UTF8.

One use case is in representing serialized protobuf strings (as in the
tensorflow branch: f7ed452eba/lib/SILOptimizer/Mandatory/TFPartition.cpp (L3875)).

The original work was done by @lattner and merged into the tensorflow
branch. This PR is to upstream those changes.
2018-07-27 11:58:00 -07:00
John McCall
1eaf4768a6 Fix a dangling reference by just copying it.
...this isn't even an expensive type to copy, I have no idea why I
made ArgEmitter try to hold it by reference.
2018-07-24 02:59:12 -04:00