Skip to content

Commit ba4cedd

Browse files
authored
Merge pull request #70582 from meg-gupta/resultdependsoninsil
Make _resultDependsOn/_resultDependsOnSelf available in SIL
2 parents 9019d07 + ce38b4d commit ba4cedd

26 files changed

+230
-114
lines changed

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ final public class FunctionArgument : Argument {
5252
public var isIndirectResult: Bool {
5353
return index < parentFunction.numIndirectResultArguments
5454
}
55+
56+
public var hasResultDependsOn : Bool {
57+
return bridged.hasResultDependsOn()
58+
}
5559
}
5660

5761
public struct Phi {

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
124124
return bridged.hasUnsafeNonEscapableResult()
125125
}
126126

127+
public var hasResultDependsOnSelf: Bool {
128+
return bridged.hasResultDependsOnSelf()
129+
}
130+
127131
/// True if the callee function is annotated with @_semantics("programtermination_point").
128132
/// This means that the function terminates the program.
129133
public var isProgramTerminationPoint: Bool { hasSemanticsAttribute("programtermination_point") }

include/swift/AST/Decl.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6396,9 +6396,11 @@ class ParamDecl : public VarDecl {
63966396

63976397
/// Whether or not this parameter is '_const'.
63986398
IsCompileTimeConst = 1 << 1,
6399+
6400+
HasResultDependsOn = 1 << 2,
63996401
};
64006402

6401-
llvm::PointerIntPair<Identifier, 2, OptionSet<ArgumentNameFlags>>
6403+
llvm::PointerIntPair<Identifier, 3, OptionSet<ArgumentNameFlags>>
64026404
ArgumentNameAndFlags;
64036405
SourceLoc ParameterNameLoc;
64046406
SourceLoc ArgumentNameLoc;
@@ -6650,13 +6652,15 @@ class ParamDecl : public VarDecl {
66506652
}
66516653

66526654
bool hasResultDependsOn() const {
6653-
return DefaultValueAndFlags.getInt().contains(Flags::IsResultDependsOn);
6655+
return ArgumentNameAndFlags.getInt().contains(
6656+
ArgumentNameFlags::HasResultDependsOn);
66546657
}
66556658

66566659
void setResultDependsOn(bool value = true) {
6657-
auto flags = DefaultValueAndFlags.getInt();
6658-
DefaultValueAndFlags.setInt(value ? flags | Flags::IsResultDependsOn
6659-
: flags - Flags::IsResultDependsOn);
6660+
auto flags = ArgumentNameAndFlags.getInt();
6661+
flags = value ? flags | ArgumentNameFlags::HasResultDependsOn
6662+
: flags - ArgumentNameFlags::HasResultDependsOn;
6663+
ArgumentNameAndFlags.setInt(flags);
66606664
}
66616665

66626666
/// Does this parameter reject temporary pointer conversions?

include/swift/AST/TypeRepr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,8 @@ class SpecifierTypeRepr : public TypeRepr {
10921092
static bool classof(const TypeRepr *T) {
10931093
return T->getKind() == TypeReprKind::Ownership ||
10941094
T->getKind() == TypeReprKind::Isolated ||
1095-
T->getKind() == TypeReprKind::CompileTimeConst;
1095+
T->getKind() == TypeReprKind::CompileTimeConst ||
1096+
T->getKind() == TypeReprKind::ResultDependsOn;
10961097
}
10971098
static bool classof(const SpecifierTypeRepr *T) { return true; }
10981099

include/swift/AST/Types.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,20 +2241,20 @@ class ParameterTypeFlags {
22412241

22422242
ParameterTypeFlags(bool variadic, bool autoclosure, bool nonEphemeral,
22432243
ParamSpecifier specifier, bool isolated, bool noDerivative,
2244-
bool compileTimeConst)
2244+
bool compileTimeConst, bool hasResultDependsOn)
22452245
: value((variadic ? Variadic : 0) | (autoclosure ? AutoClosure : 0) |
22462246
(nonEphemeral ? NonEphemeral : 0) |
2247-
uint8_t(specifier) << SpecifierShift |
2248-
(isolated ? Isolated : 0) |
2247+
uint8_t(specifier) << SpecifierShift | (isolated ? Isolated : 0) |
22492248
(noDerivative ? NoDerivative : 0) |
2250-
(compileTimeConst ? CompileTimeConst : 0)){}
2249+
(compileTimeConst ? CompileTimeConst : 0) |
2250+
(hasResultDependsOn ? ResultDependsOn : 0)) {}
22512251

22522252
/// Create one from what's present in the parameter type
22532253
inline static ParameterTypeFlags
22542254
fromParameterType(Type paramTy, bool isVariadic, bool isAutoClosure,
22552255
bool isNonEphemeral, ParamSpecifier ownership,
2256-
bool isolated, bool isNoDerivative,
2257-
bool compileTimeConst);
2256+
bool isolated, bool isNoDerivative, bool compileTimeConst,
2257+
bool hasResultDependsOn);
22582258

22592259
bool isNone() const { return !value; }
22602260
bool isVariadic() const { return value.contains(Variadic); }
@@ -2421,7 +2421,8 @@ class YieldTypeFlags {
24212421
/*autoclosure*/ false,
24222422
/*nonEphemeral*/ false, getOwnershipSpecifier(),
24232423
/*isolated*/ false, /*noDerivative*/ false,
2424-
/*compileTimeConst*/false);
2424+
/*compileTimeConst*/ false,
2425+
/*hasResultDependsOn*/ false);
24252426
}
24262427

24272428
bool operator ==(const YieldTypeFlags &other) const {
@@ -7517,7 +7518,7 @@ inline TupleTypeElt TupleTypeElt::getWithType(Type T) const {
75177518
inline ParameterTypeFlags ParameterTypeFlags::fromParameterType(
75187519
Type paramTy, bool isVariadic, bool isAutoClosure, bool isNonEphemeral,
75197520
ParamSpecifier ownership, bool isolated, bool isNoDerivative,
7520-
bool compileTimeConst) {
7521+
bool compileTimeConst, bool hasResultDependsOn) {
75217522
// FIXME(Remove InOut): The last caller that needs this is argument
75227523
// decomposition. Start by enabling the assertion there and fixing up those
75237524
// callers, then remove this, then remove
@@ -7527,8 +7528,8 @@ inline ParameterTypeFlags ParameterTypeFlags::fromParameterType(
75277528
ownership == ParamSpecifier::InOut);
75287529
ownership = ParamSpecifier::InOut;
75297530
}
7530-
return {isVariadic, isAutoClosure, isNonEphemeral, ownership, isolated,
7531-
isNoDerivative, compileTimeConst};
7531+
return {isVariadic, isAutoClosure, isNonEphemeral, ownership,
7532+
isolated, isNoDerivative, compileTimeConst, hasResultDependsOn};
75327533
}
75337534

75347535
inline const Type *BoundGenericType::getTrailingObjectsPointer() const {

include/swift/Parse/Parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,9 +1449,9 @@ class Parser {
14491449

14501450
TypeRepr *applyAttributeToType(TypeRepr *Ty, const TypeAttributes &Attr,
14511451
ParamDecl::Specifier Specifier,
1452-
SourceLoc SpecifierLoc,
1453-
SourceLoc IsolatedLoc,
1454-
SourceLoc ConstLoc);
1452+
SourceLoc SpecifierLoc, SourceLoc IsolatedLoc,
1453+
SourceLoc ConstLoc,
1454+
SourceLoc ResultDependsOnLoc);
14551455

14561456
//===--------------------------------------------------------------------===//
14571457
// Pattern Parsing

include/swift/SIL/SILArgument.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,15 @@ class SILFunctionArgument : public SILArgument {
366366
ValueOwnershipKind ownershipKind, const ValueDecl *decl = nullptr,
367367
bool isNoImplicitCopy = false,
368368
LifetimeAnnotation lifetimeAnnotation = LifetimeAnnotation::None,
369-
bool isCapture = false,
370-
bool isParameterPack = false)
369+
bool isCapture = false, bool isParameterPack = false,
370+
bool hasResultDependsOn = false)
371371
: SILArgument(ValueKind::SILFunctionArgument, parentBlock, type,
372372
ownershipKind, decl) {
373373
sharedUInt32().SILFunctionArgument.noImplicitCopy = isNoImplicitCopy;
374374
sharedUInt32().SILFunctionArgument.lifetimeAnnotation = lifetimeAnnotation;
375375
sharedUInt32().SILFunctionArgument.closureCapture = isCapture;
376376
sharedUInt32().SILFunctionArgument.parameterPack = isParameterPack;
377+
sharedUInt32().SILFunctionArgument.hasResultDependsOn = hasResultDependsOn;
377378
}
378379

379380
// A special constructor, only intended for use in
@@ -425,6 +426,14 @@ class SILFunctionArgument : public SILArgument {
425426
sharedUInt32().SILFunctionArgument.lifetimeAnnotation = newValue;
426427
}
427428

429+
bool hasResultDependsOn() const {
430+
return sharedUInt32().SILFunctionArgument.hasResultDependsOn;
431+
}
432+
433+
void setHasResultDependsOn(bool flag = true) {
434+
sharedUInt32().SILFunctionArgument.hasResultDependsOn = flag;
435+
}
436+
428437
Lifetime getLifetime() const {
429438
return getType()
430439
.getLifetime(*getFunction())

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ struct BridgedFunction {
418418
BRIDGED_INLINE bool isGenericFunction() const;
419419
BRIDGED_INLINE bool hasSemanticsAttr(BridgedStringRef attrName) const;
420420
BRIDGED_INLINE bool hasUnsafeNonEscapableResult() const;
421+
BRIDGED_INLINE bool hasResultDependsOnSelf() const;
421422
BRIDGED_INLINE EffectsKind getEffectAttribute() const;
422423
BRIDGED_INLINE PerformanceConstraints getPerformanceConstraints() const;
423424
BRIDGED_INLINE InlineStrategy getInlineStrategy() const;
@@ -810,6 +811,7 @@ struct BridgedArgument {
810811
BRIDGED_INLINE BridgedArgumentConvention getConvention() const;
811812
BRIDGED_INLINE bool isSelf() const;
812813
BRIDGED_INLINE bool isReborrow() const;
814+
BRIDGED_INLINE bool hasResultDependsOn() const;
813815
};
814816

815817
struct OptionalBridgedArgument {

include/swift/SIL/SILBridgingImpl.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,13 @@ bool BridgedArgument::isSelf() const {
430430
return fArg->isSelf();
431431
}
432432

433-
bool BridgedArgument::isReborrow() const {
434-
return getArgument()->isReborrow();
433+
bool BridgedArgument::hasResultDependsOn() const {
434+
auto *fArg = static_cast<swift::SILFunctionArgument*>(getArgument());
435+
return fArg->hasResultDependsOn();
435436
}
436437

438+
bool BridgedArgument::isReborrow() const { return getArgument()->isReborrow(); }
439+
437440
//===----------------------------------------------------------------------===//
438441
// BridgedSubstitutionMap
439442
//===----------------------------------------------------------------------===//
@@ -588,6 +591,10 @@ bool BridgedFunction::hasUnsafeNonEscapableResult() const {
588591
return getFunction()->hasUnsafeNonEscapableResult();
589592
}
590593

594+
bool BridgedFunction::hasResultDependsOnSelf() const {
595+
return getFunction()->hasResultDependsOnSelf();
596+
}
597+
591598
BridgedFunction::EffectsKind BridgedFunction::getEffectAttribute() const {
592599
return (EffectsKind)getFunction()->getEffectsKind();
593600
}

include/swift/SIL/SILFunction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ class SILFunction
443443
/// lifetime-dependence on an argument.
444444
unsigned HasUnsafeNonEscapableResult : 1;
445445

446+
unsigned HasResultDependsOnSelf : 1;
447+
446448
static void
447449
validateSubclassScope(SubclassScope scope, IsThunk_t isThunk,
448450
const GenericSpecializationInformation *genericInfo) {
@@ -727,6 +729,11 @@ class SILFunction
727729
HasUnsafeNonEscapableResult = value;
728730
}
729731

732+
bool hasResultDependsOnSelf() const { return HasResultDependsOnSelf; }
733+
734+
void setHasResultDependsOnSelf(bool flag = true) {
735+
HasResultDependsOnSelf = flag;
736+
}
730737
/// Returns true if this is a reabstraction thunk of escaping function type
731738
/// whose single argument is a potentially non-escaping closure. i.e. the
732739
/// thunks' function argument may itself have @inout_aliasable parameters.

0 commit comments

Comments
 (0)