Skip to content

[runtime] move the empty Dictionary and Set singletons to rodata #5850

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 1 commit into from
Nov 19, 2016

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented Nov 18, 2016

Basically just a mirror of what Array does.

Resolves rdar://18220063

@Gankra
Copy link
Contributor Author

Gankra commented Nov 18, 2016

@swift-ci please test

@@ -41,6 +49,62 @@ swift::_SwiftEmptyArrayStorage swift::_swiftEmptyArrayStorage = {
}
};



swift::_SwiftEmptyDictionaryStorage swift::_swiftEmptyDictionaryStorage = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you mark this const and constexpr so that we guarantee it ends up in rodata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Want me to do that to the existing Array decl too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Argh:

/ContiguousArrayBuffer.swift:59:23: error: cannot pass immutable value as inout argument: '_swiftEmptyArrayStorage' is a 'let' constant
    Builtin.addressof(&_swiftEmptyArrayStorage))
                      ^~~~~~~~~~~~~~~~~~~~~~~~

Any bright ideas, or are we forced to give up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also: (void*)1 is illegal in a constexpr. I gave up and just made it nullptr with the understanding that there's no conceivable way a null non-nullable pointer that is never looked at could matter.

@@ -2473,6 +2473,11 @@ collections = [
/// keys, followed by the values.
//
// See the docs at the top of the file for more details on this type
//
// NOTE: The precise layout of this type is relied on in the runtime
// to provide a statically allocated empty singleton.
Copy link
Contributor

@jrose-apple jrose-apple Nov 18, 2016

Choose a reason for hiding this comment

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

This is pretty awful and we should stop doing it [later]. Maybe we can make some rule about classes containing exactly one member, which could then be defined as a C struct in SwiftShims.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These classes don't contain exactly one member; I'm not sure what you're picturing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. You're picturing defining it only once in Stubs, and then importing it into Swift?

Should work... what special rule is needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

You'd need some rule that promises that the layout algorithm is what you expect, i.e. that the single member immediately follows the retain count header (modulo any alignment requirements), even given the empty superclass. I can't see what layout algorithm wouldn't do this, but then again @slavapestov recently discovered that our ObjC layout wasted 8 bytes for no particular reason on certain classes, so...

Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely plan for the compiler to be allowed to reorder class and struct members, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok wait does putting this stuff in rodata even make sense? The reference count has to be mutable, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, and even then it couldn't be in true const memory anyway because it contains absolute addresses that would need to be relocated at load time (until libswiftCore lives in the dyld shared cache, at least).

Copy link
Contributor

Choose a reason for hiding this comment

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

I still think it'd be nice to put the Swift compiler in charge of emitting these objects instead of C++ code. Doesn't seem like it'd be terribly difficult to wire up, if you want to take a shot at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the interest of incremental improvement, are you fine with moving forward with this PR as-is for now? The Dictionary/Array layouts at this level in the system are basically finalized, so the only thing that could break these are someone implementing a new class layout algorithm.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, I have no problem taking this patch in its current state.

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - cf6767a0225108c28c0ff194e14db892bb31e5dc
Test requested by - @gankro

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - cf6767a0225108c28c0ff194e14db892bb31e5dc
Test requested by - @gankro

@Gankra
Copy link
Contributor Author

Gankra commented Nov 18, 2016

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - cf6767a0225108c28c0ff194e14db892bb31e5dc
Test requested by - @gankro

@Gankra
Copy link
Contributor Author

Gankra commented Nov 18, 2016

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - cf6767a0225108c28c0ff194e14db892bb31e5dc
Test requested by - @gankro

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - cf6767a0225108c28c0ff194e14db892bb31e5dc
Test requested by - @gankro

@Gankra
Copy link
Contributor Author

Gankra commented Nov 18, 2016

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 21405f1
Test requested by - @gankro

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 21405f1
Test requested by - @gankro

@Gankra
Copy link
Contributor Author

Gankra commented Nov 18, 2016

Ah good, master is just broken. 🙃

@jrose-apple
Copy link
Contributor

Bruno reverted the offending commit.

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 21405f1
Test requested by - @jrose-apple

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 21405f1
Test requested by - @jrose-apple

@Gankra
Copy link
Contributor Author

Gankra commented Nov 18, 2016

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 21405f1
Test requested by - @gankro

@Gankra
Copy link
Contributor Author

Gankra commented Nov 19, 2016

@swift-ci please smoke test Linux Platform

@Gankra
Copy link
Contributor Author

Gankra commented Nov 19, 2016

The Linux Test that's failing seems to be REPL tests looking for xcrun? I sincerely hope this PR isn't causing that...

@Gankra Gankra merged commit 2865657 into swiftlang:master Nov 19, 2016
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.

5 participants