Skip to content

Migrate unsafe functions into their own Unsafe modules #361

@lehins

Description

@lehins

This is a proposal and hasn't been set in stone yet. Please feel free to comment your opinion on the matter in this ticket.

Prelude: It has been requested many times that we provide access to all constructors from vector package. Giving access to those constructors allows violation of many invariants and hence is unsafe. Quote from #357:

Decide what is best way to expose constructors for vectors. It have been requested numerous times: #245, #343, #171, #63 (tangentially related), #49. It's of course totally unsafe. Still it's very useful to have on occasion

The best approach to tackle this is to create special Unsafe modules and export such constructors form there. This also spawned a discussion that it would make sense to migrate all of the of the unsafe functions to such modules (eg. unsafeIndex, unsafeRead, etc.), in order to provide a clear boundary between safe and dangerous functionality, which can have different qualified imports in the user land.

Doing such migration of unsafe functionality is worthwhile in a long run, but immediate problem is that it will cause a lot of breakage. Therefore it would have to be done in a few stages across couple of major releases.

  1. Next minor release vector-0.12.2.0 would be adding these modules with all of the unsafe functions exported from there:
module Data.Vector.Unsafe
module Data.Vector.Generic.Unsafe
module Data.Vector.Primitive.Unsafe
module Data.Vector.Storable.Unsafe
module Data.Vector.Unboxed.Unsafe
  1. Next major release vector-0.13, would continue to export all unsafe function from the Unsafe modules and their current locations, but latter ones would get DEPRECATED pragma added to them. This way such change will be visible to all the users
  2. The following major release vector-0.14 would have those unsafe functions removed from their current locations, but only if such release happens at least a year after vector-0.13 that deprecated unsafe functions.

Other relevant points to discuss:

  1. Do we stretch out the deprecation timeline over a longer period of time (eg. announce in vector-0.13, deprecated in vector-0.14 and remove in vector-0.15) It will take a couple of years.
  2. Do we also provide Unsafe modules for Bundle?
  3. Do we have separate Unsafe modules for Mutable vs immutable. My opinion is that such separation is not needed, since there aren't any name clashes of top of my head. And if there are any they can be mitigated by renaming, since this change is additive.
  4. Should we bother with monomorphic unsafe exports or instead only export Generic unsafe functions?
  5. Is the whole thing really worth it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions