Skip to content

Commit b9487d1

Browse files
committed
Cache the value type of a generic param when cloning
1 parent 6ffaf4b commit b9487d1

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ namespace {
12771277
break;
12781278
case GenericTypeParamKind::Value:
12791279
printField((StringRef)"value", "param_kind");
1280+
printRec(decl->getValueType(), "value_type");
12801281
break;
12811282
}
12821283
printAttributes(decl);

lib/AST/GenericParamList.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/GenericParamList.h"
1818

1919
#include "swift/AST/ASTContext.h"
20+
#include "swift/AST/TypeCheckRequests.h"
2021
#include "swift/AST/TypeRepr.h"
2122
#include "swift/Basic/Assertions.h"
2223

@@ -78,6 +79,12 @@ GenericParamList::clone(DeclContext *dc) const {
7879
dc, param->getName(), GenericTypeParamDecl::InvalidDepth,
7980
param->getIndex(), param->getParamKind(), param->getOpaqueTypeRepr());
8081
newParam->setInherited(param->getInherited().getEntries());
82+
83+
// Cache the value type computed from the previous param to the new one.
84+
ctx.evaluator.cacheOutput(
85+
GenericTypeParamDeclGetValueTypeRequest{newParam},
86+
param->getValueType());
87+
8188
params.push_back(newParam);
8289
}
8390

test/SILGen/vector_literal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-emit-silgen %s -disable-availability-checking -enable-experimental-feature ValueGenerics | %FileCheck %s
22

3-
// 123REQUIRES123: swift_feature_ValueGenerics
3+
// REQUIRES: swift_feature_ValueGenerics
44

55
import Synchronization
66

test/Sema/vector.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,19 @@ func foo() {
6464
sprites = .init(bricks: bricks) // expected-error {{cannot convert value of type 'Vector<1, MySprite>' to expected argument type 'Vector<40, MySprite>'}}
6565
// expected-note@-1 {{arguments to generic parameter 'count' ('1' and '40') are expected to be equal}}
6666
}
67+
68+
// Make sure the deserialized integer generic argument gets treated as an integer
69+
// generic argument when we clone the generic param list for extensions.
70+
extension Vector where Element: ~Copyable {
71+
func forEach(_ body: (borrowing Element) -> Void) {
72+
for i in 0 ..< count {
73+
body(self[i])
74+
}
75+
}
76+
77+
func enumerated(_ body: (Int, borrowing Element) -> Void) {
78+
for i in 0 ..< count {
79+
body(i, self[i])
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)