Skip to content

Commit 3d2f6aa

Browse files
authored
Merge pull request #26524 from slavapestov/irgen-validate-decl-fix
IRGen: Fix crash if the type of a class stored property hasn't been validated yet
2 parents 6d571a0 + 19344e0 commit 3d2f6aa

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/AST/AttrKind.h"
2323
#include "swift/AST/Decl.h"
2424
#include "swift/AST/IRGenOptions.h"
25-
#include "swift/AST/LazyResolver.h"
2625
#include "swift/AST/Module.h"
2726
#include "swift/AST/Pattern.h"
2827
#include "swift/AST/PrettyStackTrace.h"
@@ -298,9 +297,6 @@ namespace {
298297
SILType classType,
299298
bool superclass) {
300299
for (VarDecl *var : theClass->getStoredProperties()) {
301-
if (!var->hasInterfaceType())
302-
IGM.Context.getLazyResolver()->resolveDeclSignature(var);
303-
304300
SILType type = classType.getFieldType(var, IGM.getSILModule());
305301

306302
// Lower the field type.

lib/IRGen/GenEnum.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#include "swift/AST/Decl.h"
108108
#include "swift/AST/Expr.h"
109109
#include "swift/AST/IRGenOptions.h"
110+
#include "swift/AST/LazyResolver.h"
110111
#include "swift/IRGen/Linking.h"
111112
#include "swift/SIL/SILModule.h"
112113
#include "llvm/IR/Function.h"
@@ -5778,6 +5779,9 @@ EnumImplStrategy::get(TypeConverter &TC, SILType type, EnumDecl *theEnum) {
57785779
continue;
57795780
}
57805781

5782+
if (!elt->hasInterfaceType())
5783+
TC.IGM.Context.getLazyResolver()->resolveDeclSignature(elt);
5784+
57815785
// Compute whether this gives us an apparent payload or dynamic layout.
57825786
// Note that we do *not* apply substitutions from a bound generic instance
57835787
// yet. We want all instances of a generic enum to share an implementation

lib/IRGen/GenType.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/CanTypeVisitor.h"
1919
#include "swift/AST/Decl.h"
2020
#include "swift/AST/GenericEnvironment.h"
21+
#include "swift/AST/LazyResolver.h"
2122
#include "swift/AST/IRGenOptions.h"
2223
#include "swift/AST/PrettyStackTrace.h"
2324
#include "swift/AST/Types.h"
@@ -1919,6 +1920,9 @@ namespace {
19191920
return true;
19201921

19211922
for (auto field : decl->getStoredProperties()) {
1923+
if (!field->hasInterfaceType())
1924+
IGM.Context.getLazyResolver()->resolveDeclSignature(field);
1925+
19221926
if (visit(field->getInterfaceType()->getCanonicalType()))
19231927
return true;
19241928
}
@@ -1940,9 +1944,13 @@ namespace {
19401944
return false;
19411945

19421946
for (auto elt : decl->getAllElements()) {
1943-
if (elt->hasAssociatedValues() &&
1944-
!elt->isIndirect() &&
1945-
visit(elt->getArgumentInterfaceType()->getCanonicalType()))
1947+
if (!elt->hasAssociatedValues() || elt->isIndirect())
1948+
continue;
1949+
1950+
if (!elt->hasInterfaceType())
1951+
IGM.Context.getLazyResolver()->resolveDeclSignature(elt);
1952+
1953+
if (visit(elt->getArgumentInterfaceType()->getCanonicalType()))
19461954
return true;
19471955
}
19481956
return false;

lib/SIL/SILType.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/SIL/SILType.h"
14+
#include "swift/AST/ASTMangler.h"
15+
#include "swift/AST/Decl.h"
1416
#include "swift/AST/ExistentialLayout.h"
1517
#include "swift/AST/GenericEnvironment.h"
18+
#include "swift/AST/LazyResolver.h"
1619
#include "swift/AST/Module.h"
17-
#include "swift/AST/ASTMangler.h"
1820
#include "swift/AST/Type.h"
1921
#include "swift/SIL/AbstractionPattern.h"
2022
#include "swift/SIL/SILFunctionConventions.h"
@@ -138,6 +140,9 @@ bool SILType::canRefCast(SILType operTy, SILType resultTy, SILModule &M) {
138140
SILType SILType::getFieldType(VarDecl *field, SILModule &M) const {
139141
auto baseTy = getASTType();
140142

143+
if (!field->hasInterfaceType())
144+
field->getASTContext().getLazyResolver()->resolveDeclSignature(field);
145+
141146
AbstractionPattern origFieldTy = M.Types.getAbstractionPattern(field);
142147
CanType substFieldTy;
143148
if (field->hasClangNode()) {
@@ -165,6 +170,9 @@ SILType SILType::getEnumElementType(EnumElementDecl *elt, SILModule &M) const {
165170
return SILType(objectType, getCategory());
166171
}
167172

173+
if (!elt->hasInterfaceType())
174+
elt->getASTContext().getLazyResolver()->resolveDeclSignature(elt);
175+
168176
// If the case is indirect, then the payload is boxed.
169177
if (elt->isIndirect() || elt->getParentEnum()->isIndirect()) {
170178
auto box = M.Types.getBoxTypeForEnumElement(*this, elt);
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
final class Burger {
2-
let onions: Bool = true
3-
let cheeseSlices: Int = 0
1+
public struct InnerStruct {
2+
let field: Int = 0
3+
4+
public init() {}
5+
}
6+
7+
public enum InnerEnum {
8+
case field(Int)
9+
}
10+
11+
public struct OuterStruct {
12+
let first: InnerStruct = InnerStruct()
13+
let second: InnerEnum = InnerEnum.field(0)
14+
15+
public init() {}
16+
}
17+
18+
public final class Burger {
19+
public let onions: Bool = true
20+
public let complex: OuterStruct = OuterStruct()
21+
public let cheeseSlices: Int = 0
22+
}
23+
24+
@_fixed_layout
25+
public final class Burrito {
26+
public let filling: OuterStruct = OuterStruct()
27+
public let cilantro: Int = 0
428
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
22
// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
3+
// RUN: %target-build-swift -enable-library-evolution %S/Inputs/library.swift %S/main.swift
4+
// RUN: %target-build-swift -enable-library-evolution -whole-module-optimization %S/Inputs/library.swift %S/main.swift
35

46
func meltCheese(_ burger: Burger) -> Int {
57
return burger.cheeseSlices
68
}
9+
10+
@inlinable
11+
func bestBurrito(_ burrito: Burrito) -> Int {
12+
return burrito.cilantro
13+
}

0 commit comments

Comments
 (0)