File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
test/queries/style/DeadCode Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -2554,6 +2554,10 @@ private class LocalQArg extends AnnotationArg {
2554
2554
LocalQArg ( ) { this .getValue ( ) = "local?" }
2555
2555
}
2556
2556
2557
+ private class DiscardEntityArg extends AnnotationArg {
2558
+ DiscardEntityArg ( ) { this .getValue ( ) = "discard_entity" }
2559
+ }
2560
+
2557
2561
private class MonotonicAggregatesArg extends AnnotationArg {
2558
2562
MonotonicAggregatesArg ( ) { this .getValue ( ) = "monotonicAggregates" }
2559
2563
}
@@ -2641,6 +2645,15 @@ class OverlayLocalQ extends Annotation {
2641
2645
override string toString ( ) { result = "overlay[local?]" }
2642
2646
}
2643
2647
2648
+ /** An `overlay[discard_entity]` annotation. */
2649
+ class OverlayDiscardEntity extends Annotation {
2650
+ OverlayDiscardEntity ( ) {
2651
+ this .getName ( ) = "overlay" and this .getArgs ( 0 ) instanceof DiscardEntityArg
2652
+ }
2653
+
2654
+ override string toString ( ) { result = "overlay[discard_entity]" }
2655
+ }
2656
+
2644
2657
/** A `language[monotonicAggregates]` annotation. */
2645
2658
class MonotonicAggregates extends Annotation {
2646
2659
MonotonicAggregates ( ) { this .getArgs ( 0 ) instanceof MonotonicAggregatesArg }
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ private AstNode queryPredicate() {
39
39
result = queryPredicate ( ) .getAChild ( )
40
40
}
41
41
42
+ private AstNode discardPredicate ( ) {
43
+ result .( Predicate ) .getAnAnnotation ( ) instanceof OverlayDiscardEntity
44
+ }
45
+
42
46
AstNode hackyShouldBeTreatedAsAlive ( ) {
43
47
// Stages from the shared DataFlow impl are copy-pasted, so predicates that are dead in one stage are not dead in another.
44
48
result = any ( Module mod | mod .getName ( ) .matches ( "Stage%" ) ) .getAMember ( ) .( ClasslessPredicate ) and
@@ -58,7 +62,7 @@ AstNode hackyShouldBeTreatedAsAlive() {
58
62
*/
59
63
private AstNode alive ( ) {
60
64
//
61
- // The 4 base cases.
65
+ // The 6 base cases.
62
66
//
63
67
// 1) everything that can be imported.
64
68
result = publicApi ( )
@@ -73,7 +77,11 @@ private AstNode alive() {
73
77
// 4) Things that aren't really alive, but that this query treats as live.
74
78
result = hackyShouldBeTreatedAsAlive ( )
75
79
or
76
- result instanceof TopLevel // toplevel is always alive.
80
+ // 5) discard predicates
81
+ result = discardPredicate ( )
82
+ or
83
+ // 6) toplevel is always alive.
84
+ result instanceof TopLevel
77
85
or
78
86
// recursive cases
79
87
result = aliveStep ( alive ( ) )
Original file line number Diff line number Diff line change @@ -66,3 +66,6 @@ private class CImpl1 extends AstNode { }
66
66
final class CPublic1 = CImpl1 ;
67
67
68
68
private class CImpl2 extends AstNode { }
69
+
70
+ overlay [ discard_entity]
71
+ private predicate discard ( @foo x ) { any ( ) }
You can’t perform that action at this time.
0 commit comments