Skip to content

Commit 30041a4

Browse files
authored
Merge pull request #60968 from apple/egorzhdan/scs-sildebuglocation
[cxx-interop][SwiftCompilerSources] Use `swift::SILDebugLocation` instead of `BridgedLocation`
2 parents 8a146bc + 3dc584e commit 30041a4

File tree

6 files changed

+62
-78
lines changed

6 files changed

+62
-78
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ function(add_swift_compiler_modules_library name)
126126
get_versioned_target_triple(target ${SWIFT_HOST_VARIANT_SDK}
127127
${SWIFT_HOST_VARIANT_ARCH} "${deployment_version}")
128128

129+
# Let Swift discover SwiftShims headers which are included by some headers
130+
# under `include/swift`.
131+
get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
132+
set(sdk_option ${sdk_option} "-I" "${swift_exec_bin_dir}/../lib")
133+
129134
set(all_obj_files)
130135
set(all_module_targets)
131136
set(syntaxparse_obj_files)

SwiftCompilerSources/Sources/SIL/Location.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import SILBridging
1414

1515
public struct Location {
16-
let bridged: BridgedLocation
16+
let bridged: swift.SILDebugLocation
1717

1818
/// Keeps the debug scope but marks it as auto-generated.
1919
public var autoGenerated: Location {

include/swift/SIL/SILBridging.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "swift/Basic/BasicBridging.h"
1717
#include "swift/Basic/BridgedSwiftObject.h"
18+
#include "swift/SIL/SILLocation.h"
1819
#include <stdbool.h>
1920
#include <stddef.h>
2021
#include <string>
@@ -39,12 +40,6 @@ typedef struct {
3940
const void * _Nonnull opaqueCtxt;
4041
} BridgedPassContext;
4142

42-
typedef struct {
43-
void * _Null_unspecified word0;
44-
void * _Null_unspecified word1;
45-
void * _Null_unspecified word2;
46-
} BridgedLocation;
47-
4843
typedef struct {
4944
void * _Nullable typePtr;
5045
} BridgedType;
@@ -166,7 +161,7 @@ typedef struct {
166161
typedef struct {
167162
OptionalBridgedInstruction insertBefore;
168163
OptionalBridgedBasicBlock insertAtEnd;
169-
BridgedLocation loc;
164+
swift::SILDebugLocation loc;
170165
} BridgedBuilder;
171166

172167
// Must be in sync with SILInstruction::MemoryBehavior
@@ -337,7 +332,8 @@ SwiftInt SILType_getCaseIdxOfEnumType(BridgedType type,
337332

338333
BridgedSubstitutionMap SubstitutionMap_getEmpty();
339334

340-
BridgedLocation SILLocation_getAutogeneratedLocation(BridgedLocation loc);
335+
swift::SILDebugLocation
336+
SILLocation_getAutogeneratedLocation(swift::SILDebugLocation loc);
341337

342338
BridgedBasicBlock SILArgument_getParent(BridgedArgument argument);
343339
BridgedArgumentConvention SILArgument_getConvention(BridgedArgument argument);
@@ -348,7 +344,7 @@ BridgedBasicBlock SILInstruction_getParent(BridgedInstruction inst);
348344
BridgedArrayRef SILInstruction_getOperands(BridgedInstruction inst);
349345
void SILInstruction_setOperand(BridgedInstruction inst, SwiftInt index,
350346
BridgedValue value);
351-
BridgedLocation SILInstruction_getLocation(BridgedInstruction inst);
347+
swift::SILDebugLocation SILInstruction_getLocation(BridgedInstruction inst);
352348
BridgedMemoryBehavior SILInstruction_getMemBehavior(BridgedInstruction inst);
353349
bool SILInstruction_mayRelease(BridgedInstruction inst);
354350

include/swift/SIL/SILBridgingUtils.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@
2525

2626
namespace swift {
2727

28-
inline SILLocation getSILLocation(BridgedLocation loc) {
29-
return reinterpret_cast<SILDebugLocation *>(&loc)->getLocation();
30-
}
31-
32-
inline RegularLocation getRegularLocation(BridgedLocation loc) {
33-
return RegularLocation(getSILLocation(loc));
34-
}
35-
36-
inline const SILDebugScope *getSILDebugScope(BridgedLocation loc) {
37-
return reinterpret_cast<SILDebugLocation *>(&loc)->getScope();
38-
}
39-
4028
inline SILType getSILType(BridgedType ty) {
4129
return SILType::getFromOpaqueValue(ty.typePtr);
4230
}
@@ -49,10 +37,6 @@ inline SILValue castToSILValue(BridgedValue value) {
4937
return static_cast<ValueBase *>(value.obj);
5038
}
5139

52-
inline SILDebugLocation castToDebugLocation(BridgedLocation loc) {
53-
return *reinterpret_cast<SILDebugLocation *>(&loc);
54-
}
55-
5640
inline SILType castToSILType(BridgedType type) {
5741
return SILType::getFromOpaqueValue(type.typePtr);
5842
}

include/swift/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module ASTBridging {
1616

1717
module SILBridging {
1818
header "SIL/SILBridging.h"
19+
header "SIL/SILLocation.h"
1920
requires cplusplus
2021
export *
2122
}

lib/SIL/Utils/SILBridging.cpp

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ SwiftMetatype SILNode::getSILNodeMetatype(SILNodeKind kind) {
3737
return metatype;
3838
}
3939

40-
static_assert(sizeof(BridgedLocation) == sizeof(SILDebugLocation),
41-
"BridgedLocation has wrong size");
42-
4340
/// Fills \p storage with all Values from the bridged \p values array.
4441
ArrayRef<SILValue> swift::getSILValues(BridgedValueArray values,
4542
SmallVectorImpl<SILValue> &storage) {
@@ -565,10 +562,10 @@ BridgedSubstitutionMap SubstitutionMap_getEmpty() {
565562
// SILLocation
566563
//===----------------------------------------------------------------------===//
567564

568-
BridgedLocation SILLocation_getAutogeneratedLocation(BridgedLocation loc) {
565+
SILDebugLocation SILLocation_getAutogeneratedLocation(SILDebugLocation loc) {
569566
SILDebugLocation autoGenLoc(RegularLocation::getAutoGeneratedLocation(),
570-
castToDebugLocation(loc).getScope());
571-
return *reinterpret_cast<BridgedLocation *>(&autoGenLoc);
567+
loc.getScope());
568+
return autoGenLoc;
572569
}
573570

574571
//===----------------------------------------------------------------------===//
@@ -721,9 +718,8 @@ void SILInstruction_setOperand(BridgedInstruction inst, SwiftInt index,
721718
castToInst(inst)->setOperand((unsigned)index, castToSILValue(value));
722719
}
723720

724-
BridgedLocation SILInstruction_getLocation(BridgedInstruction inst) {
725-
SILDebugLocation loc = castToInst(inst)->getDebugLocation();
726-
return *reinterpret_cast<BridgedLocation *>(&loc);
721+
SILDebugLocation SILInstruction_getLocation(BridgedInstruction inst) {
722+
return castToInst(inst)->getDebugLocation();
727723
}
728724

729725
BridgedMemoryBehavior SILInstruction_getMemBehavior(BridgedInstruction inst) {
@@ -972,51 +968,52 @@ BridgedInstruction SILBuilder_createBuiltinBinaryFunction(
972968
BridgedType operandType, BridgedType resultType,
973969
BridgedValueArray arguments) {
974970
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
975-
getSILDebugScope(b.loc));
971+
b.loc.getScope());
976972
SmallVector<SILValue, 16> argValues;
977-
return {builder.createBuiltinBinaryFunction(getRegularLocation(b.loc),
978-
name, getSILType(operandType), getSILType(resultType),
979-
getSILValues(arguments, argValues))};
973+
return {builder.createBuiltinBinaryFunction(
974+
RegularLocation(b.loc.getLocation()), name, getSILType(operandType),
975+
getSILType(resultType), getSILValues(arguments, argValues))};
980976
}
981977

982978
BridgedInstruction SILBuilder_createCondFail(BridgedBuilder b,
983979
BridgedValue condition, StringRef message) {
984980
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
985-
getSILDebugScope(b.loc));
986-
return {builder.createCondFail(getRegularLocation(b.loc),
981+
b.loc.getScope());
982+
return {builder.createCondFail(RegularLocation(b.loc.getLocation()),
987983
castToSILValue(condition), message)};
988984
}
989985

990986
BridgedInstruction SILBuilder_createIntegerLiteral(BridgedBuilder b,
991987
BridgedType type, SwiftInt value) {
992988
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
993-
getSILDebugScope(b.loc));
994-
return {builder.createIntegerLiteral(getRegularLocation(b.loc),
989+
b.loc.getScope());
990+
return {builder.createIntegerLiteral(RegularLocation(b.loc.getLocation()),
995991
getSILType(type), value)};
996992
}
997993

998994
BridgedInstruction SILBuilder_createAllocStack(BridgedBuilder b,
999995
BridgedType type, SwiftInt hasDynamicLifetime, SwiftInt isLexical,
1000996
SwiftInt wasMoved) {
1001997
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1002-
getSILDebugScope(b.loc));
1003-
return {builder.createAllocStack(getRegularLocation(b.loc), getSILType(type),
1004-
None, hasDynamicLifetime != 0, isLexical != 0, wasMoved != 0)};
998+
b.loc.getScope());
999+
return {builder.createAllocStack(
1000+
RegularLocation(b.loc.getLocation()), getSILType(type), None,
1001+
hasDynamicLifetime != 0, isLexical != 0, wasMoved != 0)};
10051002
}
10061003

10071004
BridgedInstruction SILBuilder_createDeallocStack(BridgedBuilder b,
10081005
BridgedValue operand) {
10091006
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1010-
getSILDebugScope(b.loc));
1011-
return {builder.createDeallocStack(getRegularLocation(b.loc),
1007+
b.loc.getScope());
1008+
return {builder.createDeallocStack(RegularLocation(b.loc.getLocation()),
10121009
castToSILValue(operand))};
10131010
}
10141011

10151012
BridgedInstruction SILBuilder_createDeallocStackRef(BridgedBuilder b,
10161013
BridgedValue operand) {
10171014
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1018-
getSILDebugScope(b.loc));
1019-
return {builder.createDeallocStackRef(getRegularLocation(b.loc),
1015+
b.loc.getScope());
1016+
return {builder.createDeallocStackRef(RegularLocation(b.loc.getLocation()),
10201017
castToSILValue(operand))};
10211018
}
10221019

@@ -1025,17 +1022,17 @@ SILBuilder_createUncheckedRefCast(BridgedBuilder b,
10251022
BridgedValue op,
10261023
BridgedType type) {
10271024
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1028-
getSILDebugScope(b.loc));
1029-
return {builder.createUncheckedRefCast(getRegularLocation(b.loc),
1025+
b.loc.getScope());
1026+
return {builder.createUncheckedRefCast(RegularLocation(b.loc.getLocation()),
10301027
castToSILValue(op), getSILType(type))};
10311028
}
10321029

10331030
BridgedInstruction SILBuilder_createSetDeallocating(BridgedBuilder b,
10341031
BridgedValue op, bool isAtomic) {
10351032
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1036-
getSILDebugScope(b.loc));
1033+
b.loc.getScope());
10371034
return {builder.createSetDeallocating(
1038-
getRegularLocation(b.loc), castToSILValue(op),
1035+
RegularLocation(b.loc.getLocation()), castToSILValue(op),
10391036
isAtomic ? RefCountingInst::Atomicity::Atomic
10401037
: RefCountingInst::Atomicity::NonAtomic)};
10411038
}
@@ -1044,34 +1041,35 @@ BridgedInstruction
10441041
SILBuilder_createFunctionRef(BridgedBuilder b,
10451042
BridgedFunction function) {
10461043
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1047-
getSILDebugScope(b.loc));
1048-
return {builder.createFunctionRef(getRegularLocation(b.loc),
1044+
b.loc.getScope());
1045+
return {builder.createFunctionRef(RegularLocation(b.loc.getLocation()),
10491046
castToFunction(function))};
10501047
}
10511048

10521049
BridgedInstruction SILBuilder_createCopyValue(BridgedBuilder b,
10531050
BridgedValue op) {
10541051
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1055-
getSILDebugScope(b.loc));
1056-
return {builder.createCopyValue(getRegularLocation(b.loc),
1052+
b.loc.getScope());
1053+
return {builder.createCopyValue(RegularLocation(b.loc.getLocation()),
10571054
castToSILValue(op))};
10581055
}
10591056

10601057
BridgedInstruction SILBuilder_createCopyAddr(BridgedBuilder b,
10611058
BridgedValue from, BridgedValue to,
10621059
SwiftInt takeSource, SwiftInt initializeDest) {
10631060
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1064-
getSILDebugScope(b.loc));
1065-
return {builder.createCopyAddr(getRegularLocation(b.loc), castToSILValue(from),
1066-
castToSILValue(to), IsTake_t(takeSource != 0),
1067-
IsInitialization_t(initializeDest != 0))};
1061+
b.loc.getScope());
1062+
return {builder.createCopyAddr(RegularLocation(b.loc.getLocation()),
1063+
castToSILValue(from), castToSILValue(to),
1064+
IsTake_t(takeSource != 0),
1065+
IsInitialization_t(initializeDest != 0))};
10681066
}
10691067

10701068
BridgedInstruction SILBuilder_createDestroyValue(BridgedBuilder b,
10711069
BridgedValue op) {
10721070
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1073-
getSILDebugScope(b.loc));
1074-
return {builder.createDestroyValue(getRegularLocation(b.loc),
1071+
b.loc.getScope());
1072+
return {builder.createDestroyValue(RegularLocation(b.loc.getLocation()),
10751073
castToSILValue(op))};
10761074
}
10771075

@@ -1080,11 +1078,11 @@ BridgedInstruction SILBuilder_createApply(BridgedBuilder b,
10801078
BridgedSubstitutionMap subMap,
10811079
BridgedValueArray arguments) {
10821080
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1083-
getSILDebugScope(b.loc));
1081+
b.loc.getScope());
10841082
SmallVector<SILValue, 16> argValues;
1085-
return {builder.createApply(getRegularLocation(b.loc), castToSILValue(function),
1086-
castToSubstitutionMap(subMap),
1087-
getSILValues(arguments, argValues))};
1083+
return {builder.createApply(
1084+
RegularLocation(b.loc.getLocation()), castToSILValue(function),
1085+
castToSubstitutionMap(subMap), getSILValues(arguments, argValues))};
10881086
}
10891087

10901088
static EnumElementDecl *getEnumElement(SILType enumType, int caseIndex) {
@@ -1100,12 +1098,11 @@ BridgedInstruction SILBuilder_createUncheckedEnumData(BridgedBuilder b,
11001098
BridgedValue enumVal, SwiftInt caseIdx,
11011099
BridgedType resultType) {
11021100
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1103-
getSILDebugScope(b.loc));
1101+
b.loc.getScope());
11041102
SILValue en = castToSILValue(enumVal);
1105-
return {builder.createUncheckedEnumData(getRegularLocation(b.loc),
1106-
castToSILValue(enumVal),
1107-
getEnumElement(en->getType(), caseIdx),
1108-
castToSILType(resultType))};
1103+
return {builder.createUncheckedEnumData(
1104+
RegularLocation(b.loc.getLocation()), castToSILValue(enumVal),
1105+
getEnumElement(en->getType(), caseIdx), castToSILType(resultType))};
11091106
}
11101107

11111108
BridgedInstruction SILBuilder_createSwitchEnumInst(BridgedBuilder b,
@@ -1114,7 +1111,7 @@ BridgedInstruction SILBuilder_createSwitchEnumInst(BridgedBuilder b,
11141111
const void * _Nullable enumCases,
11151112
SwiftInt numEnumCases) {
11161113
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1117-
getSILDebugScope(b.loc));
1114+
b.loc.getScope());
11181115
using BridgedCase = const std::pair<SwiftInt, BridgedBasicBlock>;
11191116
ArrayRef<BridgedCase> cases(static_cast<BridgedCase *>(enumCases),
11201117
(unsigned)numEnumCases);
@@ -1129,7 +1126,7 @@ BridgedInstruction SILBuilder_createSwitchEnumInst(BridgedBuilder b,
11291126
assert(mappedElements.count(c.first) && "wrong enum element index");
11301127
convertedCases.push_back({mappedElements[c.first], castToBasicBlock(c.second)});
11311128
}
1132-
return {builder.createSwitchEnum(getRegularLocation(b.loc),
1129+
return {builder.createSwitchEnum(RegularLocation(b.loc.getLocation()),
11331130
castToSILValue(enumVal),
11341131
castToBasicBlock(defaultBlock), convertedCases)};
11351132
}
@@ -1138,8 +1135,9 @@ BridgedInstruction SILBuilder_createBranch(
11381135
BridgedBuilder b, BridgedBasicBlock destBlock,
11391136
BridgedValueArray arguments) {
11401137
SILBuilder builder(castToInst(b.insertBefore), castToBasicBlock(b.insertAtEnd),
1141-
getSILDebugScope(b.loc));
1138+
b.loc.getScope());
11421139
SmallVector<SILValue, 16> argValues;
1143-
return {builder.createBranch(getRegularLocation(b.loc),
1144-
castToBasicBlock(destBlock), getSILValues(arguments, argValues))};
1140+
return {builder.createBranch(RegularLocation(b.loc.getLocation()),
1141+
castToBasicBlock(destBlock),
1142+
getSILValues(arguments, argValues))};
11451143
}

0 commit comments

Comments
 (0)