Skip to content

Commit 1597d04

Browse files
Merge pull request #5272 from swiftwasm/main
[pull] swiftwasm from main
2 parents b222135 + 38c89bf commit 1597d04

File tree

106 files changed

+2961
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2961
-546
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ REMARK(remark_indexing_system_module,none,
271271
"%select{|; skipping because of a broken swiftinterface}1",
272272
(StringRef, bool))
273273

274+
ERROR(error_create_symbolic_interfaces_dir,none,
275+
"creating symbolic interfaces directory: %0", (StringRef))
276+
ERROR(error_symbolic_interfaces_failed_status_check,none,
277+
"failed file status check: %0", (StringRef))
278+
ERROR(error_write_symbolic_interface,none,
279+
"writing symbolic interface file: %0", (StringRef))
280+
REMARK(remark_emitting_symbolic_interface_module,none,
281+
"emitting symbolic interface at %0"
282+
"%select{|; skipping because it's up to date}1",
283+
(StringRef, bool))
284+
274285
ERROR(error_wrong_number_of_arguments,none,
275286
"wrong number of '%0' arguments (expected %1, got %2)",
276287
(StringRef, int, int))

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6681,6 +6681,8 @@ ERROR(noimplicitcopy_attr_not_allowed_on_moveonlytype,none,
66816681
"'@_noImplicitCopy' has no effect when applied to a move only type", ())
66826682
ERROR(moveonly_enums_do_not_support_indirect,none,
66836683
"move-only enum %0 cannot be marked indirect or have indirect cases yet", (Identifier))
6684+
ERROR(moveonly_cast,none,
6685+
"move-only types cannot be conditionally cast", ())
66846686

66856687
//------------------------------------------------------------------------------
66866688
// MARK: Type inference from default expressions

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ struct PrintOptions {
318318
/// Suppress emitting @available(*, noasync)
319319
bool SuppressNoAsyncAvailabilityAttr = false;
320320

321+
/// Whether to print the \c{/*not inherited*/} comment on factory initializers.
322+
bool PrintFactoryInitializerComment = true;
323+
321324
/// How to print opaque return types.
322325
enum class OpaqueReturnTypePrintingMode {
323326
/// 'some P1 & P2'.

include/swift/Basic/Features.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ EXPERIMENTAL_FEATURE(BuiltinMacros, false)
167167
/// declare an attribute which is discoverable and constructable at runtime.
168168
EXPERIMENTAL_FEATURE(RuntimeDiscoverableAttrs, false)
169169

170+
/// Import C++ class templates as semantically-meaningless symbolic
171+
/// Swift types and C++ methods as symbolic functions with blank
172+
/// signatures.
173+
EXPERIMENTAL_FEATURE(ImportSymbolicCXXDecls, false)
174+
170175
#undef EXPERIMENTAL_FEATURE
171176
#undef UPCOMING_FEATURE
172177
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

include/swift/ClangImporter/ClangImporter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ class ClangImporter final : public ClangModuleLoader {
555555
/// Emit diagnostics for declarations named name that are members
556556
/// of the provided baseType.
557557
void diagnoseMemberValue(const DeclName &name, const Type &baseType) override;
558+
559+
/// Enable the symbolic import experimental feature for the given callback.
560+
void withSymbolicFeatureEnabled(llvm::function_ref<void(void)> callback);
558561
};
559562

560563
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,
@@ -569,6 +572,13 @@ getModuleCachePathFromClang(const clang::CompilerInstance &Instance);
569572
/// Whether the given parameter name identifies a completion handler.
570573
bool isCompletionHandlerParamName(StringRef paramName);
571574

575+
namespace importer {
576+
577+
/// Returns true if the given module has a 'cplusplus' requirement.
578+
bool requiresCPlusPlus(const clang::Module *module);
579+
580+
} // namespace importer
581+
572582
} // end namespace swift
573583

574584
#endif

include/swift/IDE/ModuleInterfacePrinting.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <string>
2020
#include <vector>
2121

22+
namespace clang {
23+
class Module;
24+
}
25+
2226
namespace swift {
2327
class ASTContext;
2428
class ASTPrinter;
@@ -68,6 +72,10 @@ void printHeaderInterface(StringRef Filename, ASTContext &Ctx,
6872
void printSwiftSourceInterface(SourceFile &File, ASTPrinter &Printer,
6973
const PrintOptions &Options);
7074

75+
/// Print the symbolic Swift interface for a given imported clang module.
76+
void printSymbolicSwiftClangModuleInterface(ModuleDecl *M, ASTPrinter &Printer,
77+
const clang::Module *clangModule);
78+
7179
} // namespace ide
7280

7381
} // namespace swift

include/swift/Runtime/Bincompat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ bool useLegacyOptionalNilInjectionInCasting();
3838
/// Obj-C interop
3939
bool useLegacyObjCBoxingInCasting();
4040

41+
/// Whether to use legacy semantics when unboxing __SwiftValue
42+
bool useLegacySwiftValueUnboxingInCasting();
43+
4144
} // namespace bincompat
4245

4346
} // namespace runtime

include/swift/Runtime/Concurrency.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,13 @@ void swift_task_enqueueGlobalWithDeadline(long long sec, long long nsec,
729729
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
730730
void swift_task_enqueueMainExecutor(Job *job);
731731

732+
/// Return true if the caller is running in a Task on the passed Executor.
733+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
734+
bool swift_task_isOnExecutor(
735+
HeapObject * executor,
736+
const Metadata *selfType,
737+
const SerialExecutorWitnessTable *wtable);
738+
732739
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
733740

734741
/// Enqueue the given job on the main executor.
@@ -766,6 +773,17 @@ SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDeadline_hook)(
766773
int clock, Job *job,
767774
swift_task_enqueueGlobalWithDeadline_original original);
768775

776+
typedef SWIFT_CC(swift) bool (*swift_task_isOnExecutor_original)(
777+
HeapObject *executor,
778+
const Metadata *selfType,
779+
const SerialExecutorWitnessTable *wtable);
780+
SWIFT_EXPORT_FROM(swift_Concurrency)
781+
SWIFT_CC(swift) bool (*swift_task_isOnExecutor_hook)(
782+
HeapObject *executor,
783+
const Metadata *selfType,
784+
const SerialExecutorWitnessTable *wtable,
785+
swift_task_isOnExecutor_original original);
786+
769787
/// A hook to take over main executor enqueueing.
770788
typedef SWIFT_CC(swift) void (*swift_task_enqueueMainExecutor_original)(
771789
Job *job);

include/swift/SIL/OwnershipUtils.h

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,6 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
///
13-
/// Terminology:
14-
///
15-
/// Simple liveness:
16-
/// - Ends at lifetime-ending operations.
17-
/// - Transitively follows guaranteed forwarding operations and address uses
18-
/// within the current scope.
19-
/// - Assumes inner scopes are complete, including borrow and address scopes
20-
/// - Rarely returns AddressUseKind::PointerEscape.
21-
/// - Per-definition dominance holds
22-
/// - Insulates outer scopes from inner scope details. Maintains the
23-
/// invariant that inlining cannot pessimize optimization.
24-
///
25-
/// Transitive liveness
26-
/// - Transitively follows uses within inner scopes, including forwarding
27-
/// operations and address uses.
28-
/// - Much more likely to returns AddressUseKind::PointerEscape
29-
/// - Per-definition dominance holds
30-
/// - Does not assume that any scopes are complete.
31-
///
32-
/// Extended liveness (copy-extension and reborrow-extension)
33-
/// - Extends a live range across lifetime-ending operations
34-
/// - Depending on context: owned values are extended across copies or
35-
/// guaranteed values are extended across reborrows
36-
/// - Copy-extension is used to canonicalize an OSSA lifetime
37-
/// - Reborrow-extension is used to check borrow scopes relative to its inner
38-
/// uses and outer lifetime
39-
/// - Per-definition dominance does not hold
40-
///
41-
//===----------------------------------------------------------------------===//
4212

4313
#ifndef SWIFT_SIL_OWNERSHIPUTILS_H
4414
#define SWIFT_SIL_OWNERSHIPUTILS_H
@@ -255,6 +225,10 @@ bool findUsesOfSimpleValue(SILValue value,
255225
bool visitGuaranteedForwardingPhisForSSAValue(
256226
SILValue value, function_ref<bool(Operand *)> func);
257227

228+
//===----------------------------------------------------------------------===//
229+
// Abstractions
230+
//===----------------------------------------------------------------------===//
231+
258232
/// An operand that forwards ownership to one or more results.
259233
class ForwardingOperand {
260234
Operand *use = nullptr;
@@ -1312,13 +1286,16 @@ void visitExtendedGuaranteedForwardingPhiBaseValuePairs(
13121286
bool visitForwardedGuaranteedOperands(
13131287
SILValue value, function_ref<void(Operand *)> visitOperand);
13141288

1315-
/// Visit the phis in the same block as \p phi which are reborrows of a borrow
1316-
/// of one of the values reaching \p phi.
1289+
1290+
/// Return true of the lifetime of \p innerPhiVal depends on \p outerPhiVal.
1291+
bool isInnerAdjacentPhi(SILArgument *innerPhiVal, SILArgument *outerPhiVal);
1292+
1293+
/// Visit the phis in the same block as \p phi whose lifetime depends on \p phi.
13171294
///
13181295
/// If the visitor returns false, stops visiting and returns false. Otherwise,
13191296
/// returns true.
1320-
bool visitAdjacentReborrowsOfPhi(SILPhiArgument *phi,
1321-
function_ref<bool(SILPhiArgument *)> visitor);
1297+
bool visitInnerAdjacentPhis(SILArgument *phi,
1298+
function_ref<bool(SILArgument *)> visitor);
13221299

13231300
/// Visit each definition of a scope that immediately encloses a guaranteed
13241301
/// value. The guaranteed value effectively keeps these scopes alive.

include/swift/SIL/SILBuilder.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,22 @@ class SILBuilder {
19751975
packIndex, openedElementEnvironment));
19761976
}
19771977

1978+
PackElementGetInst *
1979+
createPackElementGet(SILLocation loc, SILValue packIndex,
1980+
SILValue pack, SILType elementType) {
1981+
return insert(PackElementGetInst::create(getFunction(),
1982+
getSILDebugLocation(loc),
1983+
packIndex, pack, elementType));
1984+
}
1985+
1986+
PackElementSetInst *
1987+
createPackElementSet(SILLocation loc, SILValue elementValue,
1988+
SILValue packIndex, SILValue pack) {
1989+
return insert(new (getModule()) PackElementSetInst(
1990+
getSILDebugLocation(loc),
1991+
elementValue, packIndex, pack));
1992+
}
1993+
19781994
ProjectBlockStorageInst *createProjectBlockStorage(SILLocation Loc,
19791995
SILValue Storage) {
19801996
auto CaptureTy = Storage->getType()

include/swift/SIL/SILCloner.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,30 @@ void SILCloner<ImplClass>::visitOpenPackElementInst(
25152515
Inst, getBuilder().createOpenPackElement(loc, newIndexValue, newEnv));
25162516
}
25172517

2518+
template <typename ImplClass>
2519+
void SILCloner<ImplClass>::visitPackElementGetInst(PackElementGetInst *Inst) {
2520+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
2521+
auto loc = getOpLocation(Inst->getLoc());
2522+
auto newIndex = getOpValue(Inst->getIndex());
2523+
auto newPack = getOpValue(Inst->getPack());
2524+
auto newElementType = getOpType(Inst->getElementType());
2525+
recordClonedInstruction(
2526+
Inst, getBuilder().createPackElementGet(loc, newIndex, newPack,
2527+
newElementType));
2528+
}
2529+
2530+
template <typename ImplClass>
2531+
void SILCloner<ImplClass>::visitPackElementSetInst(PackElementSetInst *Inst) {
2532+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
2533+
auto loc = getOpLocation(Inst->getLoc());
2534+
auto newElementValue = getOpValue(Inst->getValue());
2535+
auto newIndex = getOpValue(Inst->getIndex());
2536+
auto newPack = getOpValue(Inst->getPack());
2537+
recordClonedInstruction(
2538+
Inst, getBuilder().createPackElementSet(loc, newElementValue,
2539+
newIndex, newPack));
2540+
}
2541+
25182542
template<typename ImplClass>
25192543
void
25202544
SILCloner<ImplClass>::visitCopyBlockInst(CopyBlockInst *Inst) {

include/swift/SIL/SILInstruction.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7654,6 +7654,99 @@ class OpenPackElementInst final
76547654
}
76557655
};
76567656

7657+
/// Get the value previously stored in a pack by pack_element_set.
7658+
class PackElementGetInst final
7659+
: public InstructionBaseWithTrailingOperands<
7660+
SILInstructionKind::PackElementGetInst,
7661+
PackElementGetInst, SingleValueInstruction> {
7662+
public:
7663+
enum {
7664+
IndexOperand = 0,
7665+
PackOperand = 1
7666+
};
7667+
7668+
private:
7669+
friend SILBuilder;
7670+
7671+
PackElementGetInst(SILDebugLocation debugLoc,
7672+
ArrayRef<SILValue> allOperands,
7673+
SILType elementType)
7674+
: InstructionBaseWithTrailingOperands(allOperands, debugLoc,
7675+
elementType) {}
7676+
7677+
static PackElementGetInst *create(SILFunction &F,
7678+
SILDebugLocation debugLoc,
7679+
SILValue indexOperand,
7680+
SILValue packOperand,
7681+
SILType elementType);
7682+
7683+
public:
7684+
SILValue getIndex() const {
7685+
return getAllOperands()[IndexOperand].get();
7686+
}
7687+
7688+
SILValue getPack() const {
7689+
return getAllOperands()[PackOperand].get();
7690+
}
7691+
7692+
CanSILPackType getPackType() const {
7693+
return getPack()->getType().castTo<SILPackType>();
7694+
}
7695+
7696+
SILType getElementType() const {
7697+
return getType();
7698+
}
7699+
};
7700+
7701+
/// Set the value stored in a pack.
7702+
class PackElementSetInst
7703+
: public InstructionBase<SILInstructionKind::PackElementSetInst,
7704+
NonValueInstruction> {
7705+
public:
7706+
enum {
7707+
ValueOperand = 0,
7708+
IndexOperand = 1,
7709+
PackOperand = 2
7710+
};
7711+
7712+
private:
7713+
friend SILBuilder;
7714+
7715+
FixedOperandList<3> Operands;
7716+
7717+
PackElementSetInst(SILDebugLocation debugLoc,
7718+
SILValue valueOperand, SILValue indexOperand,
7719+
SILValue packOperand)
7720+
: InstructionBase(debugLoc),
7721+
Operands(this, valueOperand, indexOperand, packOperand) {
7722+
assert(packOperand->getType().is<SILPackType>());
7723+
}
7724+
7725+
public:
7726+
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
7727+
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
7728+
7729+
SILValue getValue() const {
7730+
return getAllOperands()[ValueOperand].get();
7731+
}
7732+
7733+
SILValue getIndex() const {
7734+
return getAllOperands()[IndexOperand].get();
7735+
}
7736+
7737+
SILValue getPack() const {
7738+
return getAllOperands()[PackOperand].get();
7739+
}
7740+
7741+
CanSILPackType getPackType() const {
7742+
return getPack()->getType().castTo<SILPackType>();
7743+
}
7744+
7745+
SILType getElementType() const {
7746+
return getValue()->getType();
7747+
}
7748+
};
7749+
76577750
/// Projects the capture storage address from a @block_storage address.
76587751
class ProjectBlockStorageInst
76597752
: public UnaryInstructionBase<SILInstructionKind::ProjectBlockStorageInst,

include/swift/SIL/SILNodes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
550550
SingleValueInstruction, None, DoesNotRelease)
551551
SINGLE_VALUE_INST(TupleElementAddrInst, tuple_element_addr,
552552
SingleValueInstruction, None, DoesNotRelease)
553+
SINGLE_VALUE_INST(PackElementGetInst, pack_element_get,
554+
SingleValueInstruction, None, DoesNotRelease)
553555
SINGLE_VALUE_INST(StructInst, struct,
554556
SingleValueInstruction, None, DoesNotRelease)
555557
SINGLE_VALUE_INST(StructExtractInst, struct_extract,
@@ -816,6 +818,8 @@ NON_VALUE_INST(EndApplyInst, end_apply,
816818
SILInstruction, MayHaveSideEffects, MayRelease)
817819
NON_VALUE_INST(AbortApplyInst, abort_apply,
818820
SILInstruction, MayHaveSideEffects, MayRelease)
821+
NON_VALUE_INST(PackElementSetInst, pack_element_set,
822+
SILInstruction, MayHaveSideEffects, DoesNotRelease)
819823

820824
// Runtime failure
821825
// FIXME: Special MemBehavior for runtime failure?

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3169,6 +3169,8 @@ static bool usesFeatureBuiltinMacros(Decl *decl) {
31693169
return false;
31703170
}
31713171

3172+
static bool usesFeatureImportSymbolicCXXDecls(Decl *decl) { return false; }
3173+
31723174
static void
31733175
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
31743176
llvm::function_ref<void()> action) {
@@ -4373,7 +4375,9 @@ void PrintAST::visitConstructorDecl(ConstructorDecl *decl) {
43734375
"unexpected convenience initializer");
43744376
}
43754377
} else if (decl->getInitKind() == CtorInitializerKind::Factory) {
4376-
Printer << "/*not inherited*/ ";
4378+
if (Options.PrintFactoryInitializerComment) {
4379+
Printer << "/*not inherited*/ ";
4380+
}
43774381
}
43784382

43794383
printContextIfNeeded(decl);

0 commit comments

Comments
 (0)