You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,10 @@ using Pkg
15
15
Pkg.add("StaticCompiler")
16
16
```
17
17
18
-
There are two main ways to use this package. The first is via the `compile` function, which can be used when you want to compile a Julia function for later use from within Julia:
18
+
There are two main ways to use this package:
19
+
20
+
### Linked compilation
21
+
The first option is via the `compile` function, which can be used when you want to compile a Julia function for later use from within Julia:
19
22
```julia
20
23
julia>using StaticCompiler
21
24
@@ -43,7 +46,8 @@ julia> fib_compiled(10)
43
46
```
44
47
See the file `tests/runtests.jl` for some examples of functions that work with `compile` (and some that don't, marked with `@test_skip`).
45
48
46
-
The second way to use this package is via the `compile_executable` and `compile_shlib` functions, for use when you want to compile a Julia function to a native executable or shared library for use from outside of Julia:
49
+
### Standalone compilation
50
+
The second way to use this package is via the `compile_executable` and `compile_shlib` functions, for when you want to compile a Julia function to a native executable or shared library for use from outside of Julia:
47
51
```julia
48
52
julia>using StaticCompiler, StaticTools
49
53
@@ -68,7 +72,7 @@ This package uses the [GPUCompiler package](https://github.com/JuliaGPU/GPUCompi
68
72
## Limitations
69
73
70
74
* GC-tracked allocations and global variables do work with `compile`, but the way they are implemented is brittle and can be dangerous. Allocate with care.
71
-
* GC-tracked allocations and global variables do *not* work with `compile_executable`(yet).
72
-
*Type unstable code is not yet supported.
73
-
*Doesn't currently work on Windows.
74
-
*If you find any other limitations, let us know. There's probably lots.
75
+
* GC-tracked allocations and global variables do *not* work with `compile_executable`or `compile_shlib`. This has some interesting consequences, including that all functions _within_ the function you want to compile must either be inlined or return only native types (otherwise Julia would have to allocate a place to put the results, which will fail).
76
+
*Since error handling relies on libjulia, you can only throw errors from standalone-compiled (`compile_executable` / `compile_shlib`) code if an explicit overload has been defined for that particular error with `@device_override` (see [quirks.jl](src/quirks.jl)).
77
+
*Type instability. Type unstable code cannot currently be statically compiled via this package.
@@ -244,9 +252,6 @@ function compile_executable(f, types=(), path::String="./", name=GPUCompiler.saf
244
252
nativetype =isprimitivetype(rt) ||isa(rt, Ptr)
245
253
nativetype ||@warn"Return type `$rt` of `$f$types` does not appear to be a native type. Consider returning only a single value of a native machine type (i.e., a single float, int/uint, bool, or pointer). \n\nIgnoring this warning may result in Undefined Behavior!"
246
254
247
-
# Would be nice to use a compiler pass or something to check if there are any heap allocations or references to globals
248
-
# Keep an eye on https://github.com/JuliaLang/julia/pull/43747 for this
@@ -273,28 +302,34 @@ function compile_shlib(f, types=(), path::String="./", name=GPUCompiler.safe_nam
273
302
nativetype =isprimitivetype(rt) ||isa(rt, Ptr)
274
303
nativetype ||@warn"Return type `$rt` of `$f$types` does not appear to be a native type. Consider returning only a single value of a native machine type (i.e., a single float, int/uint, bool, or pointer). \n\nIgnoring this warning may result in Undefined Behavior!"
275
304
276
-
# Would be nice to use a compiler pass or something to check if there are any heap allocations or references to globals
277
-
# Keep an eye on https://github.com/JuliaLang/julia/pull/43747 for this
isconcretetype(rt) ||error("`$f$types` did not infer to a concrete type. Got `$rt`")
323
+
nativetype =isprimitivetype(rt) ||isa(rt, Ptr)
324
+
nativetype ||@warn"Return type `$rt` of `$f$types` does not appear to be a native type. Consider returning only a single value of a native machine type (i.e., a single float, int/uint, bool, or pointer). \n\nIgnoring this warning may result in Undefined Behavior!"
isconcretetype(tt) ||error("input type signature `$types` is not concrete")
553
-
554
-
rt =last(only(native_code_typed(f, tt)))
555
-
isconcretetype(rt) ||error("`$f$types` did not infer to a concrete type. Got `$rt`")
556
-
nativetype =isprimitivetype(rt) ||isa(rt, Ptr)
557
-
nativetype ||@warn"Return type `$rt` of `$f$types` does not appear to be a native type. Consider returning only a single value of a native machine type (i.e., a single float, int/uint, bool, or pointer). \n\nIgnoring this warning may result in Undefined Behavior!"
558
-
end
559
-
560
-
# Would be nice to use a compiler pass or something to check if there are any heap allocations or references to globals
561
-
# Keep an eye on https://github.com/JuliaLang/julia/pull/43747 for this
0 commit comments