Commit Graph

119 Commits

Author SHA1 Message Date
Mustafa Uzun
49fe1b870b fix: init_accessor_initializes_attribute_on_other_declaration error message typo 2023-08-18 14:36:57 +03:00
Nate Chandler
e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00
Doug Gregor
bf097b5bd7 [Macros] Update test case to properly use named(init). 2023-07-18 07:35:39 -07:00
Hamish Knight
9dc2d04352 [test] A couple of minor changes 2023-05-22 17:54:18 +01:00
Hamish Knight
b55f97250d [IRGen] Update coverage mapping for version 6
The coverage format version we use is automatically
set to whatever the latest version LLVM has. This
resulting in us outputting version 6 as our
format without having made the changes necessary
to reflect the new format. Update the emission
logic to take account for [the new changes in
version 6][1] (we need to include the current
working directory as the first element of the list
of files we output). Additionally, add a
`static_assert` so we don't get caught out by
version bumps in the future. Note we can't pin our
version, as it must stay in sync with the version
Clang is using.

[1]: https://llvm.org/docs/CoverageMappingFormat.html#llvm-ir-representation
2023-05-20 00:32:21 +01:00
Hamish Knight
a3848c62d5 [Profiler] Don't profile generated buffers
We may want to revisit this in the future, but for
now let's avoid profiling code in generated
buffers. To make this work we'll need to come up
with a scheme for writing out the generated buffers
such that tools like `llvm-cov` can reference them.

rdar://109562235
2023-05-20 00:32:20 +01:00
Meghana Gupta
e5eeb261d1 Fix SILInliner to create move_value in OSSA only 2023-02-26 08:47:15 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Hamish Knight
6d3545f4d5 [IRGen] Don't emit multiple copies of coverage maps
Iterating over the IRGenModules and emitting every
SILCoverageMap in the SILModule meant that we
were emitting N copies of the coverage maps for
parallel IRGen, where N is the number of output
object files.

This has always been wrong, but was previously
saved by the fact that we would drop the coverage
map on the floor if we didn't have the name data
available. This would only be the case for the
IRGenModule that had the emitted entity to
profile, in addition to any IRGenModules that
had inlined the body of a profiled enitity. As
such, this prevented the duplication from being
too egregious. However with the recent change to
emit unused name data in the case where we don't
already have name data available, we're now fully
duplicating every coverage mapping, and emitting a
ton of redundant name data.

Fix things such that we only emit coverage mapping
records for the IRGenModule that corresponds to
the entity being profiled.

rdar://102905496
2022-12-06 14:28:35 +00:00
Hamish Knight
663c0b2f82 [Profiler] Fix over-eager assert
We may have a skipped function body when walking
over a SourceFile to profile top-level code,
adjust the assertion so we ignore cases that we
don't want to profile anyway.

rdar://102405053
2022-11-16 16:05:08 +00:00
Hamish Knight
350e28b4b7 [Profiler] Rework profiling of top-level code
Instead of creating and destroying a SILProfiler
per TopLevelCodeDecl, setup a single profiler
for the top-level entry point function, and visit
all the TopLevelCodeDecls when mapping regions.
2022-10-14 17:45:14 +01:00
Hamish Knight
d0ffd29860 [test] Fix test name 2022-10-14 17:45:11 +01:00
Hamish Knight
5a8c14d583 [Profiler] Fix up a couple uses of emitProfilerIncrement
Remove a case where we know we don't have a
profiler, and avoid incrementing for a distributed
factory method. Otherwise such cases could pass
a null ASTNode, which will become an assertion
failure in a future commit.

While we're here, let's standardize on emitting
the profiler increment for function entry after
the prolog, as if there's e.g an unreachable
parameter, the increment can be safely elided
anyway.
2022-10-13 19:42:36 +01:00
Hamish Knight
bd18c37b82 [Profiler] Adopt SILDeclRef::hasUserWrittenCode
This replaces some of the existing checks, and
ensures that we don't emit coverage maps for
property wrapper backing initializers that don't
contain user code.

rdar://99931619
2022-09-29 10:08:15 +01:00
Hamish Knight
8df27a2a12 Merge pull request #61328 from hamishknight/rename-ifexpr 2022-09-28 14:46:54 +01:00
Hamish Knight
bca941b152 [AST] NFC: Rename IfExpr -> TernaryExpr
This matches what we call it in SwiftSyntax, and
is just generally clearer.
2022-09-28 10:33:31 +01:00
Hamish Knight
127eb9e008 [test] Add test case for rdar://41010883 2022-09-27 20:22:51 +01:00
Hamish Knight
fa3c951975 Merge pull request #61203 from hamishknight/pop-and-loc 2022-09-27 19:44:34 +01:00
Hamish Knight
9f93bc8dcd [Profiler] Emit increment for property wrapper backing initializers
Previously we were creating a SILProfiler for
such functions, but weren't actually emitting the
increment, leading to missed coverage.

Part of the fix for rdar://99931619
2022-09-26 12:18:44 +01:00
Hamish Knight
0431bb2d1c [IRGen] Don't emit coverage maps for synthesized Clang decls
We don't need to perform coverage mapping for any
Clang decls we've synthesized, as they have no
user-written code. This is also needed to avoid a
Clang crash when attempting to emit coverage for
decls without source locations (rdar://100172217).

rdar://82820628
2022-09-20 15:58:07 +01:00
Hamish Knight
372b7b0e33 [test] Add regression test for SR-307 2022-09-20 13:13:21 +01:00
Hamish Knight
20830cc2fb [Profiler] Avoid profiling unavailable decls
Such decls don't provide useful coverage info.

rdar://83253091
2022-09-19 10:06:36 +01:00
Hamish Knight
01c7c16c18 [IRGen] Allow lazy emission of coverage mapped functions
We previously eagerly emitted such functions to
ensure that their name data is emitted through the
profiler increment. Now that are able to emit the
profile name data separately, this is unnecessary,
and we can avoid emitting their definitions.
2022-09-16 15:47:17 +01:00
Hamish Knight
cc465937a2 [IRGen] Emit name data for unused coverage counters
Previously, if all the coverage counters for a
given SIL function were optimized out, we would
have dropped the coverage map on the floor,
leading to inaccurate coverage reports in `-O`.
However LLVM allows us to emit the name data for
the coverage maps separately by defining an
`__llvm_coverage_names` global with the name data,
which is picked up by its instrumentation lowering
pass. Use this to continue to emit coverage maps
for functions that do not get emitted.

rdar://99813754
2022-09-16 15:47:16 +01:00
Hamish Knight
1eedefe287 Merge pull request #61134 from hamishknight/comprehensive-coverage 2022-09-15 21:20:27 +01:00
Hamish Knight
c963a90754 Merge pull request #61046 from hamishknight/cant-pass-this-up 2022-09-15 17:02:13 +01:00
Hamish Knight
50367ecfa6 [Profiler] Don't walk into property initializer closures
These don't have a parent, but still shouldn't be
walked into. Be sure to check that the SILDeclRef
is for a closure.

rdar://99963912
2022-09-15 17:01:44 +01:00
Hamish Knight
b7d3f502fe [Profiler] Limit decl walking behavior
Unify the mapped behavior with the unmapped
behavior and only ever walk into a pattern binding
decls, top-level code decls, and non-nested
functions. This avoids walking into e.g nested
types, leading to duplicate coverage.

We don't need to handle the unmapped behavior
separately, as top-level code decls are always
explicit, and non-nested functions are always
checked when we create the profiler.

rdar://99963912
2022-09-15 17:01:43 +01:00
Hamish Knight
30568a60a8 [Profiler] Don't run PGO on unmapped decls
This avoids an unnecessary walk, as we don't have
any interesting profile data for such decls.
2022-09-15 17:01:42 +01:00
Hamish Knight
bf9b4b92fc [Profiler] Only map implicit getters for lazy vars
This is the only implicit getter case we care
about, the rest do not contain user-written code.
This means that we now otherwise only ever map
explicit decls, which we need to SILGen anyway. As
such I believe this should fix rdar://39332957.

We do still potentially map implicit expressions,
but should only do so for explicit property
initializers. There is one remaining bug where we
can map an implicit property wrapper backing
initalizer, which I'm tracking in rdar://99931619.
2022-09-14 20:51:52 +01:00
Hamish Knight
b582dbfa26 [Profiler] Clean up walking code a little
Use the new explicit ASTWalker actions to factor
out the skipping logic, ensuring to apply it in
post-visitation too, which fixes a PCMacro crash
(though I don't believe this is a configuration
that ever actually comes up). Also tighten up
invariants such that an `IfExpr` must appear
within an existing region.
2022-09-13 15:41:36 +01:00
Hamish Knight
00217aee23 [test] Add profiler tests for rdar://77217762
Ensure that LLVM doesn't optimize out a profiler
increment before lowering it, ensuring its name
gets recorded.
2022-09-12 12:27:36 +01:00
Anthony Latsis
3bc4c32ad8 Merge pull request #60920 from AnthonyLatsis/migrate-test-suite-to-gh-issues-17
Gardening: Migrate test suite to GH issues p. 17
2022-09-09 12:05:13 +03:00
Hamish Knight
41dd46b4f5 [test] Limit test/Profiler/rdar39146527.sil to x86_64 2022-09-08 19:03:31 +01:00
Hamish Knight
b12015c343 [SIL] Introduce the increment_profiler_counter instruction
This is a dedicated instruction for incrementing a
profiler counter, which lowers to the
`llvm.instrprof.increment` intrinsic. This
replaces the builtin instruction that was
previously used, and ensures that its arguments
are statically known. This ensures that SIL
optimization passes do not invalidate the
instruction, fixing some code coverage cases in
`-O`.

rdar://39146527
2022-09-07 17:55:13 +01:00
Anthony Latsis
f9429f9731 Gardening: Migrate test suite to GH issues: Profiler 2022-09-02 01:44:24 +03:00
Hamish Knight
27b27a400e [Profiler] Fix autoclosure property wrapper crash
We need to query the top-level expression, not
the sub-expression of a potential function
conversion.

rdar://99449154
2022-09-01 19:29:19 +01:00
Hamish Knight
7e141f4b1c [Profiler] Emit coverage for literal initializers
It's not clear why these should be excluded when
other initializers receive coverage.
2022-09-01 19:29:17 +01:00
Hamish Knight
05e2309788 [Profiler] Fix coverage mapping for switches
Previously we assumed the exit counter was the
same as the entry counter. Update the logic such
that we track break statements (including
implicitly at the end of a case), as well as
early returns and jumps to parent statements. This
follows a similar logic to what we do for if
statements.

rdar://99141044
2022-08-25 17:30:34 +01:00
Hamish Knight
caf597212c Merge pull request #60645 from hamishknight/simon-says 2022-08-19 19:58:04 +01:00
Hamish Knight
d8bab13469 [Profiler] Fix counters following DoStmts
Previously we weren't compensating for label
jumps and returns, i.e we assumed the exit count
is the same as the entry count. Ensure we follow
the same logic that other labeled statements
follow such that control flow is accounted for.

rdar://98881045
2022-08-19 15:06:11 +01:00
Hamish Knight
64fcbd9412 [Profiler] Support lazy variable initializers
Start visiting LazyInitializerExpr for profiling,
such that we emit a profile counter when
initializing the initial value for the first time.

rdar://43393937
2022-08-19 14:03:40 +01:00
Hamish Knight
df66f2777e Merge pull request #60509 from hamishknight/insurance-claim 2022-08-19 13:46:33 +01:00
Hamish Knight
d1eb6f9465 [Profiler] Avoid introducing empty unreachable regions
When computing the counter for the region
following a labeled statement such as `if`, avoid
adding a new empty region if the counter for such
a region is known to be zero, i.e unreachable.
This avoids adding spurious unreachable regions
after an if statements where each branch returns,
throws, or otherwise jumps to a parent statement.

We will however still add the region if any code
follows such a statement, making it non-empty.

rdar://29390569
2022-08-16 20:27:30 +01:00
Hamish Knight
19e1e2f7a2 [SILGen] Fix deinit coverage mapping
Stop profiling the deallocating deinitializer
function for non-ObjC classes, and instead profile
the destructor, which is where we emit the user's
code written in a `deinit`.

rdar://54443107
2022-08-11 15:09:53 +01:00
Hamish Knight
2f38f83050 [test] Rename a test 2022-08-11 15:09:53 +01:00
Joe Groff
482cc8ae24 SILGen: Emit a closure literal in a function conversion as the converted type.
Closure literals are sometimes type-checked as one type then immediately converted to another
type in the AST. One particular case of this is when a closure body never throws, but the closure
is used as an argument to a function that takes a parameter that `throws`. Emitting this naively,
by emitting the closure as its original type, then converting to throws, can be expensive for
async closures, since that takes a reabstraction thunk. Even for non-async functions, we still want
to get the benefit of reabstraction optimization for the closure literal through the conversion too.
So if the function conversion just add `throws`, emit the closure as throwing, and pass down the
context abstraction pattern when emitting the closure as well.
2022-05-04 10:24:11 -07:00
Vedant Kumar
9066d9132e Revert "[test] Fix a bug in test/Profiler/coverage_smoke.swift" (#38894)
This reverts commit ebdb4d9ace, due to
https://reviews.llvm.org/D85036 being reverted upstream.

rdar://81815347
2021-08-16 11:49:02 -07:00
Vedant Kumar
92c159ced8 Revert "[test] Fix a bug in test/Profiler/coverage_smoke.swift" (#38893)
This reverts commit 956558f23f, due to
https://reviews.llvm.org/D85036 being reverted upstream.

rdar://81815347
2021-08-16 11:46:12 -07:00
Doug Gregor
fcd5d43457 Revert "stdlib: Add reasync variants of '&&', '||' and '??'" 2021-04-05 16:45:44 -07:00