Skip to content

Commit 5d0deaa

Browse files
committed
Add Builtin.addressOfRawLayout
1 parent efb0e1e commit 5d0deaa

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

include/swift/AST/Builtins.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,13 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(InjectEnumTag, "injectEnumTag", "", Special)
11071107
/// `any Actor` existential that refers to the local actor.
11081108
BUILTIN_MISC_OPERATION_WITH_SILGEN(DistributedActorAsAnyActor, "distributedActorAsAnyActor", "n", Special)
11091109

1110+
/// addressOfRawLayout: <T: ~Copyable>(_: borrowing T) -> Builtin.RawPointer
1111+
///
1112+
/// Returns a raw pointer to the address of the raw layout type. This address is
1113+
/// only valid during a borrow access of the raw layout type or until the value
1114+
/// is either moved or consumed.
1115+
BUILTIN_SIL_OPERATION(AddressOfRawLayout, "addressOfRawLayout", Special)
1116+
11101117
/// Builtins for instrumentation added by sanitizers during SILGen.
11111118
#ifndef BUILTIN_SANITIZER_OPERATION
11121119
#define BUILTIN_SANITIZER_OPERATION(Id, Name, Attrs) BUILTIN(Id, Name, Attrs)

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ LANGUAGE_FEATURE(ExpressionMacroDefaultArguments, 422, "Expression macro as call
170170
LANGUAGE_FEATURE(BuiltinStoreRaw, 0, "Builtin.storeRaw")
171171
LANGUAGE_FEATURE(BuiltinCreateTask, 0, "Builtin.createTask and Builtin.createDiscardingTask")
172172
SUPPRESSIBLE_LANGUAGE_FEATURE(AssociatedTypeImplements, 0, "@_implements on associated types")
173+
LANGUAGE_FEATURE(BuiltinAddressOfRawLayout, 0, "Builtin.addressOfRawLayout")
173174

174175
// Swift 6
175176
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)

lib/AST/Builtins.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,15 @@ static ValueDecl *getInjectEnumTag(ASTContext &ctx, Identifier id) {
21182118
return builder.build(id);
21192119
}
21202120

2121+
static ValueDecl *getAddressOfRawLayout(ASTContext &ctx, Identifier id) {
2122+
BuiltinFunctionBuilder builder(ctx, /* genericParamCount */ 1);
2123+
2124+
builder.addParameter(makeGenericParam(), ParamSpecifier::Borrowing);
2125+
builder.setResult(makeConcrete(ctx.TheRawPointerType));
2126+
2127+
return builder.build(id);
2128+
}
2129+
21212130
/// An array of the overloaded builtin kinds.
21222131
static const OverloadedBuiltinKind OverloadedBuiltinKinds[] = {
21232132
OverloadedBuiltinKind::None,
@@ -3191,6 +3200,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
31913200

31923201
case BuiltinValueKind::DistributedActorAsAnyActor:
31933202
return getDistributedActorAsAnyActor(Context, Id);
3203+
3204+
case BuiltinValueKind::AddressOfRawLayout:
3205+
return getAddressOfRawLayout(Context, Id);
31943206
}
31953207

31963208
llvm_unreachable("bad builtin value!");

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ static bool usesFeatureExpressionMacroDefaultArguments(Decl *decl) {
359359
}
360360

361361
UNINTERESTING_FEATURE(BuiltinStoreRaw)
362+
UNINTERESTING_FEATURE(BuiltinAddressOfRawLayout)
362363

363364
// ----------------------------------------------------------------------------
364365
// MARK: - Upcoming Features

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,21 @@ static ManagedValue emitBuiltinDistributedActorAsAnyActor(
20122012
return SGF.emitDistributedActorAsAnyActor(loc, subs, args[0]);
20132013
}
20142014

2015+
static ManagedValue emitBuiltinAddressOfRawLayout(SILGenFunction &SGF,
2016+
SILLocation loc,
2017+
SubstitutionMap subs,
2018+
ArrayRef<ManagedValue> args,
2019+
SGFContext C) {
2020+
auto &ctx = SGF.getASTContext();
2021+
2022+
auto bi = SGF.B.createBuiltin(
2023+
loc, ctx.getIdentifier(getBuiltinName(BuiltinValueKind::AddressOfRawLayout)),
2024+
SILType::getRawPointerType(ctx), subs,
2025+
{ args[0].getValue() });
2026+
2027+
return ManagedValue::forObjectRValueWithoutOwnership(bi);
2028+
}
2029+
20152030
std::optional<SpecializedEmitter>
20162031
SpecializedEmitter::forDecl(SILGenModule &SGM, SILDeclRef function) {
20172032
// Only consider standalone declarations in the Builtin module.

0 commit comments

Comments
 (0)