Skip to content

Commit 5d1ddbf

Browse files
authored
Fix the signature of Builtin.Once() to take callback with an argument, to match swift_once() (#41353)
1 parent 68f48ae commit 5d1ddbf

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

lib/AST/Builtins.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,17 +1834,14 @@ static ValueDecl *getUnreachableOperation(ASTContext &Context,
18341834
static ValueDecl *getOnceOperation(ASTContext &Context,
18351835
Identifier Id,
18361836
bool withContext) {
1837-
// (RawPointer, @convention(c) ([Context]) -> ()[, Context]) -> ()
1837+
// (RawPointer, @convention(c) (Context) -> ()[, Context]) -> ()
18381838

18391839
auto HandleTy = Context.TheRawPointerType;
18401840
auto VoidTy = Context.TheEmptyTupleType;
18411841
SmallVector<AnyFunctionType::Param, 1> CFuncParams;
1842-
swift::CanType ContextTy;
1843-
if (withContext) {
1844-
ContextTy = Context.TheRawPointerType;
1845-
auto ContextArg = FunctionType::Param(ContextTy);
1846-
CFuncParams.push_back(ContextArg);
1847-
}
1842+
swift::CanType ContextTy = Context.TheRawPointerType;
1843+
auto ContextArg = FunctionType::Param(ContextTy);
1844+
CFuncParams.push_back(ContextArg);
18481845
auto Rep = FunctionTypeRepresentation::CFunctionPointer;
18491846
auto ClangType = Context.getClangFunctionType(CFuncParams, VoidTy, Rep);
18501847
auto Thin =

test/IRGen/builtins.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func testCondFail(_ b: Bool, c: Bool) {
381381
// CHECK: call void @swift_once([[WORD]]* [[PRED_PTR]], i8* %1, i8* undef)
382382
// CHECK-objc: br label %[[DONE]]
383383

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

test/SILGen/builtins.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,11 @@ func release(ptr: Builtin.NativeObject) {
859859
// Other Operations
860860
//===----------------------------------------------------------------------===//
861861

862-
func once_helper() {}
862+
func once_helper(_ context: Builtin.RawPointer) {}
863863

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

0 commit comments

Comments
 (0)