kyleoneill / chimerascript

0 stars 0 forks source link

Break up Literal #30

Open kyleoneill opened 10 months ago

kyleoneill commented 10 months ago

Implementing the reference change, I ran into an issue where the collection variants of the Literal enum caused Data to have to implement PartialEq. This is a problem. Literal must implement PartialEq and this implementation should not be spilling into Data as it can cause a panic if an equality check is made in the right scenario. The eq method of PartialEq cannot return a result.

let first_data: Data = ...;
let second_data: Data = ...;
let foo = first_data.borrow_mut();
first_data == second_data //  `eq` will try to borrow the handle for `first_data` and panic

Will likely need to split Literal again into an enum with one variant that holds the string, num, bool, sub-variants and another which holds the object and list sub-variants. The serde Deserialize derive will have to be swapped over

kyleoneill commented 9 months ago

Somewhat resolved by https://github.com/kyleoneill/chimerascript/pull/34. Literal has been broken up and Data no longer implements PartialEq, but the struct that it contains does and can still panic if an equality check is made for a collection while a mutable reference for a value contained within it is out.

This might just be an impossible to resolve structural issue with how referencing is currently handled. This can be resolved by moving to another reference system, like the variable hashmap being HashMap<String, usize> where the usize is an address in some Vec<T> which actually stores all of the data in some global MutRef. All data in this case would be behind a single reference, which solves this issue and brings others.

If stricter guards are placed around getting a mutable reference to make sure it's impossible to have one out when reading, that could also be a solution.