Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
083be48
WIP(katei): Add @convention(keypath_accessor)
kateinoigakukun May 15, 2022
6a7239d
WIP(katei): [IRGen] Add simple test case for keypath accessor convention
kateinoigakukun May 15, 2022
a229892
WIP(katei): Add keypath accessor convention variants
kateinoigakukun May 15, 2022
7a3111f
WIP(katei): [IRGen] Implement keypath accessor function generator
kateinoigakukun May 15, 2022
a6fb72e
WIP(katei) Passed tests
kateinoigakukun May 26, 2022
9bc750e
WIP(katei) [SILGen] Emit KeyPath accessor getters to be @convention(k…
kateinoigakukun May 30, 2022
2a2d587
WIP(katei): [test] Update test/SILGen for keypath accessor convention
kateinoigakukun May 30, 2022
362b854
WIP(katei): [IRGen] Skip rethunk emission for keypath getter
kateinoigakukun May 30, 2022
c4e21d5
WIP(katei): [IRGen] Fix storage type mismatch from raw i8* to indices…
kateinoigakukun May 30, 2022
2dfad30
WIP(katei): [test] Update test/IRGen for keypath accessor convention
kateinoigakukun May 30, 2022
5f3fcb5
WIP(katei): [IRGen] Create thunk if it's external accessor to be true…
kateinoigakukun May 30, 2022
967b64b
WIP(katei): [IRGen] Implement entrypoint binding logic for other acce…
kateinoigakukun May 30, 2022
efa5e0e
WIP(katei): [SILGen] Use keypath_accessor_setter convension for setters
kateinoigakukun May 30, 2022
13e17b6
WIP(katei): [test] Update test/IRGen for keypath accessor setter conv…
kateinoigakukun May 30, 2022
c57fc92
WIP(katei): [test] Update test/SILGen for keypath accessor setter con…
kateinoigakukun May 30, 2022
3733b0c
WIP(katei): [SIL] Fix bit mask layout to avoid overlapping representa…
kateinoigakukun Jun 19, 2022
560cc7d
WIP(katei): [SILGen] Emit equals and hash accessors as KeyPathAccesso…
kateinoigakukun Jun 19, 2022
b38bc88
WIP(katei): [SILGen] Emit KeyPath accessors as transparent to avoid d…
kateinoigakukun Jun 19, 2022
4810349
Revert "WIP(katei): [SILGen] Emit equals and hash accessors as KeyPat…
kateinoigakukun Jun 19, 2022
b3e6896
Revert "WIP(katei): [SILGen] Emit KeyPath accessors as transparent to…
kateinoigakukun Jun 19, 2022
22b4b87
WIP(katei): [SILGen] Extract indices tuple construction
kateinoigakukun Jun 19, 2022
c6db13b
WIP(katei): [SILGen] Emit keypath hash as keypath_accessor_hash conve…
kateinoigakukun Jun 19, 2022
fadf8fe
WIP(katei): [IRGen] Create thunk for hash iff it's external
kateinoigakukun Jun 19, 2022
5d0a60c
WIP(katei): [SILGen] Emit keypath equals as keypath_accessor_equals c…
kateinoigakukun Jun 19, 2022
e98eda0
WIP(katei): [IRGen] Create thunk for equals iff it's external
kateinoigakukun Jun 19, 2022
9cbc9de
WIP(katei): [test] Update test/SILOptimizer for keypath accessor conv…
kateinoigakukun Jun 19, 2022
d6020fb
WIP(katei): [Serialization] Fix SILFunctionTypeRepresentation
kateinoigakukun Jun 19, 2022
44f0a39
WIP(katei): Passed test/SILOptimizer/optimize_keypath.swift??
kateinoigakukun Jun 20, 2022
be68007
WIP(katei): Consume values from original explosion instead?
kateinoigakukun Jun 20, 2022
b4a437f
WIP
kateinoigakukun Jun 20, 2022
058cf74
WIP(katei): [IRGen] Fix invalid use of InvocationSubstitutions
kateinoigakukun Jun 20, 2022
71ef317
WIP(katei): [IRGen] Dellocate dynamic alloca-ed buffer
kateinoigakukun Jun 20, 2022
a8777a2
WIP(katei): [test] Update test/Constraints/keypath_dynamic_member_loo…
kateinoigakukun Jun 21, 2022
529dd1f
WIP(katei): [test] Update test/DebugInfo/keypath.swift for keypath co…
kateinoigakukun Jun 21, 2022
c02456e
WIP(katei): [IRGen] Remove debug code and rename to emitKeyPathInstan…
kateinoigakukun Jun 21, 2022
bc76a9a
Merge remote-tracking branch 'local-upstream/katei/keypath-accessor-c…
kateinoigakukun Jun 21, 2022
4e2d3c4
Revert applied patches around KeyPath for Wasm
kateinoigakukun Jun 21, 2022
056ba87
[Wasm] Ignore __main_void alias during TBD symbol validation
kateinoigakukun Jun 21, 2022
bea09fe
[Wasm] Build host toolchain with asserts
kateinoigakukun Jun 21, 2022
10eaf51
Revert "[Wasm] Build host toolchain with asserts"
kateinoigakukun Jun 22, 2022
73ccfd0
Merge remote-tracking branch 'origin/swiftwasm' into katei/downstream…
kateinoigakukun Jun 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 72 additions & 8 deletions include/swift/AST/ExtInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ enum class SILFunctionTypeRepresentation : uint8_t {
/// constructor). Except for
/// handling the "this" argument, has the same behavior as "CFunctionPointer".
CXXMethod,

/// A KeyPath accessor function, which is thin and also uses the variadic length
/// generic components serialization in trailing buffer.
KeyPathAccessorGetter,
KeyPathAccessorSetter,
KeyPathAccessorEquals,
KeyPathAccessorHash,
};

/// Returns true if the function with this convention doesn't carry a context.
Expand Down Expand Up @@ -202,6 +209,10 @@ isThinRepresentation(SILFunctionTypeRepresentation rep) {
case SILFunctionTypeRepresentation::CFunctionPointer:
case SILFunctionTypeRepresentation::Closure:
case SILFunctionTypeRepresentation::CXXMethod:
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return true;
}
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
Expand All @@ -214,6 +225,30 @@ isThickRepresentation(Repr repr) {
return !isThinRepresentation(repr);
}

/// Returns true if the function with this convention doesn't carry a context.
constexpr bool
isKeyPathAccessorRepresentation(SILFunctionTypeRepresentation rep) {
switch (rep) {
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return true;
case SILFunctionTypeRepresentation::Thick:
case SILFunctionTypeRepresentation::Block:
case SILFunctionTypeRepresentation::Thin:
case SILFunctionTypeRepresentation::Method:
case SILFunctionTypeRepresentation::ObjCMethod:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::CFunctionPointer:
case SILFunctionTypeRepresentation::Closure:
case SILFunctionTypeRepresentation::CXXMethod:
return false;
}
llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
}


constexpr SILFunctionTypeRepresentation
convertRepresentation(FunctionTypeRepresentation rep) {
switch (rep) {
Expand All @@ -225,6 +260,7 @@ convertRepresentation(FunctionTypeRepresentation rep) {
return SILFunctionTypeRepresentation::Thin;
case FunctionTypeRepresentation::CFunctionPointer:
return SILFunctionTypeRepresentation::CFunctionPointer;
return SILFunctionTypeRepresentation::Thin;
}
llvm_unreachable("Unhandled FunctionTypeRepresentation!");
}
Expand All @@ -245,6 +281,10 @@ convertRepresentation(SILFunctionTypeRepresentation rep) {
case SILFunctionTypeRepresentation::ObjCMethod:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::Closure:
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return None;
}
llvm_unreachable("Unhandled SILFunctionTypeRepresentation!");
Expand All @@ -264,6 +304,10 @@ constexpr bool canBeCalledIndirectly(SILFunctionTypeRepresentation rep) {
case SILFunctionTypeRepresentation::ObjCMethod:
case SILFunctionTypeRepresentation::Method:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return true;
}

Expand All @@ -285,6 +329,10 @@ template <typename Repr> constexpr bool shouldStoreClangType(Repr repr) {
case SILFunctionTypeRepresentation::Method:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::Closure:
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return false;
}
llvm_unreachable("Unhandled SILFunctionTypeRepresentation.");
Expand Down Expand Up @@ -395,6 +443,10 @@ class ASTExtInfoBuilder {
case SILFunctionTypeRepresentation::Thin:
case SILFunctionTypeRepresentation::CFunctionPointer:
case SILFunctionTypeRepresentation::Closure:
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return false;
case SILFunctionTypeRepresentation::ObjCMethod:
case SILFunctionTypeRepresentation::Method:
Expand Down Expand Up @@ -633,6 +685,10 @@ SILFunctionLanguage getSILFunctionLanguage(SILFunctionTypeRepresentation rep) {
case SILFunctionTypeRepresentation::Method:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::Closure:
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return SILFunctionLanguage::Swift;
}

Expand All @@ -651,17 +707,17 @@ class SILExtInfoBuilder {
// and NumMaskBits must be updated, and they must match.

// |representation|pseudogeneric| noescape | concurrent | async |differentiability|
// | 0 .. 3 | 4 | 5 | 6 | 7 | 8 .. 10 |
// | 0 .. 4 | 5 | 6 | 7 | 8 | 9 .. 11 |
//
enum : unsigned {
RepresentationMask = 0xF << 0,
PseudogenericMask = 1 << 4,
NoEscapeMask = 1 << 5,
SendableMask = 1 << 6,
AsyncMask = 1 << 7,
DifferentiabilityMaskOffset = 8,
RepresentationMask = 0x1F << 0,
PseudogenericMask = 1 << 5,
NoEscapeMask = 1 << 6,
SendableMask = 1 << 7,
AsyncMask = 1 << 8,
DifferentiabilityMaskOffset = 9,
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
NumMaskBits = 11
NumMaskBits = 12
};

unsigned bits; // Naturally sized for speed.
Expand Down Expand Up @@ -755,6 +811,10 @@ class SILExtInfoBuilder {
case Representation::Thin:
case Representation::CFunctionPointer:
case Representation::Closure:
case Representation::KeyPathAccessorGetter:
case Representation::KeyPathAccessorSetter:
case Representation::KeyPathAccessorEquals:
case Representation::KeyPathAccessorHash:
return false;
case Representation::ObjCMethod:
case Representation::Method:
Expand All @@ -778,6 +838,10 @@ class SILExtInfoBuilder {
case Representation::WitnessMethod:
case Representation::Closure:
case SILFunctionTypeRepresentation::CXXMethod:
case Representation::KeyPathAccessorGetter:
case Representation::KeyPathAccessorSetter:
case Representation::KeyPathAccessorEquals:
case Representation::KeyPathAccessorHash:
return false;
}
llvm_unreachable("Unhandled Representation in switch.");
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class alignas(1 << TypeAlignInBits) TypeBase

protected:
enum { NumAFTExtInfoBits = 11 };
enum { NumSILExtInfoBits = 11 };
enum { NumSILExtInfoBits = 12 };
union { uint64_t OpaqueBits;

SWIFT_INLINE_BITFIELD_BASE(TypeBase, bitmax(NumTypeKindBits,8) +
Expand Down
5 changes: 5 additions & 0 deletions include/swift/SIL/ApplySite.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef SWIFT_SIL_APPLYSITE_H
#define SWIFT_SIL_APPLYSITE_H

#include "swift/AST/ExtInfo.h"
#include "swift/Basic/STLExtras.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILBasicBlock.h"
Expand Down Expand Up @@ -253,6 +254,10 @@ class ApplySite {
case SILFunctionTypeRepresentation::ObjCMethod:
case SILFunctionTypeRepresentation::WitnessMethod:
case SILFunctionTypeRepresentation::Closure:
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
return true;
case SILFunctionTypeRepresentation::Block:
case SILFunctionTypeRepresentation::Thick:
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ getSILFunctionTypeRepresentationString(SILFunctionType::Representation value) {
case SILFunctionType::Representation::ObjCMethod: return "objc_method";
case SILFunctionType::Representation::WitnessMethod: return "witness_method";
case SILFunctionType::Representation::Closure: return "closure";
case SILFunctionType::Representation::KeyPathAccessorGetter: return "keypath_accessor_getter";
case SILFunctionType::Representation::KeyPathAccessorSetter: return "keypath_accessor_setter";
case SILFunctionType::Representation::KeyPathAccessorEquals: return "keypath_accessor_equals";
case SILFunctionType::Representation::KeyPathAccessorHash: return "keypath_accessor_hash";
}

llvm_unreachable("Unhandled SILFunctionTypeRepresentation in switch.");
Expand Down
6 changes: 6 additions & 0 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,12 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
case SILFunctionTypeRepresentation::WitnessMethod:
OpArgs.push_back('W');
break;
case SILFunctionTypeRepresentation::KeyPathAccessorGetter:
case SILFunctionTypeRepresentation::KeyPathAccessorSetter:
case SILFunctionTypeRepresentation::KeyPathAccessorEquals:
case SILFunctionTypeRepresentation::KeyPathAccessorHash:
OpArgs.push_back('P');
break;
}

// Coroutine kind. This is mangled in all pointer auth modes.
Expand Down
24 changes: 24 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5785,6 +5785,18 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
case SILFunctionType::Representation::Closure:
Printer << "closure";
break;
case SILFunctionType::Representation::KeyPathAccessorGetter:
Printer << "keypath_accessor_getter";
break;
case SILFunctionType::Representation::KeyPathAccessorSetter:
Printer << "keypath_accessor_setter";
break;
case SILFunctionType::Representation::KeyPathAccessorEquals:
Printer << "keypath_accessor_equals";
break;
case SILFunctionType::Representation::KeyPathAccessorHash:
Printer << "keypath_accessor_hash";
break;
}
Printer << ")";
Printer.printStructurePost(PrintStructureKind::BuiltinAttribute);
Expand Down Expand Up @@ -5869,6 +5881,18 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
case SILFunctionType::Representation::Closure:
Printer << "closure";
break;
case SILFunctionType::Representation::KeyPathAccessorGetter:
Printer << "keypath_accessor_getter";
break;
case SILFunctionType::Representation::KeyPathAccessorSetter:
Printer << "keypath_accessor_setter";
break;
case SILFunctionType::Representation::KeyPathAccessorEquals:
Printer << "keypath_accessor_equals";
break;
case SILFunctionType::Representation::KeyPathAccessorHash:
Printer << "keypath_accessor_hash";
break;
}
Printer << ")";
Printer.printStructurePost(PrintStructureKind::BuiltinAttribute);
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/ClangTypeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ const clang::Type *ClangTypeConverter::getFunctionType(
case SILFunctionType::Representation::ObjCMethod:
case SILFunctionType::Representation::WitnessMethod:
case SILFunctionType::Representation::Closure:
case SILFunctionType::Representation::KeyPathAccessorGetter:
case SILFunctionType::Representation::KeyPathAccessorSetter:
case SILFunctionType::Representation::KeyPathAccessorEquals:
case SILFunctionType::Representation::KeyPathAccessorHash:
llvm_unreachable("Expected a C-compatible representation.");
}
llvm_unreachable("unhandled representation!");
Expand Down
11 changes: 10 additions & 1 deletion lib/FrontendTool/TBD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,22 @@ bool swift::writeTBD(ModuleDecl *M, StringRef OutputFilename,
/// should be ignored (instead of potentially producing a diagnostic.)
static bool isSymbolIgnored(const StringRef& name,
const llvm::Module &IRModule) {
if (llvm::Triple(IRModule.getTargetTriple()).isOSWindows()) {
llvm::Triple triple(IRModule.getTargetTriple());
if (triple.isOSWindows()) {
// (SR-15938) Error when referencing #dsohandle in a Swift test on Windows
// On Windows, ignore the lack of __ImageBase in the TBD file.
if (name == "__ImageBase") {
return true;
}
}
if (triple.isWasm()) {
// `__main_void`, which is called by `_start` in crt1.o, is artificially
// aliased in IR module when `main` doesn't take any params.
// This alias will be hidden after https://reviews.llvm.org/D75277
if (name == "__main_void") {
return true;
}
}

return false;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/IRGen/CallEmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef SWIFT_IRGEN_CALLEMISSION_H
#define SWIFT_IRGEN_CALLEMISSION_H

#include "Address.h"
#include "Temporary.h"
#include "Callee.h"

Expand Down Expand Up @@ -49,6 +50,8 @@ class CallEmission {
/// Temporaries required by the call.
TemporarySet Temporaries;

SmallVector<StackAddress, 8> RawTempraries;

/// The function we're going to call.
Callee CurCallee;

Expand Down
Loading