Add NestedSemanticFunctionCheck diagnostic

to check for improperly nested '@_semantic' functions.

Add a missing @_semantics("array.init") in ArraySlice found by the
diagnostic.

Distinguish between array.init and array.init.empty.

Categorize the types of semantic functions by how they affect the
inliner and pass pipeline, and centralize this logic in
PerformanceInlinerUtils. The ultimate goal is to prevent inlining of
"Fundamental" @_semantics calls and @_effects calls until the late
pipeline where we can safely discard semantics. However, that requires
significant pipeline changes.

In the meantime, this change prevents the situation from getting worse
and makes the intention clear. However, it has no significant effect
on the pass pipeline and inliner.
This commit is contained in:
Andrew Trick
2020-10-20 22:14:27 -07:00
parent 0991d8db2e
commit 3128eae3f0
17 changed files with 323 additions and 79 deletions

View File

@@ -30,7 +30,8 @@ ArrayCallKind swift::getArraySemanticsKind(SILFunction *f) {
llvm::StringSwitch<ArrayCallKind>(Attrs)
.Case("array.props.isNativeTypeChecked",
ArrayCallKind::kArrayPropsIsNativeTypeChecked)
.StartsWith("array.init", ArrayCallKind::kArrayInit)
.Case("array.init", ArrayCallKind::kArrayInit)
.Case("array.init.empty", ArrayCallKind::kArrayInitEmpty)
.Case("array.uninitialized", ArrayCallKind::kArrayUninitialized)
.Case("array.uninitialized_intrinsic", ArrayCallKind::kArrayUninitializedIntrinsic)
.Case("array.finalize_intrinsic", ArrayCallKind::kArrayFinalizeIntrinsic)
@@ -682,8 +683,10 @@ static SILValue getArrayUninitializedInitResult(ArraySemanticsCall arrayCall,
SILValue swift::ArraySemanticsCall::getArrayValue() const {
ArrayCallKind arrayCallKind = getKind();
if (arrayCallKind == ArrayCallKind::kArrayInit)
if (arrayCallKind == ArrayCallKind::kArrayInit
|| arrayCallKind == ArrayCallKind::kArrayInitEmpty) {
return SILValue(SemanticsCall);
}
return getArrayUninitializedInitResult(*this, 0);
}