Skip to content

Fix the signature of Builtin.Once() to take callback with an argument, to match swift_once() #41353

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
Feb 12, 2022
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
11 changes: 4 additions & 7 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1834,17 +1834,14 @@ static ValueDecl *getUnreachableOperation(ASTContext &Context,
static ValueDecl *getOnceOperation(ASTContext &Context,
Identifier Id,
bool withContext) {
// (RawPointer, @convention(c) ([Context]) -> ()[, Context]) -> ()
// (RawPointer, @convention(c) (Context) -> ()[, Context]) -> ()

auto HandleTy = Context.TheRawPointerType;
auto VoidTy = Context.TheEmptyTupleType;
SmallVector<AnyFunctionType::Param, 1> CFuncParams;
swift::CanType ContextTy;
if (withContext) {
ContextTy = Context.TheRawPointerType;
auto ContextArg = FunctionType::Param(ContextTy);
CFuncParams.push_back(ContextArg);
}
swift::CanType ContextTy = Context.TheRawPointerType;
auto ContextArg = FunctionType::Param(ContextTy);
CFuncParams.push_back(ContextArg);
auto Rep = FunctionTypeRepresentation::CFunctionPointer;
auto ClangType = Context.getClangFunctionType(CFuncParams, VoidTy, Rep);
auto Thin =
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/builtins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func testCondFail(_ b: Bool, c: Bool) {
// CHECK: call void @swift_once([[WORD]]* [[PRED_PTR]], i8* %1, i8* undef)
// CHECK-objc: br label %[[DONE]]

func testOnce(_ p: Builtin.RawPointer, f: @escaping @convention(c) () -> ()) {
func testOnce(_ p: Builtin.RawPointer, f: @escaping @convention(c) (Builtin.RawPointer) -> ()) {
Builtin.once(p, f)
}

Expand Down
6 changes: 3 additions & 3 deletions test/SILGen/builtins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,11 @@ func release(ptr: Builtin.NativeObject) {
// Other Operations
//===----------------------------------------------------------------------===//

func once_helper() {}
func once_helper(_ context: Builtin.RawPointer) {}

// CHECK-LABEL: sil hidden [ossa] @$s8builtins4once7controlyBp_tF
// CHECK: [[T0:%.*]] = function_ref @$s8builtins11once_helperyyFTo : $@convention(c) () -> ()
// CHECK-NEXT: builtin "once"(%0 : $Builtin.RawPointer, [[T0]] : $@convention(c) () -> ())
// CHECK: [[T0:%.*]] = function_ref @$s8builtins11once_helperyyBpFTo : $@convention(c) (Builtin.RawPointer) -> ()
// CHECK-NEXT: builtin "once"(%0 : $Builtin.RawPointer, [[T0]] : $@convention(c) (Builtin.RawPointer) -> ())
func once(control: Builtin.RawPointer) {
Builtin.once(control, once_helper)
}
Expand Down