-
Notifications
You must be signed in to change notification settings - Fork 6
(feat) Add Return and Propagate Fail Correctly #67
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Semantic Analysis Performs the following semantic analysis for our DSL. ### adt_check In `semantic_check/adt_check.rs`: 1. Detects cyclic ADT definitions. This is best described with some pictures:  or, more elaborate:  2. Detects whether `Logical`, `Physical`, `LogicalProperties`, and `PhysicalProperties` types are defined, and are not the children of any other types. 3. Checks for duplicate fields in ADTs.  4. Validates the types within the fields of ADTs. Specifically: - No costed or stored types. - Only logical types may contain logical children. - Only physical types may contain physical children. - Logical `product` types may only contain [Logical] or Logical fields. - Physical `product` types may only contain [Physical] or Physical fields. ### from_ast In `from_ast`, I made the code process ADT definition first. This allows us to perform the following extra semantic analysis: 1. Verify if `Constructors` and `Patterns` are properly defined.  2. Verify if all annotated types exist when converting them into their `HIR` version. ### bug fix & others - The parser was parsing `None` as a `Constructor`. I have changed the syntax to `none` lowercase, and fixed the parser code correspondingly. - Refactored `AnalyzerErrorKind` to be `Boxed`, as clippy was complaining the type was getting too big. - Made `subtypes` in `TypeRegistry` a `BTreeMap` so that iterating over all keys is deterministic across compilations. - One semantic check I didn't implement is verifying the number of arguments in constructors, patterns, and function calls. **This will be addressed in a future PR for patterns and constructors**. For function calls, this validation will be handled in the type inference PR since functions are first-class values in our language, making it more sensible to perform there (especially since calls are also used for arrays, maps, and tuples).
Eventually, we will want `optd` to be an optimizer service. However, we would also like it to be an embeddable library. This PR creates a top-level `optd` crate that will act as the "glue" between all of our components (which right now is just `optd-core` and `optd-dsl`, but more will probably be created). Users should be able to import a single `optd` dependency and have access to all functionality we want to provide (similar to `tokio`). We do _not_ want a datafusion situation where there could be 5 different datafusion crates you need to import. There is another subtle reason we need this now. We would like to add catalog functionality to `optd`. Both the rule engine and the optimizer need access to the catalog. However, it is not entirely obvious where one would put an implementation of a catalog right now. It doesn't really make sense to put it in `optd-dsl`, but we also can't put it in `optd-core` because `optd-core` depends on `optd-dsl`, which would result in a circular dependency. By creating a top-level `optd` crate, we can put the definition of a `Catalog` trait in `optd-dsl`, and then add implementations of catalogs in the `optd` crate. This allows for flexibility in catalog implementations while not adding (arguably) irrelevant code to the `optd-dsl` crate. I removed some unused dependencies and bumped all `Cargo.toml` dependencies to their latest version. However, I updated the `Cargo.lock` with `-Z direct-minimal-versions`. This PR also reintroduces the CI checks that we disabled. The `twox-hash` problem still exists when taking a dependency on `iceberg`, so instead of `-Z minimal-versions`, I've changed it to `-Z direct-minimal-versions`.
I think it's because |
### main change Finalizes semantic analysis by checking for field number mismatches in `Patterns` and `Constructors`. Displays an error message during the `from_ast` phase, as follows:  ### extra changes - I added all type annotations I could during the `from_ast` phase, to simplify type inference. - Added the `none` type, which inherits from Option<Nothing>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What & Why
This PR adds a
return
operator in theHIR
and in theEngine
, and likewise fixes the behavior ofFails
to propagate correctly up the call stack.This has been implemented by adding a field to the
Engine
, which keeps track of the upper function call continuation.Existing test cases have been adapted: (related to
Fail
), and a new one forReturn
has been added.Some Refactoring
eval
functions member functions ofEngine
.Follow-up Work (less urgent)
AST
and mapping it to theHIR
.?
operator to unwrapoption
types.Clone
bound, but removing it leads to errors.