Skip to content

Commit d365c15

Browse files
committed
SIL: Introduce sil_property declarations for property descriptors.
This provides SILGen a place to generate the key path component information for an exported property so that it can be linked to from other modules.
1 parent 2d377a4 commit d365c15

22 files changed

+1016
-603
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ ERROR(expected_sil_instr_opcode,none,
528528
"expected SIL instruction opcode", ())
529529
ERROR(expected_tok_in_sil_instr,none,
530530
"expected '%0' in SIL instruction", (StringRef))
531+
ERROR(sil_property_generic_signature_mismatch,none,
532+
"sil_property generic signature must match original declaration", ())
531533
ERROR(sil_string_no_encoding,none,
532534
"string_literal instruction requires an encoding", ())
533535
ERROR(sil_string_invalid_encoding,none,

include/swift/AST/GenericSignature.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_AST_GENERIC_SIGNATURE_H
1818
#define SWIFT_AST_GENERIC_SIGNATURE_H
1919

20+
#include "swift/AST/PrintOptions.h"
2021
#include "swift/AST/Requirement.h"
2122
#include "swift/AST/SubstitutionList.h"
2223
#include "swift/AST/Types.h"
@@ -338,7 +339,7 @@ class alignas(1 << TypeAlignInBits) GenericSignature final
338339
TypeArrayView<GenericTypeParamType> genericParams,
339340
ArrayRef<Requirement> requirements);
340341

341-
void print(raw_ostream &OS) const;
342+
void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
342343
void dump() const;
343344
std::string getAsString() const;
344345
};

include/swift/AST/PrintOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/Identifier.h"
1919
#include "swift/AST/TypeOrExtensionDecl.h"
2020
#include "llvm/ADT/Optional.h"
21+
#include "llvm/ADT/DenseMap.h"
2122
#include <limits.h>
2223
#include <vector>
2324

include/swift/Parse/ParseSILSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace swift {
3333
virtual bool parseSILWitnessTable(Parser &P) = 0;
3434
virtual bool parseSILDefaultWitnessTable(Parser &P) = 0;
3535
virtual bool parseSILCoverageMap(Parser &P) = 0;
36+
virtual bool parseSILProperty(Parser &P) = 0;
3637
virtual bool parseSILScope(Parser &P) = 0;
3738
};
3839

include/swift/SIL/SILModule.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/SIL/SILFunction.h"
3333
#include "swift/SIL/SILGlobalVariable.h"
3434
#include "swift/SIL/SILPrintContext.h"
35+
#include "swift/SIL/SILProperty.h"
3536
#include "swift/SIL/SILType.h"
3637
#include "swift/SIL/SILVTable.h"
3738
#include "swift/SIL/SILWitnessTable.h"
@@ -103,6 +104,7 @@ class SILModule {
103104
using FunctionListType = llvm::ilist<SILFunction>;
104105
using GlobalListType = llvm::ilist<SILGlobalVariable>;
105106
using VTableListType = llvm::ilist<SILVTable>;
107+
using PropertyListType = llvm::ilist<SILProperty>;
106108
using WitnessTableListType = llvm::ilist<SILWitnessTable>;
107109
using DefaultWitnessTableListType = llvm::ilist<SILDefaultWitnessTable>;
108110
using CoverageMapListType = llvm::ilist<SILCoverageMap>;
@@ -119,6 +121,7 @@ class SILModule {
119121
friend SILLayout;
120122
friend SILType;
121123
friend SILVTable;
124+
friend SILProperty;
122125
friend SILUndef;
123126
friend SILWitnessTable;
124127
friend Lowering::SILGenModule;
@@ -184,6 +187,9 @@ class SILModule {
184187

185188
// The list of SILCoverageMaps in the module.
186189
CoverageMapListType coverageMaps;
190+
191+
// The list of SILProperties in the module.
192+
PropertyListType properties;
187193

188194
/// This is the underlying raw stream of OptRecordStream.
189195
///
@@ -458,10 +464,13 @@ class SILModule {
458464
void setOptRecordStream(std::unique_ptr<llvm::yaml::Output> &&Stream,
459465
std::unique_ptr<llvm::raw_ostream> &&RawStream);
460466

467+
PropertyListType &getPropertyList() { return properties; }
468+
const PropertyListType &getPropertyList() const { return properties; }
469+
461470
/// Look for a global variable by name.
462471
///
463472
/// \return null if this module has no such global variable
464-
SILGlobalVariable *lookUpGlobalVariable(StringRef name) const {
473+
SILGlobalVariable *lookUpGlobalVariable(StringRef name) const {
465474
return GlobalVariableMap.lookup(name);
466475
}
467476

include/swift/SIL/SILProperty.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//===--- SILProperty.h - Defines the SILProperty class ----------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines the SILProperty class, which is used to capture the
14+
// metadata about a property definition necessary for it to be resiliently
15+
// included in KeyPaths across modules.
16+
//
17+
//===----------------------------------------------------------------------===//
18+
19+
#ifndef SWIFT_SIL_SILPROPERTY_H
20+
#define SWIFT_SIL_SILPROPERTY_H
21+
22+
#include "swift/AST/GenericSignature.h"
23+
#include "swift/SIL/SILAllocated.h"
24+
#include "swift/SIL/SILInstruction.h"
25+
#include "llvm/ADT/ilist_node.h"
26+
#include "llvm/ADT/ilist.h"
27+
28+
namespace swift {
29+
30+
class SILPrintContext;
31+
32+
/// A descriptor for a public property or subscript that can be resiliently
33+
/// referenced from key paths in external modules.
34+
class SILProperty : public llvm::ilist_node<SILProperty>,
35+
public SILAllocated<SILProperty>
36+
{
37+
private:
38+
/// True if serialized.
39+
bool Serialized;
40+
41+
/// The declaration the descriptor represents.
42+
AbstractStorageDecl *Decl;
43+
44+
/// The key path component that represents its implementation.
45+
KeyPathPatternComponent Component;
46+
47+
SILProperty(bool Serialized,
48+
AbstractStorageDecl *Decl,
49+
KeyPathPatternComponent Component)
50+
: Serialized(Serialized), Decl(Decl), Component(Component)
51+
{}
52+
53+
public:
54+
static SILProperty *create(SILModule &M,
55+
bool Serialized,
56+
AbstractStorageDecl *Decl,
57+
KeyPathPatternComponent Component);
58+
59+
bool isSerialized() const { return Serialized; }
60+
61+
AbstractStorageDecl *getDecl() const { return Decl; }
62+
63+
const KeyPathPatternComponent &getComponent() const { return Component; }
64+
65+
void print(SILPrintContext &Ctx) const;
66+
};
67+
68+
} // end namespace swift
69+
70+
namespace llvm {
71+
72+
//===----------------------------------------------------------------------===//
73+
// ilist_traits for SILProperty
74+
//===----------------------------------------------------------------------===//
75+
76+
template <>
77+
struct ilist_traits<::swift::SILProperty>
78+
: public ilist_default_traits<::swift::SILProperty> {
79+
typedef ::swift::SILProperty SILProperty;
80+
81+
public:
82+
static void deleteNode(SILProperty *VT) { VT->~SILProperty(); }
83+
84+
private:
85+
void createNode(const SILProperty &);
86+
};
87+
88+
} // namespace llvm
89+
90+
#endif

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const uint16_t VERSION_MAJOR = 0;
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
5757
/// Don't worry about adhering to the 80-column limit for this line.
58-
const uint16_t VERSION_MINOR = 399; // Last change: @_weakLinked
58+
const uint16_t VERSION_MINOR = 400; // Last change: sil_property
5959

6060
using DeclIDField = BCFixed<31>;
6161

include/swift/Serialization/SerializedSILLoader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class SerializedSILLoader {
132132
/// Deserialize all DefaultWitnessTables in all SILModules.
133133
void getAllDefaultWitnessTables();
134134

135+
/// Deserialize all Properties in all SILModules.
136+
void getAllProperties();
137+
135138
SerializedSILLoader(const SerializedSILLoader &) = delete;
136139
SerializedSILLoader(SerializedSILLoader &&) = delete;
137140
SerializedSILLoader &operator=(const SerializedSILLoader &) = delete;

include/swift/Syntax/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ DECL_KEYWORD(static)
172172
SIL_KEYWORD(undef)
173173
SIL_KEYWORD(sil)
174174
SIL_KEYWORD(sil_stage)
175+
SIL_KEYWORD(sil_property)
175176
SIL_KEYWORD(sil_vtable)
176177
SIL_KEYWORD(sil_global)
177178
SIL_KEYWORD(sil_witness_table)

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,9 +3961,9 @@ void LayoutConstraintInfo::print(ASTPrinter &Printer,
39613961
}
39623962
}
39633963

3964-
void GenericSignature::print(raw_ostream &OS) const {
3964+
void GenericSignature::print(raw_ostream &OS, PrintOptions Opts) const {
39653965
StreamPrinter Printer(OS);
3966-
PrintAST(Printer, PrintOptions())
3966+
PrintAST(Printer, Opts)
39673967
.printGenericSignature(this,
39683968
PrintAST::PrintParams |
39693969
PrintAST::PrintRequirements);

0 commit comments

Comments
 (0)