[TypeChecker] SE-0347: Enable type inference from default expressions

This commit is contained in:
Pavel Yaskevich
2022-04-06 15:03:00 -07:00
parent d727a79963
commit b03021dbb7
8 changed files with 6 additions and 18 deletions

View File

@@ -752,10 +752,6 @@ namespace swift {
/// closures.
bool EnableMultiStatementClosureInference = true;
/// Enable experimental support for generic parameter inference in
/// parameter positions from associated default expressions.
bool EnableTypeInferenceFromDefaultArguments = false;
/// See \ref FrontendOptions.PrintFullConvention
bool PrintFullConvention = false;
};

View File

@@ -1104,9 +1104,6 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
Opts.EnableMultiStatementClosureInference |=
Args.hasArg(OPT_experimental_multi_statement_closures);
Opts.EnableTypeInferenceFromDefaultArguments |=
Args.hasArg(OPT_experimental_type_inference_from_defaults);
Opts.PrintFullConvention |=
Args.hasArg(OPT_experimental_print_full_convention);

View File

@@ -1780,7 +1780,8 @@ static ConstraintSystem::TypeMatchResult matchCallArguments(
if (parameterBindings[paramIdx].empty() && callee) {
auto &ctx = cs.getASTContext();
if (ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments) {
// Type inference from default value expressions.
{
auto *paramList = getParameterList(callee);
if (!paramList)
continue;

View File

@@ -464,10 +464,6 @@ Type TypeChecker::typeCheckParameterDefault(Expr *&defaultValue,
return defaultValue->getType();
}
// If inference is disabled, fail.
if (!ctx.TypeCheckerOpts.EnableTypeInferenceFromDefaultArguments)
return Type();
// Caller-side defaults are always type-checked based on the concrete
// type of the argument deduced at a particular call site.
if (isa<MagicIdentifierLiteralExpr>(defaultValue))

View File

@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/InferViaDefaults.swiftmodule -enable-experimental-type-inference-from-defaults -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift
// RUN: %target-swift-frontend -enable-experimental-type-inference-from-defaults -module-name main -typecheck -verify -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/InferViaDefaults.swiftmodule -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift
// RUN: %target-swift-frontend -module-name main -typecheck -verify -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift
func testInferFromResult<T>(_: T = 42) -> T { fatalError() } // Ok

View File

@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/InferViaDefaults.swiftmodule -enable-experimental-type-inference-from-defaults -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift
// RUN: %target-build-swift -module-name main -Xfrontend -enable-experimental-type-inference-from-defaults -parse-as-library -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift -o %t/a.out
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/InferViaDefaults.swiftmodule -module-name InferViaDefaults %S/Inputs/type_inference_via_defaults_other_module.swift
// RUN: %target-build-swift -module-name main -Xfrontend -parse-as-library -I %t %s %S/Inputs/type_inference_via_defaults_other_module.swift -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s --color
// REQUIRES: OS=macosx && CPU=x86_64

View File

@@ -1,5 +1,4 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults
var t1a: (Int...) = (1)
// expected-error@-1 {{cannot create a variadic tuple}}

View File

@@ -1,5 +1,4 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -enable-experimental-type-inference-from-defaults
func takeIntToInt(_ f: (Int) -> Int) { }
func takeIntIntToInt(_ f: (Int, Int) -> Int) { }