* [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.
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).
* [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.
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
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.
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.
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.
* 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
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.
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.
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.
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.
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.
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.
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.
- 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
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.
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.
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.