PY-48760 Implement CFG for PEP-634 match statements

I introduced a new type of CFG instructions, similar to ConditionalInstruction,
called RefutablePatternInstruction. The idea is that every pattern that can
possibly fail to match is surrounded with a pair of such instructions, helping
to describe how the control flow moves in each case. The PEP calls the opposite
type of patterns that always match "irrefutable", hence the name. We need these
synthetic instructions because otherwise some refutable patterns such as literal
ones (e.g. "42") don't leave any nodes in the graph. Incorporating the information
about irrefutable patterns right into the graph allows catching cases such
as "wildcard/name capture makes remaining patterns unreachable", both in OR
patterns and independent case clauses.

GitOrigin-RevId: beebe1890a6a824b188e6954a2c92f7ec52079e0
This commit is contained in:
Mikhail Golubev
2021-05-07 14:59:36 +03:00
committed by intellij-monorepo-bot
parent 79999b52e4
commit cb08d4de98
96 changed files with 1203 additions and 9 deletions

View File

@@ -1,4 +1,7 @@
package com.jetbrains.python.psi;
import org.jetbrains.annotations.NotNull;
public interface PyAsPattern extends PyPattern {
@NotNull PyPattern getPattern();
}

View File

@@ -1,5 +1,9 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.psi;
import org.jetbrains.annotations.Nullable;
public interface PyCaseClause extends PyStatementPart {
@Nullable PyPattern getPattern();
@Nullable PyExpression getGuardCondition();
}

View File

@@ -326,6 +326,10 @@ public class PyElementVisitor extends PsiElementVisitor {
visitPyPattern(node);
}
public void visitWildcardPattern(@NotNull PyWildcardPattern node) {
visitPyPattern(node);
}
public void visitPyClassPattern(@NotNull PyClassPattern node) {
visitPyPattern(node);
}

View File

@@ -1,5 +1,8 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.psi;
import org.jetbrains.annotations.NotNull;
public interface PyGroupPattern extends PyPattern {
@NotNull PyPattern getPattern();
}

View File

@@ -1,5 +1,12 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.psi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public interface PyMatchStatement extends PyStatement {
@Nullable PyExpression getSubject();
@NotNull List<PyCaseClause> getCaseClauses();
}

View File

@@ -1,5 +1,10 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.psi;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface PyOrPattern extends PyPattern {
@NotNull List<PyPattern> getAlternatives();
}