Skip to content

Commit d3e921d

Browse files
committed
Make _resultDependsOn available on SILFunctionArgument
1 parent d6871ed commit d3e921d

File tree

17 files changed

+99
-68
lines changed

17 files changed

+99
-68
lines changed

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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,14 @@ class SILFunctionArgument : public SILArgument {
367367
bool isNoImplicitCopy = false,
368368
LifetimeAnnotation lifetimeAnnotation = LifetimeAnnotation::None,
369369
bool isCapture = false,
370-
bool isParameterPack = false)
370+
bool isParameterPack = false, 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/SILNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class alignas(8) SILNode :
306306
SHARED_FIELD(PointerToAddressInst, uint32_t alignment);
307307
SHARED_FIELD(SILFunctionArgument, uint32_t noImplicitCopy : 1,
308308
lifetimeAnnotation : 2, closureCapture : 1,
309-
parameterPack : 1);
309+
parameterPack : 1, hasResultDependsOn : 1);
310310

311311
// Do not use `_sharedUInt32_private` outside of SILNode.
312312
} _sharedUInt32_private;

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4529,7 +4529,7 @@ static void printParameterFlags(ASTPrinter &printer,
45294529
printer.printKeyword("isolated", options, " ");
45304530

45314531
if (flags.hasResultDependsOn())
4532-
printer.printKeyword("resultDependsOn", options, " ");
4532+
printer.printKeyword("_resultDependsOn", options, " ");
45334533

45344534
if (!options.excludeAttrKind(TAK_escaping) && escaping)
45354535
printer.printKeyword("@escaping", options, " ");

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8364,9 +8364,9 @@ AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
83648364
auto label = getArgumentName();
83658365
auto internalLabel = getParameterName();
83668366
auto flags = ParameterTypeFlags::fromParameterType(
8367-
type, isVariadic(), isAutoClosure(), isNonEphemeral(),
8368-
getSpecifier(), isIsolated(), /*isNoDerivative*/ false,
8369-
isCompileTimeConst());
8367+
type, isVariadic(), isAutoClosure(), isNonEphemeral(), getSpecifier(),
8368+
isIsolated(), /*isNoDerivative*/ false, isCompileTimeConst(),
8369+
hasResultDependsOn());
83708370
return AnyFunctionType::Param(type, label, flags, internalLabel);
83718371
}
83728372

lib/Parse/ParsePattern.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ mapParsedParameters(Parser &parser,
580580
param->setIsolated(true);
581581
else if (isa<CompileTimeConstTypeRepr>(STR))
582582
param->setCompileTimeConst(true);
583-
583+
else if (isa<ResultDependsOnTypeRepr>(STR))
584+
param->setResultDependsOn(true);
584585
unwrappedType = STR->getBase();
585586
continue;
586587
}

lib/Parse/ParseType.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131

3232
using namespace swift;
3333

34-
TypeRepr *Parser::applyAttributeToType(TypeRepr *ty,
35-
const TypeAttributes &attrs,
36-
ParamDecl::Specifier specifier,
37-
SourceLoc specifierLoc,
38-
SourceLoc isolatedLoc,
39-
SourceLoc constLoc) {
34+
TypeRepr *
35+
Parser::applyAttributeToType(TypeRepr *ty, const TypeAttributes &attrs,
36+
ParamDecl::Specifier specifier,
37+
SourceLoc specifierLoc, SourceLoc isolatedLoc,
38+
SourceLoc constLoc, SourceLoc resultDependsOnLoc) {
4039
// Apply those attributes that do apply.
4140
if (!attrs.empty()) {
4241
ty = new (Context) AttributedTypeRepr(attrs, ty);
@@ -57,6 +56,10 @@ TypeRepr *Parser::applyAttributeToType(TypeRepr *ty,
5756
ty = new (Context) CompileTimeConstTypeRepr(ty, constLoc);
5857
}
5958

59+
if (resultDependsOnLoc.isValid()) {
60+
ty = new (Context) ResultDependsOnTypeRepr(ty, resultDependsOnLoc);
61+
}
62+
6063
return ty;
6164
}
6265

@@ -385,10 +388,9 @@ ParserResult<TypeRepr> Parser::parseSILBoxType(GenericParamList *generics,
385388
auto repr = SILBoxTypeRepr::create(Context, generics,
386389
LBraceLoc, Fields, RBraceLoc,
387390
LAngleLoc, Args, RAngleLoc);
388-
return makeParserResult(applyAttributeToType(repr, attrs,
389-
ParamDecl::Specifier::LegacyOwned,
390-
SourceLoc(), SourceLoc(),
391-
SourceLoc()));
391+
return makeParserResult(
392+
applyAttributeToType(repr, attrs, ParamDecl::Specifier::LegacyOwned,
393+
SourceLoc(), SourceLoc(), SourceLoc(), SourceLoc()));
392394
}
393395

394396

@@ -594,9 +596,8 @@ ParserResult<TypeRepr> Parser::parseTypeScalar(
594596
}
595597

596598
return makeParserResult(
597-
status,
598-
applyAttributeToType(tyR, attrs, specifier, specifierLoc, isolatedLoc,
599-
constLoc));
599+
status, applyAttributeToType(tyR, attrs, specifier, specifierLoc,
600+
isolatedLoc, constLoc, resultDependsOnLoc));
600601
}
601602

602603
/// parseType

0 commit comments

Comments
 (0)