Skip to content

SIL: Terminology change: [fragile] => [serialized] #8407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion include/swift/IRGen/LinkEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class LinkEntity {
return false;

SILFunction *F = getSILFunction();
return F->isTransparent() && F->isDefinition() && F->isFragile();
return F->isTransparent() && F->isDefinition() && F->isSerialized();
}

SILGlobalVariable *getSILGlobalVariable() const {
Expand Down
3 changes: 2 additions & 1 deletion include/swift/SIL/SILDeclRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace swift {
class ClassDecl;
class SILFunctionType;
enum class SILLinkage : unsigned char;
enum IsSerialized_t : unsigned char;
class SILModule;
class SILLocation;
class AnyFunctionRef;
Expand Down Expand Up @@ -263,7 +264,7 @@ struct SILDeclRef {
/// \brief True if the function should be treated as transparent.
bool isTransparent() const;
/// \brief True if the function should have its body serialized.
bool isFragile() const;
IsSerialized_t isSerialized() const;
/// \brief True if the function has noinline attribute.
bool isNoinline() const;
/// \brief True if the function has __always inline attribute.
Expand Down
27 changes: 12 additions & 15 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,10 @@ class SILFunction
unsigned Bare : 1;

/// The function's transparent attribute.
unsigned Transparent : 1; // FIXME: pack this somewhere
unsigned Transparent : 1;

/// The function's fragile attribute.
///
/// Fragile means that the function can be inlined into another module.
/// Currently this flag is set for public transparent functions and for all
/// functions in the stdlib.
unsigned Fragile : 1;
/// The function's serialized attribute.
unsigned Serialized : 2;

/// Specifies if this function is a thunk or a reabstraction thunk.
///
Expand Down Expand Up @@ -218,16 +214,17 @@ class SILFunction
SILFunction(SILModule &module, SILLinkage linkage, StringRef mangledName,
CanSILFunctionType loweredType, GenericEnvironment *genericEnv,
Optional<SILLocation> loc, IsBare_t isBareSILFunction,
IsTransparent_t isTrans, IsFragile_t isFragile, IsThunk_t isThunk,
ClassVisibility_t classVisibility, Inline_t inlineStrategy,
EffectsKind E, SILFunction *insertBefore,
IsTransparent_t isTrans, IsSerialized_t isSerialized,
IsThunk_t isThunk, ClassVisibility_t classVisibility,
Inline_t inlineStrategy, EffectsKind E,
SILFunction *insertBefore,
const SILDebugScope *debugScope);

static SILFunction *
create(SILModule &M, SILLinkage linkage, StringRef name,
CanSILFunctionType loweredType, GenericEnvironment *genericEnv,
Optional<SILLocation> loc, IsBare_t isBareSILFunction,
IsTransparent_t isTrans, IsFragile_t isFragile,
IsTransparent_t isTrans, IsSerialized_t isSerialized,
IsThunk_t isThunk = IsNotThunk,
ClassVisibility_t classVisibility = NotRelevant,
Inline_t inlineStrategy = InlineDefault,
Expand Down Expand Up @@ -385,7 +382,7 @@ class SILFunction
/// Returns true if this function can be inlined into a fragile function
/// body.
bool hasValidLinkageForFragileInline() const {
return isFragile() || isThunk() == IsReabstractionThunk;
return isSerialized() || isThunk() == IsReabstractionThunk;
}

/// Returns true if this function can be referenced from a fragile function
Expand Down Expand Up @@ -515,9 +512,9 @@ class SILFunction
IsTransparent_t isTransparent() const { return IsTransparent_t(Transparent); }
void setTransparent(IsTransparent_t isT) { Transparent = isT; }

/// Get this function's fragile attribute.
IsFragile_t isFragile() const { return IsFragile_t(Fragile); }
void setFragile(IsFragile_t isFrag) { Fragile = isFrag; }
/// Get this function's serialized attribute.
IsSerialized_t isSerialized() const { return IsSerialized_t(Serialized); }
void setSerialized(IsSerialized_t isSerialized) { Serialized = isSerialized; }

/// Get this function's thunk attribute.
IsThunk_t isThunk() const { return IsThunk_t(Thunk); }
Expand Down
17 changes: 9 additions & 8 deletions include/swift/SIL/SILGlobalVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class SILGlobalVariable
/// The linkage of the global variable.
unsigned Linkage : NumSILLinkageBits;

/// The global variable's fragile attribute.
/// Fragile means that the variable can be "inlined" into another module.
/// The global variable's serialized attribute.
/// Serialized means that the variable can be "inlined" into another module.
/// Currently this flag is set for all global variables in the stdlib.
unsigned Fragile : 1;
unsigned Serialized : 1;

/// Whether this is a 'let' property, which can only be initialized
/// once (either in its declaration, or once later), making it immutable.
Expand All @@ -76,13 +76,14 @@ class SILGlobalVariable
/// The static initializer.
SILFunction *InitializerF;

SILGlobalVariable(SILModule &M, SILLinkage linkage, bool IsFragile,
SILGlobalVariable(SILModule &M, SILLinkage linkage,
IsSerialized_t IsSerialized,
StringRef mangledName, SILType loweredType,
Optional<SILLocation> loc, VarDecl *decl);

public:
static SILGlobalVariable *create(SILModule &Module, SILLinkage Linkage,
bool IsFragile,
IsSerialized_t IsSerialized,
StringRef MangledName, SILType LoweredType,
Optional<SILLocation> Loc = None,
VarDecl *Decl = nullptr);
Expand All @@ -107,9 +108,9 @@ class SILGlobalVariable
SILLinkage getLinkage() const { return SILLinkage(Linkage); }
void setLinkage(SILLinkage linkage) { Linkage = unsigned(linkage); }

/// Get this global variable's fragile attribute.
bool isFragile() const { return Fragile != 0; }
void setFragile(bool isFrag) { Fragile = isFrag ? 1 : 0; }
/// Get this global variable's serialized attribute.
IsSerialized_t isSerialized() const;
void setSerialized(IsSerialized_t isSerialized);

/// Is this an immutable 'let' property?
bool isLet() const { return IsLet; }
Expand Down
13 changes: 9 additions & 4 deletions include/swift/SIL/SILLinkage.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ enum {
NumSILLinkageBits = 3
};

/// Related to linkage: flag if a function or global variable is fragile.
enum IsFragile_t {
IsNotFragile,
IsFragile
/// Related to linkage: flag if a function or global variable is serialized,
/// either unconditionally, or if referenced from another serialized function.
enum IsSerialized_t : unsigned char {
// Never serialized.
IsNotSerialized,
// Serialized if referenced from another serialized function.
IsSerializable,
// Always serialized.
IsSerialized
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, IsSerialized is not a very good choice for a name. It is too easy to think that something was serialized by the SIL serializer already. I'd prefer names which would use a different verb. Or they could indicate the possibility, e.g. NotToBeSerialized, CanBeSerialized, ShouldBeSerialized....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better than "fragile" no? :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is better than "fragile", but not good enough, IMHO ;-)

};

/// Strip external from public_external, hidden_external. Otherwise just return
Expand Down
8 changes: 4 additions & 4 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class SILModule {
/// source file, starting from the specified element number.
///
/// If \p makeModuleFragile is true, all functions and global variables of
/// the module are marked as fragile. This is used for compiling the stdlib.
/// the module are marked as serialized. This is used for compiling the stdlib.
static std::unique_ptr<SILModule>
constructSIL(ModuleDecl *M, SILOptions &Options, FileUnit *sf = nullptr,
Optional<unsigned> startElem = None,
Expand Down Expand Up @@ -466,7 +466,7 @@ class SILModule {
CanSILFunctionType type,
IsBare_t isBareSILFunction,
IsTransparent_t isTransparent,
IsFragile_t isFragile,
IsSerialized_t isSerialized,
IsThunk_t isThunk);

/// \brief Return the declaration of a function, or create it if it doesn't
Expand All @@ -477,7 +477,7 @@ class SILModule {
CanSILFunctionType type,
IsBare_t isBareSILFunction,
IsTransparent_t isTransparent,
IsFragile_t isFragile,
IsSerialized_t isSerialized,
IsThunk_t isThunk = IsNotThunk,
SILFunction::ClassVisibility_t CV =
SILFunction::NotRelevant);
Expand All @@ -497,7 +497,7 @@ class SILModule {
SILLinkage linkage, StringRef name, CanSILFunctionType loweredType,
GenericEnvironment *genericEnv, Optional<SILLocation> loc,
IsBare_t isBareSILFunction, IsTransparent_t isTrans,
IsFragile_t isFragile, IsThunk_t isThunk = IsNotThunk,
IsSerialized_t isSerialized, IsThunk_t isThunk = IsNotThunk,
SILFunction::ClassVisibility_t classVisibility = SILFunction::NotRelevant,
Inline_t inlineStrategy = InlineDefault,
EffectsKind EK = EffectsKind::Unspecified,
Expand Down
18 changes: 10 additions & 8 deletions include/swift/SIL/SILWitnessTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace swift {
class SILFunction;
class SILModule;
class NormalProtocolConformance;
enum IsSerialized_t : unsigned char;

/// A mapping from each requirement of a protocol to the SIL-level entity
/// satisfying the requirement for a concrete type.
Expand Down Expand Up @@ -190,13 +191,13 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
/// that is not a declaration.
bool IsDeclaration;

/// Whether or not this witness table is fragile. Fragile means that the
/// table may be serialized and "inlined" into another module.
bool IsFragile;
/// Whether or not this witness table is serialized, which allows
/// devirtualization from another module.
bool Serialized;

/// Private constructor for making SILWitnessTable definitions.
SILWitnessTable(SILModule &M, SILLinkage Linkage,
bool IsFragile, StringRef Name,
IsSerialized_t Serialized, StringRef Name,
NormalProtocolConformance *Conformance,
ArrayRef<Entry> entries);

Expand All @@ -209,7 +210,7 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
public:
/// Create a new SILWitnessTable definition with the given entries.
static SILWitnessTable *create(SILModule &M, SILLinkage Linkage,
bool IsFragile,
IsSerialized_t Serialized,
NormalProtocolConformance *Conformance,
ArrayRef<Entry> entries);

Expand All @@ -236,8 +237,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
/// Returns true if this witness table is a definition.
bool isDefinition() const { return !isDeclaration(); }

/// Returns true if this witness table is fragile.
bool isFragile() const { return IsFragile; }
/// Returns true if this witness table is going to be (or was) serialized.
IsSerialized_t isSerialized() const;

/// Return all of the witness table entries.
ArrayRef<Entry> getEntries() const { return Entries; }
Expand Down Expand Up @@ -265,7 +266,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
void setLinkage(SILLinkage l) { Linkage = l; }

/// Change a SILWitnessTable declaration into a SILWitnessTable definition.
void convertToDefinition(ArrayRef<Entry> newEntries, bool isFragile);
void convertToDefinition(ArrayRef<Entry> newEntries,
IsSerialized_t isSerialized);

/// Print the witness table.
void print(llvm::raw_ostream &OS, bool Verbose = false) const;
Expand Down
12 changes: 6 additions & 6 deletions include/swift/SILOptimizer/Utils/GenericCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
namespace swift {

class GenericCloner : public TypeSubstCloner<GenericCloner> {
IsFragile_t Fragile;
IsSerialized_t Serialized;
const ReabstractionInfo &ReInfo;
CloneCollector::CallbackType Callback;

public:
friend class SILCloner<GenericCloner>;

GenericCloner(SILFunction *F,
IsFragile_t Fragile,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo,
SubstitutionList ParamSubs,
StringRef NewName,
CloneCollector::CallbackType Callback)
: TypeSubstCloner(*initCloned(F, Fragile, ReInfo, NewName), *F,
: TypeSubstCloner(*initCloned(F, Serialized, ReInfo, NewName), *F,
ParamSubs), ReInfo(ReInfo), Callback(Callback) {
assert(F->getDebugScope()->Parent != getCloned()->getDebugScope()->Parent);
}
Expand All @@ -53,13 +53,13 @@ class GenericCloner : public TypeSubstCloner<GenericCloner> {
/// direct) according to \p ReInfo.
static SILFunction *
cloneFunction(SILFunction *F,
IsFragile_t Fragile,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo,
SubstitutionList ParamSubs,
StringRef NewName,
CloneCollector::CallbackType Callback =nullptr) {
// Clone and specialize the function.
GenericCloner SC(F, Fragile, ReInfo, ParamSubs,
GenericCloner SC(F, Serialized, ReInfo, ParamSubs,
NewName, Callback);
SC.populateCloned();
SC.cleanUp(SC.getCloned());
Expand All @@ -83,7 +83,7 @@ class GenericCloner : public TypeSubstCloner<GenericCloner> {

private:
static SILFunction *initCloned(SILFunction *Orig,
IsFragile_t Fragile,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo,
StringRef NewName);
/// Clone the body of the function into the empty function that was created
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SILOptimizer/Utils/Generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class GenericFuncSpecializer {
SILModule &M;
SILFunction *GenericFunc;
SubstitutionList ParamSubs;
IsFragile_t Fragile;
IsSerialized_t Serialized;
const ReabstractionInfo &ReInfo;

SubstitutionMap ContextSubs;
Expand All @@ -259,7 +259,7 @@ class GenericFuncSpecializer {
public:
GenericFuncSpecializer(SILFunction *GenericFunc,
SubstitutionList ParamSubs,
IsFragile_t Fragile,
IsSerialized_t Serialized,
const ReabstractionInfo &ReInfo);

/// If we already have this specialization, reuse it.
Expand Down
16 changes: 8 additions & 8 deletions include/swift/SILOptimizer/Utils/SpecializationMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SpecializationMangler : public Mangle::ASTMangler {
/// The specialization pass.
SpecializationPass Pass;

IsFragile_t Fragile;
IsSerialized_t Serialized;

/// The original function which is specialized.
SILFunction *Function;
Expand All @@ -46,9 +46,9 @@ class SpecializationMangler : public Mangle::ASTMangler {
llvm::raw_svector_ostream ArgOpBuffer;

protected:
SpecializationMangler(SpecializationPass P, IsFragile_t Fragile,
SpecializationMangler(SpecializationPass P, IsSerialized_t Serialized,
SILFunction *F)
: Pass(P), Fragile(Fragile), Function(F), ArgOpBuffer(ArgOpStorage) {}
: Pass(P), Serialized(Serialized), Function(F), ArgOpBuffer(ArgOpStorage) {}

SILFunction *getFunction() const { return Function; }

Expand All @@ -72,9 +72,9 @@ class GenericSpecializationMangler : public SpecializationMangler {

GenericSpecializationMangler(SILFunction *F,
SubstitutionList Subs,
IsFragile_t Fragile,
IsSerialized_t Serialized,
bool isReAbstracted)
: SpecializationMangler(SpecializationPass::GenericSpecializer, Fragile, F),
: SpecializationMangler(SpecializationPass::GenericSpecializer, Serialized, F),
Subs(Subs), isReAbstracted(isReAbstracted) {}

std::string mangle();
Expand All @@ -88,9 +88,9 @@ class PartialSpecializationMangler : public SpecializationMangler {
public:
PartialSpecializationMangler(SILFunction *F,
CanSILFunctionType SpecializedFnTy,
IsFragile_t Fragile,
IsSerialized_t Serialized,
bool isReAbstracted)
: SpecializationMangler(SpecializationPass::GenericSpecializer, Fragile, F),
: SpecializationMangler(SpecializationPass::GenericSpecializer, Serialized, F),
SpecializedFnTy(SpecializedFnTy), isReAbstracted(isReAbstracted) {}

std::string mangle();
Expand Down Expand Up @@ -141,7 +141,7 @@ class FunctionSignatureSpecializationMangler : public SpecializationMangler {

public:
FunctionSignatureSpecializationMangler(SpecializationPass Pass,
IsFragile_t Fragile,
IsSerialized_t Serialized,
SILFunction *F);
void setArgumentConstantProp(unsigned OrigArgIdx, LiteralInst *LI);
void setArgumentClosureProp(unsigned OrigArgIdx, PartialApplyInst *PAI);
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
/// in source control, you should also update the comment to briefly
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
const uint16_t VERSION_MINOR = 327; // Last change: begin_access/end_access
const uint16_t VERSION_MINOR = 328; // Last change: fragile => serialized

using DeclID = PointerEmbeddedInt<unsigned, 31>;
using DeclIDField = BCFixed<31>;
Expand Down
6 changes: 3 additions & 3 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,10 @@ bool LinkEntity::isAvailableExternally(IRGenModule &IGM) const {
bool LinkEntity::isFragile(IRGenModule &IGM) const {
switch (getKind()) {
case Kind::SILFunction:
return getSILFunction()->isFragile();
return getSILFunction()->isSerialized();

case Kind::SILGlobalVariable:
return getSILGlobalVariable()->isFragile();
return getSILGlobalVariable()->isSerialized();

case Kind::ReflectionAssociatedTypeDescriptor:
case Kind::ReflectionSuperclassDescriptor:
Expand All @@ -1283,7 +1283,7 @@ bool LinkEntity::isFragile(IRGenModule &IGM) const {
// not public, it must be fragile.
if (swift::isAvailableExternally(L) && !hasPublicVisibility(L))
return true;
return wt->isFragile();
return wt->isSerialized();
}
}
return false;
Expand Down
Loading