From 0d367382065349c176ab0e5d5379f70cd88d4989 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Tue, 6 Jun 2023 23:49:29 -0400 Subject: [PATCH 1/2] Enable sil-verify-all on noimplicitcopy_consuming_parameters and noimplicitcopy_borrowing_parameters.swift. I found on 5.9 that this caught a small issue in MoveOnlyWrappedTypeLowering. I am going to fix that issue in the next commit. --- test/SILOptimizer/noimplicitcopy_borrowing_parameters.swift | 2 +- test/SILOptimizer/noimplicitcopy_consuming_parameters.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SILOptimizer/noimplicitcopy_borrowing_parameters.swift b/test/SILOptimizer/noimplicitcopy_borrowing_parameters.swift index f283399593d59..712f620f162fb 100644 --- a/test/SILOptimizer/noimplicitcopy_borrowing_parameters.swift +++ b/test/SILOptimizer/noimplicitcopy_borrowing_parameters.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-sil %s -verify +// RUN: %target-swift-frontend -emit-sil %s -verify -sil-verify-all //////////////////////// // MARK: Declarations // diff --git a/test/SILOptimizer/noimplicitcopy_consuming_parameters.swift b/test/SILOptimizer/noimplicitcopy_consuming_parameters.swift index 6668032bdae9c..e9a3f21e340db 100644 --- a/test/SILOptimizer/noimplicitcopy_consuming_parameters.swift +++ b/test/SILOptimizer/noimplicitcopy_consuming_parameters.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-sil %s -verify +// RUN: %target-swift-frontend -emit-sil %s -verify -sil-verify-all //////////////////////// // MARK: Declarations // From 9d955148d960c6c3d97cfe97bafc5d1c6c49dda0 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Tue, 6 Jun 2023 20:44:25 -0700 Subject: [PATCH 2/2] [borrowing/consuming] Be sure to visit boxes with trivial @moveonly types. This was not caught on main since I wasn't the tests with -sil-verify-all enabled... but it seems that it was caught by the verifier on 5.9. I have since enabled sil-verify-all by default on both of those tests (noimplicitcopy_consuming_parameter.swift and noimplicitcopy_borrowing_parameter.swift). rdar://110364874 --- .../Mandatory/MoveOnlyWrappedTypeEliminator.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp b/lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp index 0782d4f8592a3..92b594f1bcf63 100644 --- a/lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp +++ b/lib/SILOptimizer/Mandatory/MoveOnlyWrappedTypeEliminator.cpp @@ -279,6 +279,18 @@ struct SILMoveOnlyWrappedTypeEliminator { } // namespace +/// Returns true if this is a moveonlywrapped type whose underlying type is a +/// trivial type /or/ if this is a boxed type of that sort. +static bool isMoveOnlyWrappedTrivial(SILValue value) { + auto *fn = value->getFunction(); + SILType type = value->getType(); + if (type.removingMoveOnlyWrapper().isTrivial(fn)) + return true; + if (type.isBoxedMoveOnlyWrappedType(fn)) + return type.getSILBoxFieldType(fn).removingMoveOnlyWrapper().isTrivial(fn); + return false; +} + bool SILMoveOnlyWrappedTypeEliminator::process() { bool madeChange = true; @@ -314,7 +326,7 @@ bool SILMoveOnlyWrappedTypeEliminator::process() { continue; if (trivialOnly && - !v->getType().removingMoveOnlyWrapper().isTrivial(*fn)) + !isMoveOnlyWrappedTrivial(v)) continue; v->unsafelyEliminateMoveOnlyWrapper(fn);