Skip to content

Conversation

@gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Jun 6, 2023

rdar://108383660

gottesmm added 11 commits June 6, 2023 12:37
…() instead of getASTType() to prevent us from looking through no implicit copy types while serializing.

This change makes sense since, in general, when serializing we do not want to
look through no implicit copy types since we are trying to 1-1 preserve the
SIL.
…h the AST serialization machinery.

This looks like a thinko from the early part of the implementation. Without
this, the machinery doesn't recognize the layout and just asserts.
…uming/Borrowing.

I also added a static_assert to make sure that we always catch this in the
future.
…e_addr.

The reason why I am using a different instruction for addresses and objects here
is that the object checker doesnt have to deal with things like initialization.
…lywrapper_addr.

Just the $*T -> $*@moveOnly T variant for addresses. Unlike the object version
this acts like a cast rather than something that provides semantics from the
frontend to the optimizer.
I am going to use this to unwrap ${ @moveOnly T } so that I can pass it to
partial_apply that expect a ${ T }
@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 6, 2023

@swift-ci smoke test

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@gottesmm gottesmm force-pushed the noimplicitcopy-borrow-consuming branch from 6b38d73 to 23b439a Compare June 6, 2023 22:11
@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 6, 2023

@swift-ci smoke test

@gottesmm gottesmm force-pushed the noimplicitcopy-borrow-consuming branch from 23b439a to 59c8cff Compare June 6, 2023 22:12
@gottesmm
Copy link
Contributor Author

gottesmm commented Jun 6, 2023

@swift-ci smoke test

Comment on lines +103 to +127
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are identical except for the isa<...> tests on the instructions. You could define one bool isPartialApplyUser(SILInstruction* user, bool isUser) and replace those tests with isa<PartialApplyInst>(...) == isUser

Comment on lines +202 to +213
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this one not suppose to raise any errors since it's not an escaping closure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I am going to fix that in a subsequent commit. This is providing the initial support. There will not be a source break when I fix it since we are removing an error.

Comment on lines +332 to 336
// We want to specifically use getASTType() here instead of getRawASTType()
// to ensure that we can correctly get our substituted field type. If we
// need to rewrap the type layer, we do it below.
substFieldTy =
getASTType()->getTypeOfMember(&TC.M, field)->getCanonicalType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside: I think we ought to do something about this getASTType / getRawASTType thing since it's a bit confusing from a naming perspective alone; the only difference is with removing any move-only wrapper. That wrapper type needs to be more widely supported, since it's now being serialized and carried through the pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From working with it, I think that the only way to do this is to have a lot of tests that exercise the behavior. If you have a better name, I am more than happy to rename it.

}
// CHECK: Doing something MyOtherName
f2()
}
Copy link
Member

@kavon kavon Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should test copy x being passed to a consuming parameter here too.

Comment on lines +318 to +328
func testAddressOnlyBorrowingEnum<T>(_ x: borrowing AddressOnlyEnum<T>) {
// expected-error @-1 {{'x' is borrowed and cannot be consumed}}
switch x { // expected-note {{consumed here}}
case let .x(y):
_ = y
break
case let .y(z):
_ = z
break
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we really need to tune these diagnostics to tell users that they can and are required to make an explicit copy.

Comment on lines +131 to +146
func testLoadableBorrowingEnum(_ x: borrowing LoadableEnum) {
// expected-error @-1 {{'x' is borrowed and cannot be consumed}}
switch x { // expected-note {{consumed here}}
case let .x(y):
_ = y
break
case .y:
break
}
}

func testLoadableBorrowingCopyOperator(_ x: borrowing NonTrivialStruct) {
_ = copy x
let _ = copy x
consumeVal(copy x)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should mix copy x into more situations to make sure its got coverage, since that's what makes it different from the noncopyable types. For example, we could take this switch test and write a positive / corrected version with switch copy x which I don't think we've tried to ensure it's fine with it.

Comment on lines +270 to +274
func testTrivialConsumingConsumeAndUseReinit(_ x: consuming TrivialStruct) {
let _ = x
x = TrivialStruct()
borrowValBorrowing(x)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something I haven't seen yet is that we're still preventing implicit copies on the parameter binding even after you've reassigned it, whether it's a consuming or borrowing parameter. Also makes me wonder what happens when you do x = x... does it require you to write x = copy x ?

Also, a test that entures we still enforce no-implicit-copy after an explicit copy of the param.

@gottesmm gottesmm merged commit 29672c5 into swiftlang:main Jun 7, 2023
@gottesmm gottesmm deleted the noimplicitcopy-borrow-consuming branch June 7, 2023 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants