Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e0dd80f
Handle long tagged NSStrings
Catfish-Man Aug 6, 2022
93b6e1b
[interop][SwiftToCxx] NFC, add test coverage for resilient mutating m…
hyp Aug 8, 2022
7ecf84a
[interop][SwiftToCxx] ensure that resilient class values are supported
hyp Aug 8, 2022
8f4658f
[CSClosure] Start using recorded targets for `ReturnStmt`s
xedin Aug 8, 2022
422dbe4
[ResultBuilder] AST transform: don't try type erasure of result expre…
xedin Aug 8, 2022
bf224c7
[interop][SwiftToCxx] pass structs to generic functions
hyp Aug 8, 2022
b3d8875
Iterate on the long tagged string test
Catfish-Man Aug 8, 2022
f966017
Review feedback
Catfish-Man Aug 9, 2022
330fc0b
[interop][SwiftToCxx] generic functions should return value types cor…
hyp Aug 9, 2022
7a4bcff
Revert "Merge pull request #60453 from etcwilde/ewilde/add-missing-bo…
etcwilde Aug 9, 2022
15b3659
Revert "Merge pull request #60368 from etcwilde/ewilde/backdeploy56"
etcwilde Aug 9, 2022
58420a1
LoadableByAddress: Updating global variables' types
aschwaighofer Aug 5, 2022
9d96ed9
AST: Rename 'canonical wrt. generic signature' to 'reduced'
slavapestov Aug 9, 2022
4a041c5
AST: Rename ConformanceAccessPath to ConformancePath
slavapestov Aug 9, 2022
93387f8
Merge pull request #60459 from etcwilde/ewilde/revert-backdeploy56
etcwilde Aug 9, 2022
ad26df0
Revert "[Sema] Propagate nonisolated attribute from wrapped property …
theblixguy Aug 9, 2022
2ebc7a2
Merge pull request #60449 from xedin/dont-erase-result-during-transform
xedin Aug 9, 2022
74d47a1
[interop][SwiftToCxx] update swift type representation docs with diff…
hyp Aug 9, 2022
03f2225
Merge pull request #60463 from slavapestov/reduced-types
slavapestov Aug 9, 2022
c537cd2
[interop][SwiftToCxx] NFC, move swift::_impl::OpaqueStorage into _Swi…
hyp Aug 9, 2022
4abba8c
Merge pull request #60448 from hyp/eng/resilient++
hyp Aug 9, 2022
ad00633
Fix assert
Catfish-Man Aug 9, 2022
f371c43
[interop][SwiftToCxx] pass boxed resilient value types to generic fun…
hyp Aug 9, 2022
d23a64e
[interop][SwiftToCxx] NFC, reformat printTypeGenericTraits
hyp Aug 9, 2022
27a27fe
Fix test
Catfish-Man Aug 9, 2022
2baa1e4
Merge pull request #60450 from aschwaighofer/globals_and_large_types
aschwaighofer Aug 9, 2022
035bee6
Merge pull request #60466 from hyp/eng/opaquelayoutdocs++
hyp Aug 10, 2022
fbd8f0e
Merge pull request #60472 from hyp/eng/generic-value-types
hyp Aug 10, 2022
25e1793
[Distributed] more specific errorCodes for dist failures; hide the ma…
ktoso Aug 10, 2022
7701ddc
Merge pull request #60428 from Catfish-Man/tag-youre-it
swift-ci Aug 10, 2022
cb0721f
Merge pull request #60470 from slavapestov/rename-conformance-path
slavapestov Aug 10, 2022
9eb6dd3
Merge pull request #60480 from apple/wip-dont-hang-bad-target-call
ktoso Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions SwiftCompilerSources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ else()
set(compatibility_libs
"swiftCompatibility50-${platform}"
"swiftCompatibility51-${platform}"
"swiftCompatibility56-${platform}"
"swiftCompatibilityConcurrency-${platform}"
"swiftCompatibilityDynamicReplacements-${platform}")

list(APPEND b0_deps ${compatibility_libs})
Expand Down
34 changes: 20 additions & 14 deletions docs/CppInteroperability/SwiftTypeRepresentationInC++.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ C++.

### Value Types

1) Primitive Swift types like `Int`, `Float` , `OpaquePointer`, `UnsafePointer<int>?` are mapped to primitive C++ types. `int` , `float`, `void *`, int `* _Nullable` .
1) Primitive Swift types like `Int`, `Float` , `OpaquePointer`, `UnsafePointer<int>?` are mapped to primitive C++ types. `int` , `float`, `void *`, `int * _Nullable`.

* Debug info: Does C++ debug info suffices?

Expand All @@ -29,13 +29,23 @@ class swift::String {
```c++
class Foundation::URL {
...
union {
alignas(8) char buffer[8]; // Swift value is stored here.
void *resilientPtr;
};
uintptr_t pointer; // pointer has alignment to compute buffer offset?
alignas(N) char buffer[M]; // Swift value is stored here.
};
```

concrete examples:

```c++
// representation for buffer aligned at 8:
{/*pointer=*/0x3, ....}; // buffer is alignas(2^3 = 8)

// representation for buffer aligned at 16:
{/*pointer=*/0x4, ....}; // buffer is alignas(2^4 = 16)

// where pointer < 10 for inline stores.
```

* Debug info: ...


Expand All @@ -44,10 +54,8 @@ class Foundation::URL {
```c++
class CryptoKit::SHA256 {
...
union {
alignas(8) char buffer[8];
void *resilientPtr; // Swift value is stored on the heap pointed by this pointer.
};
uintptr_t pointer; // Swift value is stored on the heap pointed by this pointer.
alignas(8) char buffer[8];
};
```

Expand All @@ -66,15 +74,13 @@ class swift::Array<swift::Int> {
* Debug info: ...


6) Generic opaque-layout / resilient / opaque-layout template type params Swift value type, e.g. SHA256`?`, is mapped to a C++ class that stores the value boxed up on the heap, e.g.:
6) Generic opaque-layout / resilient / opaque-layout template type params Swift value type, e.g. `SHA256?`, is mapped to a C++ class that stores the value boxed up on the heap, e.g.:

```c++
class swift::Optional<CryptoKit::SHA256> {
...
union {
alignas(8) char buffer[8];
void *resilientPtr; // Swift value is stored on the heap pointed by this pointer.
};
uintptr_t pointer; // Swift value is stored on the heap pointed by this pointer.
alignas(N) char buffer[M];
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/Lexicon.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ thunk helpers" sometimes seen in Swift backtraces come from.)

Broadly, an "access path" is a list of "accesses" which must be chained together
to compute some output from an input. For instance, the generics system has a
type called a `ConformanceAccessPath` which explains how to, for example,
type called a `ConformancePath` which explains how to, for example,
walk from `T: Collection` to `T: Sequence` to `T.Iterator: IteratorProtocol`.
There are several different kinds of "access path" in different parts of the compiler,
but they all follow this basic theme.
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NamedDecl;
namespace swift {

class AbstractClosureExpr;
class ConformanceAccessPath;
class ConformancePath;
class RootProtocolConformance;

namespace Mangle {
Expand Down Expand Up @@ -560,7 +560,7 @@ class ASTMangler : public Mangler {
void appendConcreteProtocolConformance(
const ProtocolConformance *conformance,
GenericSignature sig);
void appendDependentProtocolConformance(const ConformanceAccessPath &path,
void appendDependentProtocolConformance(const ConformancePath &path,
GenericSignature sig);
void appendOpParamForLayoutConstraint(LayoutConstraint Layout);

Expand Down
30 changes: 15 additions & 15 deletions include/swift/AST/GenericSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace rewriting {
/// \c Sequence conformance of \c C (because \c Collection inherits
/// \c Sequence). Finally, it extracts the conformance of the associated type
/// \c Iterator to \c IteratorProtocol from the \c Sequence protocol.
class ConformanceAccessPath {
class ConformancePath {
public:
/// An entry in the conformance access path, which is described by the
/// dependent type on which the conformance is stated as the protocol to
Expand All @@ -80,7 +80,7 @@ class ConformanceAccessPath {
private:
ArrayRef<Entry> path;

ConformanceAccessPath(ArrayRef<Entry> path) : path(path) {}
ConformancePath(ArrayRef<Entry> path) : path(path) {}

friend class GenericSignatureImpl;
friend class rewriting::RequirementMachine;
Expand Down Expand Up @@ -213,9 +213,9 @@ class GenericSignature {
SmallVector<Requirement, 4>
requirementsNotSatisfiedBy(GenericSignature otherSig) const;

/// Return the canonical version of the given type under this generic
/// Return the reduced version of the given type under this generic
/// signature.
CanType getCanonicalTypeInContext(Type type) const;
CanType getReducedType(Type type) const;

/// Check invariants.
void verify() const;
Expand Down Expand Up @@ -383,7 +383,7 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
/// generic signature.
///
/// The type parameters must be known to not be concrete within the context.
bool areSameTypeParameterInContext(Type type1, Type type2) const;
bool areReducedTypeParametersEqual(Type type1, Type type2) const;

/// Determine if \c sig can prove \c requirement, meaning that it can deduce
/// T: Foo or T == U (etc.) with the information it knows. This includes
Expand All @@ -392,26 +392,26 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
bool isRequirementSatisfied(
Requirement requirement, bool allowMissing = false) const;

bool isCanonicalTypeInContext(Type type) const;
bool isReducedType(Type type) const;

/// Determine whether the given type parameter is defined under this generic
/// signature.
bool isValidTypeInContext(Type type) const;
bool isValidTypeParameter(Type type) const;

/// Retrieve the conformance access path used to extract the conformance of
/// Retrieve the conformance path used to extract the conformance of
/// interface \c type to the given \c protocol.
///
/// \param type The interface type whose conformance access path is to be
/// \param type The type parameter whose conformance path is to be
/// queried.
/// \param protocol A protocol to which \c type conforms.
///
/// \returns the conformance access path that starts at a requirement of
/// \returns the conformance path that starts at a requirement of
/// this generic signature and ends at the conformance that makes \c type
/// conform to \c protocol.
///
/// \seealso ConformanceAccessPath
ConformanceAccessPath getConformanceAccessPath(Type type,
ProtocolDecl *protocol) const;
/// \seealso ConformancePath
ConformancePath getConformancePath(Type type,
ProtocolDecl *protocol) const;

/// Lookup a nested type with the given name within this type parameter.
TypeDecl *lookupNestedType(Type type, Identifier name) const;
Expand Down Expand Up @@ -487,9 +487,9 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
SmallVector<Requirement, 4>
requirementsNotSatisfiedBy(GenericSignature otherSig) const;

/// Return the canonical version of the given type under this generic
/// Return the reduced version of the given type under this generic
/// signature.
CanType getCanonicalTypeInContext(Type type) const;
CanType getReducedType(Type type) const;
};

void simple_display(raw_ostream &out, GenericSignature sig);
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ class alignas(1 << TypeAlignInBits) TypeBase
return const_cast<TypeBase*>(this)->computeCanonicalType();
}

/// getCanonicalType - Stronger canonicalization which folds away equivalent
/// getReducedType - Stronger canonicalization which folds away equivalent
/// associated types, or type parameters that have been made concrete.
CanType getCanonicalType(GenericSignature sig);
CanType getReducedType(GenericSignature sig);

/// Canonical protocol composition types are minimized only to a certain
/// degree to preserve ABI compatibility. This routine enables performing
Expand Down
12 changes: 2 additions & 10 deletions include/swift/Basic/Statistics.def
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,8 @@ FRONTEND_STATISTIC(Sema, NumRequirementMachineCompletionSteps)
/// Number of new rules added by concrete term unification.
FRONTEND_STATISTIC(Sema, NumRequirementMachineUnifiedConcreteTerms)

/// Number of generic signature builders constructed. Rough proxy for
/// amount of work the GSB does analyzing type signatures.
FRONTEND_STATISTIC(Sema, NumGenericSignatureBuilders)

/// Number of steps in the GSB's redundant requirements algorithm, which is in
/// the worst-case exponential.
FRONTEND_STATISTIC(Sema, NumRedundantRequirementSteps)

/// Number of conformance access paths we had to compute.
FRONTEND_STATISTIC(Sema, NumConformanceAccessPathsRecorded)
/// Number of conformance paths we had to compute.
FRONTEND_STATISTIC(Sema, NumConformancePathsRecorded)

/// Number of lazy requirement signatures registered.
FRONTEND_STATISTIC(Sema, NumLazyRequirementSignatures)
Expand Down
1 change: 0 additions & 1 deletion include/swift/Frontend/BackDeploymentLibs.def
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")
BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency")
BACK_DEPLOYMENT_LIB((5, 6), all, "swiftCompatibility56")

#undef BACK_DEPLOYMENT_LIB
2 changes: 1 addition & 1 deletion include/swift/SIL/AbstractionPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ class AbstractionPattern {
OrigType = origType;
GenericSig = CanGenericSignature();
if (OrigType->hasTypeParameter()) {
assert(OrigType == signature.getCanonicalTypeInContext(origType));
assert(OrigType == signature.getReducedType(origType));
GenericSig = signature;
}
}
Expand Down
6 changes: 6 additions & 0 deletions include/swift/SIL/SILGlobalVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ class SILGlobalVariable
return getLoweredTypeInContext(context).castTo<SILFunctionType>();
}

void unsafeSetLoweredType(SILType newType) { LoweredType = newType; }
void unsafeAppend(SILInstruction *i) { StaticInitializerBlock.push_back(i); }
void unsafeRemove(SILInstruction *i, SILModule &mod) {
StaticInitializerBlock.erase(i, mod);
}

StringRef getName() const { return Name; }

void setDeclaration(bool isD) { IsDeclaration = isD; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class DifferentiableActivityInfo {
auto type = value->getType().getASTType();
// Remap archetypes in the derivative generic signature, if it exists.
if (type->hasArchetype()) {
type = derivativeGenericSignature.getCanonicalTypeInContext(
type = derivativeGenericSignature.getReducedType(
type->mapTypeOutOfContext());
}
// Look up conformance in the current module.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Differentiation/LinearMapInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class LinearMapInfo {
derivative->getLoweredFunctionType()->getSubstGenericSignature();
auto *linMapStruct = getLinearMapStruct(origBB);
auto linMapStructType =
linMapStruct->getDeclaredInterfaceType()->getCanonicalType(
linMapStruct->getDeclaredInterfaceType()->getReducedType(
derivativeGenSig);
Lowering::AbstractionPattern pattern(derivativeGenSig, linMapStructType);
return typeConverter.getLoweredType(pattern, linMapStructType,
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3541,15 +3541,15 @@ isGenericFunctionTypeCanonical(GenericSignature sig,
return false;

for (auto param : params) {
if (!sig->isCanonicalTypeInContext(param.getPlainType()))
if (!sig->isReducedType(param.getPlainType()))
return false;
if (!param.getInternalLabel().empty()) {
// Canonical types don't have internal labels
return false;
}
}

return sig->isCanonicalTypeInContext(result);
return sig->isReducedType(result);
}

AnyFunctionType *AnyFunctionType::withExtInfo(ExtInfo info) const {
Expand Down Expand Up @@ -3771,7 +3771,7 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature sig,
}

// We have to construct this generic function type. Determine whether
// it's canonical. Unfortunately, isCanonicalTypeInContext can cause
// it's canonical. Unfortunately, isReducedType() can cause
// new GenericFunctionTypes to be created and thus invalidate our insertion
// point.
bool isCanonical = isGenericFunctionTypeCanonical(sig, params, result);
Expand All @@ -3788,7 +3788,7 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature sig,
if (info.hasValue())
globalActor = info->getGlobalActor();

if (globalActor && !sig->isCanonicalTypeInContext(globalActor))
if (globalActor && !sig->isReducedType(globalActor))
isCanonical = false;

size_t allocSize = totalSizeToAlloc<AnyFunctionType::Param, Type>(
Expand Down
20 changes: 10 additions & 10 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3357,9 +3357,9 @@ void ASTMangler::appendProtocolConformanceRef(
}

/// Retrieve the index of the conformance requirement indicated by the
/// conformance access path entry within the given set of requirements.
/// conformance path entry within the given set of requirements.
static unsigned conformanceRequirementIndex(
const ConformanceAccessPath::Entry &entry,
const ConformancePath::Entry &entry,
ArrayRef<Requirement> requirements) {
unsigned result = 0;
for (const auto &req : requirements) {
Expand All @@ -3377,7 +3377,7 @@ static unsigned conformanceRequirementIndex(
}

void ASTMangler::appendDependentProtocolConformance(
const ConformanceAccessPath &path,
const ConformancePath &path,
GenericSignature sig) {
ProtocolDecl *currentProtocol = nullptr;
for (const auto &entry : path) {
Expand Down Expand Up @@ -3441,19 +3441,19 @@ void ASTMangler::appendAnyProtocolConformance(

if (conformingType->isTypeParameter()) {
assert(genericSig && "Need a generic signature to resolve conformance");
auto path = genericSig->getConformanceAccessPath(conformingType,
conformance.getAbstract());
auto path = genericSig->getConformancePath(conformingType,
conformance.getAbstract());
appendDependentProtocolConformance(path, genericSig);
} else if (auto opaqueType = conformingType->getAs<OpaqueTypeArchetypeType>()) {
GenericSignature opaqueSignature =
opaqueType->getDecl()->getOpaqueInterfaceGenericSignature();
ConformanceAccessPath conformanceAccessPath =
opaqueSignature->getConformanceAccessPath(
ConformancePath conformancePath =
opaqueSignature->getConformancePath(
opaqueType->getInterfaceType(),
conformance.getAbstract());

// Append the conformance access path with the signature of the opaque type.
appendDependentProtocolConformance(conformanceAccessPath, opaqueSignature);
// Append the conformance path with the signature of the opaque type.
appendDependentProtocolConformance(conformancePath, opaqueSignature);
appendType(conformingType, genericSig);
appendOperator("HO");
} else {
Expand Down Expand Up @@ -3488,7 +3488,7 @@ void ASTMangler::appendConcreteProtocolConformance(
auto type = conditionalReq.getFirstType();
if (type->hasArchetype())
type = type->mapTypeOutOfContext();
CanType canType = type->getCanonicalType(sig);
CanType canType = type->getReducedType(sig);
auto proto = conditionalReq.getProtocolDecl();

ProtocolConformanceRef conformance;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4106,7 +4106,7 @@ findGenericParameterReferences(CanGenericSignature genericSig,

// If the type parameter is beyond the domain of the existential generic
// signature, ignore it.
if (!genericSig->isValidTypeInContext(type)) {
if (!genericSig->isValidTypeParameter(type)) {
return GenericParameterReferenceInfo();
}

Expand Down
Loading