Yes.
you say that if you take a dependency on Int
Depending on a pointer makes the unsafety obvious, but pointers aren't required for unsafety.
we are almost certain that you mean to take a dependency on something else
Yes. More precisely, you mean to take a dependency on something whose lifetime can't be represented by the language at the point of initialization. By definition, declaring a type non-Escapable means that the compiler is responsible for keeping it's lifetime confined to that "something". You have asked to take a dependency on a lifetime that is not visible to the compiler, and thus not enforcable.
But depending on an escapable BitwiseCopyable value is still a meaningful thing to do. For example, it is very common to project a value out of one non-Escapable type into another:
@lifetime(copy ref)
func foo(ref: MyRef) -> MyRef {
unsafe MyRef(pointer: ref._pointer)
}
We should not require _overrideLifetime here as long as the compiler can see that _pointer is a projection into ref.
I could be convinced that requiring unsafe on the initializer is unnecessary because it is almost always redundant. Even when depending on an Int, we will also require unsafe _overrideLifetime in almost all unsafe situations. But requiring unsafe is a defensible position. It is relatively harmless because you will usually need it anyway, and I would rather error on the side that allows reversing the decision in the future.
I do have strong opinions that depending on an escapable BitwiseCopyable value:
-
is not modeled as a dependence on an immortal value
-
requires _overrideLifetime in order to escape the dependent value whenever the compiler cannot deduce ownership of the BitwiseCopyable value.
-
does not require _overrideLifetime to escape the dependent value when the BitwiseCopyable value is projected out of a value that has ownership.