-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Expr.asTerm
#10694
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 Expr.asTerm
#10694
Conversation
Should we also replace TypeRepr.of and TypeTree.of ? |
No, |
I meant |
a9ea7c8
to
53f0bcc
Compare
I don't really understand what contextual means here, could you give an example of what would go wrong if we tried defining |
It means we only have the name of the type All that is unrelated with the change in this PR. |
This PR addresses the main usability concern described in #10685 while keeping an intention based naming convention. |
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.
LGTM
To echo the concern raised by @smarter , maybe we should do the same for Type[T]
for consistency.
/** Returns the `Tree` representation this expression. | ||
* Same as `asTerm` but typed as a `Tree`. | ||
*/ | ||
def asTree: Tree |
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.
An Expr[T]
is always a Term
, and Term <: Tree
, maybe asTerm
is sufficient.
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.
It is sufficient. I added this one because it is an intuitive name. Maybe it is better to remove it. Users can always define their extension method that does the same in a couple of lines of they prefer asTree
in their use cases. It can also be added back in a future version of the library.
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 it's better to remove and only keep asTerm
. For IDE support, the two versions make no difference, which is different from the case for size
and length
.
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 will remove asTree
We cannot do the same for |
5d46d33
to
bbb5209
Compare
* Add `Expr.asTerm` under `reflect` * Deprecate `Tree.of` and `Term.of` for simpler migration from M2 to M3 This change make the intent of the operation clearer. We call `asTerm` to see the expression as a `Term` just like we call `asExpr` make the `Term` and `Expr[Any]`. t It will simplify code that needs to acceess the trees. As these are extension methods, they can also be accessed explicilty using `reflect.asTerm(expr)` which can be useful in some situations. Remove asTree
bbb5209
to
257716e
Compare
Expr.asTerm
underreflect
Tree.of
andTerm.of
for simpler migration from M2 to M3This change make the intent of the operation clearer. We call
asTerm
to see the expression as aTerm
just like we callasExpr
make theTerm
andExpr[Any]
.It will simplify code that needs to access the trees.
As these are extension methods, they can also be accessed explicitly using
reflect.asTerm(expr)
orreflect.asTree(expr)
which can be useful in some situations.