Skip to content

(feat) Semantic Check: ADTs et alia #60

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
merged 26 commits into from
Apr 11, 2025
Merged

(feat) Semantic Check: ADTs et alia #60

merged 26 commits into from
Apr 11, 2025

Conversation

AlSchlo
Copy link
Collaborator

@AlSchlo AlSchlo commented Apr 8, 2025

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:

image

or, more elaborate:

image

  1. Detects whether Logical, Physical, LogicalProperties, and PhysicalProperties types are defined, and are not the children of any other types.

  2. Checks for duplicate fields in ADTs.

image

  1. 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.

image

  1. 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).

@codecov-commenter
Copy link

codecov-commenter commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 88.40113% with 288 lines in your changes missing coverage. Please review.

Project coverage is 79.2%. Comparing base (ad270d3) to head (5e481ca).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
optd-dsl/src/analyzer/error.rs 26.3% 190 Missing ⚠️
...td-dsl/src/analyzer/semantic_check/cycle_detect.rs 85.0% 19 Missing ⚠️
optd-dsl/src/analyzer/semantic_check/adt_check.rs 98.0% 15 Missing ⚠️
optd-dsl/src/cli/compile.rs 0.0% 13 Missing ⚠️
optd-dsl/src/cli/main.rs 0.0% 11 Missing ⚠️
optd-dsl/src/analyzer/from_ast/expr.rs 98.4% 10 Missing ⚠️
optd-dsl/src/analyzer/from_ast/pattern.rs 94.2% 10 Missing ⚠️
optd-dsl/src/analyzer/from_ast/types.rs 97.8% 8 Missing ⚠️
optd-dsl/src/analyzer/types.rs 84.3% 5 Missing ⚠️
optd-dsl/src/utils/tests.rs 0.0% 3 Missing ⚠️
... and 3 more
Additional details and impacted files
Files with missing lines Coverage Δ
optd-dsl/src/analyzer/context.rs 89.0% <100.0%> (ø)
optd-dsl/src/analyzer/map.rs 96.6% <100.0%> (ø)
...ptd-dsl/src/analyzer/semantic_check/scope_check.rs 88.5% <100.0%> (+<0.1%) ⬆️
optd-dsl/src/lexer/lex.rs 97.9% <100.0%> (+<0.1%) ⬆️
optd-dsl/src/utils/error.rs 25.0% <ø> (ø)
optd-dsl/src/analyzer/from_ast/converter.rs 98.4% <98.3%> (+0.5%) ⬆️
optd-dsl/src/lexer/tokens.rs 0.0% <0.0%> (ø)
optd-dsl/src/parser/expr.rs 81.2% <91.3%> (+<0.1%) ⬆️
optd-dsl/src/utils/tests.rs 89.6% <0.0%> (-1.5%) ⬇️
optd-dsl/src/analyzer/types.rs 98.5% <84.3%> (+0.1%) ⬆️
... and 8 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AlSchlo AlSchlo marked this pull request as ready for review April 10, 2025 14:43
@AlSchlo AlSchlo changed the title Alexis/adt check (feat) Semantic Check: ADTs Apr 10, 2025
@AlSchlo AlSchlo changed the title (feat) Semantic Check: ADTs (feat) Semantic Check: ADTs et alia Apr 10, 2025
@AlSchlo AlSchlo changed the title (feat) Semantic Check: ADTs et alia (feat) Semantic Check: ADTs et Alia Apr 10, 2025
@AlSchlo AlSchlo changed the title (feat) Semantic Check: ADTs et Alia (feat) Semantic Check: ADTs et alia Apr 10, 2025
Copy link
Member

@yliang412 yliang412 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AlSchlo AlSchlo merged commit 3f4ccc7 into main Apr 11, 2025
11 checks passed
@AlSchlo AlSchlo deleted the alexis/adt-check branch April 11, 2025 20:32
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.

3 participants