The standard library’s print() function will be more limited, because it depends on reflection for some functionality.
That makes sense in production, but I think we should be able to relax this restriction in debug mode. For instance, most Swift Wasm apps rely on Embedded Swift to ship binaries between 500-3000 KiB, but when testing a web app locally, a 40 MiB binary with debug metadata loads just as fast. To be clear, I think we should support an Embedded-Debug mode with the same compile-time restrictions as regular embedded, but which spits out a larger binary with type metadata for regular print, debugPrint, etc.
protocol P {
func f()
func g<T>(_: T)
}
extension Int: P { ... }
let p: Any = 42
p.f() // okay
p.g(1) // not okay: requires unspecialized generics
Was the type of p supposed to be any P?
Non-allocating Embedded Swift will identify places where the implementation requires a heap allocation. This includes: [...]
What about instead of banning allocation, we make allocation explicit, similar to Zig? I know this would require more language changes, but even in Embedded Swift, developers might have an efficient arena allocator where they want to allocate indirect enums, initialize classes, or create arrays. For instance:
indirect enum Expr {
case literal(Int)
case add(Expr, Expr)
case multiply(Expr, Expr)
}
func allocatingFunction(explicitAllocator: MyArenaAllocator) {
// Strawman syntax
let expr = Expr<MyArenaAllocator>(allocator: explicitAllocator).literal(5)
}
I know the syntax I'm proposing is terrible, but my point is that there's value in explicit, custom allocators -- even for non-Embedded Swift. So, if Swift gains support for custom allocators, non-allocating mode would simply become explicit-allocation mode.
P.S. Very exciting to see Embedded Swift grow!