3 ms·
A lot of this and a few other links in this thread end up looking like creating an AST limited to the operations you want to expose to the user, in a serializab
by moron4hire 7y ago
A lot of this and a few other links in this thread end up looking like creating an AST limited to the operations you want to expose to the user, in a serializable way. I think that's even called out explicitly in the articles. But I'm left thinking "what is the serialized structure of an AST?" It's source code. So we've implemented a language that then we have to use from within our code that is not as ergonomic as the host language.
In a way, it's kind of like type-safe eval(), with the limited nature of the purpose-specific implementation creating a sandbox of types around the eval, i.e. the impl isn't complete enough to give us turing completeness, File IO, or other things that would let the data turn into executable code that could escape the sandbox. So I'm curious to see if some wrappers around Roslyn[0] could get us less verbosity than Roslyn itself, a more complete impl that doesn't have to be written for every application, and the sandboxing necessary to prevent it from being handing the user a fully-automatic submachine gun pointed at our database.
Maybe it's something like a white-list for Roslyn structures. You could take a C# file, parse it with Roslyn, filter through the white-list, and either error-out if the user is doing something nefarious, or compile the structure and continue as normal. And then the code that we pass around as data could just be C# code, rather than having to have our own AST structures that we serialize on our own.
Maybe you could even allow limited forms of looping by injecting infinite-loop-breaking code that does some simple pre-/post-condition checking. Like "while(true) loops are only allowed to execute 10K times", or "for loops need to be bounded correctly for the update expression, and the index must not be modified in the body".
[0] Side note: my office is in a neighborhood called "Rosslyn", so I'm constantly misspelling one or the other.