Skip to content

Support for address based array initialization under opaque values mode #7470

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

Merged

Conversation

shajrawi
Copy link

@shajrawi shajrawi commented Feb 14, 2017

part of rdar://problem/30080769

We have to keep (some) address operations on existentials unless we change the way we initialize arrays:

Consider the following code-patern:

%3 = apply %2<Any>(%1) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
%5 = tuple_extract %3 : $(Array<Any>, Builtin.RawPointer)
%6 = pointer_to_address %5 : $Builtin.RawPointer to [strict] $*Any
%7 = init_existential_addr %6 : $*Any, $Int
%10 = integer_literal $Builtin.Int2048, 3,
%11 = apply %8(%10, %9) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
store %11 to [trivial] %7 : $*Int
%13 = apply %0(%4) : $@convention(thin) (@owned Array<Any>) -> ()

Above we are initializing an array of any, we have a pointer to the array’s storage (which is actually a memory address), the init_existential_addr instruction initializes the array’s storage before we store the integer literal ‘3’ into it.

Adding a new init_existential instruction that takes an opaque value does not make any sense in here, we have to keep using the _addr instruction and deal with addresses.

This patch enables the pattern described above in opaque values mode.

@shajrawi
Copy link
Author

@swift-ci Please smoke test

@@ -2965,12 +2965,15 @@ namespace {
// it's not already there. (Note that this potentially includes
// conventions which pass indirectly without transferring
// ownership, like Itanium C++.)
if (SGF.silConv.isSILIndirect(param)) {
if (SGF.silConv.isSILIndirect(param) || specialDest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a tad convoluted. Would it work to do this?

if (specialDest) {
  emitIndirectInto
  Args.push
  return
}
if (isSILIndirect) {
  emitIndirect
  Args.push
  return
}

Copy link
Author

Choose a reason for hiding this comment

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

Done - updated PR

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Some small comments.

emitIndirectInto(std::move(arg), origParamType,
loweredSubstParamType, *specialDest);
Args.push_back(ManagedValue::forInContext());
} else {
assert(SGF.silConv.isSILIndirect(param));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an && message here?

Copy link
Author

Choose a reason for hiding this comment

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

That assert was removed in updated PR - added && message to the new asserts

// CHECK: apply %{{.*}}<Any>(%{{.*}}) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
// CHECK: tuple_extract %{{.*}} : $(Array<Any>, Builtin.RawPointer)
// CHECK: pointer_to_address %{{.*}} : $Builtin.RawPointer to [strict] $*Any
// CHECK: init_existential_addr %{{.*}} : $*Any, $Int
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add more precise FileCheck lines here? I prefer to use register matching like:

[[FOO:%.*]]

Also can you use a } // end sil function '' check to make sure that we do not match lines below?

I have run into many of these issues in SILGen = /.

Copy link
Author

Choose a reason for hiding this comment

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

Done - updated test case in PR

@shajrawi shajrawi force-pushed the var_args_SpecialDest_opaque_mode branch from 6d13bff to 90dfd7f Compare February 14, 2017 21:27
@shajrawi
Copy link
Author

@swift-ci Please smoke test

// CHECK: %[[APY:.*]] = apply %{{.*}}<Any>(%{{.*}}) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
// CHECK: %[[BRW:.*]] = begin_borrow %[[APY]]
// CHECK: %[[TPL:.*]] = tuple_extract %[[BRW]] : $(Array<Any>, Builtin.RawPointer), 1
// CHECK: %[[PTR:.*]] = pointer_to_address %[[TPL]] : $Builtin.RawPointer to [strict] $*Any
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add more to the test case for ownership. Specifically, can you make sure that we are ending the borrow and properly destroying APY?

Copy link
Author

Choose a reason for hiding this comment

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

Done

@shajrawi shajrawi force-pushed the var_args_SpecialDest_opaque_mode branch from 90dfd7f to 0e8e6d7 Compare February 14, 2017 21:46
@shajrawi shajrawi force-pushed the var_args_SpecialDest_opaque_mode branch from 0e8e6d7 to 03d55cd Compare February 14, 2017 21:47
@shajrawi
Copy link
Author

@swift-ci Please smoke test

@shajrawi shajrawi merged commit 2b8dfaf into swiftlang:master Feb 14, 2017
@shajrawi shajrawi deleted the var_args_SpecialDest_opaque_mode branch February 14, 2017 22:39
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