-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Finish up SE-0096 #3888
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
Finish up SE-0096 #3888
Conversation
|
@swift-ci please smoke test. |
test/Parse/type_expr.swift
Outdated
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.
Will fix this once I get a CI status for this build.
|
@jtbandes Thank you for alerting me of the user shadowing of |
lib/Parse/ParseExpr.cpp
Outdated
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.
Does this mean: x.dynamicType doesn't form DynamicTypeExpr any more?
Since sizeof(x.dynamicType) used to be commonly used,
I want to provide fix-it for it in #3883, that relies on DynamicTypeExpr.
Second round fix-it is probably OK:
sizeof(x.dynamicType) => sizeof(type(of: x)) => MemoryLayout<TypeOfX>.size.
Anyway, if so, I think I should adjust #3883 code.
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.
x.dynamicType is removed from the language. type(of: x) forms a DynamicTypeExpr.
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.
If it causes you too much pain it can probably be removed. Much as I think it's nice to have this migration aid, the user will receive a "no such member" error even if it isn't here which should be hint enough that dynamicType is gone. A special cased note can be added to Sema to diagnose this too.
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.
IMO, we should parse and build AST as much as possible.
I tried this PR locally:
func foo<T>(_: T.Type) {}
let x = 1
foo(x.dynamicType)result:
test3888.swift:3:6: error: '.dynamicType' is deprecated. Use 'type(of: ...)' instead
foo(x.dynamicType)
^~~~~~~~~~~~
type(of: )
test3888.swift:3:1: error: cannot invoke 'foo' with an argument list of type '(Int)'
foo(x.dynamicType)
^
test3888.swift:3:1: note: expected an argument list of type '(T.Type)'
foo(x.dynamicType)
^
In this case, I think, we should not emit the second error.
Since x.dynamicType doesn't form DynamicTypeExpr, but just UnresolvedDeclRefExpr of x, TypeChecker cannot know the intended type of x.dynamicType.
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.
Or, could you stop consuming the token here, and remove continue; at the next line, so that it fall back to UnresolvedDotExpr?
That way, result:
test3888.swift:3:6: error: '.dynamicType' is deprecated. Use 'type(of: ...)' instead
foo(x.dynamicType)
^~~~~~~~~~~~
type(of: )
test3888.swift:3:5: error: value of type 'Int' has no member 'dynamicType'
foo(x.dynamicType)
^ ~~~~~~~~~~~
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.
That's a fantastic idea. It now falls through to that. Hope that helps your patch
|
@swift-ci please smoke test. |
Be laxer about the parsing for type(of:) so as not to get in the way of other declarations that may use ‘type’ as their base name.
9eb2300 to
d4f0250
Compare
|
@swift-ci please smoke test. |
|
@swift-ci please smoke test. |
|
Speaking of shadowing, is there anything preventing someone from writing It seems like it would be ideal to put this function in the standard library, even if its actual implementation is replaced by the compiler via some magical hack. I don't know if that's even feasible, though. |
|
So even if we could put this in stdlib right now why is shadowing this thing a worthwhile feature to have? What use-case could you have for overloading a language primitive? |
|
I don't think shadowing would really be a good idea for user code, just that there might be code existing today which is weirdly broken by this. It should either allow shadowing (in which case |
|
I'm more concerned about the use case that @rintaro brings up than this. If the user has overloaded |
|
@swift-ci please smoke test. |
What's in this pull request?
dynamicTypeis no longer a keyword. There is, however, a diagnostic that will aid migration so usage ofdynamicTypeas an identifier for a static variable is still banned. The parser is also strict about the kind of spelling it will accept fortype(of:)and will backtrack if it cannot parse such an expression so we don't step on user's toes.Resolved bug number: (SR-)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.