-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[InterfaceGen] Only print 'mutating' and 'nonmutating' on accessors #19459
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
[InterfaceGen] Only print 'mutating' and 'nonmutating' on accessors #19459
Conversation
2ddf52b
to
bd1e0ff
Compare
test/ModuleInterface/modifiers.swift
Outdated
// CHECK-NEXT: {{^}} @objc get | ||
// CHECK-NEXT: set[[NEWVALUE]] {} | ||
// CHECK-NEXT: } | ||
public @objc dynamic var d: Int { |
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.
Uh. You shouldn't be able to mix attributes in the middle of modifiers like this…
Also, please do add tests for mutating get
and nonmutating set
, now that it's come up.
6f7fad5
to
1d66ef3
Compare
@swift-ci please smoke test |
1d66ef3
to
b53fd33
Compare
@swift-ci please smoke test |
lib/AST/ASTPrinter.cpp
Outdated
auto ctxType = ASD->getDeclContext()->getDeclaredInterfaceType(); | ||
return !ASD->isSetterMutating() && | ||
ASD->isInstanceMember() && | ||
!ctxType->hasReferenceSemantics(); |
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.
@slavapestov, there's not really a better way to do this check that'll handle constrained protocol extensions, right?
(Also, the ASD->isInstanceMember
check isn't quite right; if it's a non-instance member, it might still have a nonmutating setter. I think it's !A && (!B || !C)
.)
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 is the same logic that was factored out of PrintAST::printAccessors
, but I think you're right about the logic being wrong.
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.
Turns out several tests were relying on the existing behavior 😞
lib/AST/ASTPrinter.cpp
Outdated
if (asd->getGetter() == D && hasMutatingGetter(asd)) | ||
Printer << "mutating "; | ||
if (asd->getSetter() == D && hasNonMutatingSetter(accessor->getStorage())) | ||
Printer << "nonmutating "; |
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.
Nitpick: printKeyword
.
4a64948
to
da75805
Compare
test/IDE/print_ast_tc_decls.swift
Outdated
// PASS_RW_PROP_GET_SET-NEXT: {{^}} static var extStaticProp: Int { get set }{{$}} | ||
// PASS_RW_PROP_NO_GET_SET-NEXT: {{^}} static var extStaticProp: Int{{$}} | ||
// PASS_RW_PROP_GET_SET-NEXT: {{^}} static var extStaticProp: Int { get nonmutating set }{{$}} | ||
// PASS_RW_PROP_NO_GET_SET-NEXT: {{^}} static var extStaticProp: Int { get nonmutating set }{{$}} |
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.
@jrose-apple What do you think about fallout like this?
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 incorrect; those are mutating sets.
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.
D'oh. You're right.
1013ef1
to
cd70f0f
Compare
@swift-ci please smoke test |
@jrose-apple I think this is correct now. |
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.
Whew, I think this is finally it.
lib/AST/Decl.cpp
Outdated
case AccessorKind::Modify: | ||
return false; | ||
} | ||
llvm_unreachable("bad addressor kind"); |
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.
Copy/paste error:"addressor" instead of "accessor". Also, the switch statement is over-indented.
test/ModuleInterface/modifiers.swift
Outdated
// RUN: %FileCheck %s < %t/Test.swiftinterface | ||
// RUN: %target-swift-frontend -emit-module -o /dev/null -merge-modules %t/Test.swiftmodule -disable-objc-attr-requires-foundation-module -emit-interface-path - -module-name Test | %FileCheck %s | ||
|
||
// REQUIRES: objc_interop |
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.
Instead of this, Saleem's been having us put -enable-objc-interop
in the RUN lines. That works as long as you don't need the ObjC runtime.
cd70f0f
to
b7ecb92
Compare
@swift-ci please smoke test |
test/SILGen/dynamic_accessors.swift
Outdated
|
||
@inlinable public func foo() { | ||
let x = MyObjCClass() | ||
// CHECK: objc_method %{{[0-9]+}} : $MyObjCClass, #MyObjCClass.a!getter.1.foreign |
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.
@jrose-apple Do you think this test is sufficient? It runs on the SIL from both the original source and the generated interface.
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'd add a check for a subscript too, but other than that yes, this looks good.
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.
Done.
b7da13f
to
cafda8a
Compare
cafda8a
to
161ea99
Compare
test/SILGen/dynamic_accessors.swift
Outdated
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -emit-module -o /dev/null -disable-objc-attr-requires-foundation-module -emit-interface-path %t/dynamic_accessors.swiftinterface %s | ||
// RUN: %target-swift-emit-silgen -disable-objc-attr-requires-foundation-module %s | %FileCheck %s | ||
// RUN: %target-swift-frontend -emit-silgen -disable-objc-attr-requires-foundation-module %t/dynamic_accessors.swiftinterface | %FileCheck %s |
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.
Missing -enable-objc-interop
on these. (I'm checking because I just got bitten by it.)
@swift-ci please smoke test |
This PR restricts the allowed set of implicit contextual decl modifiers on accessors to just 'mutating' and 'nonmutating'.
This comes up because we'll print
dynamic
on accessors, so the previous patch to disallowfinal
is insufficient.