Skip to content

Fix SILGenFunction::emitBasicProlog for @lifetime with default args. #78539

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
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,9 +1643,12 @@ uint16_t SILGenFunction::emitBasicProlog(
emitIndirectErrorParameter(*this, *errorType, *origErrorType, DC);
}

// Parameters with scoped dependencies may lower differently.
// Parameters with scoped dependencies may lower differently. Parameters are
// relative to the current SILGenFunction, not the passed in DeclContext. For
// example, the an argument initializer's DeclContext is the enclosing
// function definition rather that the initializer's generator function.
llvm::SmallPtrSet<ParamDecl *, 2> scopedDependencyParams;
if (auto afd = dyn_cast<AbstractFunctionDecl>(DC)) {
if (auto afd = dyn_cast<AbstractFunctionDecl>(FunctionDC)) {
if (auto deps = afd->getLifetimeDependencies()) {
for (auto &dep : *deps) {
auto scoped = dep.getScopeIndices();
Expand Down
10 changes: 9 additions & 1 deletion test/SILGen/addressable_for_dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Foo { var x: String }
struct Bar { var foo: Foo }

struct Dep: ~Escapable {
var x: Int
var x: Int = 0

@lifetime(immortal)
init() { }
Expand Down Expand Up @@ -98,3 +98,11 @@ extension Bar {
return bar.dependencyOnSelf()
}
}

// CHECK-LABEL: sil {{.*}}@$s28addressable_for_dependencies14defaulArgument1iySi_tFfA_ :
// CHECK-SAME: $@convention(thin) () -> Int {

// CHECK-LABEL: sil {{.*}}@$s28addressable_for_dependencies14defaulArgument1iySi_tF :
// CHECK-SAME: $@convention(thin) (Int) -> @lifetime(borrow 0) () {
@lifetime(borrow i)
func defaulArgument(i: Int = 0) {}