Skip to content

[pull] swiftwasm from main #3813

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
merged 18 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bc09cc9
[SILGen] Handled foreign funcs with async, error, and more.
nate-chandler Oct 28, 2021
e400a96
GSB: Loosen up verifyGenericSignature()
slavapestov Oct 29, 2021
153654c
GSB: Perform conditional requirement inference in AbstractGenericSign…
slavapestov Oct 29, 2021
22609ac
Merge pull request #39957 from nate-chandler/rdar80704984_2
nate-chandler Oct 29, 2021
f9122a7
[moveOnly] Implement a new _copy function that performs an explicit c…
gottesmm Oct 29, 2021
3a5049f
[stdlib] Mark _move as public.
gottesmm Oct 29, 2021
89e0f45
[Result Builders] Correct type witness substitution when computing in…
hborla Oct 29, 2021
06fbca6
Merge pull request #39983 from slavapestov/gsb-conditional-inference
slavapestov Oct 30, 2021
17def18
[Result Builders] When inferring result builder attributes on value w…
hborla Oct 30, 2021
3ea9e9e
Merge pull request #39984 from gottesmm/pr-135d6a4f34ad56ff7b7f978fdb…
gottesmm Oct 30, 2021
f38f25a
AST: Factor out AbstractGenericSignatureRequest into a new buildGener…
slavapestov Oct 30, 2021
ee5a3fe
AST: AbstractGenericSignatureRequest and InferredGenericSignatureRequ…
slavapestov Oct 30, 2021
25ac1f5
AST: Refactor verifyGenericSignature() to use AbstractGenericSignatur…
slavapestov Oct 30, 2021
0eb6622
AST: Move expensive generic signature checks to GenericSignature.cpp
slavapestov Oct 30, 2021
0d167a4
AST: Move GenericSignatureBuilder.h from include/swift/AST/ to lib/AST/
slavapestov Oct 30, 2021
c31a590
Merge pull request #39988 from hborla/result-builder-attr-substitution
hborla Oct 30, 2021
0251957
[SE-0320] Added protocol CodingKeyRepresentable (#34458)
mortenbekditlevsen Oct 30, 2021
78de7d1
Merge pull request #39990 from slavapestov/completely-encapsulate-gsb
slavapestov Oct 30, 2021
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
30 changes: 30 additions & 0 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5205,6 +5205,36 @@ independent of the operand. In terms of specific types:
In ownership qualified functions, a ``copy_value`` produces a +1 value that must
be consumed at most once along any path through the program.

explicit_copy_value
```````````````````

::

sil-instruction ::= 'explicit_copy_value' sil-operand

%1 = explicit_copy_value %0 : $A

Performs a copy of a loadable value as if by the value's type lowering and
returns the copy. The returned copy semantically is a value that is completely
independent of the operand. In terms of specific types:

1. For trivial types, this is equivalent to just propagating through the trivial
value.
2. For reference types, this is equivalent to performing a ``strong_retain``
operation and returning the reference.
3. For ``@unowned`` types, this is equivalent to performing an
``unowned_retain`` and returning the operand.
4. For aggregate types, this is equivalent to recursively performing a
``copy_value`` on its components, forming a new aggregate from the copied
components, and then returning the new aggregate.

In ownership qualified functions, a ``explicit_copy_value`` produces a +1 value
that must be consumed at most once along any path through the program.

When move only variable checking is performed, ``explicit_copy_value`` is
treated as an explicit copy asked for by the user that should not be rewritten
and should be treated as a non-consuming use.

move_value
``````````

Expand Down
18 changes: 18 additions & 0 deletions include/swift/AST/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,24 @@ BUILTIN_MISC_OPERATION(DestroyTaskGroup,
/// the SILVerifier.
BUILTIN_MISC_OPERATION(Move, "move", "", Special)

/// A builtin that can only be called from a transparent generic function. Takes
/// two operands, the first operand the result address, the second operand the
/// input address. Transforms into
///
/// %input = load [take] %inputAddr
/// %result = explicit_copy_value %input
/// store %result to [init] %resultAddr
/// store %input to [init] %inputAddr
///
/// transparently inlined into a caller that has the generic of the callee
/// specialized into a loadable type. If the transparent inlining does not
/// specialize the type (due to being inlined into a non-generic context, the
/// SILVerifier will abort).
///
/// Illegal to call except for in Swift._copy in the stdlib. This is enforced by
/// the SILVerifier.
BUILTIN_MISC_OPERATION(Copy, "copy", "", Special)

// BUILTIN_MISC_OPERATION_WITH_SILGEN - Miscellaneous operations that are
// specially emitted during SIL generation.
//
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ NOTE(capturepromotion_variable_defined_here,none,
ERROR(move_operator_used_on_generic_or_existential_value, none,
"move() used on a generic or existential value", ())

// copy operator used on generic or evalue
ERROR(copy_operator_used_on_generic_or_existential_value, none,
"copy() used on a generic or existential value", ())

// noimplicitcopy on generic or existential binding
ERROR(noimplicitcopy_used_on_generic_or_existential, none,
"@_noImplicitCopy can not be used on a generic or existential typed "
Expand Down
29 changes: 28 additions & 1 deletion include/swift/AST/GenericSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ class GenericSignature {

public:
/// Create a new generic signature with the given type parameters and
/// requirements.
/// requirements. The requirements must already be minimal and canonical;
/// to build a signature from an arbitrary set of requirements, use
/// swift::buildGenericSignature() instead.
static GenericSignature get(ArrayRef<GenericTypeParamType *> params,
ArrayRef<Requirement> requirements,
bool isKnownCanonical = false);
Expand Down Expand Up @@ -494,6 +496,31 @@ int compareAssociatedTypes(AssociatedTypeDecl *assocType1,

int compareDependentTypes(Type type1, Type type2);

/// Verify the correctness of the given generic signature.
///
/// This routine will test that the given generic signature is both minimal
/// and canonical, emitting errors if it is not.
void validateGenericSignature(ASTContext &context,
GenericSignature sig);

/// Verify all of the generic signatures in the given module.
void validateGenericSignaturesInModule(ModuleDecl *module);

/// Build a generic signature from the given requirements, which are not
/// required to be minimal or canonical, and may contain unresolved
/// DependentMemberTypes.
///
/// If \p baseSignature is non-null, the new parameters and requirements
/// are added on; existing requirements of the base signature might become
/// redundant.
///
/// If \p baseSignature is null, build a new signature from scratch.
GenericSignature buildGenericSignature(
ASTContext &ctx,
GenericSignature baseSignature,
SmallVector<GenericTypeParamType *, 2> addedParameters,
SmallVector<Requirement, 2> addedRequirements);

} // end namespace swift

namespace llvm {
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/SemanticAttrs.def
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ SEMANTICS_ATTR(FORCE_EMIT_OPT_REMARK_PREFIX, "optremark")
SEMANTICS_ATTR(OBJC_FORBID_ASSOCIATED_OBJECTS, "objc.forbidAssociatedObjects")

SEMANTICS_ATTR(LIFETIMEMANAGEMENT_MOVE, "lifetimemanagement.move")
SEMANTICS_ATTR(LIFETIMEMANAGEMENT_COPY, "lifetimemanagement.copy")

SEMANTICS_ATTR(NO_PERFORMANCE_ANALYSIS, "no_performance_analysis")

Expand Down
30 changes: 18 additions & 12 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -1411,11 +1411,17 @@ class ClassAncestryFlagsRequest :

void simple_display(llvm::raw_ostream &out, AncestryFlags value);

/// AbstractGenericSignatureRequest and InferredGenericSignatureRequest
/// return this type, which stores a GenericSignature together with a bit
/// indicating if there were any errors detected in the original
/// requirements.
using GenericSignatureWithError = llvm::PointerIntPair<GenericSignature, 1>;

class AbstractGenericSignatureRequest :
public SimpleRequest<AbstractGenericSignatureRequest,
GenericSignature (const GenericSignatureImpl *,
SmallVector<GenericTypeParamType *, 2>,
SmallVector<Requirement, 2>),
GenericSignatureWithError (const GenericSignatureImpl *,
SmallVector<GenericTypeParamType *, 2>,
SmallVector<Requirement, 2>),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;
Expand All @@ -1424,7 +1430,7 @@ class AbstractGenericSignatureRequest :
friend SimpleRequest;

// Evaluation.
GenericSignature
GenericSignatureWithError
evaluate(Evaluator &evaluator,
const GenericSignatureImpl *baseSignature,
SmallVector<GenericTypeParamType *, 2> addedParameters,
Expand All @@ -1442,13 +1448,13 @@ class AbstractGenericSignatureRequest :

class InferredGenericSignatureRequest :
public SimpleRequest<InferredGenericSignatureRequest,
GenericSignature (ModuleDecl *,
const GenericSignatureImpl *,
GenericParamList *,
WhereClauseOwner,
SmallVector<Requirement, 2>,
SmallVector<TypeLoc, 2>,
bool),
GenericSignatureWithError (ModuleDecl *,
const GenericSignatureImpl *,
GenericParamList *,
WhereClauseOwner,
SmallVector<Requirement, 2>,
SmallVector<TypeLoc, 2>,
bool),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;
Expand All @@ -1457,7 +1463,7 @@ class InferredGenericSignatureRequest :
friend SimpleRequest;

// Evaluation.
GenericSignature
GenericSignatureWithError
evaluate(Evaluator &evaluator,
ModuleDecl *parentModule,
const GenericSignatureImpl *baseSignature,
Expand Down
18 changes: 9 additions & 9 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
//===----------------------------------------------------------------------===//

SWIFT_REQUEST(TypeChecker, AbstractGenericSignatureRequest,
GenericSignature (const GenericSignatureImpl *,
SmallVector<GenericTypeParamType *, 2>,
SmallVector<Requirement, 2>),
GenericSignatureWithError (const GenericSignatureImpl *,
SmallVector<GenericTypeParamType *, 2>,
SmallVector<Requirement, 2>),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ApplyAccessNoteRequest,
evaluator::SideEffect(ValueDecl *), Cached, NoLocationInfo)
Expand Down Expand Up @@ -131,12 +131,12 @@ SWIFT_REQUEST(TypeChecker, HasImplementationOnlyImportsRequest,
SWIFT_REQUEST(TypeChecker, ModuleLibraryLevelRequest,
LibraryLevel(ModuleDecl *), Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, InferredGenericSignatureRequest,
GenericSignature (ModuleDecl *,
const GenericSignatureImpl *,
GenericParamList *,
WhereClauseOwner,
SmallVector<Requirement, 2>,
SmallVector<TypeLoc, 2>, bool),
GenericSignatureWithError (ModuleDecl *,
const GenericSignatureImpl *,
GenericParamList *,
WhereClauseOwner,
SmallVector<Requirement, 2>,
SmallVector<TypeLoc, 2>, bool),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, DistributedModuleIsAvailableRequest,
bool(ModuleDecl *), Cached, NoLocationInfo)
Expand Down
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ LANGUAGE_FEATURE(BuiltinBuildExecutor, 0, "Executor-building builtins", true)
LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building builtin", true)
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "MainActor executor building builtin", true)
LANGUAGE_FEATURE(BuiltinMove, 0, "Builtin.move()", true)
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()", true)

#undef LANGUAGE_FEATURE
9 changes: 9 additions & 0 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,15 @@ class SILBuilder {
CopyValueInst(getSILDebugLocation(Loc), operand));
}

ExplicitCopyValueInst *createExplicitCopyValue(SILLocation Loc,
SILValue operand) {
assert(!operand->getType().isTrivial(getFunction()) &&
"Should not be passing trivial values to this api. Use instead "
"emitCopyValueOperation");
return insert(new (getModule())
ExplicitCopyValueInst(getSILDebugLocation(Loc), operand));
}

DestroyValueInst *createDestroyValue(SILLocation Loc, SILValue operand,
bool poisonRefs = false) {
assert(isLoadableOrOpaque(operand->getType()));
Expand Down
15 changes: 15 additions & 0 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,21 @@ void SILCloner<ImplClass>::visitCopyValueInst(CopyValueInst *Inst) {
getOpValue(Inst->getOperand())));
}

template <typename ImplClass>
void SILCloner<ImplClass>::visitExplicitCopyValueInst(
ExplicitCopyValueInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
if (!getBuilder().hasOwnership()) {
SILValue newValue = getBuilder().emitCopyValueOperation(
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()));
return recordFoldedValue(Inst, newValue);
}

recordClonedInstruction(
Inst, getBuilder().createExplicitCopyValue(
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand())));
}

template <typename ImplClass>
void SILCloner<ImplClass>::visitMoveValueInst(MoveValueInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
Expand Down
9 changes: 9 additions & 0 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7267,6 +7267,15 @@ class CopyValueInst
: UnaryInstructionBase(DebugLoc, operand, operand->getType()) {}
};

class ExplicitCopyValueInst
: public UnaryInstructionBase<SILInstructionKind::ExplicitCopyValueInst,
SingleValueInstruction> {
friend class SILBuilder;

ExplicitCopyValueInst(SILDebugLocation DebugLoc, SILValue operand)
: UnaryInstructionBase(DebugLoc, operand, operand->getType()) {}
};

#define UNCHECKED_REF_STORAGE(Name, ...) \
class StrongCopy##Name##ValueInst \
: public UnaryInstructionBase< \
Expand Down
4 changes: 4 additions & 0 deletions include/swift/SIL/SILNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
// A copy_value's retain semantics are fully encapsulated in OSSA
// invariants. It has no side effects relative to other OSSA values.
BRIDGED_SINGLE_VALUE_INST(CopyValueInst, copy_value,
SingleValueInstruction, None, DoesNotRelease)
// A copy_value instruction that was explicitly asked for by the user. Left
// alone by OSSA optimizations.
SINGLE_VALUE_INST(ExplicitCopyValueInst, explicit_copy_value,
SingleValueInstruction, None, DoesNotRelease)
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
SINGLE_VALUE_INST(StrongCopy##Name##ValueInst, strong_copy_##name##_value, \
Expand Down
30 changes: 12 additions & 18 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "swift/AST/ASTContext.h"
#include "ClangTypeConverter.h"
#include "ForeignRepresentationInfo.h"
#include "GenericSignatureBuilder.h"
#include "SubstitutionMapStorage.h"
#include "swift/AST/ClangModuleLoader.h"
#include "swift/AST/ConcreteDeclRef.h"
Expand All @@ -28,7 +29,6 @@
#include "swift/AST/ForeignErrorConvention.h"
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/GenericSignature.h"
#include "swift/AST/GenericSignatureBuilder.h"
#include "swift/AST/ImportCache.h"
#include "swift/AST/IndexSubset.h"
#include "swift/AST/KnownProtocols.h"
Expand Down Expand Up @@ -4253,13 +4253,11 @@ OpaqueTypeArchetypeType::get(OpaqueTypeDecl *Decl, unsigned ordinal,
}
# endif
#endif
auto signature = evaluateOrDefault(
ctx.evaluator,
AbstractGenericSignatureRequest{
Decl->getOpaqueInterfaceGenericSignature().getPointer(),
auto signature = buildGenericSignature(
ctx,
Decl->getOpaqueInterfaceGenericSignature(),
/*genericParams=*/{ },
std::move(newRequirements)},
nullptr);
std::move(newRequirements));

auto reqs = signature->getLocalRequirements(opaqueParamType);
auto superclass = reqs.superclass;
Expand Down Expand Up @@ -5024,10 +5022,10 @@ CanGenericSignature ASTContext::getOpenedArchetypeSignature(Type type) {
auto genericParam = GenericTypeParamType::get(0, 0, *this);
Requirement requirement(RequirementKind::Conformance, genericParam,
existential);
auto genericSig = evaluateOrDefault(
evaluator,
AbstractGenericSignatureRequest{nullptr, {genericParam}, {requirement}},
GenericSignature());
auto genericSig = buildGenericSignature(*this,
GenericSignature(),
{genericParam},
{requirement});

CanGenericSignature canGenericSig(genericSig);

Expand Down Expand Up @@ -5125,13 +5123,9 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
}
}

auto genericSig = evaluateOrDefault(
evaluator,
AbstractGenericSignatureRequest{
derivedClassSig.getPointer(),
std::move(addedGenericParams),
std::move(addedRequirements)},
GenericSignature());
auto genericSig = buildGenericSignature(*this, derivedClassSig,
std::move(addedGenericParams),
std::move(addedRequirements));
getImpl().overrideSigCache.insert(std::make_pair(key, genericSig));
return genericSig;
}
Expand Down
8 changes: 2 additions & 6 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,8 @@ CanGenericSignature ASTBuilder::demangleGenericSignature(

decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint,
ASTBuilder>(node, requirements, *this);
return evaluateOrDefault(Ctx.evaluator,
AbstractGenericSignatureRequest{
nominalDecl->getGenericSignature().getPointer(),
{},
std::move(requirements)},
GenericSignature())
return buildGenericSignature(Ctx, nominalDecl->getGenericSignature(),
{}, std::move(requirements))
.getCanonicalSignature();
}

Expand Down
2 changes: 2 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,8 @@ static bool usesFeatureBuiltinMove(Decl *decl) {
return false;
}

static bool usesFeatureBuiltinCopy(Decl *decl) { return false; }

static bool usesFeatureInheritActorContext(Decl *decl) {
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
for (auto param : *func->getParameters()) {
Expand Down
9 changes: 3 additions & 6 deletions lib/AST/AutoDiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,9 @@ GenericSignature autodiff::getConstrainedDerivativeGenericSignature(
requirements.push_back(req);
}
}
return evaluateOrDefault(
ctx.evaluator,
AbstractGenericSignatureRequest{derivativeGenSig.getPointer(),
/*addedGenericParams*/ {},
std::move(requirements)},
nullptr);
return buildGenericSignature(ctx, derivativeGenSig,
/*addedGenericParams*/ {},
std::move(requirements));
}

// Given the rest of a `Builtin.applyDerivative_{jvp|vjp}` or
Expand Down
Loading