Skip to content

Commit

Permalink
Merge pull request #629 from swiftwasm/master
Browse files Browse the repository at this point in the history
[pull] swiftwasm from master
  • Loading branch information
kateinoigakukun authored Apr 11, 2020
2 parents d57818f + 1af01ed commit 84199cf
Show file tree
Hide file tree
Showing 133 changed files with 2,344 additions and 1,297 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ CHANGELOG
Swift 5.3
----------

* [SE-0268][]:

A `didSet` observer which does not refer to the `oldValue` in its body or does not explicitly request it by placing it in the parameter list (i.e. `didSet(oldValue)`) will no longer trigger a call to the property getter to fetch the `oldValue`.

```swift
class C {
var value: Int = 0 {
didSet { print("didSet called!") }
}
}

let c = C()
// This does not trigger a call to the getter for 'value'
// because the 'didSet' observer on 'value' does not
// refer to the 'oldValue' in its body, which means
// the 'oldValue' does not need to be fetched.
c.value = 1
```

* [SE-0276][]:

Catch clauses in a `do`-`catch` statement can now include multiple patterns in a comma-separated list. The body of a `catch` clause will be executed if a thrown error matches any of its patterns.
Expand Down Expand Up @@ -7982,6 +8001,7 @@ Swift 1.0
[SE-0254]: <https://github.com/apple/swift-evolution/blob/master/proposals/0254-static-subscripts.md>
[SE-0266]: <https://github.com/apple/swift-evolution/blob/master/proposals/0266-synthesized-comparable-for-enumerations.md>
[SE-0267]: <https://github.com/apple/swift-evolution/blob/master/proposals/0267-where-on-contextually-generic.md>
[SE-0268]: <https://github.com/apple/swift-evolution/blob/master/proposals/0268-didset-semantics.md>
[SE-0269]: <https://github.com/apple/swift-evolution/blob/master/proposals/0269-implicit-self-explicit-capture.md>
[SE-0276]: <https://github.com/apple/swift-evolution/blob/master/proposals/0276-multi-pattern-catch-clauses.md>
[SE-0280]: <https://github.com/apple/swift-evolution/blob/master/proposals/0280-enum-cases-as-protocol-witnesses.md>
Expand Down
2 changes: 1 addition & 1 deletion benchmark/single-source/DataBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func withUnsafeMutableBytes(_ N: Int, data: Data) {
@inline(never)
func copyBytes(_ N: Int, data: Data) {
let amount = data.count
var buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: amount)
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: amount)
defer { buffer.deallocate() }
for _ in 1...N {
data.copyBytes(to: buffer, from: 0..<amount)
Expand Down
2 changes: 2 additions & 0 deletions docs/Diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,5 @@ An expected diagnostic is denoted by a comment which begins with `expected-error
- (Required) The expected error message. The message should be enclosed in double curly braces and should not include the `error:`/`warning:`/`note:`/`remark:` prefix. For example, `// expected-error {{invalid redeclaration of 'y'}}` would match an error with that message on the same line. The expected message does not need to match the emitted message verbatim. As long as the expected message is a substring of the original message, they will match.

- (Optional) Expected fix-its. These are each enclosed in double curly braces and appear after the expected message. An expected fix-it consists of a column range followed by the text it's expected to be replaced with. For example, `let r : Int i = j // expected-error{{consecutive statements}} {{12-12=;}}` will match a fix-it attached to the consecutive statements error which inserts a semicolon at column 12, just after the 't' in 'Int'. The special {{none}} specifier is also supported, which will cause the diagnostic match to fail if unexpected fix-its are produced.

- (Optional) Expected educational notes. These appear as a comma separated list after the expected message, enclosed in double curly braces and prefixed by 'educational-notes='. For example, `{{educational-notes=some-note,some-other-note}}` will verify the educational notes with filenames `some-note` and `some-other-note` appear. Do not include the file extension when specifying note names.
15 changes: 13 additions & 2 deletions docs/OptimizationTips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@ three different optimization levels:

In the Xcode UI, one can modify the current optimization level as follows:

...

In the Project Navigator, select the project icon to enter the Project Editor.
In the project editor, select the icon under the "Project" header to enter
the project settings editor. From there, an optimization setting can be applied
to every target in the project by changing the "Optimization Level" field under
the "Build Settings" header.

To apply a custom optimization level to a particular target, select that target
under the "Targets" header in the Project Editor and override the
"Optimization Level" field under its "Build Settings" header.

If a given optimization level is not available in the UI, its corresponding flag
can be manually specified by selecting the ``Other...`` level in
the "Optimization Level" dropdown.

Whole Module Optimizations (WMO)
================================
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ class ASTMangler : public Mangler {

std::string mangleLocalTypeDecl(const TypeDecl *type);

std::string mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl);

enum SpecialContext {
ObjCContext,
ClangImporterContext,
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,9 @@ ERROR(attr_specialize_unknown_parameter_name,none,
ERROR(attr_specialize_expected_bool_value,none,
"expected a boolean true or false value in '_specialize' attribute", ())

WARNING(attr_specialize_export_true_no_op,none,
"'exported: true' has no effect in '_specialize' attribute", ())

ERROR(attr_specialize_missing_parameter_label_or_where_clause,none,
"expected a parameter label or a where clause in '_specialize' attribute", ())

Expand Down
15 changes: 7 additions & 8 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,10 @@ ERROR(missing_unwrap_optional_try,none,
ERROR(missing_forced_downcast,none,
"%0 is not convertible to %1; "
"did you mean to use 'as!' to force downcast?", (Type, Type))
WARNING(coercion_may_fail_warning,none,
"coercion from %0 to %1 may fail; use 'as?' or 'as!' instead",
(Type, Type))

ERROR(missing_explicit_conversion,none,
"%0 is not implicitly convertible to %1; "
"did you mean to use 'as' to explicitly convert?", (Type, Type))
Expand Down Expand Up @@ -1221,7 +1225,7 @@ ERROR(invalid_autoclosure_forwarding,none,
"add () to forward @autoclosure parameter", ())
ERROR(invalid_differentiable_function_conversion_expr,none,
"a '@differentiable%select{|(linear)}0' function can only be formed from "
"a reference to a 'func' or a literal closure", (bool))
"a reference to a 'func' or 'init' or a literal closure", (bool))
NOTE(invalid_differentiable_function_conversion_parameter,none,
"did you mean to take a '%0' closure?", (StringRef))
ERROR(invalid_autoclosure_pointer_conversion,none,
Expand Down Expand Up @@ -2651,14 +2655,14 @@ NOTE(construct_raw_representable_from_unwrapped_value,none,
"construct %0 from unwrapped %1 value", (Type, Type))

ERROR(decl_from_hidden_module,none,
"cannot use %0 %1 %select{here|"
"cannot use %0 %1 %select{here|as property wrapper here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances}2; "
"%select{%3 has been imported as implementation-only|"
"it is an SPI imported from %3}4",
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
ERROR(conformance_from_implementation_only_module,none,
"cannot use conformance of %0 to %1 %select{here|"
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances}2; %3 has been imported "
"as implementation-only",
Expand Down Expand Up @@ -4456,11 +4460,6 @@ ERROR(dynamic_with_transparent,none,
"a declaration cannot be both '@_tranparent' and 'dynamic'",
())

ERROR(dynamic_and_library_evolution_not_supported,none,
"marking non-'@objc' Swift declaration 'dynamic' in library evolution mode is not supported",
())


//------------------------------------------------------------------------------
// MARK: @_dynamicReplacement(for:)
//------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions include/swift/AST/PrettyStackTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ void printDifferentiabilityWitnessDescription(
llvm::raw_ostream &out, const SILDifferentiabilityWitnessKey key,
bool addNewline = true);

/// PrettyStackTraceDeclContext - Observe that we are processing a
/// specific decl context.
class PrettyStackTraceDeclContext : public llvm::PrettyStackTraceEntry {
const DeclContext *DC;
const char *Action;
public:
PrettyStackTraceDeclContext(const char *action, const DeclContext *DC)
: DC(DC), Action(action) {}
virtual void print(llvm::raw_ostream &OS) const;
};

} // end namespace swift

#endif
3 changes: 3 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class SILOptions {
/// Controls whether or not paranoid verification checks are run.
bool VerifyAll = false;

/// If true, no SIL verification is done at all.
bool VerifyNone = false;

/// Are we debugging sil serialization.
bool DebugSerialization = false;

Expand Down
9 changes: 7 additions & 2 deletions include/swift/Frontend/DiagnosticVerifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ struct CapturedDiagnosticInfo {
unsigned Line;
unsigned Column;
SmallVector<DiagnosticInfo::FixIt, 2> FixIts;
SmallVector<std::string, 1> EducationalNotes;

CapturedDiagnosticInfo(llvm::SmallString<128> Message,
llvm::SmallString<32> FileName,
DiagnosticKind Classification, SourceLoc Loc,
unsigned Line, unsigned Column,
SmallVector<DiagnosticInfo::FixIt, 2> FixIts)
SmallVector<DiagnosticInfo::FixIt, 2> FixIts,
SmallVector<std::string, 1> EducationalNotes)
: Message(Message), FileName(FileName), Classification(Classification),
Loc(Loc), Line(Line), Column(Column), FixIts(FixIts) {}
Loc(Loc), Line(Line), Column(Column), FixIts(FixIts),
EducationalNotes(EducationalNotes) {
std::sort(EducationalNotes.begin(), EducationalNotes.end());
}
};
/// This class implements support for -verify mode in the compiler. It
/// buffers up diagnostics produced during compilation, then checks them
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
def sil_verify_all : Flag<["-"], "sil-verify-all">,
HelpText<"Verify SIL after each transform">;

def sil_verify_none : Flag<["-"], "sil-verify-none">,
HelpText<"Completely disable SIL verification">;

def verify_all_substitution_maps : Flag<["-"], "verify-all-substitution-maps">,
HelpText<"Verify all SubstitutionMaps on construction">;

Expand Down
6 changes: 6 additions & 0 deletions include/swift/SIL/SILBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
InstList.splice(end(), Other->InstList);
}

void spliceAtBegin(SILBasicBlock *Other) {
InstList.splice(begin(), Other->InstList);
}

bool empty() const { return InstList.empty(); }
iterator begin() { return InstList.begin(); }
iterator end() { return InstList.end(); }
Expand Down Expand Up @@ -202,6 +206,8 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {

void cloneArgumentList(SILBasicBlock *Other);

void moveArgumentList(SILBasicBlock *from);

/// Erase a specific argument from the arg list.
void eraseArgument(int Index);

Expand Down
3 changes: 3 additions & 0 deletions include/swift/SIL/SILInstructionWorklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
/// Returns true if the worklist is empty.
bool isEmpty() const { return worklist.empty(); }

/// Returns the number of elements in the worklist.
unsigned size() const { return worklist.size(); }

/// Add the specified instruction to the worklist if it isn't already in it.
void add(SILInstruction *instruction) {
if (worklist.insert(instruction).second) {
Expand Down
22 changes: 20 additions & 2 deletions include/swift/SILOptimizer/Analysis/EscapeAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ class EscapeAnalysis : public BottomUpIPAnalysis {
/// True if this is a summary graph.
bool isSummaryGraph;

/// True if the graph could be computed.
bool valid = true;

/// Track the currently active intrusive worklist -- one at a time.
CGNodeWorklist *activeWorklist = nullptr;

Expand Down Expand Up @@ -859,6 +862,22 @@ class EscapeAnalysis : public BottomUpIPAnalysis {
bool forwardTraverseDefer(CGNode *startNode, CGNodeVisitor &&visitor);

public:

/// Returns true if the graph could be computed.
///
/// For very large functions (> 10000 nodes), graphs are not cumputed to
/// avoid quadratic complexity of the node merging algorithm.
bool isValid() const {
assert((valid || isEmpty()) && "invalid graph must not contain nodes");
return valid;
}

/// Invalides the graph in case it's getting too large.
void invalidate() {
clear();
valid = false;
}

/// Get the content node pointed to by \p ptrVal.
///
/// If \p ptrVal cannot be mapped to a node, return nullptr.
Expand Down Expand Up @@ -1045,8 +1064,7 @@ class EscapeAnalysis : public BottomUpIPAnalysis {
/// If \p ai is an optimizable @_semantics("array.uninitialized") call, return
/// valid call information.
ArrayUninitCall
canOptimizeArrayUninitializedCall(ApplyInst *ai,
const ConnectionGraph *conGraph);
canOptimizeArrayUninitializedCall(ApplyInst *ai);

/// Return true of this tuple_extract is the result of an optimizable
/// @_semantics("array.uninitialized") call.
Expand Down
7 changes: 7 additions & 0 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/ProtocolConformanceRef.h"
#include "swift/Basic/Defer.h"
#include "swift/Demangling/ManglingMacros.h"
#include "swift/Demangling/ManglingUtils.h"
#include "swift/Demangling/Demangler.h"
#include "swift/Strings.h"
Expand Down Expand Up @@ -691,6 +692,12 @@ std::string ASTMangler::mangleLocalTypeDecl(const TypeDecl *type) {
return finalize();
}

std::string ASTMangler::mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl) {
DWARFMangling = true;
OptimizeProtocolNames = false;
return mangleDeclAsUSR(decl->getNamingDecl(), MANGLING_PREFIX_STR);
}

void ASTMangler::appendSymbolKind(SymbolKind SKind) {
switch (SKind) {
case SymbolKind::Default: return;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7088,7 +7088,7 @@ Identifier OpaqueTypeDecl::getOpaqueReturnTypeIdentifier() const {
{
llvm::raw_svector_ostream os(mangleBuf);
Mangle::ASTMangler mangler;
os << mangler.mangleDeclAsUSR(getNamingDecl(), MANGLING_PREFIX_STR);
os << mangler.mangleOpaqueTypeDecl(this);
}

OpaqueReturnTypeIdentifier = getASTContext().getIdentifier(mangleBuf);
Expand Down
7 changes: 7 additions & 0 deletions lib/AST/PrettyStackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,10 @@ void swift::printDifferentiabilityWitnessDescription(
if (addNewline)
out << '\n';
}

void PrettyStackTraceDeclContext::print(llvm::raw_ostream &out) const {
out << "While " << Action << " in decl context:\n";
out << " ---\n";
DC->printContext(out, /*indent=*/4);
out << " ---\n";
}
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3314,7 +3314,7 @@ ClangModuleUnit::ClangModuleUnit(ModuleDecl &M,
clangModule(clangModule) {
// Capture the file metadata before it goes away.
if (clangModule)
ASTSourceDescriptor = {*clangModule};
ASTSourceDescriptor = {*const_cast<clang::Module *>(clangModule)};
}

StringRef ClangModuleUnit::getModuleDefiningPath() const {
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.DisableSILPerfOptimizations |= Args.hasArg(OPT_disable_sil_perf_optzns);
Opts.CrossModuleOptimization |= Args.hasArg(OPT_CrossModuleOptimization);
Opts.VerifyAll |= Args.hasArg(OPT_sil_verify_all);
Opts.VerifyNone |= Args.hasArg(OPT_sil_verify_none);
Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization);
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);
Expand Down
Loading

0 comments on commit 84199cf

Please sign in to comment.