Skip to content

Commit 2d6e6f8

Browse files
authored
Merge pull request #673 from swiftwasm/master
[pull] swiftwasm from master
2 parents ce86f8e + 061c6d0 commit 2d6e6f8

File tree

75 files changed

+1867
-892
lines changed

Some content is hidden

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

75 files changed

+1867
-892
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,13 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
907907
endif()
908908

909909
find_package(Python2 COMPONENTS Interpreter REQUIRED)
910-
find_package(Python3 COMPONENTS Interpreter REQUIRED)
910+
find_package(Python3 COMPONENTS Interpreter)
911+
if(NOT Python3_Interpreter_FOUND)
912+
message(WARNING "Python3 not found, using python2 as a fallback")
913+
add_executable(Python3::Interpreter IMPORTED)
914+
set_target_properties(Python3::Interpreter PROPERTIES
915+
IMPORTED_LOCATION ${Python2_EXECUTABLE})
916+
endif()
911917

912918
#
913919
# Find optional dependencies.

benchmark/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ set(SWIFT_BENCH_MODULES
9696
single-source/Hanoi
9797
single-source/Hash
9898
single-source/Histogram
99-
single-source/InsertCharacter
100-
single-source/IntegerParsing
99+
single-source/HTTP2StateMachine
101100
single-source/Integrate
102101
single-source/IterateData
103102
single-source/Join

benchmark/Package.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ func getSingleSourceLibraries(subDirectory: String) -> [String] {
2222
let fileURLs = try! f.contentsOfDirectory(at: dirURL,
2323
includingPropertiesForKeys: nil)
2424
return fileURLs.compactMap { (path: URL) -> String? in
25-
let c = path.lastPathComponent.split(separator: ".")
26-
// Too many components. Must be a gyb file.
27-
if c.count > 2 {
28-
return nil
29-
}
30-
if c[1] != "swift" {
25+
guard let lastDot = path.lastPathComponent.lastIndex(of: ".") else {
3126
return nil
3227
}
28+
let ext = String(path.lastPathComponent.suffix(from: lastDot))
29+
guard ext == ".swift" else { return nil }
30+
31+
let name = String(path.lastPathComponent.prefix(upTo: lastDot))
3332

34-
let name = String(c[0])
33+
// Test names must have a single component.
34+
if name.contains(".") { return nil }
3535

36-
// We do not support this test.
3736
if unsupportedTests.contains(name) {
37+
// We do not support this test.
3838
return nil
3939
}
4040

benchmark/single-source/HTTP2StateMachine.swift

Lines changed: 390 additions & 0 deletions
Large diffs are not rendered by default.

benchmark/utils/main.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ import FloatingPointPrinting
8484
import Hanoi
8585
import Hash
8686
import Histogram
87-
import InsertCharacter
88-
import IntegerParsing
87+
import HTTP2StateMachine
8988
import Integrate
9089
import IterateData
9190
import Join
@@ -268,8 +267,7 @@ registerBenchmark(FloatingPointPrinting)
268267
registerBenchmark(Hanoi)
269268
registerBenchmark(HashTest)
270269
registerBenchmark(Histogram)
271-
registerBenchmark(InsertCharacter)
272-
registerBenchmark(IntegerParsing)
270+
registerBenchmark(HTTP2StateMachine)
273271
registerBenchmark(IntegrateTest)
274272
registerBenchmark(IterateData)
275273
registerBenchmark(Join)

docs/ContinuousIntegration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Source Compatibility Testing](#source-compatibility-testing)
1313
- [Sourcekit Stress Testing](#sourcekit-stress-testing)
1414
- [Specific Preset Testing](#specific-preset-testing)
15+
- [Running Non-Executable Device Tests](#running-non-executable-device-tests)
1516
- [Build Swift Toolchain](#build-swift-toolchain)
1617
- [Testing Compiler Performance](#testing-compiler-performance)
1718
- [Swift Community Hosted CI Pull Request Testing](#swift-community-hosted-ci-pull-request-testing)
@@ -161,8 +162,18 @@ For example:
161162
```
162163
preset=buildbot_incremental,tools=RA,stdlib=RD,smoketest=macosx,single-thread
163164
@swift-ci Please test with preset macOS
165+
```
166+
167+
### Running Non-Executable Device Tests
168+
169+
Using the specific preset testing, one can run non-executable device tests by
170+
telling swift-ci:
164171

165172
```
173+
preset=buildbot,tools=RA,stdlib=RD,test=non_executable
174+
@swift-ci Please test with preset macOS
175+
```
176+
166177
### Build Swift Toolchain
167178

168179
Platform | Comment | Check Status

docs/DebuggingTheCompiler.rst

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ where to stop in the debugger. Rather than trying to guess/check if one has an
8080
asserts swift compiler, one can use the following options to cause the
8181
diagnostic engine to assert on the first error/warning:
8282

83-
* -Xllvm -swift-diagnostics-assert-on-error=1
84-
* -Xllvm -swift-diagnostics-assert-on-warning=1
83+
* ``-Xllvm -swift-diagnostics-assert-on-error=1``
84+
* ``-Xllvm -swift-diagnostics-assert-on-warning=1``
8585

8686
These allow one to dump a stack trace of where the diagnostic is being emitted
8787
(if run without a debugger) or drop into the debugger if a debugger is attached.
@@ -548,10 +548,17 @@ it's quite easy to do this manually:
548548

549549
a. Add the compiler option ``-Xllvm -sil-opt-pass-count=<n>``, where ``<n>``
550550
is the number of optimizations to run.
551-
b. Bisect: find n where the executable crashes, but does not crash with n-1.
552-
Note that n can be quite large, e.g. > 100000 (just try
553-
n = 10, 100, 1000, 10000, etc. to find an upper bound).
554-
c. Add another option ``-Xllvm -sil-print-pass-name``. The output can be
551+
552+
b. Bisect: find n where the executable crashes, but does not crash
553+
with n-1. First just try n = 10, 100, 1000, 10000, etc. to find
554+
an upper bound). Then can either bisect the invocation by hand or
555+
place the invocation into a script and use
556+
``./llvm-project/llvm/utils/bisect`` to automatically bisect
557+
based on the scripts error code. Example invocation::
558+
559+
bisect --start=0 --end=10000 ./invoke_swift_passing_N.sh "%(count)s"
560+
561+
c. Once one finds ``n``, Add another option ``-Xllvm -sil-print-pass-name``. The output can be
555562
large, so it's best to redirect stderr to a file (``2> output``).
556563
In the output search for the last pass before ``stage Address Lowering``.
557564
It should be the ``Run #<n-1>``. This line tells you the name of the bad
@@ -687,3 +694,65 @@ Multiple Logs at a Time
687694
Note, you can also turn on more than one log at a time as well, e.x.::
688695

689696
(lldb) log enable -f /tmp/lldb-types-log.txt lldb types expression
697+
698+
Using git-bisect in the presence of branch forwarding/feature branches
699+
======================================================================
700+
701+
``git-bisect`` is a useful tool for finding where a regression was
702+
introduced. Sadly ``git-bisect`` does not handle long lived branches
703+
and will in fact choose commits from upstream branches that may be
704+
missing important content from the downstream branch. As an example,
705+
consider a situation where one has the following straw man commit flow
706+
graph::
707+
708+
github/master -> github/tensorflow
709+
710+
In this case if one attempts to use ``git-bisect`` on
711+
github/tensorflow, ``git-bisect`` will sometimes choose commits from
712+
github/master resulting in one being unable to compile/test specific
713+
tensorflow code that has not been upstreamed yet. Even worse, what if
714+
we are trying to bisect in between two that were branched from
715+
github/tensorflow and have had subsequent commits cherry-picked on
716+
top. Without any loss of generality, lets call those two tags
717+
``tag-tensorflow-bad`` and ``tag-tensorflow-good``. Since both of
718+
these tags have had commits cherry-picked on top, they are technically
719+
not even on the github/tensorflow branch, but rather in a certain
720+
sense are a tag of a feature branch from master/tensorflow. So,
721+
``git-bisect`` doesn't even have a clear history to bisect on in
722+
multiple ways.
723+
724+
With those constraints in mind, we can bisect! We just need to be
725+
careful how we do it. Lets assume that we have a test script called
726+
``test.sh`` that indicates error by the error code. With that in hand,
727+
we need to compute the least common ancestor of the good/bad
728+
commits. This is traditionally called the "merge base" of the
729+
commits. We can compute this as so::
730+
731+
TAG_MERGE_BASE=$(git merge-base tags/tag-tensorflow-bad tags/tag-tensorflow-good)
732+
733+
Given that both tags were taken from the feature branch, the reader
734+
can prove to themselves that this commit is guaranteed to be on
735+
``github/tensorflow`` and not ``github/master`` since all commits from
736+
``github/master`` are forwarded using git merges.
737+
738+
Then lets assume that we checked out ``$TAG_MERGE_BASE`` and then ran
739+
``test.sh`` and did not hit any error. Ok, we can not bisect. Sadly,
740+
as mentioned above if we run git-bisect in between ``$TAG_MERGE_BASE``
741+
and ``tags/tag-tensorflow-bad``, ``git-bisect`` will sometimes choose
742+
commits from ``github/master`` which would cause ``test.sh`` to fail
743+
if we are testing tensorflow specific code! To work around this
744+
problem, we need to start our bisect and then tell ``git-bisect`` to
745+
ignore those commits by using the skip sub command::
746+
747+
git bisect start tags/tag-tensorflow-bad $TAG_MERGE_BASE
748+
for rev in $(git rev-list $TAG_MERGE_BASE..tags/tag-tensorflow-bad --merges --first-parent); do
749+
git rev-list $rev^2 --not $rev^
750+
done | xargs git bisect skip
751+
752+
Once this has been done, one uses ``git-bisect`` normally. One thing
753+
to be aware of is that ``git-bisect`` will return a good/bad commits
754+
on the feature branch and if one of those commits is a merge from the
755+
upstream branch, one will need to analyze the range of commits from
756+
upstream for the bad commit afterwards. The commit range in the merge
757+
should be relatively small though compared with the large git history
758+
one just bisected.

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5243,7 +5243,7 @@ class VarDecl : public AbstractStorageDecl {
52435243
///
52445244
/// \code
52455245
/// @Lazy var i = 17
5246-
/// \end
5246+
/// \endcode
52475247
///
52485248
/// Or when there is no initializer but each composed property wrapper has
52495249
/// a suitable `init(wrappedValue:)`.

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,8 @@ ERROR(nonstatic_operator_in_nominal,none,
902902
"operator %0 declared in type %1 must be 'static'",
903903
(Identifier, DeclName))
904904
ERROR(nonstatic_operator_in_extension,none,
905-
"operator %0 declared in extension of %1 must be 'static'",
906-
(Identifier, TypeRepr*))
905+
"operator %0 declared in extension%select{| of %2}1 must be 'static'",
906+
(Identifier, bool, TypeRepr*))
907907
ERROR(nonfinal_operator_in_class,none,
908908
"operator %0 declared in non-final class %1 must be 'final'",
909909
(Identifier, Type))

include/swift/AST/Expr.h

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4041,7 +4041,61 @@ class OpaqueValueExpr : public Expr {
40414041
SourceRange getSourceRange() const { return Range; }
40424042

40434043
static bool classof(const Expr *E) {
4044-
return E->getKind() == ExprKind::OpaqueValue;
4044+
return E->getKind() == ExprKind::OpaqueValue;
4045+
}
4046+
};
4047+
4048+
/// A placeholder to substitute with a \c wrappedValue initialization expression
4049+
/// for a property with an attached property wrapper.
4050+
///
4051+
/// Wrapped value placeholder expressions are injected around the
4052+
/// \c wrappedValue argument in a synthesized \c init(wrappedValue:)
4053+
/// call. This injection happens for properties with attached property wrappers
4054+
/// that can be initialized out-of-line with a wrapped value expression, rather
4055+
/// than calling \c init(wrappedValue:) explicitly.
4056+
///
4057+
/// Wrapped value placeholders store the original initialization expression
4058+
/// if one exists, along with an opaque value placeholder that can be bound
4059+
/// to a different wrapped value expression.
4060+
class PropertyWrapperValuePlaceholderExpr : public Expr {
4061+
SourceRange Range;
4062+
OpaqueValueExpr *Placeholder;
4063+
Expr *WrappedValue;
4064+
4065+
PropertyWrapperValuePlaceholderExpr(SourceRange Range, Type Ty,
4066+
OpaqueValueExpr *placeholder,
4067+
Expr *wrappedValue)
4068+
: Expr(ExprKind::PropertyWrapperValuePlaceholder, /*Implicit=*/true, Ty),
4069+
Range(Range), Placeholder(placeholder), WrappedValue(wrappedValue) {}
4070+
4071+
public:
4072+
static PropertyWrapperValuePlaceholderExpr *
4073+
create(ASTContext &ctx, SourceRange range, Type ty, Expr *wrappedValue);
4074+
4075+
/// The original wrappedValue initialization expression provided via
4076+
/// \c = on a proprety with attached property wrappers.
4077+
Expr *getOriginalWrappedValue() const {
4078+
return WrappedValue;
4079+
}
4080+
4081+
void setOriginalWrappedValue(Expr *value) {
4082+
WrappedValue = value;
4083+
}
4084+
4085+
/// An opaque value placeholder that will be used to substitute in a
4086+
/// different wrapped value expression for out-of-line initialization.
4087+
OpaqueValueExpr *getOpaqueValuePlaceholder() const {
4088+
return Placeholder;
4089+
}
4090+
4091+
void setOpaqueValuePlaceholder(OpaqueValueExpr *placeholder) {
4092+
Placeholder = placeholder;
4093+
}
4094+
4095+
SourceRange getSourceRange() const { return Range; }
4096+
4097+
static bool classof(const Expr *E) {
4098+
return E->getKind() == ExprKind::PropertyWrapperValuePlaceholder;
40454099
}
40464100
};
40474101

include/swift/AST/ExprNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ EXPR(VarargExpansion, Expr)
126126
EXPR(DynamicType, Expr)
127127
EXPR(RebindSelfInConstructor, Expr)
128128
EXPR(OpaqueValue, Expr)
129+
EXPR(PropertyWrapperValuePlaceholder, Expr)
129130
EXPR(DefaultArgument, Expr)
130131
EXPR(BindOptional, Expr)
131132
EXPR(OptionalEvaluation, Expr)

include/swift/AST/PropertyWrappers.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ struct PropertyWrapperBackingPropertyInfo {
141141
///
142142
/// \code
143143
/// @Lazy var i = 17
144-
/// \end
144+
/// \endcode
145145
///
146146
/// This is the specified initial value (\c 17), which is suitable for
147147
/// embedding in the expression \c initializeFromOriginal.
@@ -190,12 +190,13 @@ void simple_display(
190190
llvm::raw_ostream &out,
191191
const PropertyWrapperBackingPropertyInfo &backingInfo);
192192

193-
/// Given the initializer for the given property with an attached property
194-
/// wrapper, dig out the original initialization expression.
193+
/// Given the initializer for a property with an attached property wrapper,
194+
/// dig out the wrapped value placeholder for the original initialization
195+
/// expression.
195196
///
196-
/// Cannot just dig out the getOriginalInit() value because this function checks
197-
/// types, etc. Erroneous code won't return a result from here.
198-
Expr *findOriginalPropertyWrapperInitialValue(VarDecl *var, Expr *init);
197+
/// \note The wrapped value placeholder is injected for properties that can
198+
/// be initialized out-of-line using an expression of the wrapped property type.
199+
PropertyWrapperValuePlaceholderExpr *findWrappedValuePlaceholder(Expr *init);
199200

200201
} // end namespace swift
201202

lib/AST/ASTDumper.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,18 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
25112511
PrintWithColorRAII(OS, ParenthesisColor) << ')';
25122512
}
25132513

2514+
void visitPropertyWrapperValuePlaceholderExpr(
2515+
PropertyWrapperValuePlaceholderExpr *E) {
2516+
printCommon(E, "property_wrapper_value_placeholder_expr");
2517+
OS << '\n';
2518+
printRec(E->getOpaqueValuePlaceholder());
2519+
if (auto *value = E->getOriginalWrappedValue()) {
2520+
OS << '\n';
2521+
printRec(value);
2522+
}
2523+
PrintWithColorRAII(OS, ParenthesisColor) << ')';
2524+
}
2525+
25142526
void visitDefaultArgumentExpr(DefaultArgumentExpr *E) {
25152527
printCommon(E, "default_argument_expr");
25162528
OS << " default_args_owner=";

lib/AST/ASTWalker.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,23 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
508508

509509
Expr *visitOpaqueValueExpr(OpaqueValueExpr *E) { return E; }
510510

511+
Expr *visitPropertyWrapperValuePlaceholderExpr(
512+
PropertyWrapperValuePlaceholderExpr *E) {
513+
if (auto *placeholder = doIt(E->getOpaqueValuePlaceholder()))
514+
E->setOpaqueValuePlaceholder(dyn_cast<OpaqueValueExpr>(placeholder));
515+
else
516+
return nullptr;
517+
518+
if (E->getOriginalWrappedValue()) {
519+
if (auto *newValue = doIt(E->getOriginalWrappedValue()))
520+
E->setOriginalWrappedValue(newValue);
521+
else
522+
return nullptr;
523+
}
524+
525+
return E;
526+
}
527+
511528
Expr *visitDefaultArgumentExpr(DefaultArgumentExpr *E) { return E; }
512529

513530
Expr *visitInterpolatedStringLiteralExpr(InterpolatedStringLiteralExpr *E) {

0 commit comments

Comments
 (0)