Skip to content

Commit 5de0615

Browse files
authored
Merge pull request #985 from swiftwasm/master
[pull] swiftwasm from master
2 parents 9c7df0c + 902fcc2 commit 5de0615

Some content is hidden

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

56 files changed

+1348
-393
lines changed

include/swift/ABI/Metadata.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ struct TargetExistentialTypeMetadata
20002000
}
20012001

20022002
/// Retrieve the set of protocols required by the existential.
2003-
ArrayRef<ProtocolDescriptorRef> getProtocols() const {
2003+
llvm::ArrayRef<ProtocolDescriptorRef> getProtocols() const {
20042004
return { this->template getTrailingObjects<ProtocolDescriptorRef>(),
20052005
NumProtocols };
20062006
}
@@ -2013,7 +2013,7 @@ struct TargetExistentialTypeMetadata
20132013
}
20142014

20152015
/// Retrieve the set of protocols required by the existential.
2016-
MutableArrayRef<ProtocolDescriptorRef> getMutableProtocols() {
2016+
llvm::MutableArrayRef<ProtocolDescriptorRef> getMutableProtocols() {
20172017
return { this->template getTrailingObjects<ProtocolDescriptorRef>(),
20182018
NumProtocols };
20192019
}
@@ -2535,13 +2535,13 @@ struct TargetProtocolConformanceDescriptor final
25352535
getWitnessTable(const TargetMetadata<Runtime> *type) const;
25362536

25372537
/// Retrieve the resilient witnesses.
2538-
ArrayRef<ResilientWitness> getResilientWitnesses() const{
2538+
llvm::ArrayRef<ResilientWitness> getResilientWitnesses() const {
25392539
if (!Flags.hasResilientWitnesses())
25402540
return { };
25412541

2542-
return ArrayRef<ResilientWitness>(
2543-
this->template getTrailingObjects<ResilientWitness>(),
2544-
numTrailingObjects(OverloadToken<ResilientWitness>()));
2542+
return llvm::ArrayRef<ResilientWitness>(
2543+
this->template getTrailingObjects<ResilientWitness>(),
2544+
numTrailingObjects(OverloadToken<ResilientWitness>()));
25452545
}
25462546

25472547
ConstTargetPointer<Runtime, GenericWitnessTable>
@@ -2828,23 +2828,23 @@ class TargetGenericEnvironment
28282828

28292829
public:
28302830
/// Retrieve the cumulative generic parameter counts at each level of genericity.
2831-
ArrayRef<uint16_t> getGenericParameterCounts() const {
2832-
return ArrayRef<uint16_t>(this->template getTrailingObjects<uint16_t>(),
2831+
llvm::ArrayRef<uint16_t> getGenericParameterCounts() const {
2832+
return llvm::makeArrayRef(this->template getTrailingObjects<uint16_t>(),
28332833
Flags.getNumGenericParameterLevels());
28342834
}
28352835

28362836
/// Retrieve the generic parameters descriptors.
2837-
ArrayRef<GenericParamDescriptor> getGenericParameters() const {
2838-
return ArrayRef<GenericParamDescriptor>(
2839-
this->template getTrailingObjects<GenericParamDescriptor>(),
2840-
getGenericParameterCounts().back());
2837+
llvm::ArrayRef<GenericParamDescriptor> getGenericParameters() const {
2838+
return llvm::makeArrayRef(
2839+
this->template getTrailingObjects<GenericParamDescriptor>(),
2840+
getGenericParameterCounts().back());
28412841
}
28422842

28432843
/// Retrieve the generic requirements.
2844-
ArrayRef<GenericRequirementDescriptor> getGenericRequirements() const {
2845-
return ArrayRef<GenericRequirementDescriptor>(
2846-
this->template getTrailingObjects<GenericRequirementDescriptor>(),
2847-
Flags.getNumGenericRequirements());
2844+
llvm::ArrayRef<GenericRequirementDescriptor> getGenericRequirements() const {
2845+
return llvm::makeArrayRef(
2846+
this->template getTrailingObjects<GenericRequirementDescriptor>(),
2847+
Flags.getNumGenericRequirements());
28482848
}
28492849
};
28502850

@@ -4604,7 +4604,8 @@ class DynamicReplacementScope
46044604
DynamicReplacementDescriptor>;
46054605
friend TrailingObjects;
46064606

4607-
ArrayRef<DynamicReplacementDescriptor> getReplacementDescriptors() const {
4607+
llvm::ArrayRef<DynamicReplacementDescriptor>
4608+
getReplacementDescriptors() const {
46084609
return {this->template getTrailingObjects<DynamicReplacementDescriptor>(),
46094610
numReplacements};
46104611
}

include/swift/AST/AutoDiff.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,16 @@ class DerivativeFunctionTypeError
394394
: public llvm::ErrorInfo<DerivativeFunctionTypeError> {
395395
public:
396396
enum class Kind {
397+
/// Original function type has no semantic results.
397398
NoSemanticResults,
399+
/// Original function type has multiple semantic results.
400+
// TODO(TF-1250): Support function types with multiple semantic results.
398401
MultipleSemanticResults,
399-
NonDifferentiableParameters,
402+
/// Differentiability parmeter indices are empty.
403+
NoDifferentiabilityParameters,
404+
/// A differentiability parameter does not conform to `Differentiable`.
405+
NonDifferentiableDifferentiabilityParameter,
406+
/// The original result type does not conform to `Differentiable`.
400407
NonDifferentiableResult
401408
};
402409

@@ -406,42 +413,35 @@ class DerivativeFunctionTypeError
406413
/// The error kind.
407414
Kind kind;
408415

416+
/// The type and index of a differentiability parameter or result.
417+
using TypeAndIndex = std::pair<Type, unsigned>;
418+
409419
private:
410420
union Value {
411-
IndexSubset *indices;
412-
Type type;
413-
Value(IndexSubset *indices) : indices(indices) {}
414-
Value(Type type) : type(type) {}
421+
TypeAndIndex typeAndIndex;
422+
Value(TypeAndIndex typeAndIndex) : typeAndIndex(typeAndIndex) {}
415423
Value() {}
416424
} value;
417425

418426
public:
419427
explicit DerivativeFunctionTypeError(AnyFunctionType *functionType, Kind kind)
420428
: functionType(functionType), kind(kind), value(Value()) {
421429
assert(kind == Kind::NoSemanticResults ||
422-
kind == Kind::MultipleSemanticResults);
423-
};
424-
425-
explicit DerivativeFunctionTypeError(AnyFunctionType *functionType, Kind kind,
426-
IndexSubset *nonDiffParameterIndices)
427-
: functionType(functionType), kind(kind), value(nonDiffParameterIndices) {
428-
assert(kind == Kind::NonDifferentiableParameters);
430+
kind == Kind::MultipleSemanticResults ||
431+
kind == Kind::NoDifferentiabilityParameters);
429432
};
430433

431434
explicit DerivativeFunctionTypeError(AnyFunctionType *functionType, Kind kind,
432-
Type nonDiffResultType)
433-
: functionType(functionType), kind(kind), value(nonDiffResultType) {
434-
assert(kind == Kind::NonDifferentiableResult);
435+
TypeAndIndex nonDiffTypeAndIndex)
436+
: functionType(functionType), kind(kind), value(nonDiffTypeAndIndex) {
437+
assert(kind == Kind::NonDifferentiableDifferentiabilityParameter ||
438+
kind == Kind::NonDifferentiableResult);
435439
};
436440

437-
IndexSubset *getNonDifferentiableParameterIndices() const {
438-
assert(kind == Kind::NonDifferentiableParameters);
439-
return value.indices;
440-
}
441-
442-
Type getNonDifferentiableResultType() const {
443-
assert(kind == Kind::NonDifferentiableResult);
444-
return value.type;
441+
TypeAndIndex getNonDifferentiableTypeAndIndex() const {
442+
assert(kind == Kind::NonDifferentiableDifferentiabilityParameter ||
443+
kind == Kind::NonDifferentiableResult);
444+
return value.typeAndIndex;
445445
}
446446

447447
void log(raw_ostream &OS) const override;

include/swift/AST/Decl.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,12 @@ class alignas(1 << DeclAlignInBits) Decl {
558558
IsIncompatibleWithWeakReferences : 1
559559
);
560560

561-
SWIFT_INLINE_BITFIELD(StructDecl, NominalTypeDecl, 1,
561+
SWIFT_INLINE_BITFIELD(StructDecl, NominalTypeDecl, 1+1,
562562
/// True if this struct has storage for fields that aren't accessible in
563563
/// Swift.
564-
HasUnreferenceableStorage : 1
564+
HasUnreferenceableStorage : 1,
565+
/// True if this struct is imported from C++ and not trivially copyable.
566+
IsCxxNotTriviallyCopyable : 1
565567
);
566568

567569
SWIFT_INLINE_BITFIELD(EnumDecl, NominalTypeDecl, 2+1,
@@ -3822,6 +3824,14 @@ class StructDecl final : public NominalTypeDecl {
38223824
void setHasUnreferenceableStorage(bool v) {
38233825
Bits.StructDecl.HasUnreferenceableStorage = v;
38243826
}
3827+
3828+
bool isCxxNotTriviallyCopyable() const {
3829+
return Bits.StructDecl.IsCxxNotTriviallyCopyable;
3830+
}
3831+
3832+
void setIsCxxNotTriviallyCopyable(bool v) {
3833+
Bits.StructDecl.IsCxxNotTriviallyCopyable = v;
3834+
}
38253835
};
38263836

38273837
/// This is the base type for AncestryOptions. Each flag describes possible

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,8 +2990,6 @@ ERROR(implements_attr_protocol_not_conformed_to,none,
29902990
ERROR(differentiable_attr_no_vjp_or_jvp_when_linear,none,
29912991
"cannot specify 'vjp:' or 'jvp:' for linear functions; use '@transpose' "
29922992
"attribute for transpose registration instead", ())
2993-
ERROR(differentiable_attr_void_result,none,
2994-
"cannot differentiate void function %0", (DeclName))
29952993
ERROR(differentiable_attr_overload_not_found,none,
29962994
"%0 does not have expected type %1", (DeclNameRef, Type))
29972995
// TODO(TF-482): Change duplicate `@differentiable` attribute diagnostic to also
@@ -3010,9 +3008,6 @@ ERROR(differentiable_attr_invalid_access,none,
30103008
"derivative function %0 is required to either be public or "
30113009
"'@usableFromInline' because the original function %1 is public or "
30123010
"'@usableFromInline'", (DeclNameRef, DeclName))
3013-
ERROR(differentiable_attr_result_not_differentiable,none,
3014-
"can only differentiate functions with results that conform to "
3015-
"'Differentiable', but %0 does not conform to 'Differentiable'", (Type))
30163011
ERROR(differentiable_attr_protocol_req_where_clause,none,
30173012
"'@differentiable' attribute on protocol requirement cannot specify "
30183013
"'where' clause", ())
@@ -3119,6 +3114,9 @@ ERROR(autodiff_attr_original_void_result,none,
31193114
ERROR(autodiff_attr_original_multiple_semantic_results,none,
31203115
"cannot differentiate functions with both an 'inout' parameter and a "
31213116
"result", ())
3117+
ERROR(autodiff_attr_result_not_differentiable,none,
3118+
"can only differentiate functions with results that conform to "
3119+
"'Differentiable', but %0 does not conform to 'Differentiable'", (Type))
31223120

31233121
// differentiation `wrt` parameters clause
31243122
ERROR(diff_function_no_parameters,none,
@@ -4274,8 +4272,8 @@ ERROR(objc_invalid_on_subscript,none,
42744272
ERROR(objc_invalid_on_static_subscript,none,
42754273
"%0 cannot be %" OBJC_ATTR_SELECT "1", (DescriptiveDeclKind, unsigned))
42764274
ERROR(objc_invalid_with_generic_params,none,
4277-
"method cannot be %" OBJC_ATTR_SELECT "0 because it has generic "
4278-
"parameters", (unsigned))
4275+
"%0 cannot be %" OBJC_ATTR_SELECT "1 because it has generic parameters",
4276+
(DescriptiveDeclKind, unsigned))
42794277
ERROR(objc_convention_invalid,none,
42804278
"%0 is not representable in Objective-C, so it cannot be used"
42814279
" with '@convention(%1)'", (Type, StringRef))

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,7 @@ class GenericSignatureBuilder {
519519

520520
ProtocolConformanceRef operator()(CanType dependentType,
521521
Type conformingReplacementType,
522-
ProtocolDecl *conformedProtocol) const {
523-
return builder->lookupConformance(dependentType,
524-
conformingReplacementType,
525-
conformedProtocol);
526-
}
522+
ProtocolDecl *conformedProtocol) const;
527523
};
528524

529525
/// Retrieve a function that can perform conformance lookup for this

include/swift/AST/Type.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ enum class SubstFlags {
147147
/// Map member types to their desugared witness type.
148148
DesugarMemberTypes = 0x02,
149149
/// Substitute types involving opaque type archetypes.
150-
SubstituteOpaqueArchetypes = 0x04,
151-
/// Force substitution of opened archetypes. Normally -- without these flag --
152-
/// opened archetype conformances are not substituted.
153-
ForceSubstituteOpenedExistentials = 0x08,
150+
SubstituteOpaqueArchetypes = 0x04
154151
};
155152

156153
/// Options for performing substitutions into a type.

include/swift/AST/Types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,10 +2696,10 @@ enum class FunctionTypeRepresentation : uint8_t {
26962696
/// A "thin" function that needs no context.
26972697
Thin,
26982698

2699-
/// A C function pointer, which is thin and also uses the C calling
2700-
/// convention.
2699+
/// A C function pointer (or reference), which is thin and also uses the C
2700+
/// calling convention.
27012701
CFunctionPointer,
2702-
2702+
27032703
/// The value of the greatest AST function representation.
27042704
Last = CFunctionPointer,
27052705
};
@@ -2980,8 +2980,8 @@ class AnyFunctionType : public TypeBase {
29802980
// We preserve a full clang::Type *, not a clang::FunctionType * as:
29812981
// 1. We need to keep sugar in case we need to present an error to the user.
29822982
// 2. The actual type being stored is [ignoring sugar] either a
2983-
// clang::PointerType or a clang::BlockPointerType which points to a
2984-
// clang::FunctionType.
2983+
// clang::PointerType, a clang::BlockPointerType, or a
2984+
// clang::ReferenceType which points to a clang::FunctionType.
29852985
const clang::Type *ClangFunctionType;
29862986

29872987
bool empty() const { return !ClangFunctionType; }

include/swift/Basic/LLVM.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ namespace llvm {
3838
template <typename T, unsigned N> class SmallVector;
3939
template <unsigned N> class SmallString;
4040
template <typename T, unsigned N> class SmallSetVector;
41+
#if !defined(swiftCore_EXPORTS)
4142
template<typename T> class ArrayRef;
4243
template<typename T> class MutableArrayRef;
44+
#endif
4345
template<typename T> class TinyPtrVector;
4446
template<typename T> class Optional;
4547
template <typename ...PTs> class PointerUnion;
@@ -63,9 +65,11 @@ namespace swift {
6365
using llvm::cast_or_null;
6466

6567
// Containers.
68+
#if !defined(swiftCore_EXPORTS)
6669
using llvm::ArrayRef;
67-
using llvm::iterator_range;
6870
using llvm::MutableArrayRef;
71+
#endif
72+
using llvm::iterator_range;
6973
using llvm::None;
7074
using llvm::Optional;
7175
using llvm::PointerUnion;

include/swift/Demangling/TypeDecoder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/Basic/LLVM.h"
2424
#include "swift/Runtime/Unreachable.h"
2525
#include "swift/Strings.h"
26+
#include "llvm/ADT/ArrayRef.h"
2627
#include <vector>
2728

2829
namespace swift {
@@ -876,7 +877,7 @@ class TypeDecoder {
876877
}
877878
}
878879
genericArgsLevels.push_back(genericArgsBuf.size());
879-
std::vector<ArrayRef<BuiltType>> genericArgs;
880+
std::vector<llvm::ArrayRef<BuiltType>> genericArgs;
880881
for (unsigned i = 0; i < genericArgsLevels.size() - 1; ++i) {
881882
auto start = genericArgsLevels[i], end = genericArgsLevels[i+1];
882883
genericArgs.emplace_back(genericArgsBuf.data() + start,

include/swift/Reflection/TypeRef.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,11 @@ class OpaqueArchetypeTypeRef final : public TypeRef {
346346
// Each ArrayRef in ArgumentLists references into the buffer owned by this
347347
// vector, which must not be modified after construction.
348348
std::vector<const TypeRef *> AllArgumentsBuf;
349-
std::vector<ArrayRef<const TypeRef *>> ArgumentLists;
350-
351-
static TypeRefID Profile(StringRef idString,
352-
StringRef description, unsigned ordinal,
353-
ArrayRef<ArrayRef<const TypeRef *>> argumentLists) {
349+
std::vector<llvm::ArrayRef<const TypeRef *>> ArgumentLists;
350+
351+
static TypeRefID
352+
Profile(StringRef idString, StringRef description, unsigned ordinal,
353+
llvm::ArrayRef<llvm::ArrayRef<const TypeRef *>> argumentLists) {
354354
TypeRefID ID;
355355
ID.addString(idString.str());
356356
ID.addInteger(ordinal);
@@ -362,14 +362,13 @@ class OpaqueArchetypeTypeRef final : public TypeRef {
362362

363363
return ID;
364364
}
365-
365+
366366
public:
367-
OpaqueArchetypeTypeRef(StringRef id,
368-
StringRef description, unsigned ordinal,
369-
ArrayRef<ArrayRef<const TypeRef *>> argumentLists)
370-
: TypeRef(TypeRefKind::OpaqueArchetype),
371-
ID(id), Description(description), Ordinal(ordinal)
372-
{
367+
OpaqueArchetypeTypeRef(
368+
StringRef id, StringRef description, unsigned ordinal,
369+
llvm::ArrayRef<llvm::ArrayRef<const TypeRef *>> argumentLists)
370+
: TypeRef(TypeRefKind::OpaqueArchetype), ID(id), Description(description),
371+
Ordinal(ordinal) {
373372
std::vector<unsigned> argumentListLengths;
374373

375374
for (auto argList : argumentLists) {
@@ -379,25 +378,24 @@ class OpaqueArchetypeTypeRef final : public TypeRef {
379378
}
380379
auto *data = AllArgumentsBuf.data();
381380
for (auto length : argumentListLengths) {
382-
ArgumentLists.push_back(ArrayRef<const TypeRef *>(data, length));
381+
ArgumentLists.push_back(llvm::ArrayRef<const TypeRef *>(data, length));
383382
data += length;
384383
}
385384
assert(data == AllArgumentsBuf.data() + AllArgumentsBuf.size());
386385
}
387-
386+
388387
template <typename Allocator>
389-
static const OpaqueArchetypeTypeRef *create(Allocator &A,
390-
StringRef id, StringRef description,
391-
unsigned ordinal,
392-
ArrayRef<ArrayRef<const TypeRef *>> arguments) {
388+
static const OpaqueArchetypeTypeRef *
389+
create(Allocator &A, StringRef id, StringRef description, unsigned ordinal,
390+
llvm::ArrayRef<llvm::ArrayRef<const TypeRef *>> arguments) {
393391
FIND_OR_CREATE_TYPEREF(A, OpaqueArchetypeTypeRef,
394392
id, description, ordinal, arguments);
395393
}
396394

397-
ArrayRef<ArrayRef<const TypeRef *>> getArgumentLists() const {
395+
llvm::ArrayRef<llvm::ArrayRef<const TypeRef *>> getArgumentLists() const {
398396
return ArgumentLists;
399397
}
400-
398+
401399
unsigned getOrdinal() const {
402400
return Ordinal;
403401
}

0 commit comments

Comments
 (0)