Skip to content

Commit 2ca988e

Browse files
authored
Merge pull request #40584 from slavapestov/sil-lowering-gsb-workaround-5.6
SIL: Workaround for GenericSignatureBuilder bug [5.6]
2 parents 80af928 + 6e46da7 commit 2ca988e

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ namespace swift {
283283
/// Whether to dump debug info for request evaluator cycles.
284284
bool DebugDumpCycles = false;
285285

286+
/// Disable SIL substituted function types.
287+
bool DisableSubstSILFunctionTypes = false;
288+
286289
/// Whether to diagnose an ephemeral to non-ephemeral conversion as an
287290
/// error.
288291
bool DiagnoseInvalidEphemeralnessAsError = false;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ def enable_experimental_static_assert :
464464
Flag<["-"], "enable-experimental-static-assert">,
465465
HelpText<"Enable experimental #assert">;
466466

467+
def disable_subst_sil_function_types :
468+
Flag<["-"], "disable-subst-sil-function-types">,
469+
HelpText<"Disable substituted function types for SIL type lowering of function values">;
470+
467471
def enable_experimental_named_opaque_types :
468472
Flag<["-"], "enable-experimental-named-opaque-types">,
469473
HelpText<"Enable experimental support for named opaque result types">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
838838
}
839839
}
840840

841+
Opts.DisableSubstSILFunctionTypes =
842+
Args.hasArg(OPT_disable_subst_sil_function_types);
843+
841844
if (auto A = Args.getLastArg(OPT_requirement_machine_EQ)) {
842845
auto value = llvm::StringSwitch<Optional<RequirementMachineMode>>(A->getValue())
843846
.Case("off", RequirementMachineMode::Disabled)

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,8 +1649,8 @@ class SubstFunctionTypePatternVisitor
16491649
newGPMapping.insert({gp, newParamTy});
16501650
auto substGPTy = Type(gp).subst(substGPMap)->castTo<GenericTypeParamType>();
16511651
substRequirements.push_back(Requirement(RequirementKind::SameType,
1652-
substGPTy,
1653-
newParamTy));
1652+
newParamTy,
1653+
substGPTy));
16541654
assert(!substReplacementTypes[substGPTy->getIndex()]);
16551655
substReplacementTypes[substGPTy->getIndex()] = substParamTy;
16561656
}

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,9 @@ static CanSILFunctionType getSILFunctionType(
19281928
}
19291929

19301930
bool shouldBuildSubstFunctionType = [&]{
1931+
if (TC.Context.LangOpts.DisableSubstSILFunctionTypes)
1932+
return false;
1933+
19311934
// If there is no genericity in the abstraction pattern we're lowering
19321935
// against, we don't need to introduce substitutions into the lowered
19331936
// type.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
struct G<Key: CaseIterable, Value> where Key: RawRepresentable, Value: Codable {
4+
var key: Key.RawValue
5+
}
6+
7+
protocol P: CaseIterable, RawRepresentable {}
8+
9+
struct Value: Codable {}
10+
11+
enum Key: Int, P {
12+
case elt
13+
}
14+
15+
func callee<Key: P>(_: Key.Type, _: @escaping (G<Key, Value>) -> Void) {}
16+
17+
// CHECK-LABEL: sil hidden [ossa] @$s029type_lowering_subst_function_A20_requirement_machine6calleryyF : $@convention(thin) () -> () {
18+
// CHECK: function_ref @$s029type_lowering_subst_function_A20_requirement_machine6calleryyFyAA1GVyAA3KeyOAA5ValueVGcfU_ : $@convention(thin) @substituted <τ_0_0, τ_0_1, τ_0_2 where τ_0_0 : CaseIterable, τ_0_0 : RawRepresentable, τ_0_0 == τ_0_2, τ_0_1 == Value> (@in_guaranteed G<τ_0_0, Value>) -> () for <Key, Value, Key>
19+
func caller() {
20+
callee(Key.self, { _ in })
21+
}
22+

0 commit comments

Comments
 (0)