Skip to content

Commit

Permalink
Merge pull request #441 from swiftwasm/master
Browse files Browse the repository at this point in the history
[pull] swiftwasm from master
  • Loading branch information
pull[bot] authored Mar 20, 2020
2 parents fb56bb9 + 70971b5 commit 8055997
Show file tree
Hide file tree
Showing 536 changed files with 4,835 additions and 4,440 deletions.
177 changes: 46 additions & 131 deletions docs/SIL.rst

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2433,10 +2433,6 @@ struct TargetProtocolConformanceDescriptor final
using OverloadToken = typename TrailingObjects::template OverloadToken<T>;

public:
using WitnessTableAccessorFn
= const TargetWitnessTable<Runtime> *(const TargetMetadata<Runtime>*,
const TargetWitnessTable<Runtime> **);

using GenericRequirementDescriptor =
TargetGenericRequirementDescriptor<Runtime>;

Expand Down
26 changes: 0 additions & 26 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,32 +332,6 @@ class ASTContext final {
llvm::BumpPtrAllocator &
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;

private:
bool SemanticQueriesEnabled = false;

public:
/// Returns \c true if legacy semantic AST queries are enabled.
///
/// The request evaluator generally subsumes the use of this bit. However,
/// there are clients - mostly SourceKit - that rely on the fact that this bit
/// being \c false causes some property wrapper requests to return null
/// sentinel values. These clients should be migrated off of this interface
/// to syntactic requests as soon as possible.
///
/// rdar://60516325
bool areLegacySemanticQueriesEnabled() const {
return SemanticQueriesEnabled;
}

/// Enable "semantic queries".
///
/// Setting this bit tells property wrapper requests to return a semantic
/// value. It does not otherwise affect compiler behavior and should be
/// removed as soon as possible.
void setLegacySemanticQueriesEnabled() {
SemanticQueriesEnabled = true;
}

public:
/// Allocate - Allocate memory from the ASTContext bump pointer.
void *Allocate(unsigned long bytes, unsigned alignment,
Expand Down
5 changes: 2 additions & 3 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class ASTMangler : public Mangler {
DynamicThunk,
SwiftAsObjCThunk,
ObjCAsSwiftThunk,
DirectMethodReferenceThunk,
};

ASTMangler(bool DWARFMangling = false)
Expand All @@ -98,14 +97,14 @@ class ASTMangler : public Mangler {
std::string mangleClosureEntity(const AbstractClosureExpr *closure,
SymbolKind SKind);

std::string mangleEntity(const ValueDecl *decl, bool isCurried,
std::string mangleEntity(const ValueDecl *decl,
SymbolKind SKind = SymbolKind::Default);

std::string mangleDestructorEntity(const DestructorDecl *decl,
bool isDeallocating, SymbolKind SKind);

std::string mangleConstructorEntity(const ConstructorDecl *ctor,
bool isAllocating, bool isCurried,
bool isAllocating,
SymbolKind SKind = SymbolKind::Default);

std::string mangleIVarInitDestroyEntity(const ClassDecl *decl,
Expand Down
10 changes: 5 additions & 5 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,11 @@ class ValueDecl : public Decl {
return !isObjC() && isDynamic();
}

bool isEffectiveLinkageMoreVisibleThan(ValueDecl *other) const {
return (std::min(getEffectiveAccess(), AccessLevel::Public) >
std::min(other->getEffectiveAccess(), AccessLevel::Public));
}

/// Set whether this type is 'dynamic' or not.
void setIsDynamic(bool value);

Expand Down Expand Up @@ -5983,11 +5988,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
/// vtable.
bool needsNewVTableEntry() const;

bool isEffectiveLinkageMoreVisibleThan(ValueDecl *other) const {
return (std::min(getEffectiveAccess(), AccessLevel::Public) >
std::min(other->getEffectiveAccess(), AccessLevel::Public));
}

bool isSynthesized() const {
return Bits.AbstractFunctionDecl.Synthesized;
}
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ ERROR(missing_member_dependency,none,
"dependency does not exist: %1",
(/*Expectation::Kind*/uint8_t, StringRef))
ERROR(unexpected_dependency,none,
"unexpected %0 %select{%error|%error||potential member|dynamic member}1 "
"unexpected %0 %select{%error|%error|member|potential member|dynamic member}1 "
"dependency: %2", (StringRef, /*Expectation::Kind*/uint8_t, StringRef))
ERROR(unexpected_provided_entity,none,
"unexpected provided entity: %0", (StringRef))
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/IRGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ class IRGenOptions {
/// Whether to disable shadow copies for local variables on the stack. This is
/// only used for testing.
unsigned DisableDebuggerShadowCopies : 1;

/// Whether to disable using mangled names for accessing concrete type metadata.
unsigned DisableConcreteTypeMetadataMangledNameAccessors : 1;

/// Path to the profdata file to be used for PGO, or the empty string.
std::string UseProfile = "";
Expand Down Expand Up @@ -327,6 +330,7 @@ class IRGenOptions {
UseSwiftCall(false), UseTypeLayoutValueHandling(true), GenerateProfile(false),
EnableDynamicReplacementChaining(false),
DisableRoundTripDebugTypes(false), DisableDebuggerShadowCopies(false),
DisableConcreteTypeMetadataMangledNameAccessors(false),
CmdArgs(), SanitizeCoverage(llvm::SanitizerCoverageOptions()),
TypeInfoFilter(TypeInfoDumpFilter::All) {}

Expand Down
5 changes: 4 additions & 1 deletion include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ struct PrintOptions {
/// Prints type variables and unresolved types in an expanded notation suitable
/// for debugging.
bool PrintTypesForDebugging = false;


/// Whether this print option is for printing .swiftinterface file
bool IsForSwiftInterface = false;

/// How to print opaque return types.
enum class OpaqueReturnTypePrintingMode {
/// 'some P1 & P2'.
Expand Down
4 changes: 1 addition & 3 deletions include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,7 @@ class LinkEntity {
LinkEntity() = default;

static bool isValidResilientMethodRef(SILDeclRef declRef) {
if (declRef.isForeign ||
declRef.isDirectReference ||
declRef.isCurried)
if (declRef.isForeign)
return false;

auto *decl = declRef.getDecl();
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ def disable_debugger_shadow_copies : Flag<["-"], "disable-debugger-shadow-copies
"This option is only useful for testing the compiler.">,
Flags<[FrontendOption, HelpHidden]>;

def disable_concrete_type_metadata_mangled_name_accessors : Flag<["-"], "disable-concrete-type-metadata-mangled-name-accessors">,
HelpText<"Disable concrete type metadata access by mangled name">,
Flags<[FrontendOption, HelpHidden]>;

def playground : Flag<["-"], "playground">,
HelpText<"Apply the playground semantics and transformation">;

Expand Down
63 changes: 10 additions & 53 deletions include/swift/SIL/SILDeclRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,16 @@ struct SILDeclRef {
Loc loc;
/// The Kind of this SILDeclRef.
Kind kind : 4;
/// True if the SILDeclRef is a curry thunk.
unsigned isCurried : 1;
/// True if this references a foreign entry point for the referenced decl.
unsigned isForeign : 1;
/// True if this is a direct reference to a class's method implementation
/// that isn't dynamically dispatched.
unsigned isDirectReference : 1;
/// The default argument index for a default argument getter.
unsigned defaultArgIndex : 10;

/// Produces a null SILDeclRef.
SILDeclRef() : loc(), kind(Kind::Func),
isCurried(0), isForeign(0), isDirectReference(0),
defaultArgIndex(0) {}
SILDeclRef() : loc(), kind(Kind::Func), isForeign(0), defaultArgIndex(0) {}

/// Produces a SILDeclRef of the given kind for the given decl.
explicit SILDeclRef(ValueDecl *decl, Kind kind,
bool isCurried = false,
bool isForeign = false);

/// Produces a SILDeclRef for the given ValueDecl or
Expand All @@ -174,13 +166,7 @@ struct SILDeclRef {
/// for the containing ClassDecl.
/// - If 'loc' is a global VarDecl, this returns its GlobalAccessor
/// SILDeclRef.
///
/// If 'isCurried' is true, the loc must be a method or enum element;
/// the SILDeclRef will then refer to a curry thunk with type
/// (Self) -> (Args...) -> Result, rather than a direct reference to
/// the actual method whose lowered type is (Args..., Self) -> Result.
explicit SILDeclRef(Loc loc,
bool isCurried = false,
bool isForeign = false);

/// Produce a SIL constant for a default argument generator.
Expand Down Expand Up @@ -289,16 +275,13 @@ struct SILDeclRef {
llvm::hash_code getHashCode() const {
return llvm::hash_combine(loc.getOpaqueValue(),
static_cast<int>(kind),
isCurried, isForeign, isDirectReference,
defaultArgIndex);
isForeign, defaultArgIndex);
}

bool operator==(SILDeclRef rhs) const {
return loc.getOpaqueValue() == rhs.loc.getOpaqueValue()
&& kind == rhs.kind
&& isCurried == rhs.isCurried
&& isForeign == rhs.isForeign
&& isDirectReference == rhs.isDirectReference
&& defaultArgIndex == rhs.defaultArgIndex;
}
bool operator!=(SILDeclRef rhs) const {
Expand All @@ -309,32 +292,12 @@ struct SILDeclRef {
void dump() const;

unsigned getParameterListCount() const;

// Returns the SILDeclRef for an entity at a shallower uncurry level.
SILDeclRef asCurried(bool curried = true) const {
assert(!isCurried && "can't safely go to deeper uncurry level");
// Curry thunks are never foreign.
bool willBeForeign = isForeign && !curried;
bool willBeDirect = isDirectReference;
return SILDeclRef(loc.getOpaqueValue(), kind,
curried, willBeDirect, willBeForeign,
defaultArgIndex);
}


/// Returns the foreign (or native) entry point corresponding to the same
/// decl.
SILDeclRef asForeign(bool foreign = true) const {
assert(!isCurried);
return SILDeclRef(loc.getOpaqueValue(), kind,
isCurried, isDirectReference, foreign, defaultArgIndex);
}

SILDeclRef asDirectReference(bool direct = true) const {
SILDeclRef r = *this;
// The 'direct' distinction only makes sense for curry thunks.
if (r.isCurried)
r.isDirectReference = direct;
return r;
foreign, defaultArgIndex);
}

/// True if the decl ref references a thunk from a natively foreign
Expand Down Expand Up @@ -408,15 +371,10 @@ struct SILDeclRef {
/// Produces a SILDeclRef from an opaque value.
explicit SILDeclRef(void *opaqueLoc,
Kind kind,
bool isCurried,
bool isDirectReference,
bool isForeign,
unsigned defaultArgIndex)
: loc(Loc::getFromOpaqueValue(opaqueLoc)),
kind(kind),
isCurried(isCurried),
isForeign(isForeign), isDirectReference(isDirectReference),
defaultArgIndex(defaultArgIndex)
: loc(Loc::getFromOpaqueValue(opaqueLoc)), kind(kind),
isForeign(isForeign), defaultArgIndex(defaultArgIndex)
{}

};
Expand All @@ -440,21 +398,20 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {

static SILDeclRef getEmptyKey() {
return SILDeclRef(PointerInfo::getEmptyKey(), Kind::Func,
false, false, false, 0);
false, 0);
}
static SILDeclRef getTombstoneKey() {
return SILDeclRef(PointerInfo::getTombstoneKey(), Kind::Func,
false, false, false, 0);
false, 0);
}
static unsigned getHashValue(swift::SILDeclRef Val) {
unsigned h1 = PointerInfo::getHashValue(Val.loc.getOpaqueValue());
unsigned h2 = UnsignedInfo::getHashValue(unsigned(Val.kind));
unsigned h3 = (Val.kind == Kind::DefaultArgGenerator)
? UnsignedInfo::getHashValue(Val.defaultArgIndex)
: UnsignedInfo::getHashValue(Val.isCurried);
: 0;
unsigned h4 = UnsignedInfo::getHashValue(Val.isForeign);
unsigned h5 = UnsignedInfo::getHashValue(Val.isDirectReference);
return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7) ^ (h5 << 11);
return h1 ^ (h2 << 4) ^ (h3 << 9) ^ (h4 << 7);
}
static bool isEqual(swift::SILDeclRef const &LHS,
swift::SILDeclRef const &RHS) {
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SIL/SILVTableVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ struct SortedFuncList {
Mangle::ASTMangler mangler;
std::string mangledName;
if (auto *cd = dyn_cast<ConstructorDecl>(afd))
mangledName = mangler.mangleConstructorEntity(cd, 0, 0);
mangledName = mangler.mangleConstructorEntity(cd, 0);
else
mangledName = mangler.mangleEntity(afd, 0);
mangledName = mangler.mangleEntity(afd);

elts.push_back(std::make_pair(mangledName, afd));
}
Expand Down
2 changes: 2 additions & 0 deletions include/swift/TBDGen/TBDGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#ifndef SWIFT_IRGEN_TBDGEN_H
#define SWIFT_IRGEN_TBDGEN_H

#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "swift/Basic/Version.h"
#include <vector>

namespace llvm {
class raw_ostream;
Expand Down
9 changes: 1 addition & 8 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ std::string ASTMangler::mangleClosureEntity(const AbstractClosureExpr *closure,
return finalize();
}

std::string ASTMangler::mangleEntity(const ValueDecl *decl, bool isCurried,
SymbolKind SKind) {
std::string ASTMangler::mangleEntity(const ValueDecl *decl, SymbolKind SKind) {
beginMangling();
appendEntity(decl);
if (isCurried)
appendOperator("Tc");
appendSymbolKind(SKind);
return finalize();
}
Expand All @@ -99,12 +96,9 @@ std::string ASTMangler::mangleDestructorEntity(const DestructorDecl *decl,

std::string ASTMangler::mangleConstructorEntity(const ConstructorDecl *ctor,
bool isAllocating,
bool isCurried,
SymbolKind SKind) {
beginMangling();
appendConstructorEntity(ctor, isAllocating);
if (isCurried)
appendOperator("Tc");
appendSymbolKind(SKind);
return finalize();
}
Expand Down Expand Up @@ -587,7 +581,6 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
case SymbolKind::DynamicThunk: return appendOperator("TD");
case SymbolKind::SwiftAsObjCThunk: return appendOperator("To");
case SymbolKind::ObjCAsSwiftThunk: return appendOperator("TO");
case SymbolKind::DirectMethodReferenceThunk: return appendOperator("Td");
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr,
bool printFullConvention,
bool printSPIs) {
PrintOptions result;
result.IsForSwiftInterface = true;
result.PrintLongAttrsOnSeparateLines = true;
result.TypeDefinitions = true;
result.PrintIfConfig = false;
Expand Down
33 changes: 33 additions & 0 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,39 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
case DAK_Rethrows:
case DAK_Infix:
return false;
case DAK_Override: {
if (!Options.IsForSwiftInterface)
break;
// When we are printing Swift interface, we have to skip the override keyword
// if the overriden decl is invisible from the interface. Otherwise, an error
// will occur while building the Swift module because the overriding decl
// doesn't override anything.
// We couldn't skip every `override` keywords becuase they change the
// ABI if the overriden decl is also publically visible.
// For public-override-internal case, having `override` doesn't have ABI
// implication. Thus we can skip them.
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (auto *BD = VD->getOverriddenDecl()) {
if (!BD->hasClangNode() &&
VD->isEffectiveLinkageMoreVisibleThan(BD))
return false;
}
}
break;
}
case DAK_Custom: {
if (!Options.IsForSwiftInterface)
break;
// For Swift interface, we should only print function builder attribute
// on parameter decls. Printing the attribute elsewhere isn't ABI relevant.
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (VD->getAttachedFunctionBuilder() == this) {
if (!isa<ParamDecl>(D))
return false;
}
}
break;
}
default:
break;
}
Expand Down
Loading

0 comments on commit 8055997

Please sign in to comment.