[silgen] Add support for emitting guaranteed self behind the flag -enable-guaranteed-self.

This does not have any tests since I am going to start going through SILGen
tests and updating them for guaranteed self as the appropriate tests.

*NOTE* There is more work to be done in terms of thunks, but the basic
functionality is done.

rdar://15729033

Swift SVN r23653
This commit is contained in:
Michael Gottesman
2014-12-03 21:20:25 +00:00
parent 123b8e6f61
commit 6fdf2a2a2f
4 changed files with 18 additions and 3 deletions

View File

@@ -88,6 +88,9 @@ public:
/// Should we optimize function signatures. Disabled by default. /// Should we optimize function signatures. Disabled by default.
bool EnableFuncSigOpts = true; bool EnableFuncSigOpts = true;
/// Should we emit self as a guaranteed parameter. Disabled by default.
bool EnableGuaranteedSelf = false;
}; };
} // end namespace swift } // end namespace swift

View File

@@ -238,4 +238,7 @@ def disable_func_sig_opts : Flag<["-"], "disable-func-sig-opts">,
def interpret : Flag<["-"], "interpret">, HelpText<"Immediate mode">, ModeOpt; def interpret : Flag<["-"], "interpret">, HelpText<"Immediate mode">, ModeOpt;
def enable_guaranteed_self : Flag<["-"], "enable-guaranteed-self">,
HelpText<"Enable the passing of self as a guaranteed parameter">;
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden] } // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

View File

@@ -865,6 +865,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization); Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization);
Opts.PrintInstCounts |= Args.hasArg(OPT_print_inst_counts); Opts.PrintInstCounts |= Args.hasArg(OPT_print_inst_counts);
Opts.EnableFuncSigOpts &= !Args.hasArg(OPT_disable_func_sig_opts); Opts.EnableFuncSigOpts &= !Args.hasArg(OPT_disable_func_sig_opts);
Opts.EnableGuaranteedSelf |= Args.hasArg(OPT_enable_guaranteed_self);
return false; return false;
} }

View File

@@ -481,7 +481,11 @@ static CanSILFunctionType getSILFunctionType(SILModule &M,
namespace { namespace {
/// The default Swift conventions. /// The default Swift conventions.
struct DefaultConventions : Conventions { struct DefaultConventions : Conventions {
DefaultConventions() : Conventions(ConventionsKind::Default) {} bool hasGuaranteedSelf;
DefaultConventions(bool guaranteedSelf)
: Conventions(ConventionsKind::Default),
hasGuaranteedSelf(guaranteedSelf) {}
ParameterConvention getIndirectParameter(unsigned index, ParameterConvention getIndirectParameter(unsigned index,
CanType type) const override { CanType type) const override {
@@ -502,6 +506,8 @@ namespace {
} }
ParameterConvention getDirectSelfParameter(CanType type) const override { ParameterConvention getDirectSelfParameter(CanType type) const override {
if (hasGuaranteedSelf)
return ParameterConvention::Direct_Guaranteed;
return ParameterConvention::Direct_Owned; return ParameterConvention::Direct_Owned;
} }
@@ -561,9 +567,11 @@ static CanSILFunctionType getNativeSILFunctionType(SILModule &M,
extInfo, DefaultBlockConventions()); extInfo, DefaultBlockConventions());
case AnyFunctionType::Representation::Thin: case AnyFunctionType::Representation::Thin:
case AnyFunctionType::Representation::Thick: case AnyFunctionType::Representation::Thick: {
bool enableGuaranteedSelf = M.getOptions().EnableGuaranteedSelf;
return getSILFunctionType(M, origType, substType, substInterfaceType, return getSILFunctionType(M, origType, substType, substInterfaceType,
extInfo, DefaultConventions()); extInfo, DefaultConventions(enableGuaranteedSelf));
}
} }
} }