Skip to content
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

SIL: Thread type expansion context through to function convention apis #31470

Merged
merged 3 commits into from May 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 33 additions & 28 deletions include/swift/AST/Types.h
Expand Up @@ -3776,8 +3776,7 @@ class SILParameterInfo {
/// Return the type of a call argument matching this parameter.
///
/// \c t must refer back to the function type this is a parameter for.
CanType getArgumentType(SILModule &M,
const SILFunctionType *t) const;
CanType getArgumentType(SILModule &M, const SILFunctionType *t, TypeExpansionContext context) const;
ParameterConvention getConvention() const {
return TypeAndConvention.getInt();
}
Expand Down Expand Up @@ -3832,8 +3831,9 @@ class SILParameterInfo {
/// storage. Therefore they will be passed using an indirect formal
/// convention, and this method will return an address type. However, in
/// canonical SIL the opaque arguments might not have an address type.
SILType getSILStorageType(SILModule &M,
const SILFunctionType *t) const; // in SILFunctionConventions.h
SILType getSILStorageType(
SILModule &M, const SILFunctionType *t,
TypeExpansionContext context) const; // in SILFunctionConventions.h
SILType getSILStorageInterfaceType() const;

/// Return a version of this parameter info with the type replaced.
Expand Down Expand Up @@ -3865,9 +3865,9 @@ class SILParameterInfo {
/// type, apply any substitutions from the function type to it to
/// get a substituted version of it, as you would get from
/// SILFunctionType::getUnsubstitutedType.
SILParameterInfo getUnsubstituted(SILModule &M,
const SILFunctionType *fnType) const {
return getWithInterfaceType(getArgumentType(M, fnType));
SILParameterInfo getUnsubstituted(SILModule &M, const SILFunctionType *fnType,
TypeExpansionContext context) const {
return getWithInterfaceType(getArgumentType(M, fnType, context));
}

void profile(llvm::FoldingSetNodeID &id) {
Expand Down Expand Up @@ -3952,9 +3952,9 @@ class SILResultInfo {
/// The type of a return value corresponding to this result.
///
/// \c t must refer back to the function type this is a parameter for.
CanType getReturnValueType(SILModule &M,
const SILFunctionType *t) const;
CanType getReturnValueType(SILModule &M, const SILFunctionType *t,
TypeExpansionContext context) const;

ResultConvention getConvention() const {
return TypeAndConvention.getInt();
}
Expand All @@ -3964,8 +3964,9 @@ class SILResultInfo {
/// storage. Therefore they will be returned using an indirect formal
/// convention, and this method will return an address type. However, in
/// canonical SIL the opaque results might not have an address type.
SILType getSILStorageType(SILModule &M,
const SILFunctionType *t) const; // in SILFunctionConventions.h
SILType getSILStorageType(
SILModule &M, const SILFunctionType *t,
TypeExpansionContext context) const; // in SILFunctionConventions.h
SILType getSILStorageInterfaceType() const;
/// Return a version of this result info with the type replaced.
SILResultInfo getWithInterfaceType(CanType type) const {
Expand Down Expand Up @@ -4006,9 +4007,9 @@ class SILResultInfo {
/// type, apply any substitutions from the function type to it to
/// get a substituted version of it, as you would get from
/// SILFunctionType::getUnsubstitutedType.
SILResultInfo getUnsubstituted(SILModule &M,
const SILFunctionType *fnType) const {
return getWithInterfaceType(getReturnValueType(M, fnType));
SILResultInfo getUnsubstituted(SILModule &M, const SILFunctionType *fnType,
TypeExpansionContext context) const {
return getWithInterfaceType(getReturnValueType(M, fnType, context));
}

void profile(llvm::FoldingSetNodeID &id) {
Expand Down Expand Up @@ -4066,18 +4067,18 @@ class SILYieldInfo : public SILParameterInfo {
->getCanonicalType());
}

CanType getYieldValueType(SILModule &M,
const SILFunctionType *fnType) const {
return getArgumentType(M, fnType);
CanType getYieldValueType(SILModule &M, const SILFunctionType *fnType,
TypeExpansionContext context) const {
return getArgumentType(M, fnType, context);
}

/// Treating this yield info as a component of the given function
/// type, apply any substitutions from the function type to it to
/// get a substituted version of it, as you would get from
/// SILFunctionType::getUnsubstitutedType.
SILYieldInfo getUnsubstituted(SILModule &M,
const SILFunctionType *fnType) const {
return getWithInterfaceType(getYieldValueType(M, fnType));
SILYieldInfo getUnsubstituted(SILModule &M, const SILFunctionType *fnType,
TypeExpansionContext context) const {
return getWithInterfaceType(getYieldValueType(M, fnType, context));
}
};

Expand Down Expand Up @@ -4528,14 +4529,15 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
/// this function depends on the current SIL stage and is known by
/// SILFunctionConventions. It may be a wider tuple that includes formally
/// indirect results.
SILType getDirectFormalResultsType(SILModule &M);
SILType getDirectFormalResultsType(SILModule &M,
TypeExpansionContext expansion);

/// Get a single non-address SILType for all SIL results regardless of whether
/// they are formally indirect. The actual SIL result type of an apply
/// instruction that calls this function depends on the current SIL stage and
/// is known by SILFunctionConventions. It may be a narrower tuple that omits
/// formally indirect results.
SILType getAllResultsSubstType(SILModule &M);
SILType getAllResultsSubstType(SILModule &M, TypeExpansionContext expansion);
SILType getAllResultsInterfaceType();

/// Does this function have a blessed Swift-native error result?
Expand Down Expand Up @@ -4678,12 +4680,13 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
return getInvocationGenericSignature() && !getInvocationSubstitutions();
}

CanType getSelfInstanceType(SILModule &M) const;
CanType getSelfInstanceType(SILModule &M, TypeExpansionContext context) const;

/// If this is a @convention(witness_method) function with a class
/// constrained self parameter, return the class constraint for the
/// Self type.
ClassDecl *getWitnessMethodClass(SILModule &M) const;
ClassDecl *getWitnessMethodClass(SILModule &M,
TypeExpansionContext context) const;

/// If this is a @convention(witness_method) function, return the conformance
/// for which the method is a witness. If it isn't that convention, return
Expand Down Expand Up @@ -4875,8 +4878,9 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
return getExtInfo().getDifferentiabilityKind();
}

bool isNoReturnFunction(SILModule &M) const; // Defined in SILType.cpp

bool isNoReturnFunction(SILModule &M, TypeExpansionContext context)
const; // Defined in SILType.cpp

/// Create a SILFunctionType with the same structure as this one,
/// but with a different (or new) set of invocation substitutions.
/// The substitutions must have the same generic signature as this.
Expand Down Expand Up @@ -4956,7 +4960,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
TypeExpansionContext context);

SILType substInterfaceType(SILModule &M,
SILType interfaceType) const;
SILType interfaceType,
TypeExpansionContext context) const;

/// Return the unsubstituted function type equivalent to this type; that is, the type that has the same
/// argument and result types as `this` type after substitutions, if any.
Expand Down
6 changes: 5 additions & 1 deletion include/swift/SIL/ApplySite.h
Expand Up @@ -23,6 +23,7 @@

#include "swift/SIL/SILBasicBlock.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/SILFunction.h"

namespace swift {

Expand Down Expand Up @@ -180,7 +181,10 @@ class ApplySite {
}

/// Return the type.
SILType getType() const { return getSubstCalleeConv().getSILResultType(); }
SILType getType() const {
return getSubstCalleeConv().getSILResultType(
getFunction()->getTypeExpansionContext());
}

/// Get the type of the callee without the applied substitutions.
CanSILFunctionType getOrigCalleeType() const {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SIL/SILFunction.h
Expand Up @@ -416,7 +416,7 @@ class SILFunction

void setEntryCount(ProfileCounter Count) { EntryCount = Count; }

bool isNoReturnFunction() const;
bool isNoReturnFunction(TypeExpansionContext context) const;

/// Unsafely rewrite the lowered type of this function.
///
Expand Down