Skip to content

Add a lit test showing and documenting how to use builtins in -parse-stdlib mode #68519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/Frontend/implicit-builtins-import.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This is just an example and documentation of how -parse-stdlib implicitly imports the Builtin module.
// Note that a lot of builtins expect some types to be defined in the stdlib, otherwise the builtin will be unavailable.
// Therefore "-module-name Swift" is significant (otherwise the types won't be find in the module we're building).
//
// Example:
// %target-swift-emit-ir -parse-stdlib %s
// Builtin.unreachable() // <<< error: module 'Builtin' has no member named 'unreachable'
//
// The real problem is that the 'unreachable' builtin needs the Never type (that's its return type).
//
// Example:
// %target-swift-emit-ir -parse-stdlib -module-name Swift %s
// enum Never {}
// Builtin.unreachable() // works

// RUN: %target-swift-emit-ir -parse-stdlib -module-name Swift %s

enum Never {}

Builtin.unreachable()
Builtin.int_trap()