Skip to content

Commit 4878991

Browse files
committed
[embedded] Add initial tests; fix two issues in IRGen.
1 parent 349d37a commit 4878991

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,14 +1412,14 @@ deleteAndReenqueueForEmissionValuesDependentOnCanonicalPrespecializedMetadataRec
14121412
void IRGenerator::emitLazyDefinitions() {
14131413
if (SIL.getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
14141414
// In embedded Swift, the compiler cannot emit any metadata, etc.
1415-
assert(LazyTypeMetadata.empty() &&
1416-
LazySpecializedTypeMetadataRecords.empty() &&
1417-
LazyTypeContextDescriptors.empty() &&
1418-
LazyOpaqueTypeDescriptors.empty() &&
1419-
LazyFunctionDefinitions.empty() &&
1420-
LazyCanonicalSpecializedMetadataAccessors.empty() &&
1421-
LazyMetadataAccessors.empty() &&
1422-
LazyWitnessTables.empty());
1415+
LazyTypeMetadata.clear();
1416+
LazySpecializedTypeMetadataRecords.clear();
1417+
LazyTypeContextDescriptors.clear();
1418+
LazyOpaqueTypeDescriptors.clear();
1419+
LazyFunctionDefinitions.clear();
1420+
LazyCanonicalSpecializedMetadataAccessors.clear();
1421+
LazyMetadataAccessors.clear();
1422+
LazyWitnessTables.clear();
14231423
}
14241424

14251425
while (!LazyTypeMetadata.empty() ||

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
601601
if (canSkipNominal(NTD))
602602
return;
603603

604+
if (NTD->getASTContext().LangOpts.hasFeature(Feature::Embedded))
605+
return;
606+
604607
auto declaredType = NTD->getDeclaredType()->getCanonicalType();
605608

606609
if (!NTD->getObjCImplementationDecl()) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not %target-swift-frontend -emit-ir %s -parse-stdlib -enable-experimental-feature Embedded 2>&1 | %FileCheck %s
2+
3+
public protocol Player {}
4+
struct Concrete: Player {}
5+
6+
// CHECK: error: existential can cause metadata allocation or locks
7+
public func test() -> any Player {
8+
Concrete()
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded | %FileCheck %s
2+
3+
struct Bool {}
4+
5+
protocol Player {
6+
func play()
7+
var canPlay: Bool { get }
8+
}
9+
10+
struct Concrete : Player {
11+
func play() { }
12+
var canPlay: Bool { Bool() }
13+
}
14+
15+
func start(p: some Player) {
16+
p.play()
17+
}
18+
19+
public func main() {
20+
start(p: Concrete())
21+
}
22+
23+
// CHECK-LABEL: declare hidden swiftcc void @"$s4main8ConcreteVACycfC"()
24+
25+
// CHECK-LABEL: declare hidden swiftcc void @"$s4main5start1pyx_tAA6PlayerRzlFAA8ConcreteV_Tg5"()
26+
27+
// CHECK-LABEL: define swiftcc void @"$s4mainAAyyF"()
28+
// CHECK-NEXT: entry:
29+
// CHECK-NEXT: call swiftcc void @"$s4main8ConcreteVACycfC"()
30+
// CHECK-NEXT: call swiftcc void @"$s4main5start1pyx_tAA6PlayerRzlFAA8ConcreteV_Tg5"()
31+
// CHECK-NEXT: ret void
32+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)