Skip to content

Commit d04d8c1

Browse files
authored
Merge pull request #68001 from Azoy/raw-deserialize
[Sema] Fix raw layout deserialization
2 parents aec59f2 + dadbbb4 commit d04d8c1

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,6 +3369,13 @@ ResolveRawLayoutLikeTypeRequest::evaluate(Evaluator &evaluator,
33693369
StructDecl *sd,
33703370
RawLayoutAttr *attr) const {
33713371
assert(attr->LikeType);
3372+
3373+
// If the attribute has a fixed type representation, then it was likely
3374+
// deserialized and the type has already been computed.
3375+
if (auto fixedTy = dyn_cast<FixedTypeRepr>(attr->LikeType)) {
3376+
return fixedTy->getType();
3377+
}
3378+
33723379
// Resolve the like type in the struct's context.
33733380
return TypeResolution::resolveContextualType(
33743381
attr->LikeType, sd, llvm::None,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public protocol Foo {}
2+
extension Bool: Foo {}
3+
4+
@_rawLayout(like: T)
5+
public struct Fred<T: Foo>: ~Copyable {
6+
public init() {}
7+
}

test/Serialization/raw_layout.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -enable-experimental-feature RawLayout -module-name raw_layout_fred -o %t %S/Inputs/raw_layout.swift
3+
// RUN: %target-swift-frontend -I %t -emit-ir %s -verify | %FileCheck %s
4+
5+
import raw_layout_fred
6+
7+
// CHECK: %T15raw_layout_fred4FredVySbG = type <{ [1 x i8] }>
8+
9+
do {
10+
// CHECK: {{%.*}} = alloca %T15raw_layout_fred4FredVySbG
11+
// CHECK: call swiftcc void @"$s15raw_layout_fred4FredVACyxGycfC"
12+
let _ = Fred<Bool>()
13+
}

0 commit comments

Comments
 (0)