Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize #[coverage] attribute #130766

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clarfonthey
Copy link
Contributor

@clarfonthey clarfonthey commented Sep 23, 2024

Closes #84605, which passed FCP.

Stabilisation report here: #84605 (comment)

Also added to reference here: rust-lang/reference#1628


try-job: aarch64-apple
try-job: x86_64-gnu
try-job: x86_64-msvc

@rustbot
Copy link
Collaborator

rustbot commented Sep 23, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 23, 2024
@rustbot
Copy link
Collaborator

rustbot commented Sep 23, 2024

Some changes occurred in coverage tests.

cc @Zalathar

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@clarfonthey clarfonthey force-pushed the stable-coverage-attribute branch from dc49513 to 4b64d0d Compare September 23, 2024 23:49
@rust-log-analyzer

This comment has been minimized.

@clarfonthey clarfonthey force-pushed the stable-coverage-attribute branch from 4b64d0d to 2a11c1d Compare September 24, 2024 01:36
@rust-log-analyzer

This comment has been minimized.

@clarfonthey clarfonthey force-pushed the stable-coverage-attribute branch from 2a11c1d to 8037f0c Compare September 24, 2024 02:29
@rust-log-analyzer

This comment has been minimized.

@nnethercote
Copy link
Contributor

I will forward this to a more appropriate reviewer:

r? @Zalathar

@rustbot rustbot assigned Zalathar and unassigned nnethercote Sep 24, 2024
@clarfonthey
Copy link
Contributor Author

FWIW, I'm currently working on fixing the test errors-- my computer kept crashing which made it difficult to run all the tests. Unfortunately a lot of coverage tests are now off-by-one due to the removal of the line enabling the feature, and they're all going to have to be re-blessed.

@clarfonthey clarfonthey force-pushed the stable-coverage-attribute branch from 8037f0c to 53c467b Compare September 24, 2024 03:19
@rust-log-analyzer

This comment has been minimized.

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Sep 24, 2024

Appear to be getting very weird crashes with the debuginfo tests. From the backtrace:

Backtrace
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x000075b3eae5d463 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78
#2  0x000075b3eae04120 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x000075b3eadeb4c3 in __GI_abort () at abort.c:79
#4  0x000075b3eb0e451b in fatal_error_exit (status=-1) at Python/pylifecycle.c:2737
#5  fatal_error (fd=<optimized out>, header=header@entry=1, prefix=prefix@entry=0x75b3eb372990 <__func__.10.lto_priv.1> "PyImport_AppendInittab", msg=msg@entry=0x75b3eb2bf7c0 "PyImport_AppendInittab() may not be called after Py_Initialize()", status=status@entry=-1) at Python/pylifecycle.c:2848
#6  0x000075b3eb0e4899 in _Py_FatalErrorFunc (func=0x75b3eb372990 <__func__.10.lto_priv.1> "PyImport_AppendInittab", msg=0x75b3eb2bf7c0 "PyImport_AppendInittab() may not be called after Py_Initialize()") at Python/pylifecycle.c:2934
#7  0x000075b3eb034330 in PyImport_AppendInittab (name=<optimized out>, initfunc=<optimized out>) at Python/import.c:1499
#8  0x000075b3e9c61aa2 in InitializePythonRAII () at /usr/src/debug/lldb/lldb-18.1.8.src/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:110
#9  lldb_private::ScriptInterpreterPythonImpl::Initialize () at /usr/src/debug/lldb/lldb-18.1.8.src/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:2938
#10 0x000075b3eae608fb in __pthread_once_slow (once_control=0x75b3ea3c32a4 <lldb_private::ScriptInterpreterPython::Initialize()::g_once_flag>, init_routine=0x75b3ddc9e2e0 <std::__once_proxy()>) at pthread_once.c:116
#11 0x000075b3eae60979 in ___pthread_once (once_control=<optimized out>, init_routine=<optimized out>) at pthread_once.c:143
#12 0x000075b3e96f5180 in __gthread_once () at /usr/include/c++/14.1.1/x86_64-pc-linux-gnu/bits/gthr-default.h:713
#13 call_once<lldb_private::ScriptInterpreterPython::Initialize()::<lambda()> > () at /usr/include/c++/14.1.1/mutex:916
#14 call_once<lldb_private::ScriptInterpreterPython::Initialize()::<lambda()> > () at /usr/include/llvm/Support/Threading.h:89
#15 lldb_private::ScriptInterpreterPython::Initialize () at /usr/src/debug/lldb/lldb-18.1.8.src/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:348
#16 lldb_private::lldb_initialize_ScriptInterpreterPython () at /usr/src/debug/lldb/lldb-18.1.8.src/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:64
#17 lldb_private::SystemInitializerFull::Initialize () at /usr/src/debug/lldb/lldb-18.1.8.src/build/source/Plugins/Plugins.def:104
#18 0x000075b3e95c543e in lldb_private::SystemLifetimeManager::Initialize () at /usr/src/debug/lldb/lldb-18.1.8.src/source/Initialization/SystemLifetimeManager.cpp:36
#19 lldb::SBDebugger::InitializeWithErrorHandling () at /usr/src/debug/lldb/lldb-18.1.8.src/source/API/SBDebugger.cpp:219
#20 0x000075b3e9727ddb in lldb::SBDebugger::Initialize () at /usr/src/debug/lldb/lldb-18.1.8.src/source/API/SBDebugger.cpp:175
#21 _wrap_SBDebugger_Initialize () at /usr/src/debug/lldb/lldb-18.1.8.src/build/bindings/python/LLDBWrapPython.cpp:23282
#22 0x000075b3eb13bd1b in cfunction_vectorcall_NOARGS (func=0x75b3ea6f6750, args=<optimized out>, nargsf=<optimized out>, kwnames=0x0) at ./Include/cpython/methodobject.h:50
#23 0x000075b3eb15caed in _PyObject_VectorcallTstate (tstate=0x75b3eb5e3198 <_PyRuntime+459704>, callable=0x75b3ea6f6750, args=0x75b3eb5f1468, nargsf=9223372036854775808, kwnames=0x0) at ./Include/internal/pycore_call.h:92
#24 PyObject_Vectorcall (callable=0x75b3ea6f6750, args=0x75b3eb5f1468, nargsf=9223372036854775808, kwnames=0x0) at Objects/call.c:325
#25 0x000075b3eb141829 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/bytecodes.c:2715
#26 0x000075b3eb2064b5 in PyEval_EvalCode (co=0x5cdfa44d2040, globals=<optimized out>, locals=0x75b3ea855980) at Python/ceval.c:578
#27 0x000075b3eb222a76 in builtin_exec_impl (module=<optimized out>, source=0x5cdfa44d2040, globals=0x75b3ea855980, locals=0x75b3ea855980, closure=<optimized out>) at Python/bltinmodule.c:1096
#28 builtin_exec (module=<optimized out>, args=<optimized out>, nargs=<optimized out>, kwnames=<optimized out>) at Python/clinic/bltinmodule.c.h:586
#29 0x000075b3eb15cc3e in cfunction_vectorcall_FASTCALL_KEYWORDS (func=<optimized out>, args=0x75b3ea86e358, nargsf=<optimized out>, kwnames=0x0) at Objects/methodobject.c:438
#30 0x000075b3eb146c11 in PyCFunction_Call (callable=0x75b3ea938770, args=0x75b3ea86e340, kwargs=0x75b3ea86fec0) at Objects/call.c:387
#31 _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/bytecodes.c:3263
#32 0x000075b3eb16798b in _PyObject_VectorcallTstate (tstate=0x75b3eb5e3198 <_PyRuntime+459704>, callable=0x75b3ea93c040, args=0x7ffce28e7510, nargsf=2, kwnames=0x0) at ./Include/internal/pycore_call.h:92
#33 object_vacall (tstate=tstate@entry=0x75b3eb5e3198 <_PyRuntime+459704>, base=<optimized out>, callable=0x75b3ea93c040, vargs=0x7ffce28e75a0) at Objects/call.c:850
#34 0x000075b3eb1999eb in PyObject_CallMethodObjArgs (obj=<optimized out>, name=<optimized out>) at Objects/call.c:911
#35 0x000075b3eb198f19 in import_find_and_load (tstate=0x75b3eb5e3198 <_PyRuntime+459704>, abs_name=0x75b3ea7ac360) at Python/import.c:2779
#36 PyImport_ImportModuleLevelObject (name=0x75b3ea7ac360, globals=<optimized out>, locals=<optimized out>, fromlist=0x75b3eb56a460 <_Py_NoneStruct>, level=0) at Python/import.c:2862
#37 0x000075b3eb1494d1 in import_name (tstate=<optimized out>, frame=<optimized out>, name=0x75b3ea7ac360, fromlist=0x75b3eb56a460 <_Py_NoneStruct>, level=0x75b3eb573aa8 <_PyRuntime+3272>) at Python/ceval.c:2482
#38 _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/bytecodes.c:2144
#39 0x000075b3eb2064b5 in PyEval_EvalCode (co=0x5cdfa44ec7e0, globals=<optimized out>, locals=0x75b3ea77ef00) at Python/ceval.c:578
#40 0x000075b3eb22a84a in run_eval_code_obj (tstate=tstate@entry=0x75b3eb5e3198 <_PyRuntime+459704>, co=co@entry=0x5cdfa44ec7e0, globals=globals@entry=0x75b3ea77ef00, locals=locals@entry=0x75b3ea77ef00) at Python/pythonrun.c:1722
#41 0x000075b3eb22572f in run_mod (mod=mod@entry=0x5cdfa450e6a0, filename=filename@entry=0x75b3ea7c1590, globals=globals@entry=0x75b3ea77ef00, locals=locals@entry=0x75b3ea77ef00, flags=flags@entry=0x7ffce28e7b90, arena=arena@entry=0x75b3ea8b5fd0) at Python/pythonrun.c:1743
#42 0x000075b3eb23fd14 in pyrun_file (fp=fp@entry=0x5cdfa43ec550, filename=filename@entry=0x75b3ea7c1590, start=start@entry=257, globals=globals@entry=0x75b3ea77ef00, locals=locals@entry=0x75b3ea77ef00, closeit=closeit@entry=1, flags=0x7ffce28e7b90) at Python/pythonrun.c:1643
#43 0x000075b3eb23f5a1 in _PyRun_SimpleFileObject (fp=0x5cdfa43ec550, filename=0x75b3ea7c1590, closeit=1, flags=0x7ffce28e7b90) at Python/pythonrun.c:433
#44 0x000075b3eb23ecff in _PyRun_AnyFileObject (fp=0x5cdfa43ec550, filename=0x75b3ea7c1590, closeit=1, flags=0x7ffce28e7b90) at Python/pythonrun.c:78
#45 0x000075b3eb2374c4 in pymain_run_file_obj (program_name=0x75b3ea77f030, filename=0x75b3ea7c1590, skip_source_first_line=0) at Modules/main.c:360
#46 pymain_run_file (config=0x75b3eb585d78 <_PyRuntime+77720>) at Modules/main.c:379
#47 pymain_run_python (exitcode=0x7ffce28e7b64) at Modules/main.c:633
#48 Py_RunMain () at Modules/main.c:713
#49 0x000075b3eb1f1c2c in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:767
#50 0x000075b3eadece08 in __libc_start_call_main (main=main@entry=0x5cdf84c7e120 <main>, argc=argc@entry=4, argv=argv@entry=0x7ffce28e7df8) at ../sysdeps/nptl/libc_start_call_main.h:58
#51 0x000075b3eadececc in __libc_start_main_impl (main=0x5cdf84c7e120 <main>, argc=4, argv=0x7ffce28e7df8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffce28e7de8) at ../csu/libc-start.c:360
#52 0x00005cdf84c7e045 in _start ()

I'm just going to run ./x clean and hope that fixes it. But it looks like there might be some weird inconsistency between Rust wanting to run the version of LLVM in the repo, and the one on my machine…


Yeah, okay. It might also be a difference in Python 3.12 that broke something too, but either way, the debuginfo tests show up as failing on my machine and the coverage tests show up as passing also, so, something weird is afoot.

@traviscross
Copy link
Contributor

cc @rust-lang/lang

@jieyouxu
Copy link
Member

Yeah, okay. It might also be a difference in Python 3.12 that broke something too, but either way, the debuginfo tests show up as failing on my machine and the coverage tests show up as passing also, so, something weird is afoot.

I'm not exactly sure what debuginfo tests want, but bootstrap and other parts of compiletest AFAIK assumes Python 3.10 exactly, not 3.9 or 3.12.

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Sep 24, 2024

I'm not exactly sure what debuginfo tests want, but bootstrap and other parts of compiletest AFAIK assumes Python 3.10 exactly, not 3.9 or 3.12.

That feels worth documenting somewhere, considering how on my end that just shows up as LLVM hard-crashing and not as a wrong Python version. Like, maybe even worth having a virtualenv setup for the repo just to guarantee the right Python version is being used.

@jieyouxu
Copy link
Member

I'm not sure if that's the root cause of your crashes, but if it is, then yes

@clarfonthey
Copy link
Contributor Author

Well, I'm currently installing 3.10, so, we'll hopefully find out!

@jieyouxu
Copy link
Member

jieyouxu commented Sep 24, 2024

Actually sorry minor correction: it's not bootstrap that expects Python 3.10 (as I see there is a toolstate check that goes through 3.10+ as well), but something in compiletest (maybe debuginfo tests?) expect Python 3.10 dll to be available.

EDIT: I remembered what it is, it's lldb debuginfo tests, that requires Python 3.10 dll to be in the PATH in windows at least.

@jieyouxu
Copy link
Member

jieyouxu commented Sep 24, 2024

That feels worth documenting somewhere, considering how on my end that just shows up as LLVM hard-crashing and not as a wrong Python version. Like, maybe even worth having a virtualenv setup for the repo just to guarantee the right Python version is being used.

This is cc #125706, #126092 and #128392

@clarfonthey
Copy link
Contributor Author

You linked #128392 twice, which I assume is a mistake.

@jieyouxu
Copy link
Member

jieyouxu commented Sep 24, 2024

You linked #128392 twice, which I assume is a mistake.

I meant to link #126092 which is probably most relevant for your lldb(?) crash here, but I had both issues ending in 92 open at once and I got confused.

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Sep 24, 2024

Yeah, I'm giving up on getting the debuginfo tests working. But I'll poke around to see if I can get the other tests to replicate their issues.

I would have to downgrade my system Python version, since the tests explicitly link /usr/bin/python instead of /usr/bin/env python.

@clarfonthey
Copy link
Contributor Author

It seems that even running the test suite via docker, I can't replicate the latest errors. Running ../x test --stage 2 inside the container either passes with no issues, or gives me an error about being unable to find ld

Looks like I've stumbled my way into the realm of cursed compiler testing issues that I don't know how to fix.

Copy link
Member

@wesleywiser wesleywiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and the stabilization report @clarfonthey!

I'm satisfied with the implementation and covering tests.

r=me when rebased

@clarfonthey
Copy link
Contributor Author

Rebased, let's see if I caught everything…

@jieyouxu
Copy link
Member

@bors rollup=never (a bunch of coverage tests)
@bors p=1 (conflict-prone)

@clarfonthey
Copy link
Contributor Author

clarfonthey commented Dec 15, 2024

(I would wait for the PR runs to finish first, since last time I had a bunch of issues that weren't caught by my local testing, and I want to verify those pass before we clog up the merge queue.)

(Also, there's still those debuginfo tests that don't work without Docker because LLVM doesn't understand what compatibility means. 😠)

@clarfonthey
Copy link
Contributor Author

Seems to pass!

@jieyouxu
Copy link
Member

@bors r=@wesleywiser (I expect some coverage tests to fail)

@bors
Copy link
Contributor

bors commented Dec 15, 2024

📌 Commit 9e17904 has been approved by wesleywiser

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 15, 2024
@jieyouxu
Copy link
Member

@bors p=1 (conflict-prone)

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 16, 2024
…e, r=wesleywiser

Stabilize #[coverage] attribute

Closes rust-lang#84605, which passed FCP.

Stabilisation report here: rust-lang#84605 (comment)

Also added to reference here: rust-lang/reference#1628
@bors
Copy link
Contributor

bors commented Dec 16, 2024

⌛ Testing commit 9e17904 with merge 15c5045...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 16, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 16, 2024
@Zalathar
Copy link
Contributor

Zalathar commented Dec 16, 2024

(Unrelated to the above failure)

Optional suggestion: Instead of deleting #![feature(coverage_attribute)] from tests, consider commenting it out instead. The .coverage snapshots would still need to be re-blessed, but the .cov-map snapshots wouldn't change at all, which might make this PR less bitrotty. Then the commented-out lines could be deleted in a later PR, separate from the stabilization PR.

(Feel free to only do this if you think it would actually help.)

@clarfonthey clarfonthey force-pushed the stable-coverage-attribute branch from 9e17904 to cccbaae Compare December 16, 2024 03:13
@clarfonthey
Copy link
Contributor Author

I think I figured out the issue— one test required the profiler runtime which wasn't tested on the PR tests, but is tested in the merge tests. It should work now.

@Zalathar
Copy link
Contributor

Giving this a try job on the main targets that run coverage tests:

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 16, 2024
…e, r=<try>

Stabilize #[coverage] attribute

Closes rust-lang#84605, which passed FCP.

Stabilisation report here: rust-lang#84605 (comment)

Also added to reference here: rust-lang/reference#1628

---

try-job: aarch64-apple
try-job: x86_64-gnu
try-job: x86_64-msvc
@bors
Copy link
Contributor

bors commented Dec 16, 2024

⌛ Trying commit cccbaae with merge 95f4974...

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-apple failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Updating files:  98% (49830/50846)
Updating files:  99% (50338/50846)
Updating files: 100% (50846/50846)
Updating files: 100% (50846/50846), done.
Switched to a new branch 'try'
branch 'try' set up to track 'origin/try'.
[command]/opt/homebrew/bin/git log -1 --format=%H
95f497457279db8af0e5a8438ed676d79e18f493
##[group]Run src/ci/scripts/setup-environment.sh
src/ci/scripts/setup-environment.sh
---
file:.git/config remote.origin.url=https://github.com/rust-lang-ci/rust
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config gc.auto=0
file:.git/config http.https://github.com/.extraheader=AUTHORIZATION: basic ***
file:.git/config branch.try.remote=origin
file:.git/config branch.try.merge=refs/heads/try
file:.git/config remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
file:.git/config submodule.library/backtrace.active=true
file:.git/config submodule.library/backtrace.url=https://github.com/rust-lang/backtrace-rs.git
file:.git/config submodule.library/stdarch.active=true
---
---- [coverage-run] tests/coverage/attr/nested.rs stdout ----
Saved the actual coverage to "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/attr/nested.coverage-run/nested.coverage"
diff of coverage:

103    LL|       |    closure_expr();
104    LL|       |    closure_tail();
105    LL|       |}
106 


The actual coverage differed from the expected coverage.
The actual coverage differed from the expected coverage.

error: 1 errors occurred comparing coverage output.
status: exit status: 0
command: "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/ci-llvm/bin/llvm-cov" "show" "--format=text" "--show-line-counts-or-regions" "--Xdemangler" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage0-tools-bin/coverage-dump" "--Xdemangler" "--demangle" "--instr-profile" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/attr/nested.coverage-run/default.profdata" "--object" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/attr/nested.coverage-run/a"
--- stdout -------------------------------
    1|       |#![feature(stmt_expr_attributes)]
    2|       |//@ edition: 2021
    3|       |
    4|       |// Demonstrates the interaction between #[coverage(off)] and various kinds of
    5|       |// nested function.
    6|       |
    7|       |#[coverage(off)]
    8|       |fn do_stuff() {}
    9|       |
   10|       |#[coverage(off)]
   11|       |fn outer_fn() {
   12|       |    fn middle_fn() {
   13|       |        fn inner_fn() {
   14|       |            do_stuff();
   16|       |        do_stuff();
   17|       |    }
   18|       |    do_stuff();
   19|       |}
   19|       |}
   20|       |
   21|       |struct MyOuter;
   22|       |impl MyOuter {
   23|       |    #[coverage(off)]
   24|       |    fn outer_method(&self) {
   25|       |        struct MyMiddle;
   26|       |        impl MyMiddle {
   27|       |            fn middle_method(&self) {
   28|       |                struct MyInner;
   29|       |                impl MyInner {
   30|       |                    fn inner_method(&self) {
   31|       |                        do_stuff();
   33|       |                }
   34|       |                do_stuff();
   35|       |            }
   36|       |        }
   36|       |        }
   37|       |        do_stuff();
   38|       |    }
   39|       |}
   40|       |
   41|       |trait MyTrait {
   42|       |    fn trait_method(&self);
   43|       |}
   44|       |impl MyTrait for MyOuter {
   45|       |    #[coverage(off)]
   46|       |    fn trait_method(&self) {
   47|       |        struct MyMiddle;
   48|       |        impl MyTrait for MyMiddle {
   49|       |            fn trait_method(&self) {
   50|       |                struct MyInner;
   51|       |                impl MyTrait for MyInner {
   52|       |                    fn trait_method(&self) {
   53|       |                        do_stuff();
   55|       |                }
   56|       |                do_stuff();
   57|       |            }
   58|       |        }
   58|       |        }
   59|       |        do_stuff();
   60|       |    }
   61|       |}
   62|       |
   63|      1|fn closure_expr() {
   64|      1|    let _outer = #[coverage(off)]
   65|       |    || {
   66|       |        let _middle = || {
   67|       |            let _inner = || {
   68|       |                do_stuff();
   70|       |            do_stuff();
   71|       |        };
   72|       |        do_stuff();
   73|       |    };
   73|       |    };
   74|      1|    do_stuff();
   75|      1|}
   76|       |
   77|       |// This syntax is allowed, even without #![feature(stmt_expr_attributes)].
   78|      1|fn closure_tail() {
   79|      1|    let _outer = {
   80|       |        #[coverage(off)]
   82|       |            let _middle = {
   83|       |                || {
   84|       |                    let _inner = {
   85|       |                        || {
---
   94|       |    };
   95|      1|    do_stuff();
   96|      1|}
   97|       |
   98|       |#[coverage(off)]
   99|       |fn main() {
  100|       |    outer_fn();
  101|       |    MyOuter.outer_method();
  102|       |    MyOuter.trait_method();
  103|       |    closure_expr();
  104|       |    closure_tail();
  105|       |}
stderr: none


---- [coverage-run] tests/coverage/branch/if-let.rs stdout ----
---- [coverage-run] tests/coverage/branch/if-let.rs stdout ----
Saved the actual coverage to "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/branch/if-let.coverage-run/if-let.coverage"
diff of coverage:

68    LL|       |}
69    LL|       |
70    LL|       |// FIXME(#124118) Actually instrument if-let and let-chains for branch coverage.
71 


The actual coverage differed from the expected coverage.
The actual coverage differed from the expected coverage.

error: 1 errors occurred comparing coverage output.
status: exit status: 0
command: "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/ci-llvm/bin/llvm-cov" "show" "--format=text" "--show-line-counts-or-regions" "--Xdemangler" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage0-tools-bin/coverage-dump" "--Xdemangler" "--demangle" "--instr-profile" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/branch/if-let.coverage-run/default.profdata" "--object" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/branch/if-let.coverage-run/a" "--show-branches=count"
    1|       |#![feature(let_chains)]
    1|       |#![feature(let_chains)]
    2|       |//@ edition: 2021
    3|       |//@ compile-flags: -Zcoverage-options=branch
    4|       |//@ llvm-cov-flags: --show-branches=count
    5|       |
    6|       |macro_rules! no_merge {
    8|       |        for _ in 0..1 {}
    9|       |    };
   10|       |}
   11|       |
   11|       |
   12|      3|fn if_let(input: Option<&str>) {
   13|      3|    no_merge!();
   15|      3|    if let Some(x) = input {
                              ^2
  ------------------
  ------------------
  |  Branch (15:12): [True: 2, False: 1]
  ------------------
   16|      2|        say(x);
   17|      2|    } else {
   18|      1|        say("none");
   19|      1|    }
   20|      3|    say("done");
   21|      3|}
   22|       |
   23|     15|fn if_let_chain(a: Option<&str>, b: Option<&str>) {
   24|     15|    if let Some(x) = a
  ------------------
  ------------------
  |  Branch (24:12): [True: 12, False: 3]
  ------------------
   25|     12|        && let Some(y) = b
  ------------------
  ------------------
  |  Branch (25:16): [True: 8, False: 4]
   26|      8|    {
   26|      8|    {
   27|      8|        say(x);
   28|      8|        say(y);
   29|      8|    } else {
   30|      7|        say("not both");
   31|      7|    }
   32|     15|    say("done");
   33|     15|}
   34|       |
   35|       |#[coverage(off)]
   36|       |fn say(message: &str) {
   37|       |    core::hint::black_box(message);
   38|       |}
   39|       |
   40|       |#[coverage(off)]
   41|       |fn main() {
   42|       |    if_let(Some("x"));
   43|       |    if_let(Some("x"));
   44|       |    if_let(None);
   46|       |    for _ in 0..8 {
   46|       |    for _ in 0..8 {
   47|       |        if_let_chain(Some("a"), Some("b"));
   49|       |    for _ in 0..4 {
   49|       |    for _ in 0..4 {
   50|       |        if_let_chain(Some("a"), None);
   52|       |    for _ in 0..2 {
   52|       |    for _ in 0..2 {
   53|       |        if_let_chain(None, Some("b"));
   55|       |    if_let_chain(None, None);
   56|       |}
   57|       |
   57|       |
   58|       |// FIXME(#124118) Actually instrument if-let and let-chains for branch coverage.
stderr: none


---- [coverage-run] tests/coverage/coverage_attr_closure.rs stdout ----
---- [coverage-run] tests/coverage/coverage_attr_closure.rs stdout ----
Saved the actual coverage to "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/coverage_attr_closure.coverage-run/coverage_attr_closure.coverage"
diff of coverage:

40    LL|       |    contains_closures_on();
41    LL|       |    contains_closures_off();
42    LL|       |}
43 


The actual coverage differed from the expected coverage.
The actual coverage differed from the expected coverage.

error: 1 errors occurred comparing coverage output.
status: exit status: 0
command: "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/ci-llvm/bin/llvm-cov" "show" "--format=text" "--show-line-counts-or-regions" "--Xdemangler" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/stage0-tools-bin/coverage-dump" "--Xdemangler" "--demangle" "--instr-profile" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/coverage_attr_closure.coverage-run/default.profdata" "--object" "/Users/runner/work/rust/rust/build/aarch64-apple-darwin/test/coverage/coverage_attr_closure.coverage-run/a"
--- stdout -------------------------------
    1|       |#![feature(stmt_expr_attributes)]
    2|       |#![allow(dead_code)]
    3|       |//@ edition: 2021
    4|       |
    5|       |static GLOBAL_CLOSURE_ON: fn(&str) = #[coverage(on)]
    6|      0||input: &str| {
    7|      0|    println!("{input}");
    8|      0|};
    9|       |static GLOBAL_CLOSURE_OFF: fn(&str) = #[coverage(off)]
   10|       ||input: &str| {
   11|       |    println!("{input}");
   12|       |};
   13|       |
   14|       |#[coverage(on)]
   15|      1|fn contains_closures_on() {
   16|      1|    let _local_closure_on = #[coverage(on)]
   17|      0|    |input: &str| {
   18|      0|        println!("{input}");
   19|      0|    };
   20|      1|    let _local_closure_off = #[coverage(off)]
   21|       |    |input: &str| {
   22|       |        println!("{input}");
   24|      1|}
   25|       |
   25|       |
   26|       |#[coverage(off)]
   27|       |fn contains_closures_off() {
   28|       |    let _local_closure_on = #[coverage(on)]
   29|      0|    |input: &str| {
   30|      0|        println!("{input}");
   31|      0|    };
   32|       |    let _local_closure_off = #[coverage(off)]
   33|       |    |input: &str| {
   34|       |        println!("{input}");
   36|       |}
   37|       |
   37|       |
   38|       |#[coverage(off)]
   39|       |fn main() {
   40|       |    contains_closures_on();
   41|       |    contains_closures_off();
   42|       |}
stderr: none



@bors
Copy link
Contributor

bors commented Dec 16, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for function attribute #[coverage]