From 9b7d632160fae4d1b536248f84addcfd64b65c24 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Thu, 12 Jan 2017 23:56:47 -0800 Subject: [PATCH] [QoI] Cleanup AST after trying to shrink constraint system of invalid expression Since `ConstraintSystem::shrink` is going to attempt to type-check sub-expressions separately it's essential to clean-up AST if constraint generation or solving of the such expressions fails, otherwise if such solving resulted in creation of implicit expression type variables might leak to the outside. --- lib/Sema/CSSolver.cpp | 13 +++++++++++++ ...le-executed-at-swift-lib-ast-type-cpp-3771.swift | 3 +-- ...-swift-tupletypeelt-swift-astcontext-const.swift | 3 +-- ...le-executed-at-swift-lib-ast-type-cpp-1130.swift | 3 +-- ...le-executed-at-swift-lib-ast-type-cpp-1130.swift | 3 +-- ...-swift-tupletypeelt-swift-astcontext-const.swift | 4 +--- ...le-executed-at-swift-lib-ast-type-cpp-1337.swift | 3 +-- ...-swift-tupletypeelt-swift-astcontext-const.swift | 3 +-- .../28641-result-case-not-implemented.swift | 3 +-- .../28642-swift-optionaltype-get-swift-type.swift | 3 +-- ...m-function-ref-swift-type-swift-type-const.swift | 3 +-- .../28646-swift-lvaluetype-get-swift-type.swift | 3 +-- 12 files changed, 24 insertions(+), 23 deletions(-) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28593-unreachable-executed-at-swift-lib-ast-type-cpp-3771.swift (80%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28623-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift (81%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28631-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift (80%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28632-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift (83%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28635-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift (74%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28639-unreachable-executed-at-swift-lib-ast-type-cpp-1337.swift (80%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28640-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift (80%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28641-result-case-not-implemented.swift (82%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28642-swift-optionaltype-get-swift-type.swift (80%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28645-swift-type-transform-llvm-function-ref-swift-type-swift-type-const.swift (80%) rename validation-test/{compiler_crashers => compiler_crashers_fixed}/28646-swift-lvaluetype-get-swift-type.swift (81%) diff --git a/lib/Sema/CSSolver.cpp b/lib/Sema/CSSolver.cpp index 764caaafb6a14..9f9c36667927c 100644 --- a/lib/Sema/CSSolver.cpp +++ b/lib/Sema/CSSolver.cpp @@ -1453,6 +1453,7 @@ bool ConstraintSystem::Candidate::solve() { // because it would assign types to expressions, which // might interfere with solving higher-level expressions. ExprCleaner cleaner(E); + CleanupIllFormedExpressionRAII cleanup(TC.Context, E); // Allocate new constraint system for sub-expression. ConstraintSystem cs(TC, DC, None); @@ -1495,6 +1496,18 @@ bool ConstraintSystem::Candidate::solve() { // Record found solutions as suggestions. this->applySolutions(solutions); + + // Solution application is going to modify AST, so we need to avoid + // clean-up, but let's double-check if we have any implicit + // expressions with type variables and nullify their types. + cleanup.disable(); + E->forEachChildExpr([&](Expr *childExpr) -> Expr * { + Type type = childExpr->getType(); + if (childExpr->isImplicit() && type && type->hasTypeVariable()) + childExpr->setType(Type()); + return childExpr; + }); + return false; } diff --git a/validation-test/compiler_crashers/28593-unreachable-executed-at-swift-lib-ast-type-cpp-3771.swift b/validation-test/compiler_crashers_fixed/28593-unreachable-executed-at-swift-lib-ast-type-cpp-3771.swift similarity index 80% rename from validation-test/compiler_crashers/28593-unreachable-executed-at-swift-lib-ast-type-cpp-3771.swift rename to validation-test/compiler_crashers_fixed/28593-unreachable-executed-at-swift-lib-ast-type-cpp-3771.swift index 2d7b5b3a5765d..06a785dc0b637 100644 --- a/validation-test/compiler_crashers/28593-unreachable-executed-at-swift-lib-ast-type-cpp-3771.swift +++ b/validation-test/compiler_crashers_fixed/28593-unreachable-executed-at-swift-lib-ast-type-cpp-3771.swift @@ -5,6 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir [{_=#keyPath(t>w diff --git a/validation-test/compiler_crashers/28623-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift b/validation-test/compiler_crashers_fixed/28623-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift similarity index 81% rename from validation-test/compiler_crashers/28623-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift rename to validation-test/compiler_crashers_fixed/28623-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift index e3ec7a3ebaa14..2c333c7a2d636 100644 --- a/validation-test/compiler_crashers/28623-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift +++ b/validation-test/compiler_crashers_fixed/28623-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift @@ -5,6 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir f#keyPath(n&_==a>c{{{{{{{{{{{{{{{{{_=b:{{{{c{{{{{{d diff --git a/validation-test/compiler_crashers/28631-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift b/validation-test/compiler_crashers_fixed/28631-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift similarity index 80% rename from validation-test/compiler_crashers/28631-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift rename to validation-test/compiler_crashers_fixed/28631-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift index ae32b2f9ea681..ec248a45d86b9 100644 --- a/validation-test/compiler_crashers/28631-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift +++ b/validation-test/compiler_crashers_fixed/28631-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift @@ -5,6 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir [{{{{{{{{{{{{{{0=#keyPath(n&_=d diff --git a/validation-test/compiler_crashers/28632-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift b/validation-test/compiler_crashers_fixed/28632-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift similarity index 83% rename from validation-test/compiler_crashers/28632-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift rename to validation-test/compiler_crashers_fixed/28632-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift index c22489c5ad611..7cf03a0912d30 100644 --- a/validation-test/compiler_crashers/28632-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift +++ b/validation-test/compiler_crashers_fixed/28632-unreachable-executed-at-swift-lib-ast-type-cpp-1130.swift @@ -5,9 +5,8 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior // REQUIRES: asserts -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir {func a> print(a==#keyPath(a{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ diff --git a/validation-test/compiler_crashers/28635-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift b/validation-test/compiler_crashers_fixed/28635-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift similarity index 74% rename from validation-test/compiler_crashers/28635-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift rename to validation-test/compiler_crashers_fixed/28635-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift index 82f3bc015f01a..e0aaea40dbae9 100644 --- a/validation-test/compiler_crashers/28635-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift +++ b/validation-test/compiler_crashers_fixed/28635-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift @@ -5,7 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir func a|Set(#keyPath(t>a>a{ diff --git a/validation-test/compiler_crashers/28639-unreachable-executed-at-swift-lib-ast-type-cpp-1337.swift b/validation-test/compiler_crashers_fixed/28639-unreachable-executed-at-swift-lib-ast-type-cpp-1337.swift similarity index 80% rename from validation-test/compiler_crashers/28639-unreachable-executed-at-swift-lib-ast-type-cpp-1337.swift rename to validation-test/compiler_crashers_fixed/28639-unreachable-executed-at-swift-lib-ast-type-cpp-1337.swift index 70b9a429a48cb..849688ae16ba6 100644 --- a/validation-test/compiler_crashers/28639-unreachable-executed-at-swift-lib-ast-type-cpp-1337.swift +++ b/validation-test/compiler_crashers_fixed/28639-unreachable-executed-at-swift-lib-ast-type-cpp-1337.swift @@ -5,6 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir print([{#keyPath(a}(t>A diff --git a/validation-test/compiler_crashers/28640-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift b/validation-test/compiler_crashers_fixed/28640-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift similarity index 80% rename from validation-test/compiler_crashers/28640-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift rename to validation-test/compiler_crashers_fixed/28640-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift index 40f87f57fa236..acaf2bc933c75 100644 --- a/validation-test/compiler_crashers/28640-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift +++ b/validation-test/compiler_crashers_fixed/28640-swift-tupletype-get-llvm-arrayref-swift-tupletypeelt-swift-astcontext-const.swift @@ -5,6 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir protocol a func a|Set(#keyPath(t>a{ diff --git a/validation-test/compiler_crashers/28641-result-case-not-implemented.swift b/validation-test/compiler_crashers_fixed/28641-result-case-not-implemented.swift similarity index 82% rename from validation-test/compiler_crashers/28641-result-case-not-implemented.swift rename to validation-test/compiler_crashers_fixed/28641-result-case-not-implemented.swift index ef6976bfe3c51..d3370b0ab9172 100644 --- a/validation-test/compiler_crashers/28641-result-case-not-implemented.swift +++ b/validation-test/compiler_crashers_fixed/28641-result-case-not-implemented.swift @@ -5,7 +5,6 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior // REQUIRES: asserts -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir {let β=b&[{{{#keyPath(n&[{{{{{{{{{{{{{{{{{{{{{{{{{{a{{{{s diff --git a/validation-test/compiler_crashers/28642-swift-optionaltype-get-swift-type.swift b/validation-test/compiler_crashers_fixed/28642-swift-optionaltype-get-swift-type.swift similarity index 80% rename from validation-test/compiler_crashers/28642-swift-optionaltype-get-swift-type.swift rename to validation-test/compiler_crashers_fixed/28642-swift-optionaltype-get-swift-type.swift index 9fe9ea6a92851..c2e862abfb3e4 100644 --- a/validation-test/compiler_crashers/28642-swift-optionaltype-get-swift-type.swift +++ b/validation-test/compiler_crashers_fixed/28642-swift-optionaltype-get-swift-type.swift @@ -5,6 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir Array(_==#keyPath(t>Void! diff --git a/validation-test/compiler_crashers/28645-swift-type-transform-llvm-function-ref-swift-type-swift-type-const.swift b/validation-test/compiler_crashers_fixed/28645-swift-type-transform-llvm-function-ref-swift-type-swift-type-const.swift similarity index 80% rename from validation-test/compiler_crashers/28645-swift-type-transform-llvm-function-ref-swift-type-swift-type-const.swift rename to validation-test/compiler_crashers_fixed/28645-swift-type-transform-llvm-function-ref-swift-type-swift-type-const.swift index f797ed802dbb5..26986fc8bd929 100644 --- a/validation-test/compiler_crashers/28645-swift-type-transform-llvm-function-ref-swift-type-swift-type-const.swift +++ b/validation-test/compiler_crashers_fixed/28645-swift-type-transform-llvm-function-ref-swift-type-swift-type-const.swift @@ -5,6 +5,5 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir (.n).h.n&[(#keyPath(t>A diff --git a/validation-test/compiler_crashers/28646-swift-lvaluetype-get-swift-type.swift b/validation-test/compiler_crashers_fixed/28646-swift-lvaluetype-get-swift-type.swift similarity index 81% rename from validation-test/compiler_crashers/28646-swift-lvaluetype-get-swift-type.swift rename to validation-test/compiler_crashers_fixed/28646-swift-lvaluetype-get-swift-type.swift index 569bfa8082f85..772fd2340a16a 100644 --- a/validation-test/compiler_crashers/28646-swift-lvaluetype-get-swift-type.swift +++ b/validation-test/compiler_crashers_fixed/28646-swift-lvaluetype-get-swift-type.swift @@ -5,8 +5,7 @@ // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// REQUIRES: deterministic-behavior -// RUN: not --crash %target-swift-frontend %s -emit-ir +// RUN: not %target-swift-frontend %s -emit-ir #keyPath(a print(Int print(_=#keyPath(a