Commit Graph

169 Commits

Author SHA1 Message Date
Tim Kientzle
cf4701ce5d [Gardening] Include Runtime/Config.h directly
This file was relying on Runtime/Config.h for SWIFT_CC() but
didn't include it directly.

I found this when some local experiments went awry in confusing
ways.
2025-01-15 15:36:56 -08:00
swift-ci
2bf8a521eb Merge remote-tracking branch 'origin/main' into rebranch 2024-08-07 09:53:42 -07:00
Ben Langmuir
1f00ffe42c Revert "[immediate] Load Foundation early enough for bridging" 2024-08-06 16:10:42 -07:00
swift-ci
ef054444fd Merge remote-tracking branch 'origin/main' into rebranch 2024-08-02 01:03:44 -07:00
Ben Langmuir
8a824d70a0 [immediate] Load Foundation early enough for bridging
Foundation needs to be loaded early in the process for Swift's runtime
to properly initialize bridging support; otherwise it may cause issues
like unrecognized selectors. When scripting, load Foundation early in
performFrontend before any swift code runs.

rdar://129528115
2024-08-01 15:02:13 -07:00
Ben Langmuir
37ced22047 [immediate] Leak SwiftJIT to avoid unmapping metadata memory
It's not safe to unmap memory that has been registered with the
swift/objc runtimes. For now, avoid this by leaking the JIT object. In
the future we should be able to detach the JIT from the allocated
memory, or be more fine-grained about which memory needs to be preserved
and which can be freed.

rdar://128432487
2024-07-29 16:22:24 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Lang Hames
06384be243 For scripts, use DYLD_FRAMEWORK/LIBRARY_PATH to find frameworks / runtimes.
Add DYLD_FRAMEWORK_PATH=/System/Library/Frameworks to the environment when
constructing swift-frontend invocations for the interpreter so that dlopen can
find autolinked frameworks. This is intended to fix
https://github.com/apple/swift/issues/68785.

As a follow-up: don't expand runtime paths to find the path to the runtime in
libImmediate, but instead hard-code "/usr/lib/swift/libswiftCore.dylib" and
allow any overrides to be found via DYLD_LIBRARY_PATH (this ensures that dyld
treats whichever libswiftCore.dylib is found as override for the one in the
shared cache, which doesn't happen if dlopen is passed a non-standard path).
2024-01-18 21:41:48 -08:00
Zak Kent
2abca625d7 Merge branch 'main' into update-immediate 2023-08-18 16:07:14 -07:00
Zak Kent
4616e03f61 [Immediate] Only add renamer plugin on macOS 2023-08-14 13:28:23 -07:00
Zak Kent
0b618fe9bf [Immediate] Replace uses of SILMaterializationUnit with EagerSwiftMaterializationUnit 2023-08-14 13:28:22 -07:00
Zak Kent
473a18d2ce [Immediate] Implement EagerSwiftMaterializationUnit 2023-08-14 13:28:22 -07:00
Zak Kent
48c36c956d [Immediate] Move SwiftMaterializationUnit to public library 2023-08-14 13:28:22 -07:00
Zak Kent
148cd6acc4 [Immediate] [Sema] Implemented Lazy Type Checking
Implements lazy type checking in Swift Immediate mode,
allowing functions to be type-checked as they are
executed.
2023-08-14 13:28:22 -07:00
Zak Kent
17fedabb5e [Immediate] Implemented SwiftMaterializationUnit
Implemented SwiftMaterializationUnit, supporting
lazy compilation of individual Swift functions.
2023-08-14 13:28:22 -07:00
Zak Kent
94530c7584 [NFC] [Immediate] Lazily materialize global values 2023-08-14 13:28:22 -07:00
Evan Wilde
e51988ecdf Rebranch: Removing extra null
allocateCString includes the null end character, so we ended up with
two, in the symbol name. This made them not match, causing failures
while attempting to run the JIT'd program.

Remove one from the symbol name length to account for the null
character.
2023-08-07 23:29:31 -07:00
Evan Wilde
36f1e68cdd [Next][JIT] Fix JIT API in Immediate
Fixing some of the JITing API differences between `next` and
`stable/20221013`.
2023-07-17 18:18:10 -07:00
Evan Wilde
26a974e772 [NFC] Headers headers headers!
Including headers that were being transitively included from LLVM
before. Also pointing them at the new locations for some of them.
2023-07-17 10:55:55 -07:00
Zak Kent
c2c41f8afd [Immediate] Only lazily compile on Darwin
Fallback to eager compilation on Linux
and Windows due to issues with older
versions of JITLink on those platforms.
2023-07-13 10:30:38 -07:00
Zak Kent
e96f1d8d59 [Immediate] Implement whole-module lazy compilation
Establishes the framework for implementing function
at-a-time lazy compilation by adding lazy re-exports.
2023-07-11 15:35:51 -07:00
Zak Kent
a12a6f13ad [Immediate] Refactor Immediate Mode to use Materialization Unit
Refactor Immediate Mode to use the Materialization Unit API,
materializing the entire `SILModule` corresponding to the script
when the `main` symbol is looked up.
2023-07-07 12:23:37 -07:00
Ben Langmuir
e759007256 [Immediate] Workaround for loading merged frameworks in immediate mode
Some frameworks that previously had a separate swift overlay have been
merged in macOS 14. This is causing symbols to not resolve if using the
new SDK but running on an older OS in immediate mode. Ideally we would
handle this automatically in JITLink as is done by the system linker,
but in the meantime add a workaround to load the correct libraries
manually.

rdar://110371405
2023-06-09 16:37:57 -07:00
Steven Wu
09b8af86fb Virtualize swift compiler outputs (#63206)
Using a virutal output backend to capture all the outputs from
swift-frontend invocation. This allows redirecting and/or mirroring
compiler outputs to multiple location using different OutputBackend.

As an example usage for the virtual outputs, teach swift compiler to
check its output determinism by running the compiler invocation
twice and compare the hash of all its outputs.

Virtual output will be used to enable caching in the future.
2023-04-05 23:34:37 +08:00
Erik Eckstein
67a98e9a37 JIT: getAddress -> getValue 2022-11-04 20:44:19 +01:00
Dario Rexin
317a6ab2d4 [Immediate]: Workaround for loading Foundation in immediate mode (#59730)
* [Immediate]: Workaround for loading Foundation in immediate mode

rdar://94645534

* Update Immediate.cpp

* Update Immediate.cpp
2022-06-28 10:03:02 -07:00
swift-ci
da1ab99326 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-22 05:56:01 -08:00
Erik Eckstein
3540c01125 rename initializeLibSwift -> InitializeSwiftModules
and some updates in comments.
2021-12-22 11:31:52 +01:00
swift-ci
41ef4e8c9d Merge remote-tracking branch 'origin/main' into rebranch 2021-12-20 09:15:08 -08:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
Ben Barham
5343c72d10 [rebranch] Fix missing includes 2021-11-13 17:04:29 +10:00
Evan Wilde
a5f11c4851 Fix the main->next merge conflicts
This cleans up all of the merge conflicts from main into next after the
rebranch merge.
2021-10-15 15:57:55 -07:00
Kuba (Brecka) Mracek
7538949859 Split out CommandLine enum into a separate static library, allow removing it from stdlib (#39591)
This is for the 'freestanding' build to stop assuming the platform has argc/argv.

- Introduce a new sub-library, libswiftCommandLineSupport.a
- Move stubs/CommandLine.cpp into this library
- Conditionally embed it into libswiftCore
- Conditionally embed it into libswiftPrivateLibcExtras if not in libswiftCore to support testing
- Add SWIFT_STDLIB_HAS_COMMANDLINE CMake (and build-script) flag
2021-10-13 07:02:43 -07:00
Arnold Schwaighofer
f958804cdc OrcRPCTargetProcessControl.h -> OrcRPCExecutorProcessControl.h 2021-08-05 12:15:23 -07:00
Evan Wilde
26af94ec2b Fix ExecutionEngine include
LLVM Commit 662c55442f17c changed the name of the header file, causing
some breakage.
2021-07-02 16:45:47 -07:00
swift_jenkins
70b3de8660 Merge remote-tracking branch 'origin/main' into next 2021-06-09 11:40:59 -07:00
Erik Eckstein
809ce72e05 libswift: build support for the initial libswift
* add the (still empty) libswift package
* add build support for libswift in CMake
* add libswift to swift-frontend and sil-opt

The build can be controlled with the LIBSWIFT_BUILD_MODE cmake variable: by default it’s “DISABLE”, which means that libswift is not built. If it’s “HOSTTOOLS”, libswift is built with a pre-installed toolchain on the host system.
2021-06-09 11:25:15 +02:00
David Zarzycki
d411b2eda1 Unbreak building against apple/main 2021-01-22 11:48:18 -05:00
David Zarzycki
9df236987c Track upstream LLVM
LLVM 1d0676b54c4e3a517719220def96dfdbc26d8048 moved a function.
2020-11-14 07:34:44 -05:00
Nathan Hawes
ded5512cdc Manually merge remote-tracking branch 'upstream/master' into master-next 2020-08-06 10:42:21 -07:00
Saleem Abdulrasool
8d21750ef3 Frontend: support dumping the JIT state
Add a debugging mechanism that enables the JIT to dump the LLVM IR and
object files to enable debugging the JIT.  This makes it easier to debug
the JIT mode failures.  The idea was from Lang Hames!
2020-08-05 09:13:49 -07:00
swift_jenkins
9192927ebc Merge remote-tracking branch 'origin/master' into master-next 2020-07-16 23:18:54 -07:00
Hamish Knight
c0a2ea7d0e Sink linker directive computation into IRGen
With an inverted pipeline, IRGen needs to be able
to compute the linker directives itself, so sink
it down such that it can be computed by the
`IRGenDescriptor`.
2020-07-15 17:46:14 -07:00
Hamish Knight
d05bfa09d6 [IRGen] Lift call to performLLVM out of IRGenRequest
Remove the side-effecting call from IRGenRequest,
instead requiring callers to handle the optimization
and emission of the LLVM module.
2020-07-15 16:46:42 -07:00
Hamish Knight
db7fea4665 Sink linker directive computation into IRGen
With an inverted pipeline, IRGen needs to be able
to compute the linker directives itself, so sink
it down such that it can be computed by the
`IRGenDescriptor`.
2020-07-13 20:42:54 -07:00
Karoy Lorentey
68351d2110 Revert "Merge remote-tracking branch 'origin/master-next'"
This reverts commit 1c9b0908e6, reversing
changes made to 3eb82c1836.
2020-06-08 16:48:38 -07:00
Robert Widmann
5481631baf Merge remote-tracking branch 'upstream/master' into master-next 2020-04-17 20:27:23 -07:00
Robert Widmann
1f2346d381 [NFC] Drastically Reduce The Scope of the Global Context
Delete all of the formalism and infrastructure around maintaining our own copy of the global context. The final frontier is the Builtins, which need to lookup intrinsics in a given scratch context and convert them into the appropriate Swift annotations and types. As these utilities have wormed their way through the compiler, I have decided to leave this alone for now.
2020-04-17 14:02:45 -07:00
Robert Widmann
993c35dcd6 Merge remote-tracking branch 'upstream/master' into contextual-clues 2020-04-17 11:52:53 -07:00
Robert Widmann
03b19f3f7e Sequester the REPL's linking machinery
All of this is in service of working around a pile of deficiencies in LLVM's Module Linker, and LLVMContext abstractions. And because we're just gonna scrap this code soon anyways, it's probably not worth the effort to push on these bugs to block the broader cleanup here.

The LLVM Linker currently does not support linking modules allocated in different contexts. This appears to be motivated in part by LLVM's lack of a facility to clone a module from one context to another. This, in turn, appears to be motivated in part by LLVMContext's lack of a robust notion of identity - which makes it harder than it needs to be to detect the mismatch.

However, it is not impossible to clone a module across contexts. We need to get creative and round-trip the module through some serialization layer. Out of convenience, that layer is currently textual IR, though bitcode would work equally well.

Given that it is no longer under the caller's control which LLVMContext we generate code in, put all the above together to arrive at an egregious hack that clones the module into the LLVMContext the REPL expects.
2020-04-16 11:57:44 -07:00