Skip to content

Fixes for __attribute__((ns_consumed)) block parameters #28527

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 2 commits into from
Dec 3, 2019

Conversation

slavapestov
Copy link
Contributor

Fixes rdar://problem/48792177.

@slavapestov
Copy link
Contributor Author

Ugh...

/Users/buildnode/jenkins/workspace/swift-PR-osx-smoke-test/branch-master/swiftpm/Sources/SPMLLBuild/llbuild.swift:13:19: error: compiled module was created by a newer version of the compiler: /Users/buildnode/jenkins/workspace/swift-PR-osx-smoke-test/branch-master/buildbot_incremental/llbuild-macosx-x86_64/products/llbuildSwift/llbuildSwift.swiftmodule
19:11:15 @_exported import llbuildSwift
19:11:15                   ^

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please clean smoke test

@slavapestov slavapestov requested a review from rjmccall December 3, 2019 01:00
@slavapestov slavapestov merged commit 1383a63 into swiftlang:master Dec 3, 2019
@@ -594,7 +597,9 @@ clang::CanQualType GenClangType::visitSILFunctionType(CanSILFunctionType type) {
break;

case ParameterConvention::Direct_Owned:
llvm_unreachable("block takes owned parameter");
extParamInfo = extParamInfo.withIsConsumed(true);
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

@varungandhi-apple You'll need to make an analogous change.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Comment for my own reference): #27479 needs to have an analogous change in ClangTypeConverter.cpp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, we don't need to make any changes since visitSILFunctionType in ClangTypeConverter is unreachable -- it should receive only AST types.

Copy link
Contributor

Choose a reason for hiding this comment

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

owned can appear in AST function parameters as well; it's in the ParameterTypeFlags.

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

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

LGTM

"# define SWIFT_RELEASES_ARGUMENT __attribute__((ns_consumed))\n"
"#else\n"
"# define SWIFT_RELEASES_ARGUMENT\n"
"#endif\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

I take it it's general policy to use Swift-specific macros here (which we can just add whenever we need them) rather than the NS ones?

clang::FunctionProtoType::ExtProtoInfo defaultEPI;
auto fnTy = clangCtx.getFunctionType(resultType, paramTypes, defaultEPI);
clang::FunctionProtoType::ExtProtoInfo extProtoInfo;
extProtoInfo.ExtParameterInfos = extParamInfos.begin();
Copy link
Contributor

@varungandhi-apple varungandhi-apple Dec 6, 2019

Choose a reason for hiding this comment

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

@slavapestov -- is SmallVector guaranteed to have contiguous storage in the resizing case? (If not, then this wouldn't work because there's no way to recover the split storage since ExtParameterInfos is a pointer). And is clangCtx.getFunctionType guaranteed to create a copy of this array? Otherwise, there's a lifetime problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes to both of these.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if these points are documented anywhere? I looked at the Doxygen and I couldn't find this. Also, is there some general guidelines at play here (e.g. "getFooType" always deep-copies everything in Clang) or is this a "yes, I know these particular points are true"?

Copy link
Contributor

Choose a reason for hiding this comment

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

All AST nodes are supposed to be self-contained in both Clang and Swift (except inasmuch as they reference other AST nodes, which should themselves be self-contained). Creating an AST node should always be deep-copying any necessary arrays into trailing storage or some other associated storage.

There might be exceptions for TypeVariableTypes in Swift, they're a weird case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants