From 5ed76afa814812edaeaff2ea7b3227c18d5de5a6 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 4 Aug 2020 12:29:59 +0200 Subject: pkg/compiler: check for unused resources If a resource is never used as an input, it is not useful. It's effectively the same as using an integer. Detect such cases, they are quite confusing. Fix all existing errors in descriptions. This uncovered some interesting bugs as well, e.g. use of a completely unrelated fd subtype after copy-paste (while the resource that was supposed to be used there is completely unused). --- pkg/compiler/testdata/errors2.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pkg/compiler/testdata') diff --git a/pkg/compiler/testdata/errors2.txt b/pkg/compiler/testdata/errors2.txt index fb69c8c5f..68b8a66df 100644 --- a/pkg/compiler/testdata/errors2.txt +++ b/pkg/compiler/testdata/errors2.txt @@ -11,6 +11,7 @@ resource r2[r1] ### recursive resource r2->r1->r2 resource r3[int32] ### unused resource r3 foo$0(a0 ptr[out, r0], a1 ptr[out, r1], a2 ptr[out, r2]) +foo$1(a0 r0, a1 r1, a2 r2) # Recursive structs/unions. @@ -175,9 +176,11 @@ resource r104[int8] resource r105[int8] resource r106[int8] ### resource r106 can't be created (never mentioned as a syscall return value or output argument/field) resource r107[int8] ### resource r107 can't be created (never mentioned as a syscall return value or output argument/field) +resource r108[int8] ### resource r108 is never used as an input(such resources are not useful) -foo$300(a r100) +foo$300(a0 r100, a1 r101, a2 r102, a3 r103, a4 r104) foo$301(a ptr[out, array[r103]], b ptr[in, s300], c r107) r104 +foo$302() r108 s300 { f1 ptr[inout, s301] -- cgit mrf-deployment