Skip to content

Commit 6a03dca

Browse files
authored
Merge pull request #3581 from swiftwasm/main
[pull] swiftwasm from main
2 parents 137b664 + 2c4f360 commit 6a03dca

File tree

68 files changed

+1789
-368
lines changed

Some content is hidden

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

68 files changed

+1789
-368
lines changed

docs/StandardLibraryProgrammersManual.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,28 @@ For historical reasons, the existing codebase generally uses `internal` as the c
7272

7373
Every entry point in the standard library that has an ABI impact must be applied an `@available` attribute that describes the earliest ABI-stable OS releases that it can be deployed on. (Currently this only applies to macOS, iOS, watchOS and tvOS, since Swift isn't ABI stable on other platforms yet.)
7474

75-
Unlike access control modifiers, we prefer to put `@available` attributes on the extension context rather than duplicating them on every individual entry point. This is an effort to fight against information overload: the `@available` attribute is information dense and it's generally easier to review/maintain if applied to a group of entry points all at once.
75+
Just like access control modifiers, we prefer to put `@available` attributes on each individual access point, rather than just the extension in which they are defined.
7676

7777
```swift
78-
// 👍
78+
// 😢👎
7979
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
8080
extension String {
8181
public func blanch() { ... }
8282
public func roast() { ... }
8383
}
84+
85+
// 🥲👍
86+
extension String {
87+
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
88+
public func blanch() { ... }
89+
90+
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
91+
public func roast() { ... }
92+
}
8493
```
8594

95+
This coding style is enforced by the ABI checker -- it will complain if an extension member declaration that needs an availability doesn't have it directly attached.
96+
8697
Features under development that haven't been released yet must be marked with the placeholder version number `9999`. This special version is always considered available in custom builds of the Swift toolchain (including development snapshots), but not in any ABI-stable production release.
8798

8899
```swift

include/swift/AST/ClangModuleLoader.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace swift {
3333

3434
class Decl;
3535
class DeclContext;
36+
class EffectiveClangContext;
37+
class SwiftLookupTable;
3638
class VisibleDeclConsumer;
3739

3840
/// Represents the different namespaces for types in C.
@@ -177,6 +179,9 @@ class ClangModuleLoader : public ModuleLoader {
177179
StringRef relatedEntityKind,
178180
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
179181

182+
/// Imports a clang decl directly, rather than looking up its name.
183+
virtual Decl *importDeclDirectly(const clang::NamedDecl *decl) = 0;
184+
180185
/// Instantiate and import class template using given arguments.
181186
///
182187
/// This method will find the clang::ClassTemplateSpecialization decl if
@@ -241,6 +246,21 @@ class ClangModuleLoader : public ModuleLoader {
241246

242247
virtual Type importFunctionReturnType(const clang::FunctionDecl *clangDecl,
243248
DeclContext *dc) = 0;
249+
250+
/// Find the lookup table that corresponds to the given Clang module.
251+
///
252+
/// \param clangModule The module, or null to indicate that we're talking
253+
/// about the directly-parsed headers.
254+
virtual SwiftLookupTable *
255+
findLookupTable(const clang::Module *clangModule) = 0;
256+
257+
virtual DeclName
258+
importName(const clang::NamedDecl *D,
259+
clang::DeclarationName givenName = clang::DeclarationName()) = 0;
260+
261+
/// Determine the effective Clang context for the given Swift nominal type.
262+
EffectiveClangContext virtual getEffectiveClangContext(
263+
const NominalTypeDecl *nominal) = 0;
244264
};
245265

246266
/// Describes a C++ template instantiation error.

include/swift/Basic/LangOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ namespace swift {
463463

464464
/// Whether the new experimental generics implementation is enabled.
465465
RequirementMachineMode EnableRequirementMachine =
466-
RequirementMachineMode::Disabled;
466+
RequirementMachineMode::Enabled;
467467

468468
/// Enables dumping rewrite systems from the requirement machine.
469469
bool DumpRequirementMachine = false;
@@ -670,6 +670,10 @@ namespace swift {
670670
/// Options for controlling the behavior of the Clang importer.
671671
class ClangImporterOptions final {
672672
public:
673+
/// The path to the Clang compiler executable.
674+
/// Used to detect the default include paths.
675+
std::string clangPath = "clang";
676+
673677
/// The module cache path which the Clang importer should use.
674678
std::string ModuleCachePath;
675679

include/swift/ClangImporter/ClangImporter.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ class ClangModuleUnit;
6262
class ClangNode;
6363
class Decl;
6464
class DeclContext;
65+
class EffectiveClangContext;
6566
class EnumDecl;
6667
class ImportDecl;
6768
class IRGenOptions;
6869
class ModuleDecl;
6970
class NominalTypeDecl;
7071
class StructDecl;
72+
class SwiftLookupTable;
7173
class TypeDecl;
7274
class VisibleDeclConsumer;
7375
enum class SelectorSplitKind;
@@ -457,11 +459,12 @@ class ClangImporter final : public ClangModuleLoader {
457459
/// Given a Clang module, decide whether this module is imported already.
458460
static bool isModuleImported(const clang::Module *M);
459461

460-
DeclName importName(const clang::NamedDecl *D,
461-
clang::DeclarationName givenName);
462+
DeclName importName(
463+
const clang::NamedDecl *D,
464+
clang::DeclarationName givenName = clang::DeclarationName()) override;
462465

463466
Type importFunctionReturnType(const clang::FunctionDecl *clangDecl,
464-
DeclContext *dc) override;
467+
DeclContext *dc) override;
465468

466469
Optional<std::string>
467470
getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
@@ -493,6 +496,19 @@ class ClangImporter final : public ClangModuleLoader {
493496
SubstitutionMap subst) override;
494497

495498
bool isCXXMethodMutating(const clang::CXXMethodDecl *method) override;
499+
500+
/// Find the lookup table that corresponds to the given Clang module.
501+
///
502+
/// \param clangModule The module, or null to indicate that we're talking
503+
/// about the directly-parsed headers.
504+
SwiftLookupTable *findLookupTable(const clang::Module *clangModule) override;
505+
506+
/// Determine the effective Clang context for the given Swift nominal type.
507+
EffectiveClangContext
508+
getEffectiveClangContext(const NominalTypeDecl *nominal) override;
509+
510+
/// Imports a clang decl directly, rather than looking up it's name.
511+
Decl *importDeclDirectly(const clang::NamedDecl *decl) override;
496512
};
497513

498514
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,

include/swift/SIL/SILBridging.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ typedef struct {
5050
const void * _Nonnull opaqueCtxt;
5151
} BridgedPassContext;
5252

53+
typedef struct {
54+
void * _Nonnull streamAddr;
55+
} BridgedOStream;
56+
5357
typedef struct {
5458
void * _Null_unspecified word0;
5559
void * _Null_unspecified word1;
@@ -139,6 +143,8 @@ typedef long SwiftInt;
139143

140144
void registerBridgedClass(BridgedStringRef className, SwiftMetatype metatype);
141145

146+
void OStream_write(BridgedOStream os, BridgedStringRef str);
147+
142148
void freeBridgedStringRef(BridgedStringRef str);
143149

144150
void PassContext_notifyChanges(BridgedPassContext passContext,
@@ -155,6 +161,8 @@ BridgedStringRef SILFunction_getName(BridgedFunction function);
155161
std::string SILFunction_debugDescription(BridgedFunction function);
156162
OptionalBridgedBasicBlock SILFunction_firstBlock(BridgedFunction function);
157163
OptionalBridgedBasicBlock SILFunction_lastBlock(BridgedFunction function);
164+
SwiftInt SILFunction_numIndirectResultArguments(BridgedFunction function);
165+
SwiftInt SILFunction_getSelfArgumentIndex(BridgedFunction function);
158166

159167
BridgedStringRef SILGlobalVariable_getName(BridgedGlobalVar global);
160168
std::string SILGlobalVariable_debugDescription(BridgedGlobalVar global);
@@ -175,12 +183,14 @@ BridgedInstruction SILSuccessor_getContainingInst(BridgedSuccessor succ);
175183
BridgedValue Operand_getValue(BridgedOperand);
176184
OptionalBridgedOperand Operand_nextUse(BridgedOperand);
177185
BridgedInstruction Operand_getUser(BridgedOperand);
186+
SwiftInt Operand_isTypeDependent(BridgedOperand);
178187

179188
std::string SILNode_debugDescription(BridgedNode node);
180189
OptionalBridgedOperand SILValue_firstUse(BridgedValue value);
181190
BridgedType SILValue_getType(BridgedValue value);
182191

183192
SwiftInt SILType_isAddress(BridgedType);
193+
SwiftInt SILType_isTrivial(BridgedType, BridgedFunction);
184194

185195
BridgedBasicBlock SILArgument_getParent(BridgedArgument argument);
186196

@@ -216,6 +226,7 @@ SwiftInt TryApplyInst_numArguments(BridgedInstruction ai);
216226
BridgedBasicBlock BranchInst_getTargetBlock(BridgedInstruction bi);
217227
SwiftInt SwitchEnumInst_getNumCases(BridgedInstruction se);
218228
SwiftInt SwitchEnumInst_getCaseIndex(BridgedInstruction se, SwiftInt idx);
229+
SwiftInt StoreInst_getStoreOwnership(BridgedInstruction store);
219230

220231
BridgedInstruction SILBuilder_createBuiltinBinaryFunction(
221232
BridgedInstruction insertionPoint,

include/swift/SIL/SILNodes.def

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
449449
SINGLE_VALUE_INST_RANGE(AllocationInst, AllocStackInst, AllocExistentialBoxInst)
450450

451451
ABSTRACT_SINGLE_VALUE_INST(IndexingInst, SingleValueInstruction)
452-
SINGLE_VALUE_INST(IndexAddrInst, index_addr,
453-
IndexingInst, None, DoesNotRelease)
452+
BRIDGED_SINGLE_VALUE_INST(IndexAddrInst, index_addr,
453+
IndexingInst, None, DoesNotRelease)
454454
SINGLE_VALUE_INST(TailAddrInst, tail_addr,
455455
IndexingInst, None, DoesNotRelease)
456456
SINGLE_VALUE_INST(IndexRawPointerInst, index_raw_pointer,
@@ -481,16 +481,16 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
481481

482482
// Dynamic Dispatch
483483
ABSTRACT_SINGLE_VALUE_INST(MethodInst, SingleValueInstruction)
484-
SINGLE_VALUE_INST(ClassMethodInst, class_method,
485-
MethodInst, None, DoesNotRelease)
486-
SINGLE_VALUE_INST(SuperMethodInst, super_method,
487-
MethodInst, None, DoesNotRelease)
488-
SINGLE_VALUE_INST(ObjCMethodInst, objc_method,
489-
MethodInst, None, DoesNotRelease)
490-
SINGLE_VALUE_INST(ObjCSuperMethodInst, objc_super_method,
491-
MethodInst, None, DoesNotRelease)
492-
SINGLE_VALUE_INST(WitnessMethodInst, witness_method,
493-
MethodInst, None, DoesNotRelease)
484+
BRIDGED_SINGLE_VALUE_INST(ClassMethodInst, class_method,
485+
MethodInst, None, DoesNotRelease)
486+
BRIDGED_SINGLE_VALUE_INST(SuperMethodInst, super_method,
487+
MethodInst, None, DoesNotRelease)
488+
BRIDGED_SINGLE_VALUE_INST(ObjCMethodInst, objc_method,
489+
MethodInst, None, DoesNotRelease)
490+
BRIDGED_SINGLE_VALUE_INST(ObjCSuperMethodInst, objc_super_method,
491+
MethodInst, None, DoesNotRelease)
492+
BRIDGED_SINGLE_VALUE_INST(WitnessMethodInst, witness_method,
493+
MethodInst, None, DoesNotRelease)
494494
SINGLE_VALUE_INST_RANGE(MethodInst, ClassMethodInst, WitnessMethodInst)
495495

496496
// Conversions
@@ -499,7 +499,7 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
499499
ConversionInst, None, DoesNotRelease)
500500
BRIDGED_SINGLE_VALUE_INST(AddressToPointerInst, address_to_pointer,
501501
ConversionInst, None, DoesNotRelease)
502-
SINGLE_VALUE_INST(PointerToAddressInst, pointer_to_address,
502+
BRIDGED_SINGLE_VALUE_INST(PointerToAddressInst, pointer_to_address,
503503
ConversionInst, None, DoesNotRelease)
504504
BRIDGED_SINGLE_VALUE_INST(UncheckedRefCastInst, unchecked_ref_cast,
505505
ConversionInst, None, DoesNotRelease)
@@ -531,8 +531,8 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
531531
ConversionInst, None, DoesNotRelease)
532532
SINGLE_VALUE_INST(RefToBridgeObjectInst, ref_to_bridge_object,
533533
ConversionInst, None, DoesNotRelease)
534-
SINGLE_VALUE_INST(BridgeObjectToRefInst, bridge_object_to_ref,
535-
ConversionInst, None, DoesNotRelease)
534+
BRIDGED_SINGLE_VALUE_INST(BridgeObjectToRefInst, bridge_object_to_ref,
535+
ConversionInst, None, DoesNotRelease)
536536
SINGLE_VALUE_INST(BridgeObjectToWordInst, bridge_object_to_word,
537537
ConversionInst, None, DoesNotRelease)
538538
BRIDGED_SINGLE_VALUE_INST(ThinToThickFunctionInst, thin_to_thick_function,
@@ -599,8 +599,8 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
599599
SINGLE_VALUE_INST(IsUniqueInst, is_unique,
600600
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
601601

602-
SINGLE_VALUE_INST(EndCOWMutationInst, end_cow_mutation,
603-
SingleValueInstruction, None, DoesNotRelease)
602+
BRIDGED_SINGLE_VALUE_INST(EndCOWMutationInst, end_cow_mutation,
603+
SingleValueInstruction, None, DoesNotRelease)
604604

605605
SINGLE_VALUE_INST(IsEscapingClosureInst, is_escaping_closure,
606606
SingleValueInstruction, MayRead, DoesNotRelease)
@@ -687,26 +687,26 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
687687
SingleValueInstruction, None, DoesNotRelease)
688688

689689
// Protocol and Protocol Composition Types
690-
SINGLE_VALUE_INST(InitExistentialAddrInst, init_existential_addr,
691-
SingleValueInstruction, MayWrite, DoesNotRelease)
692-
SINGLE_VALUE_INST(InitExistentialValueInst, init_existential_value,
693-
SingleValueInstruction, MayWrite, DoesNotRelease)
694-
SINGLE_VALUE_INST(OpenExistentialAddrInst, open_existential_addr,
695-
SingleValueInstruction, MayRead, DoesNotRelease)
690+
BRIDGED_SINGLE_VALUE_INST(InitExistentialAddrInst, init_existential_addr,
691+
SingleValueInstruction, MayWrite, DoesNotRelease)
692+
BRIDGED_SINGLE_VALUE_INST(InitExistentialValueInst, init_existential_value,
693+
SingleValueInstruction, MayWrite, DoesNotRelease)
694+
BRIDGED_SINGLE_VALUE_INST(OpenExistentialAddrInst, open_existential_addr,
695+
SingleValueInstruction, MayRead, DoesNotRelease)
696696
BRIDGED_SINGLE_VALUE_INST(InitExistentialRefInst, init_existential_ref,
697-
SingleValueInstruction, None, DoesNotRelease)
697+
SingleValueInstruction, None, DoesNotRelease)
698698
BRIDGED_SINGLE_VALUE_INST(OpenExistentialRefInst, open_existential_ref,
699-
SingleValueInstruction, None, DoesNotRelease)
699+
SingleValueInstruction, None, DoesNotRelease)
700700
BRIDGED_SINGLE_VALUE_INST(InitExistentialMetatypeInst, init_existential_metatype,
701-
SingleValueInstruction, None, DoesNotRelease)
701+
SingleValueInstruction, None, DoesNotRelease)
702702
BRIDGED_SINGLE_VALUE_INST(OpenExistentialMetatypeInst, open_existential_metatype,
703-
SingleValueInstruction, None, DoesNotRelease)
704-
SINGLE_VALUE_INST(OpenExistentialBoxInst, open_existential_box,
705-
SingleValueInstruction, MayRead, DoesNotRelease)
706-
SINGLE_VALUE_INST(OpenExistentialValueInst, open_existential_value,
707-
SingleValueInstruction, MayRead, DoesNotRelease)
708-
SINGLE_VALUE_INST(OpenExistentialBoxValueInst, open_existential_box_value,
709-
SingleValueInstruction, MayRead, DoesNotRelease)
703+
SingleValueInstruction, None, DoesNotRelease)
704+
BRIDGED_SINGLE_VALUE_INST(OpenExistentialBoxInst, open_existential_box,
705+
SingleValueInstruction, MayRead, DoesNotRelease)
706+
BRIDGED_SINGLE_VALUE_INST(OpenExistentialValueInst, open_existential_value,
707+
SingleValueInstruction, MayRead, DoesNotRelease)
708+
BRIDGED_SINGLE_VALUE_INST(OpenExistentialBoxValueInst, open_existential_box_value,
709+
SingleValueInstruction, MayRead, DoesNotRelease)
710710

711711
// Blocks
712712
SINGLE_VALUE_INST(ProjectBlockStorageInst, project_block_storage,

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,60 +4527,8 @@ class ConstraintSystem {
45274527
// Build a disjunction that attempts both T? and T for a particular
45284528
// type binding. The choice of T? is preferred, and we will not
45294529
// attempt T if we can type check with T?
4530-
void
4531-
buildDisjunctionForOptionalVsUnderlying(Type boundTy, Type type,
4532-
ConstraintLocator *locator) {
4533-
// NOTE: If we use other locator kinds for these disjunctions, we
4534-
// need to account for it in solution scores for forced-unwraps.
4535-
assert(locator->getPath().back().getKind() ==
4536-
ConstraintLocator::ImplicitlyUnwrappedDisjunctionChoice ||
4537-
locator->getPath().back().getKind() ==
4538-
ConstraintLocator::DynamicLookupResult);
4539-
4540-
// Create the constraint to bind to the optional type and make it
4541-
// the favored choice.
4542-
auto *bindToOptional =
4543-
Constraint::create(*this, ConstraintKind::Bind, boundTy, type, locator);
4544-
bindToOptional->setFavored();
4545-
4546-
Type underlyingType;
4547-
if (auto *fnTy = type->getAs<AnyFunctionType>())
4548-
underlyingType = replaceFinalResultTypeWithUnderlying(fnTy);
4549-
else if (auto *typeVar =
4550-
type->getWithoutSpecifierType()->getAs<TypeVariableType>()) {
4551-
auto *locator = typeVar->getImpl().getLocator();
4552-
4553-
// If `type` hasn't been resolved yet, we need to allocate a type
4554-
// variable to represent an object type of a future optional, and
4555-
// add a constraint beetween `type` and `underlyingType` to model it.
4556-
underlyingType = createTypeVariable(
4557-
getConstraintLocator(locator, LocatorPathElt::GenericArgument(0)),
4558-
TVO_PrefersSubtypeBinding | TVO_CanBindToLValue |
4559-
TVO_CanBindToNoEscape);
4560-
4561-
// Using a `typeVar` here because l-value is going to be applied
4562-
// to the underlying type below.
4563-
addConstraint(ConstraintKind::OptionalObject, typeVar, underlyingType,
4564-
locator);
4565-
} else {
4566-
underlyingType = type->getWithoutSpecifierType()->getOptionalObjectType();
4567-
}
4568-
4569-
assert(underlyingType);
4570-
4571-
if (type->is<LValueType>())
4572-
underlyingType = LValueType::get(underlyingType);
4573-
assert(!type->is<InOutType>());
4574-
4575-
auto *bindToUnderlying = Constraint::create(
4576-
*this, ConstraintKind::Bind, boundTy, underlyingType, locator);
4577-
4578-
llvm::SmallVector<Constraint *, 2> choices = {bindToOptional,
4579-
bindToUnderlying};
4580-
4581-
// Create the disjunction
4582-
addDisjunctionConstraint(choices, locator, RememberChoice);
4583-
}
4530+
void buildDisjunctionForOptionalVsUnderlying(Type boundTy, Type ty,
4531+
ConstraintLocator *locator);
45844532

45854533
// Build a disjunction for types declared IUO.
45864534
void

lib/AST/Availability.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ AvailabilityContext ASTContext::getSwift50Availability() {
259259
return AvailabilityContext(
260260
VersionRange::allGTE(llvm::VersionTuple(12,2)));
261261
} else if (target.isWatchOS()) {
262-
if (target.getArch() == llvm::Triple::ArchType::x86_64)
262+
if (target.isArch64Bit())
263263
return AvailabilityContext::alwaysAvailable();
264264

265265
return AvailabilityContext(
@@ -297,6 +297,9 @@ AvailabilityContext ASTContext::getSwift51Availability() {
297297
return AvailabilityContext(
298298
VersionRange::allGTE(llvm::VersionTuple(13,0,0)));
299299
} else if (target.isWatchOS()) {
300+
if (target.isArch64Bit())
301+
return AvailabilityContext::alwaysAvailable();
302+
300303
return AvailabilityContext(
301304
VersionRange::allGTE(llvm::VersionTuple(6,0,0)));
302305
} else {

lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ add_swift_host_library(swiftAST STATIC
7474
ProtocolConformance.cpp
7575
RawComment.cpp
7676
RequirementEnvironment.cpp
77+
RequirementMachine/HomotopyReduction.cpp
7778
RequirementMachine/GenericSignatureQueries.cpp
7879
RequirementMachine/PropertyMap.cpp
7980
RequirementMachine/ProtocolGraph.cpp

0 commit comments

Comments
 (0)