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

[SR-2250] Include Foundation framework instead of minimal NSObject.h #17615

Merged
merged 4 commits into from Jul 12, 2018
Merged

[SR-2250] Include Foundation framework instead of minimal NSObject.h #17615

merged 4 commits into from Jul 12, 2018

Conversation

maniramezan
Copy link
Contributor

@maniramezan maniramezan commented Jun 28, 2018

This change is for preventing scenarios like https://bugs.swift.org/projects/SR/issues/SR-2250

As suggested by Jordan, adding Foundation framework as a default instead of NSObject.h to prevent situations when only bridge types are used and Foundation never imports and causes an error on generated -Swift.h file.

Resolves SR-2250

@maniramezan maniramezan changed the title Include Foundation framework instead of minimal NSObject.h [SR-2250] Include Foundation framework instead of minimal NSObject.h Jul 2, 2018
Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, Mani!

@@ -0,0 +1 @@
#include <objc/NSObject.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, it's kind of weird to be putting this in PrintAsObjC/Inputs/ if tests from other folders are going to be using it too. Maybe it'd be better to put it in the normal "mock SDK" (test/Inputs/clang-importer-sdk/Frameworks/ or something) and have it include <Foundation.h> there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for reviewing it. Yeah that makes sense, it felt weird to me also to point to this file from other tests. I'll move the file and and have it include <Foundation.h> instead.

@maniramezan
Copy link
Contributor Author

Thank you for your time to help me through it.

There are currently three tests failing that I can't figure out why or how to get the root cause of it:

useBaseClass() // expected-error{{missing argument for parameter #1}}
              ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<unknown>:0: error: unexpected error produced: could not build Objective-C module '_SwiftCoreFoundationOverlayShims'
<unknown>:0: error: fatal error encountered while in -verify mode
  • Empty.swift Both compiling with -std=c++98 or -std=c++14 fails with following error:
In file included from /swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64/test-macosx-x86_64/PrintAsObjC/Output/empty.swift.tmp/empty.h:23:
In file included from /swift-source/swift/test/Inputs/clang-importer-sdk/frameworks/Foundation.framework/Headers/Foundation.h:1:
In file included from /swift-source/swift/test/Inputs/clang-importer-sdk/usr/include/Foundation.h:7:
/swift-source/swift/test/Inputs/clang-importer-sdk/usr/include/CoreFoundation.h:6:22: error: default initialization of an object of const type 'const CFAllocatorRef' (aka 'const __CFAllocator *const')
const CFAllocatorRef kCFAllocatorDefault;

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Thanks for continuing to work on this! Good catch removing the explicit -include Foundation.h too.

test/lit.cfg Outdated
@@ -384,6 +384,9 @@ config.substitutions.append(('%build-clang-importer-objc-overlays',
config.substitutions.append(('%clang-importer-sdk-path',
'%r' % (make_path(config.test_source_root, 'Inputs', 'clang-importer-sdk'))))

config.substitutions.append(('%clang-importer-sdk-frameworks',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think since this is always relative to %clang-importer-sdk-path, it's fine not to have a separate substitution for it. Substitutions are additional complexity if we're not actually making use of the flexibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aw, didn't know about the complexity of it. The reason added it was that it seems in the swift files, path to clang-importer-sdk is always hardcoded, like %S/../../Inputs/clang-importer-sdk/..., wanted to prevent that. But sounds good. Seems in the lit.cfg I can use clang-importer-sdk-path, but in the files, have to give it a relative path. I'll update the code with these changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect %clang-importer-sdk-path/frameworks to work in the individual files. What behavior are you seeing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I also expected. It works fine with lit.local.cfg as '-F %%clang-importer-sdk-path/frameworks ' but for using it in lit use cases like here, -F %clang-importer-sdk-path/frameworks is turnt into -F 'path-to-swift-repo/test/Inputs/clang-importer-sdk/' /frameworks

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. I would expect it to be -F 'path-to-swift-repo/test/Inputs/clang-importer-sdk/'/frameworks (no space), which should still work. Are you sure you didn't have a typo? We have other examples of this kind of thing working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, seems I was using different substitution that was causing that behavior. Thanks for the example, I went ahead and update the classes to use this pattern

@jrose-apple
Copy link
Contributor

We didn't really design the fake Foundation to work with C++, but I guess we need to now. For Empty.swift, adding extern at the start of the kCFAllocatorDefault declaration should be sufficient. For resolve-cross-language.swift, I suspect we're in a weird place where the dummy CoreFoundation isn't compatible with the real CoreFoundation overlay. We should be using %clang-importer-sdk instead of %clang-importer-sdk-nosource in that test, by consistency with other files in the directory.

@jrose-apple
Copy link
Contributor

Okay, let's try it!

@swift-ci Please test

@jrose-apple
Copy link
Contributor

@swift-ci Please test source compatibility

@swift-ci
Copy link
Collaborator

Build failed
Swift Test Linux Platform
Git Sha - 9df5adb

@swift-ci
Copy link
Collaborator

Build failed
Swift Test OS X Platform
Git Sha - 9df5adb

@jrose-apple jrose-apple self-assigned this Jul 12, 2018
@jrose-apple jrose-apple merged commit c8b61f9 into apple:master Jul 12, 2018
@jrose-apple
Copy link
Contributor

And, merged! Thank you, Mani!

@maniramezan
Copy link
Contributor Author

Amazing, very excited : ) Thanks for your help during this and look forward to bug you more on other tickets

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.

None yet

3 participants