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

Add class constraints for built-in classes #2005

Closed
wants to merge 54 commits into from
Closed

Add class constraints for built-in classes #2005

wants to merge 54 commits into from

Conversation

sezna
Copy link
Contributor

@sezna sezna commented Nov 5, 2024

This PR exposes some relevant built-in classes via class constraints.

Changes

  • Add TypeParameter, ClassConstraint, and ConstraintParameter AST nodes to represent the notion of a generic type that might have class constraints, and constraints that may have parameters (e.g. Exp[Int]).
    • update visitors accordingly
  • Ty can now contain arbitrary constraints
  • Add notion of primitive classes to the AST
  • Update constraint checking algorithm to check type parameters for primitive constraints at callable decl time
  • Update constraint generation algorithm to add additional user-specified constraints to arguments that are passed in to callables (fn constrained_ty)
  • Add completions for primitive classes to the language service
  • Adds a sample describing class constraints

tiny changes:

  • Add docstrings discretionally
  • Remove some unnecessary derives
  • Tried to clarify and unify jargon around classes, constraints, parameters, and arguments in general
  • Some expect_tests were updated in minor ways as their underlying types changed (Ty and TyParam, for example)
  • Improve an error message for MissingTy (it mentioned something about global types not being inferred when 99% of the time it does not apply to a global type, it applies to a callable parameter with a missing type)

TODO for this PR

  • Track down why duplicate constraints are getting generated
    I did not want to block reviewing this PR on this bug, since it isn't an experience breaker, but I would like to get it resolved before this goes in. Sometimes, multiple errors are rendered, and I've narrowed it down to duplicate constraints getting generated. I could store constraints in some sort of Set, so they're deduplicated, but I'd rather figure out what we are repeatedly visiting to generate those constraints instead of deduplicating afterwards. I'll be tracking this down while the PR is reviewed.

);
}

// TODO(sezna) figure out why the error message is duplicated in these tests

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note test

Suspicious comment
Copy link

github-actions bot commented Nov 5, 2024

Change in memory usage detected by benchmark.

Memory Report for f387f6f

Test This Branch On Main Difference
compile core + standard lib 19517141 bytes 17964197 bytes 1552944 bytes

Copy link

github-actions bot commented Nov 5, 2024

Change in memory usage detected by benchmark.

Memory Report for 81431fb

Test This Branch On Main Difference
compile core + standard lib 19517141 bytes 17964197 bytes 1552944 bytes

Cargo.toml Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Nov 5, 2024

Change in memory usage detected by benchmark.

Memory Report for 756cbab

Test This Branch On Main Difference
compile core + standard lib 19517141 bytes 17964197 bytes 1552944 bytes

@sezna
Copy link
Contributor Author

sezna commented Nov 5, 2024

I opened #2007 to replace this, since there are too many commits and it is hiding comments.

@sezna sezna closed this Nov 5, 2024
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.

2 participants