-
Notifications
You must be signed in to change notification settings - Fork 35
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
Generics - Milestone #2 #87
Open
abhishekc-sharma
wants to merge
112
commits into
ucsd-cse231-s22:2022
Choose a base branch
from
uvashishtha:main/generics
base: 2022
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Generics - Milestone #2 #87
abhishekc-sharma
wants to merge
112
commits into
ucsd-cse231-s22:2022
from
uvashishtha:main/generics
Conversation
This file contains 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
Milestone1 impl
vscode remove
test case fix
ir + constructor update
call indirect number to value
…piler-A into milestone2-impl
…op/generic-inheritance
Interop/generic inheritance
Week 8 design & conflicts
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.
Milestone 2 for Generics mainly focuses on working correctly with some of the other features.
NOTE: This PR also includes changes by the inheritance team from #83. We probably want to review and merge that one first.
What should work
Generic Functions
It is now possible to create independent functions (not within a class) that are generic. This requires that one of the parameter types is a type-variable. This then allows the return type and variables in the body to also be of that type-variable. Similar to classes, these type-variables are completely unconstrained when the function is type-checked. The instantiations of these types are inferred at the call site and the function is correspondingly monomorphized.
What probably won't work
First-Class Functions
We can now use First-Class Functions in the form of Callable types within generic classes and functions. This allows generic classes to have Callables that use type-variables as fields and parameters to functions.
What probably won't work
mklambda
inside a generic function/method. This doesn't for the sole reason that it would require traversing the entire AST in the type-checker which we didn't think was worth the additional code since this change is already somewhat substantial. We didn't need to do this earlier because type-annotations could never occur in arbitrary expressions.mklambda
changes this.Generic Inheritance
It is now possible to inherit from a class that is also generic. It is also possible to inherit from a specialization of a generic class without the subclass also being generic. Accessing the fields/methods of superclasses should be properly specialized and checked. The subtyping relationship has also now accounts for generic superclasses.
This let's us do pretty cool things like define a generic iterator library with combinators like map (but only to same type) and filter:
What probably won't work
int
,bool
, non-generic class types and type-variables. This limitation is because of the design choice to parse the superclass type-parameters as strings instead of full-fledged types.What we couldn't do
Explicit Type Annotations
We couldn't add explicit type-annotations due to the delay in merging destructuring assignment and the lack of clarity of the AST representation for expressions separated by commas.