Commit Graph

412 Commits

Author SHA1 Message Date
Andrew Trick
2ccc089b27 SILGenFunction::mergeCleanupBlocks.
Avoid emitting unnecessary basic block for cleanup chains. This is a
general approach that handles all cases while simplifying SILGen
emission and keeping the CFG in a valid state during SILGen.
2018-10-19 22:22:23 -07:00
Graydon Hoare
9ce3dc4543 [Stats] Add some tracers to SILGen. 2018-09-01 00:05:58 -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
Vedant Kumar
6d467fd31f [SILProfiler] Don't crash when coverage info for lazy getters is incomplete (#18744)
ASTWalker visits a lazy_initializer_expr once within its associated
var_decl (by way of the parent nominal type). However, SILGen visits the
lazy_initializer_expr while inside of the var_decl's getter. The result
is that there is no coverage mapping information for the contents of the
lazy init within the getter's SILProfiler.

Fixing this will require reworking how profile counters are assigned to
be more in line with what SILGen needs.

As a stop-gap, this patch prevents SILGen from asserting that coverage
mappings are complete with a defensive check which prevents a crash seen
in SR-8429.

rdar://42792053
2018-08-15 17:48:21 -07:00
Michael Gottesman
f6c77f55d0 Merge pull request #18516 from gottesmm/pr-1f01768b88d904e16c4d1fd22cdbfca3fcc2cfa4
[silgen] Replace all uses of SILFunctionBuilder with SILGenFunctionBu…
2018-08-06 08:32:29 -07:00
Michael Gottesman
6511b75de0 [silgen] Replace all uses of SILFunctionBuilder with SILGenFunctionBuilder.
This initial implementation just delegates from SILGenFunctionBuilder to
SILFunctionBuilder. I was going to start transforming verbose uses of
SILFunctionBuilder into higher level APIs on SILGenFunctionBuilder, but I have
run out of time.

This is a good incremental step forward that will let me hide the constructor of
SILFunctionBuilder after I update the optimizer and thus ensure that
SILFunctionBuilder is only used through appropriate composition APIs.

rdar://42301529
2018-08-05 17:12:36 -07:00
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00
Doug Gregor
9eb9898321 Merge pull request #18364 from DougGregor/name-lookup-requests
[Name lookup] Introduce requests for several name lookup operations.
2018-07-31 13:23:38 -07:00
Doug Gregor
2860557a77 [Name lookup] Use the declaration-based lookupQualified() where it’s easy.
Switch a number of callers of the Type-based lookupQualified() over to
the newer (and preferred) declaration-based lookupQualified(). These are
the easy ones; NFC.
2018-07-31 10:14:44 -07:00
Michael Gottesman
11b24415c1 [sil-module] Create SILFunctionBuilder and hide creation/erasing functions on SILModule.
This commit does not modify those APIs or their usage. It just:

1. Moves the APIs onto SILFunctionBuilder and makes SILFunctionBuilder a friend
   of SILModule.
2. Hides the APIs on SILModule so all users need to use SILFunctionBuilder to
   create/destroy functions.

I am doing this in order to allow for adding/removing function notifications to
be enforced via the type system in the SILOptimizer. In the process of finishing
off CallerAnalysis for FSO, I discovered that we were not doing this everywhere
we need to. After considering various other options such as:

1. Verifying after all passes that the notifications were sent correctly and
   asserting. Turned out to be expensive.
2. Putting a callback in SILModule. This would add an unnecessary virtual call.

I realized that by using a builder we can:

1. Enforce that users of SILFunctionBuilder can only construct composed function
   builders by making the composed function builder's friends of
   SILFunctionBuilder (notice I did not use the word subclass, I am talking
   about a pure composition).
2. Refactor a huge amount of code in SILOpt/SILGen that involve function
   creation onto a SILGenFunctionBuilder/SILOptFunctionBuilder struct. Many of
   the SILFunction creation code in question are straight up copies of each
   other with small variations. A builder would be a great way to simplify that
   code.
3. Reduce the size of SILModule.cpp by 25% from ~30k -> ~23k making the whole
   file easier to read.

NOTE: In this commit, I do not hide the constructor of SILFunctionBuilder since
I have not created the derived builder structs yet. Once I have created those in
a subsequent commit, I will hide that constructor.

rdar://42301529
2018-07-31 10:04:03 -07:00
Joe Groff
a6fb91a5b7 SILGen: Pick UIApplicationMain by looking directly in the Clang module.
This saves us from having to do overload resolution on the overlay module, which fails if an overlay declaration exactly matches the imported signature of the original ObjC declaration. Fixes rdar://problem/42352695 harder.
2018-07-23 12:37:24 -07:00
Slava Pestov
e606aad80f SILGen: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 22:09:13 -07:00
Joe Groff
cba32f79a5 SILGen: Cope with overloads when emitting artificial main for @UIApplicationMain.
The overlay may add overloads for UIApplicationMain for various reasons. When we generate the special `main` implementation for a `@UIApplicationMain` class, we want to call the original function from Objective-C, so pick that one where there are multiple overloads to choose from. Fixes rdar://problem/42352695.
2018-07-18 15:58:11 -07: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
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Slava Pestov
ebb1198d57 AST: There's no longer any reason to pass SubstitutionMap by const reference
SubstitutionMaps are now just a trivial pointer-sized value, so
pass them by value instead.

I did have to move a couple of functors from Type.h to SubstitutionMap.h
to resolve some issues with forward declarations.
2018-05-19 00:45:36 -07:00
Doug Gregor
4b5abbddbc [SIL] Teach *ApplyInst to traffic in SubstitutionMap.
Push SubstitutionMaps through most of SILGen and the SIL optimizers
that involve the various *ApplyInsts.
2018-05-11 13:18:06 -07:00
Vedant Kumar
bdfd220968 [Coverage] Mark symtab entries as guaranteed after intrinsic lowering
SIL optimizations may rewrite profiling intrinsics in a way that IRGen
can't lower (r://39146527). Don't claim that a coverage mapping has a
guaranteed associated symbol table entry when this happens.

I have not added a test, as this is a defensive workaround until we can
land add a SIL verifier check that prevents profiling intrinsics from
being rewritten.

rdar://40133800
2018-05-10 18:51:40 -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
Slava Pestov
175b40919f AST: Fewer headers include Expr.h, Module.h, Stmt.h 2018-04-26 22:55:26 -07:00
Vedant Kumar
b36a551550 [Coverage] Avoid emitting duplicate coverage mappings (#15835)
* [Coverage] Only instrument ClosureExprs once

ClosureExprs should only be visited for profiling purposes once, when
the SILFunction definition for the closure is being emitted.

This fixes an issue where the coverage tooling can't figure out how to
attribute the code coverage data of a closure to the right function.

rdar://39200851

* [Coverage] Assert that we don't emit duplicate coverage mappings

While generating SIL for a function with a default argument, we don't
need to emit two identical coverage mappings for the function body. The
same goes for functions which reference foreign functions.

This PR introduces an assertion which should catch similar problems in
the future.

rdar://39297172

* [Coverage] Only instrument nested functions once

Coverage counters for a nested function can be assigned once (in its
parent's scope), and then again (in its own scope). Nested functions
should only be visited for coverage mapping purposes once.

This is related to r://39200851, which is the same bug but for closures.

* [Coverage] Remove special handling of autoclosures

Treating AutoClosureExprs the same as ClosureExprs allows for some nice
code simplifications, and should be more robust.

* [Coverage] Only instrument curried instance methods once

Another fix related to r://39297172, in which we avoid instrumenting the
function associated with a curried thunk more than once.
2018-04-10 15:50:36 -07:00
Michael Gottesman
8a7e652e81 [+0-normal-args] Change SILGenFunction::emitDynamicMethodRef to return a ManagedValue.
There are a bunch of methods in this area that do not use ManagedValues, but
that should. This is another step towards unwinding the hairball.

rdar://34222540
2018-02-13 13:11:11 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Slava Pestov
48897ded11 SIL: Remove never-emitted SILDeclRef::Kind::GlobalGetter 2018-01-14 21:39:53 -08:00
Mark Lacey
b77925fcba IUO: Remove creation of IUO from emitArtificialTopLevel.
It looks like this is dead code that was once useful deal with
unaudited Objective C APIs.
2018-01-14 00:49:42 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Arnold Schwaighofer
498f30bf0c Default argument generators of functions must return 'noescaping' function types
A default argument generator must not return a @noescape function type.
Returning a @noescape function is nonsense. That means the function escapes.

* Assert that we don't return @noescape function types
* Fix for throwing default arguments
* Add more test cases
* Adapt to mangling changes

Part of:
SR-5441
rdar://36116691
2018-01-08 07:53:06 -08:00
Vedant Kumar
dd560d2aa6 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-05 17:20:20 -08:00
Vedant Kumar
cccee1df03 Revert "[Coverage] Refactor SIL generation for profiling" 2018-01-03 21:57:49 -08:00
Vedant Kumar
aba9d53736 [Coverage] Refactor SIL generation for profiling
This patch moves the ownership of profiling state from SILGenProfiling
to SILFunction, where it always belonged. Similarly, it moves ownership
of the profile reader from SILGenModule to SILModule.

The refactor sets us up to fix a few outstanding code coverage bugs and
does away with sad hacks like ProfilerRAII. It also allows us to locally
guarantee that a profile counter increment actually corresponds to the
SILFunction at hand.

That local guarantee causes a bugfix to accidentally fall out of this
refactor: we now set up the profiling state for delayed functions
correctly. Previously, we would set up a ProfilerRAII for the delayed
function, but its counter increment would never be emitted :(. This fix
constitutes the only functional change in this patch -- the rest is NFC.

As a follow-up, I plan on removing some dead code in the profiling
logic and fixing a few naming inconsistencies. I've left that for later
to keep this patch simple.
2018-01-03 11:18:40 -08:00
Arnold Schwaighofer
3e04f21a41 SIL: Remove EnableGuaranteedClosureContext now that it is the default 2017-11-27 07:25:03 -08:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05: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
Slava Pestov
a85f602636 SILGen: Clean up class_method instruction construction a bit 2017-10-03 18:48:19 -07:00
Erik Eckstein
020a283bbb SIL: Let the OpenedArchetypesTracker be constructed with a null SILFunction.
NFC
2017-08-23 09:15:00 -07:00
John McCall
7f22faf968 Substantially rework how SILGen handles bridging as part of laying the
ground work for the syntactic bridging peephole.

- Pass source and dest formal types to the bridging routines in addition
  to the dest lowered type.  The dest lowered type is still necessary
  in order to handle non-standard abstraction patterns for the dest type.

- Change bridging abstraction patterns to store bridged formal types
  instead of the formal type.

- Improve how SIL type lowering deals with import-as-member patterns.

- Fix some AST bugs where inadequate information was being stored in
  various expressions.

- Introduce the idea of a converting SGFContext and use it to regularize
  the existing id-as-Any conversion peephole.

- Improve various places in SILGen to emit directly into contexts.
2017-07-11 12:45:13 -04:00
John McCall
44fda629aa Teach SILGen to handle more bridging cases and thread SGFContexts
through a few places.

This patch should be NFC for existing patterns, but it's preparing for
using SILGen's built-in bridging capabilities for more things.
2017-06-11 01:39:51 -04:00
Robert Widmann
3b26466cef Clean up some UB
* The SILBuilder could potentially reference itself during its own
initialization if a valid insertion point was left around and a
new basic block was created.  Move basic block creation after the
initializer instead.

* CSDiag was comparing canonical types for equality directly, which
leads to mixed-type comparisons if one side of the comparison is nullptr.
Use isEqual instead.
2017-06-08 16:47:48 -07:00
Slava Pestov
f7bf7accba SILGen: Add an assertion 2017-05-09 22:27:53 -07:00
Slava Pestov
775462bf52 SILGen: Don't model closure captures as an 'uncurry level' 2017-05-09 00:56:36 -07:00
Slava Pestov
edb1e97a35 SIL: Remove uncurryLevel from SILDeclRef
All we need to store is whether the SILDeclRef directly
references the declaration, or if it references a curry
thunk, and we already have an isCurried bit for that.
2017-05-09 00:56:35 -07:00
Slava Pestov
59ed555b09 SIL: Simplify SILDeclRef constructor usages 2017-05-09 00:16:47 -07:00
Slava Pestov
b5721e8d8e AST: Remove AnyObject protocol 2017-05-02 19:45:00 -07:00
Michael Gottesman
aa76c2a5e6 [silgen] (mark_uninitialized (project_box (alloc_box))) -> (project_box (mark_uninitialized (alloc_box)))
I put in a simple fixup pass (MarkUninitializedFixup) for staging purposes. I
don't expect it to be in tree long. I just did not feel comfortable fixing up in
1 commit all of the passes up to DI.

rdar://31521023
2017-04-17 17:45:54 -07:00
Slava Pestov
d58f049608 AST: Introduce ASTContext::getAnyObjectType()
This replaces a number of usages of KnownProtocolKind::AnyObject,
which is soon going away.
2017-04-13 21:17:05 -07:00
Joe Groff
0f082dea9c Merge pull request #8589 from jckarter/magic-identifier-in-initializer
SILGen: Don't override the SourceLoc for magic identifiers in stored property initializers.
2017-04-06 13:21:45 -07:00
Joe Groff
7aa8f8cc90 SILGen: Don't override the SourceLoc for magic identifiers in stored property initializers.
Refactoring stored property initializers to reuse the codegen for default argument generators caused them to accidentally inherit this additional bit of policy we don't want. Fixes SR-4325.
2017-04-06 12:03:29 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Slava Pestov
53759f7126 Use ValueDecl::isDynamic() instead of getAttrs().hasAttribute<DynamicAttr>() 2017-03-29 00:46:43 -07:00