Commit Graph

347 Commits

Author SHA1 Message Date
Suyash Srijan
3b8128ccf9 [silgen] Move diagnostic note creation to SILGenStmt 2018-11-26 21:50:31 +00:00
Suyash Srijan
4f39e3b588 [silgen] [ast] adds param name to diagnostics 2018-11-26 18:32:06 +00:00
Suyash Srijan
f2491398ea [silgen] check if the body is not null before accessing it 2018-11-19 22:58:12 +00:00
Suyash Srijan
01fa184fcb [silgen] emit a diagnostic note only if the body is not empty 2018-11-18 19:26:45 +00:00
Suyash Srijan
b7df15c30d [silgen] emit diagnostic (note) about unreachable function body 2018-11-17 01:35:59 +00:00
Suyash Srijan
54616ec089 [silgen] Removes whitespace 2018-11-16 01:34:55 +00:00
Suyash Srijan
0d02829342 [silgen] move unreachable code emission to void emitProlog() 2018-11-16 01:31:35 +00:00
Suyash Srijan
f632e0bd46 [silgen] Update prolog code to emit unreachable if a func param is uninhabited 2018-11-15 22:41:53 +00:00
Adrian Prantl
81f9ea33be SILGen: Preserve function argument debug info for arguments needing alloc_stack
This fixes a logic error in the existing code that cause these
function arguments to appear twice, once as local variable and once as
formal parameter.

rdar://problem/37410759
2018-08-31 10:35:52 -07:00
Slava Pestov
f316d46a26 SILGen: Remove support for anonymous closure arguments that bind to tuples containing InOutType
The constraint solver no longer produces such ASTs.

Also remove a comment and some other dead code referencing the
long-gone 'deshadowing' pass.
2018-08-10 18:42:06 -07:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00
Slava Pestov
e606aad80f SILGen: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 22:09:13 -07:00
John McCall
a3bdc89d47 Tell cleanups whether they're being emitted for the normal or unwind path.
NFC, but this may become semantically important for coroutines, because
an active coroutine must be aborted instead of ended on the unwind path.
2018-07-05 02:48:41 -04:00
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
Slava Pestov
195577813b SIL: Remove type lowering support for InOutType
There is still some unfortunate hackery around InOutType in
SILGenProlog.cpp, but I don't want to clean it up yet.
2018-06-13 15:38:52 -07:00
Slava Pestov
296ce3f312 AST: Remove hack-around for getInterfaceType() on ParamDecl returning InOutType
Most callers did not want the InOutType here, and checked
the ParamDecl's flags instead.
2018-06-13 15:38:52 -07:00
David Zarzycki
8c0c55539f [SIL] NFC: Rename misleading getSwiftRValueType() to getASTType()
Reference storage types are not RValues. Also, use more SILType helper
methods to avoid line wrap.
2018-05-04 08:14:38 -04:00
Michael Gottesman
8af8e4f7c7 [+0-all-args] Fix SILGenBuilder::createFunctionInputArgument(...) for in_guaranteed parameters
This method was not distinguishing in between in_guaranteed and in
parameters. This would cause the curry thunk where this is used to not copy
in_guaranteed parameters before passing in the parameter to the
partial_apply. This can not affect +1 code since the curry thunk will always
have self at +1.

I also refactored code in:

1. SILGenPoly.
2. SILGenProlog.
3. SILGenConstructor.

to use this function instead of their own reimplementations of the same thing.

This should be NFC for +1 code and is tested by test updates when +0 is enabled.

rdar://34222540
2018-03-08 16:51:38 -08:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Adrian Prantl
9b6a9946ec Be explicit about whether a DebugInfo-carying SILInstruction has debug info.
This patch both makes debug variable information it optional on
alloc_stack and alloc_box instructions, and forced variable
information on debug_value and debug_value_addr instructions. The
change of the interface uncovered a plethora of bugs in SILGen,
SILTransform, and IRGen's LoadableByAddress pass.

Most importantly this fixes the previously commented part of the
DebugInfo/local-vars.swift.gyb testcase.

rdar://problem/37720555
2018-02-21 10:50:19 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Adrian Prantl
c74ae5f375 Remove the redundant SILLocation::getCompilerGenerated interface (NFC) 2018-01-17 11:09:23 -08:00
Vedant Kumar
d60ff05265 Rename getEmptyLocation to getCompilerGeneratedLocation 2018-01-09 12:38:45 -08:00
Vedant Kumar
e33f3b663d [DebugInfo] Add a free helper to get empty locations, NFC 2018-01-08 17:59:16 -08:00
Arnold Schwaighofer
3e04f21a41 SIL: Remove EnableGuaranteedClosureContext now that it is the default 2017-11-27 07:25:03 -08:00
Slava Pestov
8f10485798 SILGen: Tighten up assertions 2017-11-19 23:58:48 -05:00
Arnold Schwaighofer
8ea33dff0c SILGen: Fix @callee_guaranteed prolog emission for captured l-values
We need to deallocate the copy we created in the temporary location.

... and properly forward cleanup after inserting a convert_function
instruction. This didn't come up before because closures where consumed
by the ultimate apply in the chain and no compensating destroy was
neccessary.

SR-5441
rdar://33255593
2017-11-11 10:39:41 -08:00
Arnold Schwaighofer
b25344b02b SILGen: Conditionally use @callee_guaranteed contexts
We need to borrow guaranteed values with sil ownership and need to
distinguish between @callee_guaranteed and other context conventions in
a few places.

SR-5441
rdar://33255593
2017-11-03 07:09:50 -07:00
Doug Gregor
a11f9c36a0 [AST] Remove ModuleDecl from TypeBase::getCanonicalType(). 2017-10-10 10:01:39 -07:00
Michael Gottesman
bd32f9eaea [silgen] Perform last gen => SGF. Now SILGen always uses SGF. 2017-08-10 22:55:42 -07:00
Robert Widmann
4babbe95e1 Push __shared into the mangling and down thru to codegen
This does not lower to @guaranteed as of yet.
2017-07-23 21:47:25 -07:00
Robert Widmann
8cdddef2f8 Refactor Params to use flags
Also, begin to pass around base types instead of raw InOutType types.  Ideally, only Sema needs to deal with them, but this means that a bunch of callers need to unwrap any inouts that might still be lying around before forming these types.

Multiple parts of the compiler were slicing, dicing, or just dropping these flags.  Because I intend to use them for the new function type representation, I need them to be preserved all across the compiler.  As a first pass, this stubs in what will eventually be structural rules as asserts and tracks down all callers of consequence to conform to the new invariants.

This is temporary.
2017-07-19 09:49:32 -07:00
Robert Widmann
1c60011755 Use 'SGF' for SILGenFunction argument consistently 2017-07-18 14:18:48 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
Slava Pestov
13330bb2c9 SILGen: Simplify curry thunks
Now that methods are the only case where we have a function
with multiple parameter lists, we can remove the logic for
forwarding captures (methods cannot have captures), and
simplify what remains to only deal with the case of a single
'self' argument being curried.
2017-03-28 19:40:09 -07:00
Slava Pestov
2dc819d1d1 AST: Introduce new form of TypeBase::getCanonicalType()
I've fixed a few bugs recently where I had to switch
a getCanonicalType() call to instead use the stronger
GenericSignature::getCanonicalTypeInContext().

Avoid the 'if (genericSig = ...)' dance by adding a new
form of TypeBase::getCanonicalType() which takes a
signature, and if it's null, just falls back to the
standard getCanonicalType().
2017-03-27 00:18:26 -07:00
Slava Pestov
35a5594035 SILGen: Fixes for *static* 'Self'-returning methods
Take a seat and pour yourself a beer because this is
going to get pretty intense.

Recall that class methods that return 'Self', have a
'self' type of @dynamic_self X or @dynamic_self X.Type,
for some class X, based on if the method is an instance
method or a static method.

The instance type of a metatype is not lowered, and we
preserve DynamicSelfType there. This is required for
correct behavior with the SIL optimizer.

For example if you specialize a function that contains a
'metatype $((T) -> Int, T).Type' SIL instruction or
some other metatype of a structural type containing a
generic parameter, we might end up with something like
'metatype $((@dynamic_self X) -> Int, X).Type'
after substitution, for some class 'X'. Note that the
second occurrence of 'X', is in "lowered position" so
the @dynamic_self did, indeed, get stripped away.

So while *values* of @dynamic_self type don't need to
carry the fact that they're @dynamic_self at the SIL
level, because Sema has inserted all the right casts.

Metatypes do though, because when lowering the 'metatype'
instruction, IRGen has to know to emit the type metadata
from the method's 'self' parameter, and not the static
metadata for the exact class type.

Essentially, 'metatype @dynamic_self X.Type' is
the same as 'value_metatype %self : X.Type', except that
the @dynamic_self type can appear inside other structural
types also, which is something we cannot write in the
AST.

This is all well and good, but when lowering a
SILFunctionType we erase @dynamic_self from the 'self'
parameter type because when you *call* such a function
from another function, you are not necessarily calling
it on your own 'self' value. And if you are, Sema
already emitted the right unchecked downcast there to
turn the result into the right type.

The problem is that the type of an argument (the value
"inside" the function) used to always be identical to
the type of the parameter (the type from "outside" the
function, in the SILFunctionType). Of course this
assumption is no longer correct for static methods,
where the 'self' argument should really have type
@dynamic_self X.Type, not X.Type.

A further complication is closure captures, whose types
can also contain @dynamic_self inside metatypes in other
structural types. We used to erase @dynamic_self from
these.

Both of these are wrong, because if you call a generic
function <T> (T.Type) -> () with a T := @dynamic_self X
substitution (recall that substitutions are written in
terms of AST types and not lowered types) and pass in
the 'self' argument, we would pass in a value of type
X.Type and not @dynamic_self X.Type.

There were similar issues with captures, with
additional complications from nested closures.

Fix all this by having SILGenProlog emit a downcast
to turn the X.Type argument into a value of type
@dynamic_self X.Type, and tweak capture lowering to
not erase @dynamic_self from capture types.

This fixes several cases that used to fail with
asserts in SILGenApply or the SIL verifier, in particular
the example outlined in <rdar://problem/31226650>,
where we would crash when calling a protocol extension
method from a static class method (oops!).

If you got this far and still follow along,
congratulations, you now know more about DynamicSelfType
than I do.
2017-03-26 22:44:35 -07:00
Joe Shajrawi
992caba90e support stores of non-loadable types under opaque mode 2017-02-15 17:19:18 -08:00
Michael Gottesman
906763f545 [silgen] Add a SILGenFunction & argument to Cleanup::dump().
This enables LValueWritebackCleanup and a future version of EndBorrowCleanup to
dump their values which have to be looked up from SILGenFunction.
2017-02-14 13:34:46 -08:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Slava Pestov
bd4f31025f AST: GenericEnvironment::mapTypeIntoContext() no longer needs to take a ModuleDecl
Now, use LookUpConformanceInSignature instead.
2017-02-07 19:25:34 -08:00
Michael Gottesman
e192b56a88 [silgen] Create CleanupManager::dump and the relevant dump methods to dump the current cleanups.
This is useful to discover when a specific cleanup is being eliminated while
debugging. The implementation is compiled out when assertions are disabled.

rdar://29791263
2017-02-05 18:38:41 -08:00
Joe Groff
a7f23f5019 SIL: Canonicalize capture types with the AST function's generic signature.
When lowering closures, we avoid capturing the enclosing generic context when possible. However, the generic context may still be necessary to canonicalize types mentioned inside the closure, such as when an associated type is referred to that is same-typed to a concrete type. Fixes rdar://problem/30254048.
2017-02-03 12:08:57 -08:00
Slava Pestov
23c327ad3d SILGen: Canonicalize indirect return type in context
This fixes an issue where a same-type constraint making an
associated type into a tuple would lead to a crash, because
of confusion about whether it should be passed as a single
value or an exploded tuple.

Fixes <rdar://problem/30199401>.
2017-01-26 17:03:34 -08:00
Andrew Trick
1abeddcc5d [SILType] SILFunctionConventions API.
Separate formal lowered types from SIL types.
The SIL type of an argument will depend on the SIL module's conventions.
The module conventions are determined by the SIL stage and LangOpts.

Almost NFC, but specialized manglings are broken incidentally as a result of
fixes to the way passes handle book-keeping of aruments. The mangler is fixed in
the subsequent commit.

Otherwise, NFC is intended, but quite possible do to rewriting the logic in many
places.
2017-01-26 15:35:48 -08:00
swift-ci
6acd2610a7 Merge pull request #6716 from gottesmm/eliminate_deallocating_convention 2017-01-10 20:02:51 -08:00
Michael Gottesman
d944930591 Remove the deallocating convention.
This is dead code and can be re-added if it is needed. Right now though there
really isnt a ValueOwnershipKind that corresponds to deallocating and I do not
want to add a new ValueOwnershipKind for dead code.
2017-01-10 17:32:17 -08:00
Slava Pestov
99903c0146 SIL: Fix type lowering and generic inlining with DynamicSelfType
If a generic parameter was substituted for Self, we have to be careful
to not erase Self.Type down to a concrete metatype.

Also, teach the devirtualizer that a metatype of Self type does not
have an exact static type.
2017-01-09 20:53:28 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00