Skip to content

Commit 02759d1

Browse files
committed
[move-only] Add methods to AbstractionPattern to add/remove the move only bit.
The names are AbstractionPattern::with{,out}MoveOnly().
1 parent c66061a commit 02759d1

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

include/swift/SIL/AbstractionPattern.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,14 @@ class AbstractionPattern {
13371337
llvm_unreachable("bad kind");
13381338
}
13391339

1340+
/// Given that the value being abstracted is a move only type, return the
1341+
/// abstraction pattern with the move only bit removed.
1342+
AbstractionPattern withoutMoveOnly() const;
1343+
1344+
/// Given that the value being abstracted is not a move only type, return the
1345+
/// abstraction pattern with the move only bit added.
1346+
AbstractionPattern withMoveOnly() const;
1347+
13401348
/// Given that the value being abstracted is a tuple type, return
13411349
/// the abstraction pattern for its object type.
13421350
AbstractionPattern getTupleElementType(unsigned index) const;

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,80 @@ AbstractionPattern::getTupleElementType(unsigned index) const {
416416
llvm_unreachable("bad kind");
417417
}
418418

419+
AbstractionPattern AbstractionPattern::withoutMoveOnly() const {
420+
switch (getKind()) {
421+
case Kind::Invalid:
422+
llvm_unreachable("querying invalid abstraction pattern!");
423+
case Kind::PartialCurriedObjCMethodType:
424+
case Kind::CurriedObjCMethodType:
425+
case Kind::PartialCurriedCFunctionAsMethodType:
426+
case Kind::CurriedCFunctionAsMethodType:
427+
case Kind::CFunctionAsMethodType:
428+
case Kind::ObjCMethodType:
429+
case Kind::CXXMethodType:
430+
case Kind::CurriedCXXMethodType:
431+
case Kind::PartialCurriedCXXMethodType:
432+
case Kind::CXXOperatorMethodType:
433+
case Kind::CurriedCXXOperatorMethodType:
434+
case Kind::PartialCurriedCXXOperatorMethodType:
435+
case Kind::OpaqueFunction:
436+
case Kind::OpaqueDerivativeFunction:
437+
llvm_unreachable("function types can not be move only");
438+
case Kind::ClangType:
439+
llvm_unreachable("clang types can not be move only yet");
440+
case Kind::ObjCCompletionHandlerArgumentsType:
441+
llvm_unreachable("not handled yet");
442+
case Kind::Discard:
443+
llvm_unreachable("operation not needed on discarded abstractions yet");
444+
case Kind::Opaque:
445+
case Kind::Tuple:
446+
case Kind::Type:
447+
if (auto mvi = dyn_cast<SILMoveOnlyType>(getType())) {
448+
return AbstractionPattern(getGenericSignature(), mvi->getInnerType());
449+
}
450+
return *this;
451+
}
452+
453+
llvm_unreachable("bad kind");
454+
}
455+
456+
AbstractionPattern AbstractionPattern::withMoveOnly() const {
457+
switch (getKind()) {
458+
case Kind::Invalid:
459+
llvm_unreachable("querying invalid abstraction pattern!");
460+
case Kind::PartialCurriedObjCMethodType:
461+
case Kind::CurriedObjCMethodType:
462+
case Kind::PartialCurriedCFunctionAsMethodType:
463+
case Kind::CurriedCFunctionAsMethodType:
464+
case Kind::CFunctionAsMethodType:
465+
case Kind::ObjCMethodType:
466+
case Kind::CXXMethodType:
467+
case Kind::CurriedCXXMethodType:
468+
case Kind::PartialCurriedCXXMethodType:
469+
case Kind::CXXOperatorMethodType:
470+
case Kind::CurriedCXXOperatorMethodType:
471+
case Kind::PartialCurriedCXXOperatorMethodType:
472+
case Kind::OpaqueFunction:
473+
case Kind::OpaqueDerivativeFunction:
474+
llvm_unreachable("function types can not be move only");
475+
case Kind::ClangType:
476+
llvm_unreachable("clang types can not be move only yet");
477+
case Kind::ObjCCompletionHandlerArgumentsType:
478+
llvm_unreachable("not handled yet");
479+
case Kind::Discard:
480+
llvm_unreachable("operation not needed on discarded abstractions yet");
481+
case Kind::Opaque:
482+
case Kind::Tuple:
483+
case Kind::Type:
484+
if (isa<SILMoveOnlyType>(getType()))
485+
return *this;
486+
return AbstractionPattern(getGenericSignature(),
487+
SILMoveOnlyType::get(getType()));
488+
}
489+
490+
llvm_unreachable("bad kind");
491+
}
492+
419493
/// Return a pattern corresponding to the 'self' parameter of the given
420494
/// Objective-C method.
421495
AbstractionPattern

0 commit comments

Comments
 (0)