Skip to content

[+0-all] Teach silopt about normal guaranteed parameters so that it a… #13650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/sil-opt/Inputs/guaranteed-normal-args.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

open class Foo {
open func doSomething(_ f: Foo) {}
}

@_inlineable public func callFoo(f: Foo) {
f.doSomething(f)
}
17 changes: 17 additions & 0 deletions test/sil-opt/guaranteed-normal-args-negative.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/Inputs/guaranteed-normal-args.swift -o %t/TestModule.swiftmodule -emit-module -module-name TestModule
// RUN: not --crash %target-sil-opt %s -I=%t -enable-guaranteed-normal-arguments

// This is a negative test

sil_stage canonical

import TestModule

sil @callFoo : $@convention(thin) (@owned Foo) -> () {
bb0(%0 : $Foo):
%1 = class_method %0 : $Foo, #Foo.doSomething!1 : (Foo) -> (Foo) -> (), $@convention(method) (@guaranteed Foo, @owned Foo) -> ()
destroy_value %0 : $Foo
%9999 = tuple()
return %9999 : $()
}
17 changes: 17 additions & 0 deletions test/sil-opt/guaranteed-normal-args-positive.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/Inputs/guaranteed-normal-args.swift -o %t/TestModule.swiftmodule -emit-module -module-name TestModule -enable-guaranteed-normal-arguments
// RUN: %target-sil-opt %s -I=%t -enable-guaranteed-normal-arguments

// This is a positive test

sil_stage canonical

import TestModule

sil @callFoo : $@convention(thin) (@owned Foo) -> () {
bb0(%0 : $Foo):
%1 = class_method %0 : $Foo, #Foo.doSomething!1 : (Foo) -> (Foo) -> (), $@convention(method) (@guaranteed Foo, @guaranteed Foo) -> ()
destroy_value %0 : $Foo
%9999 = tuple()
return %9999 : $()
}
7 changes: 7 additions & 0 deletions tools/sil-opt/SILOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ AssumeUnqualifiedOwnershipWhenParsing(
"assume-parsing-unqualified-ownership-sil", llvm::cl::Hidden, llvm::cl::init(false),
llvm::cl::desc("Assume all parsed functions have unqualified ownership"));

static llvm::cl::opt<bool>
EnableGuaranteedNormalArguments(
"enable-guaranteed-normal-arguments", llvm::cl::Hidden, llvm::cl::init(false),
llvm::cl::desc("Assume that the input module was compiled with -enable-guaranteed-normal-arguments enabled"));

/// Regular expression corresponding to the value given in one of the
/// -pass-remarks* command line flags. Passes whose name matches this regexp
/// will emit a diagnostic.
Expand Down Expand Up @@ -315,6 +320,8 @@ int main(int argc, char **argv) {
SILOpts.EnableSILOwnership = EnableSILOwnershipOpt;
SILOpts.AssumeUnqualifiedOwnershipWhenParsing =
AssumeUnqualifiedOwnershipWhenParsing;
SILOpts.EnableGuaranteedNormalArguments =
EnableGuaranteedNormalArguments;

if (EnforceExclusivity.getNumOccurrences() != 0) {
switch (EnforceExclusivity) {
Expand Down