Skip to content

Commit e3d5ae0

Browse files
committed
Add SIL re-ingest test
1 parent e1dfdba commit e3d5ae0

File tree

3 files changed

+132
-4
lines changed

3 files changed

+132
-4
lines changed

include/swift/AST/Module.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class ModuleDecl
176176
///
177177
/// For a Swift module, this will only ever have one component, but an
178178
/// imported Clang module might actually be a submodule.
179+
///
180+
/// *Note: see `StringRef operator*()` for details on the returned name for printing
181+
/// for a Swift module.
179182
class ReverseFullNameIterator {
180183
public:
181184
// Make this look like a valid STL iterator.
@@ -196,7 +199,7 @@ class ModuleDecl
196199

197200
/// Returns the name of the current module.
198201
/// Note that for a Swift module, it returns the current module's real (binary) name,
199-
/// which can be different from the name if module aliasing was used (see -module-alias).
202+
/// which can be different from the name if module aliasing was used (see `-module-alias`).
200203
StringRef operator*() const;
201204
ReverseFullNameIterator &operator++();
202205

@@ -211,6 +214,9 @@ class ModuleDecl
211214

212215
/// This is a convenience function that writes the entire name, in forward
213216
/// order, to \p out.
217+
///
218+
/// It calls `StringRef operator*()` under the hood (see for more detail on the
219+
/// returned name for a Swift module).
214220
void printForward(raw_ostream &out, StringRef delim = ".") const;
215221
};
216222

@@ -796,6 +802,9 @@ class ModuleDecl
796802
///
797803
/// For a Swift module, this will only ever have one component, but an
798804
/// imported Clang module might actually be a submodule.
805+
///
806+
/// *Note: see `StringRef operator*()` for details on the returned name for printing
807+
/// for a Swift module.
799808
ReverseFullNameIterator getReverseFullModuleName() const {
800809
return ReverseFullNameIterator(this);
801810
}

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,8 @@ void Serializer::writeHeader(const SerializationOptions &options) {
11051105
static void flattenImportPath(const ImportedModule &import,
11061106
SmallVectorImpl<char> &out) {
11071107
llvm::raw_svector_ostream outStream(out);
1108-
// Write module 'real name' (returned by getReverseFullModuleName),
1109-
// which can be different from 'name' in case module aliasing was
1110-
// used (-module-alias flag)
1108+
// This will write the module 'real name', which can be different
1109+
// from the 'name' in case module aliasing was used (see `-module-alias`)
11111110
import.importedModule->getReverseFullModuleName().printForward(
11121111
outStream, StringRef("\0", 1));
11131112

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -module-name Tea %t/FileTea.swift -emit-module -emit-module-path %t/Tea.swiftmodule
5+
6+
// RUN: %target-swift-frontend -emit-sil %t/FileBar.swift -module-alias Coffee=Tea -I %t -o %t/Bar-output.sil
7+
// RUN: %FileCheck %s -input-file %t/Bar-output.sil
8+
9+
// RUN: %target-sil-opt -enable-sil-verify-all %t/Bar-import-real.sil -I %t -o %t/Bar-re-output.sil
10+
// RUN: %FileCheck %s -input-file %t/Bar-re-output.sil -check-prefix RE-CHECK
11+
12+
// CHECK: sil_stage canonical
13+
14+
// CHECK: import Builtin
15+
// CHECK: import Swift
16+
// CHECK: import SwiftShims
17+
18+
// CHECK: import Coffee
19+
20+
// CHECK: public func drink() -> Mild?
21+
22+
// CHECK: // main
23+
// CHECK: sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
24+
// CHECK: bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
25+
// CHECK: %2 = integer_literal $Builtin.Int32, 0 // user: %3
26+
// CHECK: %3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4
27+
// CHECK: return %3 : $Int32 // id: %4
28+
// CHECK: } // end sil function 'main'
29+
30+
// CHECK: // drink()
31+
// CHECK: sil @$s4main5drink3Tea4MildVSgyF : $@convention(thin) () -> Optional<Mild> {
32+
// CHECK: bb0:
33+
// CHECK: // function_ref brew()
34+
// CHECK: %0 = function_ref @$s3Tea4brewAA4MildVSgyF : $@convention(thin) () -> Optional<Mild> // user: %1
35+
// CHECK: %1 = apply %0() : $@convention(thin) () -> Optional<Mild> // user: %2
36+
// CHECK: return %1 : $Optional<Mild> // id: %2
37+
// CHECK: } // end sil function '$s4main5drink3Tea4MildVSgyF'
38+
39+
// CHECK: // brew()
40+
// CHECK: sil [noinline] @$s3Tea4brewAA4MildVSgyF : $@convention(thin) () -> Optional<Mild>
41+
42+
// RE-CHECK: sil_stage canonical
43+
44+
// RE-CHECK: import Builtin
45+
// RE-CHECK: import Swift
46+
// RE-CHECK: import SwiftShims
47+
48+
// RE-CHECK: import Tea
49+
50+
// RE-CHECK: public func drink() -> Mild?
51+
52+
// RE-CHECK: // main
53+
// RE-CHECK: sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
54+
// RE-CHECK: bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
55+
// RE-CHECK: %2 = integer_literal $Builtin.Int32, 0 // user: %3
56+
// RE-CHECK: %3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4
57+
// RE-CHECK: return %3 : $Int32 // id: %4
58+
// RE-CHECK: } // end sil function 'main'
59+
60+
// RE-CHECK: // drink()
61+
// RE-CHECK: sil @$s4main5drink3Tea4MildVSgyF : $@convention(thin) () -> Optional<Mild> {
62+
// RE-CHECK: bb0:
63+
// RE-CHECK: // function_ref brew()
64+
// RE-CHECK: %0 = function_ref @$s3Tea4brewAA4MildVSgyF : $@convention(thin) () -> Optional<Mild> // user: %1
65+
// RE-CHECK: %1 = apply %0() : $@convention(thin) () -> Optional<Mild> // user: %2
66+
// RE-CHECK: return %1 : $Optional<Mild> // id: %2
67+
// RE-CHECK: } // end sil function '$s4main5drink3Tea4MildVSgyF'
68+
69+
// RE-CHECK: // brew()
70+
// RE-CHECK: sil [noinline] @$s3Tea4brewAA4MildVSgyF : $@convention(thin) () -> Optional<Mild>
71+
72+
// BEGIN Bar-import-real.sil
73+
sil_stage canonical
74+
75+
import Builtin
76+
import Swift
77+
import SwiftShims
78+
79+
import Tea
80+
81+
public func drink() -> Mild?
82+
83+
// main
84+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
85+
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
86+
%2 = integer_literal $Builtin.Int32, 0 // user: %3
87+
%3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4
88+
return %3 : $Int32 // id: %4
89+
} // end sil function 'main'
90+
91+
// drink()
92+
sil @$s4main5drink3Tea4MildVSgyF : $@convention(thin) () -> Optional<Mild> {
93+
bb0:
94+
// function_ref brew()
95+
%0 = function_ref @$s3Tea4brewAA4MildVSgyF : $@convention(thin) () -> Optional<Mild> // user: %1
96+
%1 = apply %0() : $@convention(thin) () -> Optional<Mild> // user: %2
97+
return %1 : $Optional<Mild> // id: %2
98+
} // end sil function '$s4main5drink3Tea4MildVSgyF'
99+
100+
// brew()
101+
sil [noinline] @$s3Tea4brewAA4MildVSgyF : $@convention(thin) () -> Optional<Mild>
102+
103+
104+
// BEGIN FileTea.swift
105+
public struct Mild {
106+
public init() {}
107+
}
108+
109+
@inline(never)
110+
public func brew() -> Tea.Mild? {
111+
return Mild()
112+
}
113+
114+
// BEGIN FileBar.swift
115+
import Coffee
116+
117+
public func drink() -> Mild? {
118+
return brew()
119+
}
120+

0 commit comments

Comments
 (0)