Skip to content

Commit b4bed41

Browse files
committed
Add a lit test showing and documenting how to use builtins in -parse-stdlib mode
1 parent 0797d66 commit b4bed41

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This is just an example and documentation of how -parse-stdlib implicitly imports the Builtin module.
2+
// Note that a lot of builtins expect some types to be defined in the stdlib, otherwise the builtin will be unavailable.
3+
// Therefore "-module-name Swift" is significant (otherwise the types won't be find in the module we're building).
4+
//
5+
// Example:
6+
// %target-swift-emit-ir -parse-stdlib %s
7+
// Builtin.unreachable() // <<< error: module 'Builtin' has no member named 'unreachable'
8+
//
9+
// The real problem is that the 'unreachable' builtin needs the Never type (that's its return type).
10+
//
11+
// Example:
12+
// %target-swift-emit-ir -parse-stdlib -module-name Swift %s
13+
// enum Never {}
14+
// Builtin.unreachable() // works
15+
16+
// RUN: %target-swift-emit-ir -parse-stdlib -module-name Swift %s
17+
18+
enum Never {}
19+
20+
Builtin.unreachable()
21+
Builtin.int_trap()

0 commit comments

Comments
 (0)