Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transmute in assign_nested #1033

Open
Licenser opened this issue May 19, 2021 · 0 comments
Open

transmute in assign_nested #1033

Licenser opened this issue May 19, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Licenser
Copy link
Member

Describe the problem you are trying to solve

The assign nested function takes care of assigning values in the form of:

let some.nested.value[2..6][2]["key"]

The reasoning to use transmute here is listed in the code as follows:

        /* NOTE
         * This function is icky we got to do some trickery here.
         * Since it's dangerous and icky it deserves some explanation
         * What we do here is we borrow the target we want to set
         * as immutable and mem::transmute it to mutable where needed.
         *
         * We do this since there is no way to tell rust that it's safe
         * to borrow immutable out of something that's mutable even if
         * we clone data out.
         *
         * This is safe because:
         *
         * We only borrow Cow<'event, str> out of the host. So the
         * reference points to either the event or script and we
         * never mutate strings only ever replace them.
         * So even if the map the Cow originally came from we won't
         * lose the referenced data. (Famous last words)
         */

Describe the solution you'd like

No sensible re-write comes to mind here, but it's good to have this noted. Perhaps there are approaches we haven't thought of. As with other low-level optimizations, this will be resolved when tremor-script becomes a VM or compiled language.

Notes
Followup to #1015

@Licenser Licenser added the enhancement New feature or request label May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant