Skip to content

Commit affb476

Browse files
Merge pull request #4951 from swiftwasm/main
[pull] swiftwasm from main
2 parents 6b582f7 + 410a4ee commit affb476

Some content is hidden

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

63 files changed

+2475
-404
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,12 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
581581
target_link_directories(${target} PRIVATE "${sdk_dir}")
582582
583583
# Include the abi stable system stdlib in our rpath.
584-
set(swift_runtime_rpath "/usr/lib/swift")
584+
set(swift_runtime_rpath "/usr/lib/swift")
585+
586+
# Add in the toolchain directory so we can grab compatibility libraries
587+
get_filename_component(TOOLCHAIN_BIN_DIR ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
588+
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" ABSOLUTE)
589+
target_link_directories(${target} PUBLIC ${TOOLCHAIN_LIB_DIR})
585590
endif()
586591
endif()
587592
endif()

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,12 +1342,12 @@ ERROR(legacy_object_literal,none,
13421342
ERROR(unknown_pound_expr,none,
13431343
"use of unknown directive '#%0'", (StringRef))
13441344

1345-
// If expressions
1346-
ERROR(expected_expr_after_if_question,none,
1345+
// Ternary expressions
1346+
ERROR(expected_expr_after_ternary_question,none,
13471347
"expected expression after '?' in ternary expression", ())
1348-
ERROR(expected_colon_after_if_question,none,
1348+
ERROR(expected_colon_after_ternary_question,none,
13491349
"expected ':' after '? ...' in ternary expression", ())
1350-
ERROR(expected_expr_after_if_colon,none,
1350+
ERROR(expected_expr_after_ternary_colon,none,
13511351
"expected expression after '? ... :' in ternary expression", ())
13521352
ERROR(expected_expr_after_try, none,
13531353
"expected expression after 'try'", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ ERROR(invalid_force_unwrap,none,
10701070
ERROR(invalid_optional_chain,none,
10711071
"cannot use optional chaining on non-optional value of type %0",
10721072
(Type))
1073-
ERROR(if_expr_cases_mismatch,none,
1073+
ERROR(ternary_expr_cases_mismatch,none,
10741074
"result values in '? :' expression have mismatching types %0 and %1",
10751075
(Type, Type))
10761076

include/swift/AST/Expr.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5061,25 +5061,21 @@ class RebindSelfInConstructorExpr : public Expr {
50615061
return E->getKind() == ExprKind::RebindSelfInConstructor;
50625062
}
50635063
};
5064-
5065-
/// The conditional expression 'x ? y : z'.
5066-
class IfExpr : public Expr {
5064+
5065+
/// The ternary conditional expression 'x ? y : z'.
5066+
class TernaryExpr : public Expr {
50675067
Expr *CondExpr, *ThenExpr, *ElseExpr;
50685068
SourceLoc QuestionLoc, ColonLoc;
50695069
public:
5070-
IfExpr(Expr *CondExpr,
5071-
SourceLoc QuestionLoc, Expr *ThenExpr,
5072-
SourceLoc ColonLoc, Expr *ElseExpr,
5073-
Type Ty = Type())
5074-
: Expr(ExprKind::If, /*Implicit=*/false, Ty),
5075-
CondExpr(CondExpr), ThenExpr(ThenExpr), ElseExpr(ElseExpr),
5076-
QuestionLoc(QuestionLoc), ColonLoc(ColonLoc)
5077-
{}
5078-
5079-
IfExpr(SourceLoc QuestionLoc, Expr *ThenExpr, SourceLoc ColonLoc)
5080-
: IfExpr(nullptr, QuestionLoc, ThenExpr, ColonLoc, nullptr)
5081-
{}
5082-
5070+
TernaryExpr(Expr *CondExpr, SourceLoc QuestionLoc, Expr *ThenExpr,
5071+
SourceLoc ColonLoc, Expr *ElseExpr, Type Ty = Type())
5072+
: Expr(ExprKind::Ternary, /*Implicit=*/false, Ty), CondExpr(CondExpr),
5073+
ThenExpr(ThenExpr), ElseExpr(ElseExpr), QuestionLoc(QuestionLoc),
5074+
ColonLoc(ColonLoc) {}
5075+
5076+
TernaryExpr(SourceLoc QuestionLoc, Expr *ThenExpr, SourceLoc ColonLoc)
5077+
: TernaryExpr(nullptr, QuestionLoc, ThenExpr, ColonLoc, nullptr) {}
5078+
50835079
SourceLoc getLoc() const { return QuestionLoc; }
50845080
SourceLoc getStartLoc() const {
50855081
return (isFolded() ? CondExpr->getStartLoc() : QuestionLoc);
@@ -5103,7 +5099,7 @@ class IfExpr : public Expr {
51035099
bool isFolded() const { return CondExpr && ElseExpr; }
51045100

51055101
static bool classof(const Expr *E) {
5106-
return E->getKind() == ExprKind::If;
5102+
return E->getKind() == ExprKind::Ternary;
51075103
}
51085104
};
51095105

@@ -5979,7 +5975,7 @@ class TypeJoinExpr final : public Expr,
59795975
};
59805976

59815977
inline bool Expr::isInfixOperator() const {
5982-
return isa<BinaryExpr>(this) || isa<IfExpr>(this) ||
5978+
return isa<BinaryExpr>(this) || isa<TernaryExpr>(this) ||
59835979
isa<AssignExpr>(this) || isa<ExplicitCastExpr>(this);
59845980
}
59855981

include/swift/AST/ExprNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ ABSTRACT_EXPR(ExplicitCast, Expr)
194194
EXPR(Coerce, ExplicitCastExpr)
195195
EXPR_RANGE(ExplicitCast, ForcedCheckedCast, Coerce)
196196
UNCHECKED_EXPR(Arrow, Expr)
197-
EXPR(If, Expr)
197+
EXPR(Ternary, Expr)
198198
EXPR(EnumIsCase, Expr)
199199
EXPR(Assign, Expr)
200200
EXPR(CodeCompletion, Expr)

include/swift/SIL/NodeDatastructures.h

Lines changed: 165 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
//
1313
// This file defines efficient data structures for working with Nodes.
1414
//
15-
// TODO: Add an InstructionWorklist similar to BasicBlockWorklist.
16-
//
1715
//===----------------------------------------------------------------------===//
1816

1917
#ifndef SWIFT_SIL_NODEDATASTRUCTURES_H
@@ -29,7 +27,7 @@ namespace swift {
2927
/// NodeSet>`.
3028
///
3129
/// Unfortunately it's not possible to use `llvm::SetVector` directly because
32-
/// the ValueSet and StackList constructors needs a `SILFunction` argument.
30+
/// the NodeSet and StackList constructors needs a `SILFunction` argument.
3331
///
3432
/// Note: This class does not provide a `remove` method intentionally, because
3533
/// it would have a O(n) complexity.
@@ -63,6 +61,112 @@ class NodeSetVector {
6361
}
6462
};
6563

64+
/// An implementation of `llvm::SetVector<SILInstruction *,
65+
/// StackList<SILInstruction *>,
66+
/// InstructionSet>`.
67+
///
68+
/// Unfortunately it's not possible to use `llvm::SetVector` directly because
69+
/// the InstructionSet and StackList constructors needs a `SILFunction`
70+
/// argument.
71+
///
72+
/// Note: This class does not provide a `remove` method intentionally, because
73+
/// it would have a O(n) complexity.
74+
class InstructionSetVector {
75+
StackList<SILInstruction *> vector;
76+
InstructionSet set;
77+
78+
public:
79+
using iterator = typename StackList<SILInstruction *>::iterator;
80+
81+
InstructionSetVector(SILFunction *function)
82+
: vector(function), set(function) {}
83+
84+
iterator begin() const { return vector.begin(); }
85+
iterator end() const { return vector.end(); }
86+
87+
llvm::iterator_range<iterator> getRange() const {
88+
return llvm::make_range(begin(), end());
89+
}
90+
91+
bool empty() const { return vector.empty(); }
92+
93+
bool contains(SILInstruction *instruction) const {
94+
return set.contains(instruction);
95+
}
96+
97+
/// Returns true if \p instruction was not contained in the set before
98+
/// inserting.
99+
bool insert(SILInstruction *instruction) {
100+
if (set.insert(instruction)) {
101+
vector.push_back(instruction);
102+
return true;
103+
}
104+
return false;
105+
}
106+
};
107+
108+
/// A utility for processing instructions in a worklist.
109+
///
110+
/// It is basically a combination of an instruction vector and an instruction
111+
/// set. It can be used for typical worklist-processing algorithms.
112+
class InstructionWorklist {
113+
StackList<SILInstruction *> worklist;
114+
InstructionSet visited;
115+
116+
public:
117+
/// Construct an empty worklist.
118+
InstructionWorklist(SILFunction *function)
119+
: worklist(function), visited(function) {}
120+
121+
/// Initialize the worklist with \p initialBlock.
122+
InstructionWorklist(SILInstruction *initialInstruction)
123+
: InstructionWorklist(initialInstruction->getFunction()) {
124+
push(initialInstruction);
125+
}
126+
127+
/// Pops the last added element from the worklist or returns null, if the
128+
/// worklist is empty.
129+
SILInstruction *pop() {
130+
if (worklist.empty())
131+
return nullptr;
132+
return worklist.pop_back_val();
133+
}
134+
135+
/// Pushes \p instruction onto the worklist if \p instruction has never been
136+
/// push before.
137+
bool pushIfNotVisited(SILInstruction *instruction) {
138+
if (visited.insert(instruction)) {
139+
worklist.push_back(instruction);
140+
return true;
141+
}
142+
return false;
143+
}
144+
145+
/// Like `pushIfNotVisited`, but requires that \p instruction has never been
146+
/// on the worklist before.
147+
void push(SILInstruction *instruction) {
148+
assert(!visited.contains(instruction));
149+
visited.insert(instruction);
150+
worklist.push_back(instruction);
151+
}
152+
153+
/// Like `pop`, but marks the returned instruction as "unvisited". This means,
154+
/// that the instruction can be pushed onto the worklist again.
155+
SILInstruction *popAndForget() {
156+
if (worklist.empty())
157+
return nullptr;
158+
SILInstruction *instruction = worklist.pop_back_val();
159+
visited.erase(instruction);
160+
return instruction;
161+
}
162+
163+
/// Returns true if \p instruction was visited, i.e. has been added to the
164+
/// worklist.
165+
bool isVisited(SILInstruction *instruction) const {
166+
return visited.contains(instruction);
167+
}
168+
};
169+
66170
/// An implementation of `llvm::SetVector<SILValue,
67171
/// StackList<SILValue>,
68172
/// ValueSet>`.
@@ -102,6 +206,64 @@ class ValueSetVector {
102206
}
103207
};
104208

209+
/// A utility for processing values in a worklist.
210+
///
211+
/// It is basically a combination of a value vector and a value set. It can be
212+
/// used for typical worklist-processing algorithms.
213+
class ValueWorklist {
214+
StackList<SILValue> worklist;
215+
ValueSet visited;
216+
217+
public:
218+
/// Construct an empty worklist.
219+
ValueWorklist(SILFunction *function)
220+
: worklist(function), visited(function) {}
221+
222+
/// Initialize the worklist with \p initialValue.
223+
ValueWorklist(SILValue initialValue)
224+
: ValueWorklist(initialValue->getFunction()) {
225+
push(initialValue);
226+
}
227+
228+
/// Pops the last added element from the worklist or returns null, if the
229+
/// worklist is empty.
230+
SILValue pop() {
231+
if (worklist.empty())
232+
return nullptr;
233+
return worklist.pop_back_val();
234+
}
235+
236+
/// Pushes \p value onto the worklist if \p value has never been push before.
237+
bool pushIfNotVisited(SILValue value) {
238+
if (visited.insert(value)) {
239+
worklist.push_back(value);
240+
return true;
241+
}
242+
return false;
243+
}
244+
245+
/// Like `pushIfNotVisited`, but requires that \p value has never been on the
246+
/// worklist before.
247+
void push(SILValue value) {
248+
assert(!visited.contains(value));
249+
visited.insert(value);
250+
worklist.push_back(value);
251+
}
252+
253+
/// Like `pop`, but marks the returned value as "unvisited". This means, that
254+
/// the value can be pushed onto the worklist again.
255+
SILValue popAndForget() {
256+
if (worklist.empty())
257+
return nullptr;
258+
SILValue value = worklist.pop_back_val();
259+
visited.erase(value);
260+
return value;
261+
}
262+
263+
/// Returns true if \p value was visited, i.e. has been added to the worklist.
264+
bool isVisited(SILValue value) const { return visited.contains(value); }
265+
};
266+
105267
} // namespace swift
106268

107269
#endif

include/swift/SIL/SILDeclRef.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ struct SILDeclRef {
380380
bool isAlwaysInline() const;
381381
/// True if the function has the @_backDeploy attribute.
382382
bool isBackDeployed() const;
383-
383+
384+
/// Return the expected linkage for a definition of this declaration.
385+
SILLinkage getDefinitionLinkage() const;
386+
384387
/// Return the expected linkage of this declaration.
385388
SILLinkage getLinkage(ForDefinition_t forDefinition) const;
386389

0 commit comments

Comments
 (0)