Skip to content

Commit 9f1cc50

Browse files
Merge pull request #2658 from swiftwasm/main
[pull] swiftwasm from main
2 parents 52a6fbf + edcc3a2 commit 9f1cc50

File tree

77 files changed

+1787
-777
lines changed

Some content is hidden

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

77 files changed

+1787
-777
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ASTBuilder {
6666

6767
Demangle::NodeFactory &getNodeFactory() { return Factory; }
6868

69+
Type decodeMangledType(NodePointer node);
6970
Type createBuiltinType(StringRef builtinName, StringRef mangledName);
7071

7172
TypeDecl *createTypeDecl(NodePointer node);
@@ -126,6 +127,18 @@ class ASTBuilder {
126127
#include "swift/AST/ReferenceStorage.def"
127128

128129
Type createSILBoxType(Type base);
130+
using BuiltSILBoxField = llvm::PointerIntPair<Type, 1>;
131+
using BuiltSubstitution = std::pair<Type, Type>;
132+
using BuiltRequirement = swift::Requirement;
133+
using BuiltLayoutConstraint = swift::LayoutConstraint;
134+
Type createSILBoxTypeWithLayout(ArrayRef<BuiltSILBoxField> Fields,
135+
ArrayRef<BuiltSubstitution> Substitutions,
136+
ArrayRef<BuiltRequirement> Requirements);
137+
138+
bool isExistential(Type type) {
139+
return type->isExistentialType();
140+
}
141+
129142

130143
Type createObjCClassType(StringRef name);
131144

@@ -149,6 +162,11 @@ class ASTBuilder {
149162

150163
Type createParenType(Type base);
151164

165+
LayoutConstraint getLayoutConstraint(LayoutConstraintKind kind);
166+
LayoutConstraint getLayoutConstraintWithSizeAlign(LayoutConstraintKind kind,
167+
unsigned size,
168+
unsigned alignment);
169+
152170
private:
153171
bool validateParentType(TypeDecl *decl, Type parent);
154172
CanGenericSignature demangleGenericSignature(

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4690,6 +4690,9 @@ ERROR(objc_invalid_on_static_subscript,none,
46904690
ERROR(objc_invalid_with_generic_params,none,
46914691
"%0 cannot be %" OBJC_ATTR_SELECT "1 because it has generic parameters",
46924692
(DescriptiveDeclKind, unsigned))
4693+
ERROR(objc_invalid_with_generic_requirements,none,
4694+
"%0 cannot be %" OBJC_ATTR_SELECT "1 because it has a 'where' clause",
4695+
(DescriptiveDeclKind, unsigned))
46934696
ERROR(objc_convention_invalid,none,
46944697
"%0 is not representable in Objective-C, so it cannot be used"
46954698
" with '@convention(%1)'", (Type, StringRef))

include/swift/AST/IRGenOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ struct PointerAuthOptions : clang::PointerAuthOptions {
147147
/// The resume function stored in AsyncTask.
148148
PointerAuthSchema TaskResumeFunction;
149149

150+
/// The async context stored in AsyncTask.
151+
PointerAuthSchema TaskResumeContext;
152+
150153
/// The swift async context entry in the extended frame info.
151154
PointerAuthSchema AsyncContextExtendedFrameEntry;
152155
};

include/swift/AST/LayoutConstraint.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,22 @@
1717
#ifndef SWIFT_LAYOUT_CONSTRAINT_H
1818
#define SWIFT_LAYOUT_CONSTRAINT_H
1919

20+
#include "swift/AST/LayoutConstraintKind.h"
21+
#include "swift/AST/PrintOptions.h"
2022
#include "swift/AST/TypeAlignments.h"
2123
#include "swift/Basic/Debug.h"
2224
#include "swift/Basic/SourceLoc.h"
2325
#include "llvm/ADT/DenseMap.h"
2426
#include "llvm/ADT/FoldingSet.h"
2527
#include "llvm/ADT/Hashing.h"
2628
#include "llvm/ADT/StringRef.h"
27-
#include "swift/AST/PrintOptions.h"
2829

2930
namespace swift {
3031

3132
enum class AllocationArena;
3233
class ASTContext;
3334
class ASTPrinter;
3435

35-
/// Describes a layout constraint information.
36-
enum class LayoutConstraintKind : uint8_t {
37-
// It is not a known layout constraint.
38-
UnknownLayout,
39-
// It is a layout constraint representing a trivial type of a known size.
40-
TrivialOfExactSize,
41-
// It is a layout constraint representing a trivial type of a size known to
42-
// be no larger than a given size.
43-
TrivialOfAtMostSize,
44-
// It is a layout constraint representing a trivial type of an unknown size.
45-
Trivial,
46-
// It is a layout constraint representing a reference counted class instance.
47-
Class,
48-
// It is a layout constraint representing a reference counted native class
49-
// instance.
50-
NativeClass,
51-
// It is a layout constraint representing a reference counted object.
52-
RefCountedObject,
53-
// It is a layout constraint representing a native reference counted object.
54-
NativeRefCountedObject,
55-
LastLayout = NativeRefCountedObject,
56-
};
57-
5836
/// This is a class representing the layout constraint.
5937
class LayoutConstraintInfo : public llvm::FoldingSetNode {
6038
friend class LayoutConstraint;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- LayoutConstraintKind.h - Layout constraints kinds -------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines types and APIs for layout constraints.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_LAYOUT_CONSTRAINTKIND_H
18+
#define SWIFT_LAYOUT_CONSTRAINTKIND_H
19+
20+
/// Describes a layout constraint information.
21+
enum class LayoutConstraintKind : uint8_t {
22+
// It is not a known layout constraint.
23+
UnknownLayout,
24+
// It is a layout constraint representing a trivial type of a known size.
25+
TrivialOfExactSize,
26+
// It is a layout constraint representing a trivial type of a size known to
27+
// be no larger than a given size.
28+
TrivialOfAtMostSize,
29+
// It is a layout constraint representing a trivial type of an unknown size.
30+
Trivial,
31+
// It is a layout constraint representing a reference counted class instance.
32+
Class,
33+
// It is a layout constraint representing a reference counted native class
34+
// instance.
35+
NativeClass,
36+
// It is a layout constraint representing a reference counted object.
37+
RefCountedObject,
38+
// It is a layout constraint representing a native reference counted object.
39+
NativeRefCountedObject,
40+
LastLayout = NativeRefCountedObject,
41+
};
42+
43+
#endif

include/swift/AST/Requirement.h

Lines changed: 14 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef SWIFT_AST_REQUIREMENT_H
1818
#define SWIFT_AST_REQUIREMENT_H
1919

20+
#include "swift/AST/LayoutConstraint.h"
21+
#include "swift/AST/RequirementBase.h"
2022
#include "swift/AST/Type.h"
2123
#include "swift/Basic/Debug.h"
2224
#include "llvm/ADT/Hashing.h"
@@ -25,76 +27,33 @@
2527

2628
namespace swift {
2729

28-
/// Describes the kind of a requirement that occurs within a requirements
29-
/// clause.
30-
enum class RequirementKind : unsigned {
31-
/// A conformance requirement T : P, where T is a type that depends
32-
/// on a generic parameter and P is a protocol to which T must conform.
33-
Conformance,
34-
/// A superclass requirement T : C, where T is a type that depends
35-
/// on a generic parameter and C is a concrete class type which T must
36-
/// equal or be a subclass of.
37-
Superclass,
38-
/// A same-type requirement T == U, where T and U are types that shall be
39-
/// equivalent.
40-
SameType,
41-
/// A layout bound T : L, where T is a type that depends on a generic
42-
/// parameter and L is some layout specification that should bound T.
43-
Layout,
44-
45-
// Note: there is code that packs this enum in a 2-bit bitfield. Audit users
46-
// when adding enumerators.
47-
};
48-
4930
/// A single requirement placed on the type parameters (or associated
5031
/// types thereof) of a
51-
class Requirement {
52-
llvm::PointerIntPair<Type, 3, RequirementKind> FirstTypeAndKind;
53-
/// The second element of the requirement. Its content is dependent
54-
/// on the requirement kind.
55-
/// The payload of the following enum should always match the kind!
56-
/// Any access to the fields of this enum should first check if the
57-
/// requested access matches the kind of the requirement.
58-
union {
59-
Type SecondType;
60-
LayoutConstraint SecondLayout;
61-
};
62-
32+
class Requirement
33+
: public RequirementBase<Type,
34+
llvm::PointerIntPair<Type, 3, RequirementKind>,
35+
LayoutConstraint> {
6336
public:
6437
/// Create a conformance or same-type requirement.
6538
Requirement(RequirementKind kind, Type first, Type second)
66-
: FirstTypeAndKind(first, kind), SecondType(second) {
67-
assert(first);
68-
assert(second);
69-
}
39+
: RequirementBase(kind, first, second) {}
7040

7141
/// Create a layout constraint requirement.
7242
Requirement(RequirementKind kind, Type first, LayoutConstraint second)
73-
: FirstTypeAndKind(first, kind), SecondLayout(second) {
74-
assert(first);
75-
assert(second);
76-
}
77-
78-
/// Determine the kind of requirement.
79-
RequirementKind getKind() const { return FirstTypeAndKind.getInt(); }
43+
: RequirementBase(kind, first, second) {}
8044

81-
/// Retrieve the first type.
82-
Type getFirstType() const {
83-
return FirstTypeAndKind.getPointer();
84-
}
45+
/// Whether this requirement is in its canonical form.
46+
bool isCanonical() const;
8547

86-
/// Retrieve the second type.
87-
Type getSecondType() const {
88-
assert(getKind() != RequirementKind::Layout);
89-
return SecondType;
90-
}
48+
/// Get the canonical form of this requirement.
49+
Requirement getCanonical() const;
9150

9251
/// Subst the types involved in this requirement.
9352
///
9453
/// The \c args arguments are passed through to Type::subst. This doesn't
9554
/// touch the superclasses, protocols or layout constraints.
96-
template <typename... Args>
97-
Optional<Requirement> subst(Args &&... args) const {
55+
template <typename ...Args>
56+
llvm::Optional<Requirement> subst(Args &&...args) const {
9857
auto newFirst = getFirstType().subst(std::forward<Args>(args)...);
9958
if (newFirst->hasError())
10059
return None;
@@ -115,61 +74,10 @@ class Requirement {
11574
llvm_unreachable("Unhandled RequirementKind in switch.");
11675
}
11776

118-
/// Retrieve the layout constraint.
119-
LayoutConstraint getLayoutConstraint() const {
120-
assert(getKind() == RequirementKind::Layout);
121-
return SecondLayout;
122-
}
123-
124-
/// Whether this requirement is in its canonical form.
125-
bool isCanonical() const;
126-
127-
/// Get the canonical form of this requirement.
128-
Requirement getCanonical() const;
129-
13077
SWIFT_DEBUG_DUMP;
13178
void dump(raw_ostream &out) const;
13279
void print(raw_ostream &os, const PrintOptions &opts) const;
13380
void print(ASTPrinter &printer, const PrintOptions &opts) const;
134-
135-
friend llvm::hash_code hash_value(const Requirement &requirement) {
136-
using llvm::hash_value;
137-
138-
llvm::hash_code first =
139-
hash_value(requirement.FirstTypeAndKind.getOpaqueValue());
140-
llvm::hash_code second;
141-
switch (requirement.getKind()) {
142-
case RequirementKind::Conformance:
143-
case RequirementKind::Superclass:
144-
case RequirementKind::SameType:
145-
second = hash_value(requirement.getSecondType().getPointer());
146-
break;
147-
148-
case RequirementKind::Layout:
149-
second = hash_value(requirement.getLayoutConstraint());
150-
break;
151-
}
152-
153-
return llvm::hash_combine(first, second);
154-
}
155-
156-
friend bool operator==(const Requirement &lhs, const Requirement &rhs) {
157-
if (lhs.FirstTypeAndKind.getOpaqueValue()
158-
!= rhs.FirstTypeAndKind.getOpaqueValue())
159-
return false;
160-
161-
switch (lhs.getKind()) {
162-
case RequirementKind::Conformance:
163-
case RequirementKind::Superclass:
164-
case RequirementKind::SameType:
165-
return lhs.getSecondType().getPointer() ==
166-
rhs.getSecondType().getPointer();
167-
168-
case RequirementKind::Layout:
169-
return lhs.getLayoutConstraint() == rhs.getLayoutConstraint();
170-
}
171-
llvm_unreachable("Unhandled RequirementKind in switch");
172-
}
17381
};
17482

17583
inline void simple_display(llvm::raw_ostream &out, const Requirement &req) {

0 commit comments

Comments
 (0)