Commit Graph

826 Commits

Author SHA1 Message Date
Vedant Kumar
8a003a41da Coverage: fix handling of constructors and top-level decls (SR-7446) (#15966)
* [Coverage] Instrument constructor initializers (SR-7446)

We need to instrument constructor initializers, instead of the
delegating constructors which just call them.

rdar://39460313

* [Coverage] Remove dead code, NFC

* [Coverage] Use a shared profiler for constructors and member initializers

This fixes coverage reporting for member initializers and cuts down on
repeated AST traversals of pattern bindings within nominal type decls.

This allows us to remove some defensive heuristic code which dealt with
closures and if-exprs within member initializers.
2018-04-17 16:45:06 -07:00
Vedant Kumar
bb567886d8 [Coverage] Disable forced emission for unmapped decls (#15909)
Disable forced SILGen for lazy functions which are not used for code
coverage reporting.

As a drive-by, fix the forced emission logic for functions profiled for
PGO.

This helps address a compile-time issue (r://39332957).
2018-04-12 19:34:34 -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
Vedant Kumar
daa094e5e0 [Coverage] Only instrument functions which are definitions
The ASTs for functions which aren't definitions may not be fully
typechecked or well-formed, so: avoid looking at them.

This fixes at least one assertion failure seen while building a project
with coverage, and is probably good for some substantial compile-time
improvements with coverage enabled.

rdar://39069115
2018-04-05 13:33:43 -07:00
Joe Groff
8b9ffd8033 Merge pull request #15438 from jckarter/property-descriptor-irgen
IRGen: Lower property descriptors.
2018-03-23 12:51:51 -07:00
Joe Groff
ce4cda0e7a SILGen: Only emit property descriptors when -enable-keypath-resilience is passed.
This avoids the code size and build time hit until the feature is ready to turn on.
2018-03-22 14:10:44 -07:00
Mark Lacey
1dec7cc70e Remove SILGenModule::getLoweredEnumElementDecl.
This became a no-op at some point during the IUO work.
2018-03-14 23:59:26 -07:00
Slava Pestov
857f056b5f Merge pull request #15249 from slavapestov/mutating-getter-keypath-problem
Don't emit keypath descriptors for properties with mutating getters
2018-03-14 17:19:38 -07:00
Slava Pestov
1e491dce5e SILGen: Don't emit key path descriptors for properties with mutating getters
Fixes <https://bugs.swift.org/browse/SR-7176>, <rdar://problem/38439418>.
2018-03-14 16:33:08 -07:00
Joe Groff
a795b4fc0c SIL: Move responsibility for external keypath equals/hash to the caller.
A public subscript might have generic indexes that aren't unconditionally Hashable, or might use indexes that are retroactively made Hashable, so the property descriptor on the implementer's side can't always resiliently provide this information to the final instantiated KeyPath.
2018-03-14 14:05:49 -07:00
Joe Groff
a8e3c4fc8b SILGen: Emit property descriptors for (some) decls that need them.
If a property or subscript is referenceable from other modules, we need to give it a descriptor so that we can reliably build an equivalent key path in or out of that module.

There are some cases that we should handle but don't yet:

- Global and static properties ought to be key-path-able someday, so we should make descriptors for them, but this might need a new key path component kind.
- Subscripts with indexes that aren't Hashable in the current module ought to get descriptors too, in case we ever support non-hashable key path components, and also because a generic subscript might be substituted with Hashable types by an external user, or an external module might post-hoc extend a type to be Hashable, so we really need to change things so that the client supplies the hashing and equality implementations for the indexes instead of the descriptor.
2018-03-07 15:32:12 -08:00
Joe Groff
2f0a3f2e2d SILGen: Refactor key path component lowering.
Factor out the code to lower an individual key path component to be independent of overall KeyPathExpr lowering, so that we can soon reuse the same code paths to build property descriptors for resilient properties. NFC intended.
2018-02-28 15:06:44 -08:00
Graydon Hoare
76b82accbc [Stats] Simplify FrontendStatsTracer uses and formatter-definitions. 2018-02-21 14:49:24 -08:00
Mark Lacey
7f805ba2bc Replace classifyAsOptionalType with isOptionalDecl. 2018-02-05 23:59:00 -08:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Andrew Trick
2e23575f80 Fix a -debug-only=silgen crash. 2018-02-03 00:05:27 -08:00
Mark Lacey
2008674495 Make ImplicitlyUnwrappedOptional<T> an unavailable typealias.
Also remove the decl from the known decls and remove a
bunch of code referencing that decl as well as a bunch of other
random things including deserialization support.

This includes removing some specialized diagnostics code that
matched the identifier ImplicitlyUnwrappedOptional, and tweaking
diagnostics for various modes and various issues.

Fixes most of rdar://problem/37121121, among other things.
2018-02-02 08:35:53 -08:00
Graydon Hoare
5f130a8d35 [Stats] Expand FrontendStatsTracer to trace multiple entity-types. 2018-01-21 23:37:54 -08:00
Slava Pestov
48897ded11 SIL: Remove never-emitted SILDeclRef::Kind::GlobalGetter 2018-01-14 21:39:53 -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
Slava Pestov
e849ba5836 SIL: Use getConstantFunctionType() instead of getConstantType() in a few places 2018-01-10 13:58:47 -08:00
Vedant Kumar
c6bd848489 [Coverage] Assign profilers to closures without an inherited profiler
This is a step towards being able to report coverage for closures in
member initializer expressions. These closures do not inherit a
profiler, so they need a fresh one.

We currently treat initializer expressions which aren't closures as a
part of the constructor. This doesn't work for closures because the
constructor's profiler may not be available at the time the closure is
created.
2018-01-05 17:20:20 -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
1c423379c2 Merge pull request #13597 from vedantk/master
[Coverage] Refactor SIL generation for profiling
2018-01-03 12:46:22 -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
Kuba Mracek
0b7bb605cb Don't hardcode the function representation of builtin "once". Make emitLazyGlobalInitializer retrieve the convention from getBuiltinValueDecl. 2018-01-03 10:30:24 -08:00
Michael Gottesman
3d7cf92fbc [silgen] Tell prepareEpilog to emit a rethrow block instead of calling prepareRethrowEpilog.
The code inside of prepareEpilog that does this just calls prepareRethrowEpilog,
so this code is not needed.

rdar://34222540
2017-12-05 11:14:53 -08:00
Michael Gottesman
798bff756a [silgen] Rename SavedInsertionPoint => SILGenSavedInsertionPoint.
This rename makes since since:

1. This is SILGen specific functionality.
2. In the next commit I am going to be adding a SIL SavedInsertionPoint class. I
want to make sure the two can not be confused.
2017-11-08 10:40:39 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Roman Levenstein
8e9ce01852 Remove even more dead code after -sil-serialize-all is gone 2017-10-04 14:20:53 -07:00
Joe Shajrawi
f8838290a8 PGO: Fix Linux compilation issue 2017-09-26 18:52:53 -07:00
Joe Shajrawi
75939510cd PGO: Use ProfileCounter instead of Optional<uint64_t> to hold profile counts 2017-09-26 13:34:46 -07:00
Joe Shajrawi
f9e58ce851 PGO fixups: rebase on latest master 2017-09-26 11:21:26 -07:00
Joe Shajrawi
2c03144436 Add support for function_entry_count Profile counter 2017-09-26 11:10:52 -07:00
Vedant Kumar
5573313df2 [SwiftPGO] Make profile counts available to SILGenProfiler
This makes it possible to look up the execution count corresponding to
an ASTNode through SILGenFunction. The profile reader itself is stored
in a SILGenModule: this doesn't seem like the best place for it, so
suggestions for improvement are welcome!

Next, we'll actually attach this data to SIL objects and pass it all
down to IRGen.
2017-09-26 10:54:01 -07:00
Slava Pestov
92b7a33d3d SILGen: Small cleanup for default argument emission 2017-09-15 16:20:47 -07:00
Andrew Trick
1ea273444e Support printing SIL at SILGen errors. 2017-09-10 16:01:35 -07:00
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Greg Parker
0af574a7be [AST] Rename DefaultArgumentKind::Nil to NilLiteral.
This avoids a conflict with #define Nil in objc/objc.h.
2017-08-31 21:55:45 -07:00
Slava Pestov
d7821b547a SILGen: Clean up an awkward use of AbstractFunctionDecl::getImplicitSelfDecl()
NFC for now, but is required for correctness once a subsequent
patch gives 'self' a DynamicSelfType in convenience initializers.
2017-08-25 23:50:33 -07:00
Michael Gottesman
bdb032d941 [silgen] gen => SGF.
In a previous commit, I got rid of all SILGenFunction &gen. But looks like I
missed SILGenFunction gen(...). This fixes 3 such cases.
2017-08-11 09:50:36 -07:00
Roman Levenstein
2a10d8692b Clean-up the code that stored and passes the SILSerializeAll flag around.
- SILSerializeAll flag is now stored in the SILOptions and passed around as part of it
- Explicit SILSerializeAll/wholeModuleSerialized/makeModuleFragile API parameters are removed in many places
2017-06-16 17:50:33 -07:00
Slava Pestov
46bc2b160d SILGen: Remove 'overrideLocationForMagicIdentifiers' hack 2017-06-11 21:54:41 -07:00
Slava Pestov
d2b156a164 SILGen: Don't emit generator functions for caller-side default parameters
Some default parameter expressions like #file, #line, #function etc
are emitted into the caller directly by SILGen, instead of being
emitted as a call to a generator function.

In these cases, we don't need to emit the generator function at all.
2017-06-11 21:54:41 -07:00
Slava Pestov
59ed555b09 SIL: Simplify SILDeclRef constructor usages 2017-05-09 00:16:47 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Huon Wilson
b59f95418c [SIL] Extract ClassVisibility from SILFunction to SubclassScope in SILLinkage. 2017-04-13 14:17:29 -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