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
Support resolving all kinds of expressions #726
Conversation
Tests are failing because overloading prefix |
So I figured that there's actually a way to support both behaviors: An instance overload now re-assigns and requires a compatible return type, essentially equivalent to the old behavior, while a static overload does not attempt to re-assign and behaves like any other overload, allowing any return type. |
Turned out there's another issue with overloads. Let's say we have class Foo {
@operator("+")
add(other: Foo): string {
return "add";
}
}
var foo = new Foo();
foo += foo; then this will currently assign |
Getting back to this issue I figured that half of the time we'd like to know the type of an expression, not the element. Now, while elements can be converted to types and vice-versa, that's relatively inefficient because sometimes the underlying logic yields an element and sometimes it yields a type, making it necessary to go from type to element to type for example, which quickly accumulates for sub-expressions. Appears there are two ways to solve this: One is to have separate logic for resolving elements or types and the other is reworking this stuff towards resolving types only, with separate logic to obtain a target (Local, Global, Field or Property). The latter might also get rid of workarounds like |
With the |
Yeah I guess better move iteratively and make rest refactoring wok later if everything works in this PR already. This PR pretty is important and should be landed asap I think |
Ok, this should be in a merge-able state now. Some notes for follow-up PRs:
|
Btw I wonder is this issue #573 resolved with this PR? |
In TypeScript such series produce catastrophic backtracking and seems to "compiler bomb". See microsoft/TypeScript#30833 (comment) |
#573 appears to compile fine with this, yeah. Regarding the compiler bomb scenario, this compiles without a noticeable delay: class A {
get a(): A { return this; }
}
var a = new A();
a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=a.a).a).a).a).a).a).a).a).a).a).a).a).a).a).a).a).a).a).a).a |
There might still be occasions where compilation isn't as fast as it could be, though, because this is still missing some refactoring. To recap, the underlying concern for implementing this is that the compiler currently doesn't know the type of an expression it is going to compile beforehand, leading to various issues. This PR implements the utility necessary to resolve everything before compiling anything, but in its current form focuses on enabling any sort of expression, with a follow-up looking into making this more efficient, i.e. by eliminating unnecessary steps and using the new utility where it makes compilation more efficient. |
Happy to hear we haven't this problem) Great. I'll check everything asap |
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
Documentation part is here: https://docs.assemblyscript.org/details/peculiarities#unary-prefix-operations |
Continuation of #703