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

Partial eval #1077

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

nwokafor-choongsaeng
Copy link
Contributor

Terms

THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE TERMS OF THE CCLA DATED 2017-11-07 WITH FINOS/LINUX FOUNDATION (FORMERLY THE SYMPHONY SOFTWARE FOUNDATION CCLA).

THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.

@nwokafor-choongsaeng
Copy link
Contributor Author

nwokafor-choongsaeng commented Jul 9, 2023

The Interpreter has been modified to allow configurations to it. The only configuration right now is turning on partial evaluation and this is done by setting the allowPartial to true in the config. Two config values, complete and partial, are added for convenience as well.

Partial evaluation allows the interpreter to evaluate parts of a value that can be evaluated, while preserving the parts that cannot.

Note

  1. If-else will try to pick a branch. If it finds a condition that holds true, then it selects that branch and evaluates. Likewise, it discards a branch when it's condition is false. Otherwise, it will preserve the if-else structure if it contains conditions that were partially evaluated.
  2. A pattern match will always be preserved because it could contain a catch-all pattern that will always match whereas the target was only partially evaluated.

An improvement was also added to the interpreter because it previously didn't evaluate variable values that were looked-up from the state.

Partial Evaluation Example

1 + 2 + var = 3 + var

------

if 1 == 1 then 2 else if var == 2 then 3 else 4
evaluates to 
2

------

if 1 == 2 then 1 else if var == 2 then 3 else 4
evalutates to
if var == 2 then 3 else 4

@nwokafor-choongsaeng nwokafor-choongsaeng marked this pull request as ready for review July 27, 2023 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant