-
Notifications
You must be signed in to change notification settings - Fork 70
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 define-type-alias
#1294
base: main
Are you sure you want to change the base?
Add define-type-alias
#1294
Conversation
I think this PR should be blocked on a complete and tested implementation. I am sympathetic to incomplete library additions, but language features need to be complete and bullet-proof. |
I think it would be a good idea to add some documentation in these files:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some initial thoughts. Not a full review.
COALTON-USER> (type-of 'shifted-coordinate) | ||
(TUPLE INTEGER INTEGER) | ||
|
||
COALTON-USER> (describe-type-of 'shifted-coordinate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these functions and their output may need some workshopping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any feedback as far as what is good/bad about them?
@YarinHeffes Can you update the PR description with an up-to-date account of the PR? |
"remove unnecessary parentheses"))) | ||
|
||
;; (define-type-alias (name type-variables+) ...) | ||
(loop :for vars := (cst:rest (cst:second form)) :then (cst:rest vars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check that the tyvars are unique
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This takes place during the type checking phase, similar to define-struct
and define-type
src/typechecker/define-type.lisp
Outdated
(let* ((defined-variables (mapcar #'parser:keyword-src-name (parser:type-definition-vars parsed-type))) | ||
(used-variables (mapcar #'tc:tyvar-id (tc:type-variables aliased-type))) | ||
(unused-variables (loop :for tyvar :in defined-variables | ||
:when (not (member (tc:tyvar-id (partial-type-env-lookup-var partial-env tyvar parsed-type)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly shorted code: when not
=> unless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 8619ceb
src/typechecker/define-type.lisp
Outdated
(tc-note parsed-type "Type alias ~S defines unused type variable~P ~{:~A~^ ~}" | ||
(parser:identifier-src-name (parser:type-definition-name parsed-type)) | ||
number-of-unused-variables | ||
(mapcar (lambda (str) (subseq str 0 (- (length str) (1+ (position #\- (reverse str)))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(position a b :from-end t)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 8619ceb
src/typechecker/define-type.lisp
Outdated
@@ -420,6 +465,12 @@ | |||
`(member ,@(mapcar #'tc:constructor-entry-compressed-repr ctors))) | |||
(t | |||
name)) | |||
:aliased-type (let ((parser-aliased-type | |||
(parser:type-definition-aliased-type type))) | |||
(when parser-aliased-type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer if
if the value is load-bearing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 8619ceb
@@ -69,6 +70,12 @@ | |||
(predicates (util:required 'predicates) :type ty-predicate-list :read-only t) | |||
(type (util:required 'type) :type ty :read-only t)) | |||
|
|||
(defun qualified-ty= (qualified-ty1 qualified-ty2) | |||
(and (equalp (qualified-ty-predicates qualified-ty1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the predicates have different orders? is that possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would need to look more into this. However, we were previously using equalp
for equality, so this change should not break anything/change any pre-existing behavior.
@@ -71,7 +74,8 @@ | |||
;;; Types | |||
;;; | |||
|
|||
(defstruct (ty (:constructor nil))) | |||
(defstruct (ty (:constructor nil)) | |||
(alias nil :type (or null ty-list) :read-only nil)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe in a comment what this field is and when it shoes up. Give an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a comment that this could be a weak hash table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 8619ceb
src/typechecker/types.lisp
Outdated
(tgen-id type2))) | ||
|
||
(:method (type1 type2) | ||
(declare (ignore type1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore can have multiple entries: (declare (ignore a b))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 8619ceb
This is an implementation of type aliases, including:
simple aliases:
(define-type-alias Coordinate Integer)
aliases of aliases:
and readable printing in error messages.
The implementation also supports parametric type aliases
Currently, since
the
does not change types except by substituting type-variables,will compile, but it will not store the alias
Coordinate
for the variablex
, and it will not display in error messages.The functions
describe-type-alias
anddescribe-type-of
are implemented to display the definition of a type alias and the aliases of a defined symbol, respectively.